summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/gui/components/bucket_name_and_balance.rs
diff options
context:
space:
mode:
authorjoeac <me@joeac.net>2026-01-17 17:17:50 +0000
committerjoeac <me@joeac.net>2026-01-17 17:17:50 +0000
commitbf74f305894bde98033932235a4210c7d6865adf (patch)
tree051422c97fcb5d7c2eafd426ea66e1a906948747 /schist_desktop_gui/src/gui/components/bucket_name_and_balance.rs
parentfe85652e4d3e8906824baddaafd05d19105579b8 (diff)
parentf69ec8416c4e6301dcfa06791b025785d7f61b6b (diff)
Merge pull request 'random-stuff' (#4) from random-stuff into main
Reviewed-on: https://git.joeac.net/joeac/schist/pulls/4
Diffstat (limited to 'schist_desktop_gui/src/gui/components/bucket_name_and_balance.rs')
-rw-r--r--schist_desktop_gui/src/gui/components/bucket_name_and_balance.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/schist_desktop_gui/src/gui/components/bucket_name_and_balance.rs b/schist_desktop_gui/src/gui/components/bucket_name_and_balance.rs
index 24a3952..8a5a16e 100644
--- a/schist_desktop_gui/src/gui/components/bucket_name_and_balance.rs
+++ b/schist_desktop_gui/src/gui/components/bucket_name_and_balance.rs
@@ -1,7 +1,10 @@
-use iced::{widget::row, Element};
+use iced::{
+ widget::{row, text},
+ Element, Length,
+};
use schist_models::Bucket;
-use crate::gui::components::{navigation, Text};
+use crate::gui::components::navigation;
#[derive(Clone, Debug, PartialEq)]
pub struct BucketNameAndBalance {
@@ -14,11 +17,21 @@ impl BucketNameAndBalance {
}
}
-impl<'a> Into<Element<'a, navigation::Message<BucketNameAndBalance>>> for BucketNameAndBalance {
- fn into(self) -> Element<'a, navigation::Message<BucketNameAndBalance>> {
+impl<'a> From<&'a BucketNameAndBalance> for Element<'a, navigation::Message<BucketNameAndBalance>> {
+ 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::new(&self.bucket.name).as_element(),
- Text::new(&self.bucket.balance.unwrap_or(0).to_string()).as_element(),
+ 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()
}