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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
use scene::params::{ParamValue, ParamValues};
#[derive(Clone, Debug, PartialEq)]
pub struct ParamDependency {
pub param: String,
pub equals: ParamValue,
}
#[derive(Clone, Debug, PartialEq)]
pub struct SelectOption {
pub value: String,
pub label: String,
}
#[derive(Clone, Debug, PartialEq)]
pub struct NumberParamDefinition {
pub key: String,
pub label: String,
pub default_value: f64,
pub min: f64,
pub max: Option<f64>,
pub step: f64,
pub group: Option<String>,
pub keyframable: Option<bool>,
pub dependencies: Vec<ParamDependency>,
pub display_multiplier: Option<f64>,
pub unit: Option<String>,
pub short_label: Option<String>,
}
impl NumberParamDefinition {
pub fn new(
key: &str,
label: &str,
default_value: f64,
min: f64,
max: Option<f64>,
step: f64,
) -> Self {
Self {
key: key.to_string(),
label: label.to_string(),
default_value,
min,
max,
step,
group: None,
keyframable: None,
dependencies: Vec::new(),
display_multiplier: None,
unit: None,
short_label: None,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct BooleanParamDefinition {
pub key: String,
pub label: String,
pub default_value: bool,
pub group: Option<String>,
pub keyframable: Option<bool>,
pub dependencies: Vec<ParamDependency>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct ColorParamDefinition {
pub key: String,
pub label: String,
pub default_value: String,
pub group: Option<String>,
pub keyframable: Option<bool>,
pub dependencies: Vec<ParamDependency>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct SelectParamDefinition {
pub key: String,
pub label: String,
pub default_value: String,
pub options: Vec<SelectOption>,
pub group: Option<String>,
pub keyframable: Option<bool>,
pub dependencies: Vec<ParamDependency>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct TextParamDefinition {
pub key: String,
pub label: String,
pub default_value: String,
pub group: Option<String>,
pub keyframable: Option<bool>,
pub dependencies: Vec<ParamDependency>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct FontParamDefinition {
pub key: String,
pub label: String,
pub default_value: String,
pub group: Option<String>,
pub keyframable: Option<bool>,
pub dependencies: Vec<ParamDependency>,
}
#[derive(Clone, Debug, PartialEq)]
pub enum ParamDefinition {
Number(NumberParamDefinition),
Boolean(BooleanParamDefinition),
Color(ColorParamDefinition),
Select(SelectParamDefinition),
Text(TextParamDefinition),
Font(FontParamDefinition),
}
impl ParamDefinition {
pub fn key(&self) -> &str {
match self {
Self::Number(param) => ¶m.key,
Self::Boolean(param) => ¶m.key,
Self::Color(param) => ¶m.key,
Self::Select(param) => ¶m.key,
Self::Text(param) => ¶m.key,
Self::Font(param) => ¶m.key,
}
}
pub fn label(&self) -> &str {
match self {
Self::Number(param) => ¶m.label,
Self::Boolean(param) => ¶m.label,
Self::Color(param) => ¶m.label,
Self::Select(param) => ¶m.label,
Self::Text(param) => ¶m.label,
Self::Font(param) => ¶m.label,
}
}
pub fn default_value(&self) -> ParamValue {
match self {
Self::Number(param) => ParamValue::Number(param.default_value),
Self::Boolean(param) => ParamValue::Bool(param.default_value),
Self::Color(param) => ParamValue::String(param.default_value.clone()),
Self::Select(param) => ParamValue::String(param.default_value.clone()),
Self::Text(param) => ParamValue::String(param.default_value.clone()),
Self::Font(param) => ParamValue::String(param.default_value.clone()),
}
}
pub fn numeric_range(&self) -> Option<(f64, Option<f64>, f64)> {
match self {
Self::Number(param) => Some((param.min, param.max, param.step)),
_ => None,
}
}
}
pub fn build_default_param_values(params: &[ParamDefinition]) -> ParamValues {
params
.iter()
.map(|param| (param.key().to_string(), param.default_value()))
.collect()
}
|