summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/gui/screens/main_screen/view.rs
blob: 2ff575371c42753cf131e51c0150e7d8f65b5dd4 (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
44
45
46
47
48
49
50
51
52
53
use iced::{widget::Text, Element};

use crate::{gui::components::navigation, traits::Focusable};

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum View {
    Balances,
    Buckets,
    Transactions,
}

impl View {
    pub const VIEW_1: View = View::Buckets;
    pub const VIEW_2: View = View::Balances;
    pub const VIEW_3: View = View::Transactions;

    pub fn views() -> Vec<View> {
        vec![Self::VIEW_1, Self::VIEW_2, Self::VIEW_3]
    }

    pub const fn name(self) -> &'static str {
        match self {
            View::Balances => "balances",
            View::Buckets => "buckets",
            View::Transactions => "transactions",
        }
    }

    pub fn next(&self) -> View {
        match *self {
            Self::VIEW_1 => Self::VIEW_2,
            Self::VIEW_2 | Self::VIEW_3 => Self::VIEW_3,
        }
    }

    pub fn prev(&self) -> View {
        match *self {
            Self::VIEW_1 | Self::VIEW_2 => Self::VIEW_1,
            Self::VIEW_3 => Self::VIEW_2,
        }
    }
}

impl<'a> From<&'a View> for Element<'a, navigation::Message<View>> {
    fn from(val: &'a View) -> Self {
        Text::new(val.name()).into()
    }
}

impl Focusable for View {
    fn focus(&mut self) {}
    fn unfocus(&mut self) {}
}