1#[derive(Clone, Debug, PartialEq)]
5pub enum FieldKind {
6 Toggle,
7 Slider { min: f64, max: f64, step: f64 },
8 Dropdown { options: Vec<String> },
9 TextInput,
10 Button { action: String },
11 Custom { type_name: String },
12}
13
14#[derive(Clone, Debug, Default)]
16pub struct ValidationRules {
17 pub range: Option<(f64, f64)>,
18 pub length: Option<(usize, usize)>,
19 pub pattern: Option<String>,
20 pub required: bool,
21 pub error_message: Option<String>,
22}
23
24#[derive(Clone, Debug)]
26pub struct ConfirmationConfig {
27 pub title: String,
28 pub message: String,
29 pub confirm_text: String,
30 pub cancel_text: String,
31 pub is_dangerous: bool,
32}
33
34impl Default for ConfirmationConfig {
35 fn default() -> Self {
36 Self {
37 title: "Confirm Change".into(),
38 message: "Are you sure you want to change this setting?".into(),
39 confirm_text: "Confirm".into(),
40 cancel_text: "Cancel".into(),
41 is_dangerous: false,
42 }
43 }
44}
45
46#[derive(Clone, Debug)]
50pub struct FieldMeta {
51 pub name: &'static str,
53
54 pub key: &'static str,
56
57 pub title: &'static str,
59
60 pub description: &'static str,
62
63 pub category: &'static str,
65
66 pub category_order: i32,
68
69 pub kind: FieldKind,
71
72 pub depends_on: Option<&'static str>,
74
75 pub is_persisted_only: bool,
77
78 pub no_reset: bool,
80
81 pub confirm_reset: Option<&'static str>,
83
84 pub validation: Option<ValidationRules>,
86
87 pub confirmation: Option<ConfirmationConfig>,
89
90 pub platforms: Vec<&'static str>,
93}
94
95impl Default for FieldMeta {
96 fn default() -> Self {
97 Self {
98 name: "",
99 key: "",
100 title: "",
101 description: "",
102 category: "",
103 category_order: 0,
104 kind: FieldKind::Toggle,
105 depends_on: None,
106 is_persisted_only: false,
107 no_reset: false,
108 confirm_reset: None,
109 validation: None,
110 confirmation: None,
111 platforms: Vec::new(),
112 }
113 }
114}
115
116impl FieldMeta {
117 pub fn is_visible_on_current_platform(&self) -> bool {
119 if self.platforms.is_empty() {
120 return true;
121 }
122
123 let current = current_platform_name();
124
125 for &p in &self.platforms {
126 if p == "all" {
127 return true;
128 }
129 if p == current {
130 return true;
131 }
132 if p == "desktop" && matches!(current, "windows" | "macos" | "linux") {
134 return true;
135 }
136 }
137
138 false
139 }
140}
141
142fn current_platform_name() -> &'static str {
143 #[cfg(target_os = "android")]
144 {
145 "android"
146 }
147 #[cfg(target_os = "ios")]
148 {
149 "ios"
150 }
151 #[cfg(target_os = "windows")]
152 {
153 "windows"
154 }
155 #[cfg(target_os = "macos")]
156 {
157 "macos"
158 }
159 #[cfg(target_os = "linux")]
160 {
161 "linux"
162 }
163 #[cfg(not(any(
164 target_os = "android",
165 target_os = "ios",
166 target_os = "windows",
167 target_os = "macos",
168 target_os = "linux"
169 )))]
170 {
171 "unknown"
172 }
173}