use super::Settings;
#[derive(Clone)]
pub struct BoxLayoutSettings<T> {
pub hor: T,
pub ver: T,
pub width: T,
pub height: T,
pub corner: T,
pub line: T,
pub text_size: T,
pub name_size: T,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum BoxLayoutParameter {
Hor,
Ver,
Width,
Height,
Corner,
Line,
TextSize,
NameSize,
}
impl BoxLayoutParameter {
pub const fn main(self) -> LayoutParameter {
LayoutParameter::Main(self)
}
pub const fn list(self) -> LayoutParameter {
LayoutParameter::List(self)
}
pub const fn menu(self) -> LayoutParameter {
LayoutParameter::Menu(self)
}
}
impl<T> Settings<BoxLayoutParameter> for BoxLayoutSettings<T> {
type Value = T;
fn get_mut(&mut self, parameter: &BoxLayoutParameter) -> &mut T {
use BoxLayoutParameter::*;
match parameter {
Hor => &mut self.hor,
Ver => &mut self.ver,
Width => &mut self.width,
Height => &mut self.height,
Corner => &mut self.corner,
Line => &mut self.line,
TextSize => &mut self.text_size,
NameSize => &mut self.name_size,
}
}
}
resettable!(<T> BoxLayoutSettings<T> { hor, ver, width, height, corner, line, text_size, name_size });
impl BoxLayoutParameter {
pub fn parse(name: &str) -> Option<Self> {
Some(match name {
"hor" => Self::Hor,
"ver" => Self::Ver,
"width" => Self::Width,
"height" => Self::Height,
"corner" => Self::Corner,
"line" => Self::Line,
"text-size" => Self::TextSize,
"name-size" => Self::NameSize,
_ => return None,
})
}
}
#[derive(Clone)]
pub struct ViewLayoutSettings<T> {
pub hor: T,
pub ver: T,
pub zoom: T,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum ViewLayoutParameter {
Hor,
Ver,
Zoom,
}
impl<T> Settings<ViewLayoutParameter> for ViewLayoutSettings<T> {
type Value = T;
fn get_mut(&mut self, parameter: &ViewLayoutParameter) -> &mut T {
use ViewLayoutParameter::*;
match parameter {
Hor => &mut self.hor,
Ver => &mut self.ver,
Zoom => &mut self.zoom,
}
}
}
resettable!(<T> ViewLayoutSettings<T> { hor, ver, zoom });
impl ViewLayoutParameter {
pub fn parse(name: &str) -> Option<Self> {
Some(match name {
"hor" => Self::Hor,
"ver" => Self::Ver,
"zoom" => Self::Zoom,
_ => return None,
})
}
}
#[derive(Clone)]
pub struct LayoutSettings<T> {
pub main: BoxLayoutSettings<T>,
pub list: BoxLayoutSettings<T>,
pub menu: BoxLayoutSettings<T>,
pub view: ViewLayoutSettings<T>,
}
impl<T: From<f32>> LayoutSettings<T> {
#[must_use]
pub fn common() -> Self {
Self {
main: BoxLayoutSettings {
hor: 0.0.into(),
ver: 3.0.into(),
width: 12.0.into(),
height: 2.0.into(),
corner: 0.25.into(),
line: (1.0 / 0x40 as f32).into(),
text_size: (1.0 / 3.0).into(),
name_size: (1.0 / 6.0).into(),
},
list: BoxLayoutSettings {
hor: 0.0.into(),
ver: (-4.0).into(),
width: 8.0.into(),
height: 0.5.into(),
corner: 0.25.into(),
line: (1.0 / 0x40 as f32).into(),
text_size: (1.0 / 4.0).into(),
name_size: (1.0 / 6.0).into(),
},
menu: BoxLayoutSettings {
hor: 0.0.into(),
ver: 0.0.into(),
width: 5.0.into(),
height: 0.5.into(),
corner: 0.08.into(),
line: (1.0 / 0x40 as f32).into(),
text_size: 0.25.into(),
name_size: 0.35.into(),
},
view: ViewLayoutSettings {
hor: 0.0.into(),
ver: 0.0.into(),
zoom: 1.0.into(),
},
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum LayoutParameter {
Main(BoxLayoutParameter),
List(BoxLayoutParameter),
Menu(BoxLayoutParameter),
View(ViewLayoutParameter),
}
impl<T> Settings<LayoutParameter> for LayoutSettings<T> {
type Value = T;
fn get_mut(&mut self, parameter: &LayoutParameter) -> &mut T {
use LayoutParameter::*;
match parameter {
Main(parameter) => self.main.get_mut(parameter),
List(parameter) => self.list.get_mut(parameter),
Menu(parameter) => self.menu.get_mut(parameter),
View(parameter) => self.view.get_mut(parameter),
}
}
}
resettable!(<T> LayoutSettings<T> { main, list, menu });