summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_group_name.rs
blob: 98902ee7e422aab37c56b76c4043b0b3a7f76339 (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
39
40
41
42
43
use iced::{
    widget::{row, text},
    Element, Length,
};

use crate::{
    gui::components::{navigation, BucketNavigationEntry},
    impl_focusable,
};

#[derive(Clone, Debug, PartialEq)]
pub struct BucketGroupName {
    pub group: String,
    pub is_open: bool,
    pub is_focused: bool,
}

impl BucketGroupName {
    pub fn new(group: &str, is_open: bool) -> Self {
        Self {
            group: group.to_string(),
            is_open,
            is_focused: false,
        }
    }
}

impl<'a> From<&'a BucketGroupName> for Element<'a, navigation::Message<BucketNavigationEntry>> {
    fn from(bucket_group_name: &'a BucketGroupName) -> Self {
        let text_content = format!(
            "{} {}",
            if bucket_group_name.is_open {
                "v "
            } else {
                "> "
            },
            bucket_group_name.group
        );
        row![text(text_content).width(Length::Fill),].into()
    }
}

impl_focusable!(BucketGroupName);