diff options
| author | Joe Carstairs <me@joeac.net> | 2026-02-01 21:03:01 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-02-01 21:03:01 +0000 |
| commit | c16f22f14b62c6576cc5a4c42a4f45c92b0241b2 (patch) | |
| tree | 0d65dc504b489b42b455a6bda7aa1652ed6360f6 | |
| parent | 5166f6dbf06f911c5dcb21563274ca98285aca6c (diff) | |
BucketNavigationEntry may be BucketGroupName
| -rw-r--r-- | schist_desktop_gui/src/gui/components/bucket_navigation_entry.rs | 48 | ||||
| -rw-r--r-- | schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_group_name.rs | 36 |
2 files changed, 80 insertions, 4 deletions
diff --git a/schist_desktop_gui/src/gui/components/bucket_navigation_entry.rs b/schist_desktop_gui/src/gui/components/bucket_navigation_entry.rs index 79b0ba9..be11178 100644 --- a/schist_desktop_gui/src/gui/components/bucket_navigation_entry.rs +++ b/schist_desktop_gui/src/gui/components/bucket_navigation_entry.rs @@ -1,21 +1,61 @@ +use bucket_group_name::BucketGroupName; use bucket_name_and_balance::BucketNameAndBalance; use iced::Element; +use itertools::Either; use schist_models::Bucket; use crate::gui::components::navigation; +mod bucket_group_name; mod bucket_name_and_balance; #[derive(Clone, Debug, PartialEq)] -pub struct BucketNavigationEntry(BucketNameAndBalance); +pub struct BucketNavigationEntry(Either<BucketNameAndBalance, BucketGroupName>); impl BucketNavigationEntry { pub fn from_bucket(bucket: &Bucket) -> Self { - Self(BucketNameAndBalance::new(bucket)) + Self(Either::Left(BucketNameAndBalance::new(bucket))) + } + + pub fn from_group_closed(group: &str) -> Self { + Self(Either::Right(BucketGroupName::new(group, false))) + } + + pub fn from_group_open(group: &str) -> Self { + Self(Either::Right(BucketGroupName::new(group, true))) + } + + pub fn is_bucket_and<P>(&self, pred: P) -> bool + where + P: Fn(&Bucket) -> bool, + { + self.0 + .as_ref() + .map_left(|bucket_name_and_balance| pred(&bucket_name_and_balance.bucket)) + .left_or(false) + } + + pub fn is_group_and<P>(&self, pred: P) -> bool + where + P: Fn(&BucketGroupName) -> bool, + { + self.0.as_ref().map_right(pred).right_or(false) } pub fn to_string(&self) -> String { - self.0.bucket.name.clone() + self.0 + .as_ref() + .map_left(|bucket_name_and_balance| bucket_name_and_balance.bucket.name.clone()) + .map_right(|bucket_group_name| bucket_group_name.group.clone()) + .into_inner() + } + + pub fn group(&self) -> String { + self.0 + .as_ref() + .map_left(|bucket_name_and_balance| bucket_name_and_balance.bucket.group.clone()) + .map_right(|bucket_group_name| bucket_group_name.group.clone()) + .into_inner() } } @@ -23,6 +63,6 @@ impl<'a> From<&'a BucketNavigationEntry> for Element<'a, navigation::Message<BucketNavigationEntry>> { fn from(bucket_navigation_entry: &'a BucketNavigationEntry) -> Self { - (&bucket_navigation_entry.0).into() + bucket_navigation_entry.0.as_ref().either_into() } } diff --git a/schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_group_name.rs b/schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_group_name.rs new file mode 100644 index 0000000..cbc9521 --- /dev/null +++ b/schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_group_name.rs @@ -0,0 +1,36 @@ +use iced::{ + widget::{row, text}, + Element, Length, +}; + +use crate::gui::components::{navigation, BucketNavigationEntry}; + +#[derive(Clone, Debug, PartialEq)] +pub struct BucketGroupName { + pub group: String, + pub is_open: bool, +} + +impl BucketGroupName { + pub fn new(group: &str, is_open: bool) -> Self { + Self { + group: group.to_string(), + is_open, + } + } +} + +impl<'a> From<&'a BucketGroupName> for Element<'a, navigation::Message<BucketNavigationEntry>> { + fn from(bucket_group_name: &'a BucketGroupName) -> Self { + let text_content = format!( + "{} {}", + if bucket_group_name.is_open { + "v " + } else { + "> " + }, + bucket_group_name.group + ); + row![text(text_content).width(Length::Fill),].into() + } +} |
