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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use std::collections::HashMap;
pub use serde::{Deserialize, Serialize};
pub use settings_schema_derive::SettingsSchema;
pub use serde_json::to_value as to_json_value;
#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
#[serde(tag = "state", content = "content")]
pub enum Switch<T> {
Enabled(T),
Disabled,
}
impl<T> Switch<T> {
pub fn as_option(&self) -> Option<&T> {
match self {
Self::Enabled(t) => Some(t),
Self::Disabled => None,
}
}
pub fn into_option(self) -> Option<T> {
match self {
Self::Enabled(t) => Some(t),
Self::Disabled => None,
}
}
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct OptionalDefault<C> {
pub set: bool,
pub content: C,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SwitchDefault<C> {
pub enabled: bool,
pub content: C,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct VectorDefault<T> {
pub element: T,
pub content: Vec<T>,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct DictionaryDefault<T> {
pub key: String,
pub value: T,
pub content: Vec<(String, T)>,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum NumericGuiType {
TextBox,
UpDown,
Slider,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum ChoiceControlType {
Dropdown,
ButtonGroup,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct NamedEntry<T> {
pub name: String,
pub strings: HashMap<String, String>,
pub content: T,
}
#[non_exhaustive]
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(tag = "type", content = "content")]
pub enum SchemaNode {
Section(Vec<NamedEntry<SchemaNode>>),
Choice {
default: String,
variants: Vec<NamedEntry<Option<SchemaNode>>>,
gui: Option<ChoiceControlType>,
},
Optional {
default_set: bool,
content: Box<SchemaNode>,
},
Switch {
default_enabled: bool,
content: Box<SchemaNode>,
},
Boolean {
default: bool,
},
Integer {
default: i128,
min: Option<i128>,
max: Option<i128>,
step: Option<i128>,
gui: Option<NumericGuiType>,
},
Float {
default: f64,
min: Option<f64>,
max: Option<f64>,
step: Option<f64>,
gui: Option<NumericGuiType>,
},
Text {
default: String,
},
Array(Vec<SchemaNode>),
Vector {
default_element: Box<SchemaNode>,
default: serde_json::Value,
},
Dictionary {
default_key: String,
default_value: Box<SchemaNode>,
default: serde_json::Value,
},
}