summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/gui/components/bucket_name_and_balance.rs
blob: 8a5a16e70055eca03a2096163e9d210a3dc690c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use iced::{
    widget::{row, text},
    Element, Length,
};
use schist_models::Bucket;

use crate::gui::components::navigation;

#[derive(Clone, Debug, PartialEq)]
pub struct BucketNameAndBalance {
    pub bucket: Bucket,
}

impl BucketNameAndBalance {
    pub fn new(bucket: Bucket) -> Self {
        Self { bucket }
    }
}

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(bucket_name_and_balance.bucket.name.clone()).width(Length::Fill),
            text(bucket_name_and_balance.bucket.pretty_balance_per_100()).style(balance_style),
        ]
        .into()
    }
}