diff options
Diffstat (limited to 'schist_desktop_gui/src/gui/components/bucket_navigation_entry')
| -rw-r--r-- | schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_name_and_balance.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_name_and_balance.rs b/schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_name_and_balance.rs new file mode 100644 index 0000000..7abca57 --- /dev/null +++ b/schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_name_and_balance.rs @@ -0,0 +1,42 @@ +use iced::{ + widget::{row, text}, + Element, Length, +}; +use schist_models::Bucket; + +use crate::gui::components::{navigation, BucketNavigationEntry}; + +#[derive(Clone, Debug, PartialEq)] +pub struct BucketNameAndBalance { + pub bucket: Bucket, +} + +impl BucketNameAndBalance { + pub fn new(bucket: &Bucket) -> Self { + Self { + bucket: bucket.clone(), + } + } +} + +impl<'a> From<&'a BucketNameAndBalance> + for Element<'a, navigation::Message<BucketNavigationEntry>> +{ + fn from(bucket_name_and_balance: &'a BucketNameAndBalance) -> Self { + let balance_style = if bucket_name_and_balance + .bucket + .balance + .is_none_or(|balance| balance >= 0) + { + text::default + } else { + text::danger + }; + + row![ + text(bucket_name_and_balance.bucket.name.clone()).width(Length::Fill), + text(bucket_name_and_balance.bucket.pretty_balance_per_100()).style(balance_style), + ] + .into() + } +} |
