Add a total section
This commit is contained in:
parent
4cfe91039c
commit
8417c4a8db
2 changed files with 30 additions and 12 deletions
|
|
@ -11,12 +11,14 @@ use iced::{
|
|||
use iced_aw::{card, modal, selection_list};
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::{CompareLoad, CompareSide, ReportDate, Spendings, TEXT_EMPH2, TEXT_H1, TEXT_H2};
|
||||
use crate::{
|
||||
CompareLoad, CompareSide, Report, ReportDate, Spendings, TEXT_EMPH2, TEXT_H1, TEXT_H2,
|
||||
};
|
||||
|
||||
pub(crate) struct Compare<F> {
|
||||
pub(crate) struct Compare<'a, F> {
|
||||
pub left: Option<(CompareLoad, Box<dyn Spendings>)>,
|
||||
pub right: Option<(CompareLoad, Box<dyn Spendings>)>,
|
||||
pub reports: Vec<ReportDate>,
|
||||
pub archive: &'a BTreeMap<ReportDate, Report>,
|
||||
pub on_load: F,
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +51,7 @@ impl Section {
|
|||
}
|
||||
}
|
||||
|
||||
impl<M, F> iced::widget::Component<M, Renderer> for Compare<F>
|
||||
impl<'a, M, F> iced::widget::Component<M, Renderer> for Compare<'a, F>
|
||||
where
|
||||
F: FnMut(CompareSide, CompareLoad) -> M,
|
||||
{
|
||||
|
|
@ -78,7 +80,7 @@ where
|
|||
let heading_load = |on_submit: fn(_) -> _| {
|
||||
component(CompareLoadChoice {
|
||||
on_submit,
|
||||
choices: &self.reports,
|
||||
choices: self.archive.keys().copied().collect(),
|
||||
})
|
||||
};
|
||||
|
||||
|
|
@ -154,8 +156,8 @@ where
|
|||
]
|
||||
};
|
||||
|
||||
let left = self.left.as_ref().map(|(_, r)| r);
|
||||
let right = self.right.as_ref().map(|(_, r)| r);
|
||||
let left = self.left.as_ref().map(|(_, r)| &**r);
|
||||
let right = self.right.as_ref().map(|(_, r)| &**r);
|
||||
|
||||
fn item_compare<'a, I, M>(
|
||||
collapse: bool,
|
||||
|
|
@ -284,6 +286,16 @@ where
|
|||
compare
|
||||
}
|
||||
|
||||
fn mk_total<'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()))
|
||||
}
|
||||
|
||||
scrollable(table::<_, _, iced::Element<_>, _>(
|
||||
properties,
|
||||
itertools::chain![
|
||||
|
|
@ -300,6 +312,12 @@ where
|
|||
left.map(|r| r.variable()),
|
||||
right.map(|r| r.variable())
|
||||
),
|
||||
iter::once(mk_section(Section::Total)),
|
||||
item_compare(
|
||||
state.collapsed[Section::Variable],
|
||||
mk_total(self.archive, left),
|
||||
mk_total(self.archive, right),
|
||||
),
|
||||
],
|
||||
))
|
||||
.into()
|
||||
|
|
@ -361,8 +379,8 @@ where
|
|||
)
|
||||
}
|
||||
|
||||
struct CompareLoadChoice<'a, F> {
|
||||
choices: &'a [ReportDate],
|
||||
struct CompareLoadChoice<F> {
|
||||
choices: Vec<ReportDate>,
|
||||
on_submit: F,
|
||||
}
|
||||
|
||||
|
|
@ -380,7 +398,7 @@ enum CompareLoadChoiceMsg {
|
|||
Select(CompareLoad),
|
||||
}
|
||||
|
||||
impl<'a, M, F> iced::widget::Component<M, Renderer> for CompareLoadChoice<'a, F>
|
||||
impl<M, F> iced::widget::Component<M, Renderer> for CompareLoadChoice<F>
|
||||
where
|
||||
F: FnMut(CompareLoad) -> M,
|
||||
{
|
||||
|
|
@ -414,7 +432,7 @@ where
|
|||
.on_press(CompareLoadChoiceMsg::Select(CompareLoad::Current)),
|
||||
horizontal_rule(5.),
|
||||
text("Historic Reports"),
|
||||
selection_list(self.choices, |_, v| CompareLoadChoiceMsg::Select(
|
||||
selection_list(&self.choices, |_, v| CompareLoadChoiceMsg::Select(
|
||||
CompareLoad::Report(v)
|
||||
))
|
||||
.height(Length::Shrink),
|
||||
|
|
|
|||
|
|
@ -518,7 +518,7 @@ impl Application for Glaurung {
|
|||
CurrentView::Compare => component(Compare {
|
||||
left: self.compare_load(self.compare_left),
|
||||
right: self.compare_load(self.compare_right),
|
||||
reports: self.archive.keys().copied().collect(),
|
||||
archive: &self.archive,
|
||||
on_load: Message::CompareLoad,
|
||||
}),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue