diff options
| author | Joe Carstairs <me@joeac.net> | 2026-01-25 18:18:35 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-01-26 08:31:02 +0000 |
| commit | e35e6d8ba4a7685af6a24b7cd3e77ff19e5f7b80 (patch) | |
| tree | cb8cbc534905c4d4dde979f1919bfead8b5d943b /schist_desktop_gui/src/gui/components/bucket_navigation_entry | |
| parent | 409b5bc15951001c6d16c2bcfa747fda25cb3735 (diff) | |
refactor bucket_navigation_entry
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() + } +} |
