vn_settings/
layout.rs

1use super::{Resettable, Settings};
2
3#[derive(Clone)]
4pub struct BoxLayoutSettings<T> {
5    pub hor: T,
6    pub ver: T,
7    pub width: T,
8    pub height: T,
9    pub corner: T,
10    pub line: T,
11    pub text_size: T,
12    pub name_size: T,
13}
14
15#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
16pub enum BoxLayoutParameter {
17    Hor,
18    Ver,
19    Width,
20    Height,
21    Corner,
22    Line,
23    TextSize,
24    NameSize,
25}
26
27impl BoxLayoutParameter {
28    pub fn main(self) -> LayoutParameter {
29        LayoutParameter::Main(self)
30    }
31
32    pub fn list(self) -> LayoutParameter {
33        LayoutParameter::List(self)
34    }
35}
36
37impl<T> Settings<BoxLayoutParameter> for BoxLayoutSettings<T> {
38    type Value = T;
39
40    fn get_mut(&mut self, parameter: &BoxLayoutParameter) -> &mut T {
41        use BoxLayoutParameter::*;
42        match parameter {
43            Hor => &mut self.hor,
44            Ver => &mut self.ver,
45            Width => &mut self.width,
46            Height => &mut self.height,
47            Corner => &mut self.corner,
48            Line => &mut self.line,
49            TextSize => &mut self.text_size,
50            NameSize => &mut self.name_size,
51        }
52    }
53}
54
55impl<T: Resettable> Resettable for BoxLayoutSettings<T> {
56    fn reset(&mut self) {
57        self.hor.reset();
58        self.ver.reset();
59        self.width.reset();
60        self.height.reset();
61        self.corner.reset();
62        self.line.reset();
63        self.text_size.reset();
64        self.name_size.reset();
65    }
66}
67
68#[derive(Clone)]
69pub struct ViewLayoutSettings<T> {
70    pub hor: T,
71    pub ver: T,
72    pub zoom: T,
73}
74
75#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
76pub enum ViewLayoutParameter {
77    Hor,
78    Ver,
79    Zoom,
80}
81
82impl<T> Settings<ViewLayoutParameter> for ViewLayoutSettings<T> {
83    type Value = T;
84
85    fn get_mut(&mut self, parameter: &ViewLayoutParameter) -> &mut T {
86        use ViewLayoutParameter::*;
87        match parameter {
88            Hor => &mut self.hor,
89            Ver => &mut self.ver,
90            Zoom => &mut self.zoom,
91        }
92    }
93}
94
95impl<T: Resettable> Resettable for ViewLayoutSettings<T> {
96    fn reset(&mut self) {
97        self.hor.reset();
98        self.ver.reset();
99        self.zoom.reset();
100    }
101}
102
103#[derive(Clone)]
104pub struct LayoutSettings<T> {
105    pub main: BoxLayoutSettings<T>,
106    pub list: BoxLayoutSettings<T>,
107    pub view: ViewLayoutSettings<T>,
108}
109
110impl<T: From<f32>> LayoutSettings<T> {
111    pub fn common() -> Self {
112        Self {
113            main: BoxLayoutSettings {
114                hor: 0.0.into(),
115                ver: 3.0.into(),
116                width: 12.0.into(),
117                height: 2.0.into(),
118                corner: 0.25.into(),
119                line: (1.0 / 0x40 as f32).into(),
120                text_size: (1.0 / 3.0).into(),
121                name_size: (1.0 / 6.0).into(),
122            },
123            list: BoxLayoutSettings {
124                hor: 0.0.into(),
125                ver: (-4.0).into(),
126                width: 8.0.into(),
127                height: 0.5.into(),
128                corner: 0.25.into(),
129                line: (1.0 / 0x40 as f32).into(),
130                text_size: (1.0 / 4.0).into(),
131                name_size: (1.0 / 6.0).into(),
132            },
133            view: ViewLayoutSettings {
134                hor: 0.0.into(),
135                ver: 0.0.into(),
136                zoom: 1.0.into(),
137            },
138        }
139    }
140}
141
142#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
143pub enum LayoutParameter {
144    Main(BoxLayoutParameter),
145    List(BoxLayoutParameter),
146    View(ViewLayoutParameter),
147}
148
149impl<T> Settings<LayoutParameter> for LayoutSettings<T> {
150    type Value = T;
151
152    fn get_mut(&mut self, parameter: &LayoutParameter) -> &mut T {
153        use LayoutParameter::*;
154        match parameter {
155            Main(parameter) => self.main.get_mut(parameter),
156            List(parameter) => self.list.get_mut(parameter),
157            View(parameter) => self.view.get_mut(parameter),
158        }
159    }
160}
161
162impl<T: Resettable> Resettable for LayoutSettings<T> {
163    fn reset(&mut self) {
164        self.main.reset();
165        self.list.reset();
166    }
167}