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)]
|
||||
}
|
||||
|
||||
let mk_section = |section: Section| {
|
||||
let mk_section_header = |section: Section| {
|
||||
let status = state.collapsed[section];
|
||||
text_row(
|
||||
TEXT_EMPH2,
|
||||
|
|
@ -348,45 +348,37 @@ where
|
|||
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 side = side?;
|
||||
|
||||
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<_>, _>(
|
||||
properties,
|
||||
itertools::chain![
|
||||
iter::once(headings),
|
||||
iter::once(mk_section(Section::Recurring)),
|
||||
item_compare(
|
||||
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())
|
||||
),
|
||||
mk_section!(Section::Recurring, |r| r.recurring()),
|
||||
mk_section!(Section::Variable, |r| r.variable()),
|
||||
compare_row(TEXT_EMPH2, Some("Total"), mk_total(left), mk_total(right)),
|
||||
iter::once(mk_section(Section::Accounts)),
|
||||
item_compare(
|
||||
state.collapsed[Section::Accounts],
|
||||
mk_accounts(self.archive, left),
|
||||
mk_accounts(self.archive, right),
|
||||
),
|
||||
mk_section!(Section::Accounts, |s| {
|
||||
let (main_account, _) = s.main_account(self.archive);
|
||||
|
||||
std::iter::once(("Main", main_account)).chain(s.savings())
|
||||
}),
|
||||
],
|
||||
))
|
||||
.into()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue