From e35e6d8ba4a7685af6a24b7cd3e77ff19e5f7b80 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Sun, 25 Jan 2026 18:18:35 +0000 Subject: refactor bucket_navigation_entry --- .../bucket_name_and_balance.rs | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_name_and_balance.rs (limited to 'schist_desktop_gui/src/gui/components/bucket_navigation_entry') 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> +{ + 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() + } +} -- cgit v1.2.3