Reduce boilerplate in compare sections
This commit is contained in:
parent
e9ff7f7dcc
commit
7545d7768f
1 changed files with 21 additions and 29 deletions
|
|
@ -143,7 +143,7 @@ where
|
||||||
[map(a), map(b), map(c), map(d)]
|
[map(a), map(b), map(c), map(d)]
|
||||||
}
|
}
|
||||||
|
|
||||||
let mk_section = |section: Section| {
|
let mk_section_header = |section: Section| {
|
||||||
let status = state.collapsed[section];
|
let status = state.collapsed[section];
|
||||||
text_row(
|
text_row(
|
||||||
TEXT_EMPH2,
|
TEXT_EMPH2,
|
||||||
|
|
@ -348,45 +348,37 @@ where
|
||||||
compare
|
compare
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mk_accounts<'a>(
|
|
||||||
archive: &BTreeMap<ReportDate, Report>,
|
|
||||||
side: Option<&'a dyn Spendings>,
|
|
||||||
) -> Option<impl Iterator<Item = (&'a str, f64)>> {
|
|
||||||
let side = side?;
|
|
||||||
let (main_account, _) = side.main_account(archive);
|
|
||||||
|
|
||||||
Some(std::iter::once(("Main", main_account)).chain(side.savings()))
|
|
||||||
}
|
|
||||||
|
|
||||||
let mk_total = |side: Option<&dyn Spendings>| {
|
let mk_total = |side: Option<&dyn Spendings>| {
|
||||||
let side = side?;
|
let side = side?;
|
||||||
|
|
||||||
Some(("Total", side.total_spendings()))
|
Some(("Total", side.total_spendings()))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
macro_rules! mk_section {
|
||||||
|
{$section:expr, $map:expr} => {
|
||||||
|
itertools::chain![
|
||||||
|
iter::once(mk_section_header($section)),
|
||||||
|
item_compare(
|
||||||
|
state.collapsed[$section],
|
||||||
|
left.map($map),
|
||||||
|
right.map($map)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
scrollable(table::<_, _, iced::Element<_>, _>(
|
scrollable(table::<_, _, iced::Element<_>, _>(
|
||||||
properties,
|
properties,
|
||||||
itertools::chain![
|
itertools::chain![
|
||||||
iter::once(headings),
|
iter::once(headings),
|
||||||
iter::once(mk_section(Section::Recurring)),
|
mk_section!(Section::Recurring, |r| r.recurring()),
|
||||||
item_compare(
|
mk_section!(Section::Variable, |r| r.variable()),
|
||||||
state.collapsed[Section::Recurring],
|
|
||||||
left.map(|r| r.recurring()),
|
|
||||||
right.map(|r| r.recurring())
|
|
||||||
),
|
|
||||||
iter::once(mk_section(Section::Variable)),
|
|
||||||
item_compare(
|
|
||||||
state.collapsed[Section::Variable],
|
|
||||||
left.map(|r| r.variable()),
|
|
||||||
right.map(|r| r.variable())
|
|
||||||
),
|
|
||||||
compare_row(TEXT_EMPH2, Some("Total"), mk_total(left), mk_total(right)),
|
compare_row(TEXT_EMPH2, Some("Total"), mk_total(left), mk_total(right)),
|
||||||
iter::once(mk_section(Section::Accounts)),
|
mk_section!(Section::Accounts, |s| {
|
||||||
item_compare(
|
let (main_account, _) = s.main_account(self.archive);
|
||||||
state.collapsed[Section::Accounts],
|
|
||||||
mk_accounts(self.archive, left),
|
std::iter::once(("Main", main_account)).chain(s.savings())
|
||||||
mk_accounts(self.archive, right),
|
}),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
))
|
))
|
||||||
.into()
|
.into()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue