rate_config/config/
cases.rs

1use rill_config::{Config, ReadableConfig};
2use rrpack_basis::auto_path::AutoPath;
3use rrpack_basis::manifest::layouts::layout::{Label, Layout, LayoutItem, LayoutTab};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
7pub struct CaseConfig {
8    pub name: String,
9    pub tab: Option<Vec<CaseTabConfig>>,
10}
11
12impl Config for CaseConfig {}
13
14impl ReadableConfig for CaseConfig {}
15
16#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
17pub struct CaseTabConfig {
18    pub name: String,
19    pub item: Option<Vec<CaseItemConfig>>,
20    pub label: Option<Vec<LabelConfig>>,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
24pub struct CaseItemConfig {
25    pub position: (i32, i32),
26    pub size: (i32, i32),
27    pub path: AutoPath,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
31pub struct LabelConfig {
32    pub position: (i32, i32),
33    pub size: (i32, i32),
34    pub text: String,
35}
36
37impl From<CaseConfig> for Layout {
38    fn from(config: CaseConfig) -> Self {
39        let tabs = config
40            .tab
41            .unwrap_or_default()
42            .into_iter()
43            .map(LayoutTab::from)
44            .map(|tab| (tab.name.clone(), tab))
45            .collect();
46        Self {
47            name: config.name.into(),
48            tabs,
49        }
50    }
51}
52
53impl From<CaseTabConfig> for LayoutTab {
54    fn from(config: CaseTabConfig) -> Self {
55        let items = config
56            .item
57            .unwrap_or_default()
58            .into_iter()
59            .map(LayoutItem::from)
60            .collect();
61        let labels = config
62            .label
63            .unwrap_or_default()
64            .into_iter()
65            .map(Label::from)
66            .collect();
67        Self {
68            name: config.name.into(),
69            items,
70            labels,
71        }
72    }
73}
74
75impl From<CaseItemConfig> for LayoutItem {
76    fn from(config: CaseItemConfig) -> Self {
77        Self {
78            position: config.position.into(),
79            size: config.size.into(),
80            path: config.path.into(),
81        }
82    }
83}
84
85impl From<LabelConfig> for Label {
86    fn from(config: LabelConfig) -> Self {
87        Self {
88            position: config.position.into(),
89            size: config.size.into(),
90            text: config.text,
91        }
92    }
93}