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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
//! Example of a simple plugin using the nemo-plugin builder API
//!
//! This example shows how to create a basic plugin with a UI template
//! using the fluent builder pattern.
use nemo_plugin::containers;
use nemo_plugin::prelude::*;
/// Build a simple temperature monitor UI
fn build_temperature_monitor() -> PluginValue {
Panel::new()
.padding(20)
.border(1)
.border_color("theme.border")
.shadow("md")
.width(350)
.child(
"header",
Stack::vertical()
.spacing(4)
.child(
"title",
Label::new("Temperature Monitor").size("xl").weight("bold"),
)
.child(
"subtitle",
Label::new("Real-time sensor readings")
.size("sm")
.color("theme.muted"),
),
)
.child(
"controls",
Stack::vertical()
.spacing(16)
// Temperature display
.child(
"temp_display",
Panel::new()
.padding(16)
.bg_color("theme.surface")
.border(1)
.child(
"content",
Stack::vertical()
.spacing(8)
.align("center")
.child("label", Label::new("Current Temperature"))
.child(
"value",
Label::new("--°C")
.size("xl")
.weight("bold")
.bind_text("data.temperature.display"),
),
),
)
// Settings
.child(
"settings",
Stack::vertical()
.spacing(12)
// Temperature unit selector
.child(
"unit_row",
Stack::horizontal()
.spacing(8)
.child("label", Label::new("Unit:").width(100))
.child(
"celsius_btn",
Button::new("°C")
.variant("secondary")
.on_click("set_celsius")
.width(60),
)
.child(
"fahrenheit_btn",
Button::new("°F")
.variant("secondary")
.on_click("set_fahrenheit")
.width(60),
),
)
// Alert threshold
.child(
"threshold_row",
Stack::vertical()
.spacing(8)
.child("threshold_label", Label::new("Alert Threshold"))
.child(
"threshold_slider",
Slider::new()
.min(0.0)
.max(100.0)
.step(1.0)
.value(30.0)
.on_change("on_threshold_change")
.bind_value("settings.alert_threshold"),
),
)
// Enable alerts switch
.child(
"alerts_switch",
Switch::new()
.label("Enable High Temperature Alerts")
.checked(true)
.on_click("toggle_alerts")
.bind_checked("settings.alerts_enabled"),
),
)
// History chart placeholder
.child(
"history",
Panel::new()
.padding(12)
.bg_color("theme.surface")
.border(1)
.height(200)
.child(
"chart_label",
Label::new("Temperature History").weight("bold"),
),
),
)
.build()
}
/// Build a control panel with multiple inputs
fn build_control_panel() -> PluginValue {
Panel::new()
.padding(16)
.border(2)
.border_color("theme.primary")
.child(
"form",
Stack::vertical()
.spacing(12)
.child("title", Label::new("Device Control Panel").size("lg"))
// Using the helper function for input rows
.child(
"name_row",
containers::input_row(
"Device Name",
Some(120),
Input::new()
.placeholder("Enter device name")
.on_change("on_name_change"),
Some(8),
),
)
.child(
"id_row",
containers::input_row(
"Device ID",
Some(120),
Input::new()
.placeholder("Auto-generated")
.disabled(true)
.bind_value("device.id"),
Some(8),
),
)
// Action buttons
.child(
"actions",
Stack::horizontal()
.spacing(8)
.justify("end")
.child(
"save_btn",
Button::new("Save")
.variant("primary")
.on_click("save_settings"),
)
.child(
"reset_btn",
Button::new("Reset")
.variant("secondary")
.on_click("reset_settings"),
)
.child(
"delete_btn",
Button::new("Delete")
.variant("danger")
.on_click("delete_device"),
),
),
)
.build()
}
/// Build a dashboard with grid layout
fn build_dashboard() -> PluginValue {
Panel::new()
.padding(20)
.child(
"dashboard",
Stack::vertical()
.spacing(16)
.child(
"header",
Label::new("System Dashboard").size("xl").weight("bold"),
)
.child(
"metrics",
Grid::new(2)
.gap(16)
// Metric card 1
.child(
"cpu",
Panel::new().padding(16).border(1).child(
"content",
Stack::vertical()
.spacing(8)
.child("label", Label::new("CPU Usage"))
.child(
"value",
Label::new("--%")
.size("xl")
.weight("bold")
.bind_text("metrics.cpu.display"),
)
.child(
"bar",
Slider::new()
.min(0.0)
.max(100.0)
.bind_value("metrics.cpu.value"),
),
),
)
// Metric card 2
.child(
"memory",
Panel::new().padding(16).border(1).child(
"content",
Stack::vertical()
.spacing(8)
.child("label", Label::new("Memory Usage"))
.child(
"value",
Label::new("--%")
.size("xl")
.weight("bold")
.bind_text("metrics.memory.display"),
)
.child(
"bar",
Slider::new()
.min(0.0)
.max(100.0)
.bind_value("metrics.memory.value"),
),
),
)
// Metric card 3
.child(
"disk",
Panel::new().padding(16).border(1).child(
"content",
Stack::vertical()
.spacing(8)
.child("label", Label::new("Disk Usage"))
.child(
"value",
Label::new("--%")
.size("xl")
.weight("bold")
.bind_text("metrics.disk.display"),
)
.child(
"bar",
Slider::new()
.min(0.0)
.max(100.0)
.bind_value("metrics.disk.value"),
),
),
)
// Metric card 4
.child(
"network",
Panel::new().padding(16).border(1).child(
"content",
Stack::vertical()
.spacing(8)
.child("label", Label::new("Network"))
.child(
"value",
Label::new("-- MB/s")
.size("xl")
.weight("bold")
.bind_text("metrics.network.display"),
),
),
),
),
)
.build()
}
fn main() {
println!("Building temperature monitor...");
let temp_monitor = build_temperature_monitor();
println!("Temperature monitor: {:#?}", temp_monitor);
println!("\nBuilding control panel...");
let control_panel = build_control_panel();
println!("Control panel: {:#?}", control_panel);
println!("\nBuilding dashboard...");
let dashboard = build_dashboard();
println!("Dashboard: {:#?}", dashboard);
}