pub struct Switch(/* private fields */);Expand description
Builder for a Switch/Toggle component
Implementations§
Source§impl Switch
impl Switch
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new switch
Examples found in repository?
examples/simple_plugin.rs (line 104)
10fn build_temperature_monitor() -> PluginValue {
11 Panel::new()
12 .padding(20)
13 .border(1)
14 .border_color("theme.border")
15 .shadow("md")
16 .width(350)
17 .child(
18 "header",
19 Stack::vertical()
20 .spacing(4)
21 .child(
22 "title",
23 Label::new("Temperature Monitor").size("xl").weight("bold"),
24 )
25 .child(
26 "subtitle",
27 Label::new("Real-time sensor readings")
28 .size("sm")
29 .color("theme.muted"),
30 ),
31 )
32 .child(
33 "controls",
34 Stack::vertical()
35 .spacing(16)
36 // Temperature display
37 .child(
38 "temp_display",
39 Panel::new()
40 .padding(16)
41 .bg_color("theme.surface")
42 .border(1)
43 .child(
44 "content",
45 Stack::vertical()
46 .spacing(8)
47 .align("center")
48 .child("label", Label::new("Current Temperature"))
49 .child(
50 "value",
51 Label::new("--°C")
52 .size("xl")
53 .weight("bold")
54 .bind_text("data.temperature.display"),
55 ),
56 ),
57 )
58 // Settings
59 .child(
60 "settings",
61 Stack::vertical()
62 .spacing(12)
63 // Temperature unit selector
64 .child(
65 "unit_row",
66 Stack::horizontal()
67 .spacing(8)
68 .child("label", Label::new("Unit:").width(100))
69 .child(
70 "celsius_btn",
71 Button::new("°C")
72 .variant("secondary")
73 .on_click("set_celsius")
74 .width(60),
75 )
76 .child(
77 "fahrenheit_btn",
78 Button::new("°F")
79 .variant("secondary")
80 .on_click("set_fahrenheit")
81 .width(60),
82 ),
83 )
84 // Alert threshold
85 .child(
86 "threshold_row",
87 Stack::vertical()
88 .spacing(8)
89 .child("threshold_label", Label::new("Alert Threshold"))
90 .child(
91 "threshold_slider",
92 Slider::new()
93 .min(0.0)
94 .max(100.0)
95 .step(1.0)
96 .value(30.0)
97 .on_change("on_threshold_change")
98 .bind_value("settings.alert_threshold"),
99 ),
100 )
101 // Enable alerts switch
102 .child(
103 "alerts_switch",
104 Switch::new()
105 .label("Enable High Temperature Alerts")
106 .checked(true)
107 .on_click("toggle_alerts")
108 .bind_checked("settings.alerts_enabled"),
109 ),
110 )
111 // History chart placeholder
112 .child(
113 "history",
114 Panel::new()
115 .padding(12)
116 .bg_color("theme.surface")
117 .border(1)
118 .height(200)
119 .child(
120 "chart_label",
121 Label::new("Temperature History").weight("bold"),
122 ),
123 ),
124 )
125 .build()
126}Sourcepub fn label(self, label: impl Into<String>) -> Self
pub fn label(self, label: impl Into<String>) -> Self
Set the switch label
Examples found in repository?
examples/simple_plugin.rs (line 105)
10fn build_temperature_monitor() -> PluginValue {
11 Panel::new()
12 .padding(20)
13 .border(1)
14 .border_color("theme.border")
15 .shadow("md")
16 .width(350)
17 .child(
18 "header",
19 Stack::vertical()
20 .spacing(4)
21 .child(
22 "title",
23 Label::new("Temperature Monitor").size("xl").weight("bold"),
24 )
25 .child(
26 "subtitle",
27 Label::new("Real-time sensor readings")
28 .size("sm")
29 .color("theme.muted"),
30 ),
31 )
32 .child(
33 "controls",
34 Stack::vertical()
35 .spacing(16)
36 // Temperature display
37 .child(
38 "temp_display",
39 Panel::new()
40 .padding(16)
41 .bg_color("theme.surface")
42 .border(1)
43 .child(
44 "content",
45 Stack::vertical()
46 .spacing(8)
47 .align("center")
48 .child("label", Label::new("Current Temperature"))
49 .child(
50 "value",
51 Label::new("--°C")
52 .size("xl")
53 .weight("bold")
54 .bind_text("data.temperature.display"),
55 ),
56 ),
57 )
58 // Settings
59 .child(
60 "settings",
61 Stack::vertical()
62 .spacing(12)
63 // Temperature unit selector
64 .child(
65 "unit_row",
66 Stack::horizontal()
67 .spacing(8)
68 .child("label", Label::new("Unit:").width(100))
69 .child(
70 "celsius_btn",
71 Button::new("°C")
72 .variant("secondary")
73 .on_click("set_celsius")
74 .width(60),
75 )
76 .child(
77 "fahrenheit_btn",
78 Button::new("°F")
79 .variant("secondary")
80 .on_click("set_fahrenheit")
81 .width(60),
82 ),
83 )
84 // Alert threshold
85 .child(
86 "threshold_row",
87 Stack::vertical()
88 .spacing(8)
89 .child("threshold_label", Label::new("Alert Threshold"))
90 .child(
91 "threshold_slider",
92 Slider::new()
93 .min(0.0)
94 .max(100.0)
95 .step(1.0)
96 .value(30.0)
97 .on_change("on_threshold_change")
98 .bind_value("settings.alert_threshold"),
99 ),
100 )
101 // Enable alerts switch
102 .child(
103 "alerts_switch",
104 Switch::new()
105 .label("Enable High Temperature Alerts")
106 .checked(true)
107 .on_click("toggle_alerts")
108 .bind_checked("settings.alerts_enabled"),
109 ),
110 )
111 // History chart placeholder
112 .child(
113 "history",
114 Panel::new()
115 .padding(12)
116 .bg_color("theme.surface")
117 .border(1)
118 .height(200)
119 .child(
120 "chart_label",
121 Label::new("Temperature History").weight("bold"),
122 ),
123 ),
124 )
125 .build()
126}Sourcepub fn checked(self, checked: bool) -> Self
pub fn checked(self, checked: bool) -> Self
Set whether the switch is checked
Examples found in repository?
examples/simple_plugin.rs (line 106)
10fn build_temperature_monitor() -> PluginValue {
11 Panel::new()
12 .padding(20)
13 .border(1)
14 .border_color("theme.border")
15 .shadow("md")
16 .width(350)
17 .child(
18 "header",
19 Stack::vertical()
20 .spacing(4)
21 .child(
22 "title",
23 Label::new("Temperature Monitor").size("xl").weight("bold"),
24 )
25 .child(
26 "subtitle",
27 Label::new("Real-time sensor readings")
28 .size("sm")
29 .color("theme.muted"),
30 ),
31 )
32 .child(
33 "controls",
34 Stack::vertical()
35 .spacing(16)
36 // Temperature display
37 .child(
38 "temp_display",
39 Panel::new()
40 .padding(16)
41 .bg_color("theme.surface")
42 .border(1)
43 .child(
44 "content",
45 Stack::vertical()
46 .spacing(8)
47 .align("center")
48 .child("label", Label::new("Current Temperature"))
49 .child(
50 "value",
51 Label::new("--°C")
52 .size("xl")
53 .weight("bold")
54 .bind_text("data.temperature.display"),
55 ),
56 ),
57 )
58 // Settings
59 .child(
60 "settings",
61 Stack::vertical()
62 .spacing(12)
63 // Temperature unit selector
64 .child(
65 "unit_row",
66 Stack::horizontal()
67 .spacing(8)
68 .child("label", Label::new("Unit:").width(100))
69 .child(
70 "celsius_btn",
71 Button::new("°C")
72 .variant("secondary")
73 .on_click("set_celsius")
74 .width(60),
75 )
76 .child(
77 "fahrenheit_btn",
78 Button::new("°F")
79 .variant("secondary")
80 .on_click("set_fahrenheit")
81 .width(60),
82 ),
83 )
84 // Alert threshold
85 .child(
86 "threshold_row",
87 Stack::vertical()
88 .spacing(8)
89 .child("threshold_label", Label::new("Alert Threshold"))
90 .child(
91 "threshold_slider",
92 Slider::new()
93 .min(0.0)
94 .max(100.0)
95 .step(1.0)
96 .value(30.0)
97 .on_change("on_threshold_change")
98 .bind_value("settings.alert_threshold"),
99 ),
100 )
101 // Enable alerts switch
102 .child(
103 "alerts_switch",
104 Switch::new()
105 .label("Enable High Temperature Alerts")
106 .checked(true)
107 .on_click("toggle_alerts")
108 .bind_checked("settings.alerts_enabled"),
109 ),
110 )
111 // History chart placeholder
112 .child(
113 "history",
114 Panel::new()
115 .padding(12)
116 .bg_color("theme.surface")
117 .border(1)
118 .height(200)
119 .child(
120 "chart_label",
121 Label::new("Temperature History").weight("bold"),
122 ),
123 ),
124 )
125 .build()
126}Sourcepub fn on_click(self, handler: impl Into<String>) -> Self
pub fn on_click(self, handler: impl Into<String>) -> Self
Set the on_click handler
Examples found in repository?
examples/simple_plugin.rs (line 107)
10fn build_temperature_monitor() -> PluginValue {
11 Panel::new()
12 .padding(20)
13 .border(1)
14 .border_color("theme.border")
15 .shadow("md")
16 .width(350)
17 .child(
18 "header",
19 Stack::vertical()
20 .spacing(4)
21 .child(
22 "title",
23 Label::new("Temperature Monitor").size("xl").weight("bold"),
24 )
25 .child(
26 "subtitle",
27 Label::new("Real-time sensor readings")
28 .size("sm")
29 .color("theme.muted"),
30 ),
31 )
32 .child(
33 "controls",
34 Stack::vertical()
35 .spacing(16)
36 // Temperature display
37 .child(
38 "temp_display",
39 Panel::new()
40 .padding(16)
41 .bg_color("theme.surface")
42 .border(1)
43 .child(
44 "content",
45 Stack::vertical()
46 .spacing(8)
47 .align("center")
48 .child("label", Label::new("Current Temperature"))
49 .child(
50 "value",
51 Label::new("--°C")
52 .size("xl")
53 .weight("bold")
54 .bind_text("data.temperature.display"),
55 ),
56 ),
57 )
58 // Settings
59 .child(
60 "settings",
61 Stack::vertical()
62 .spacing(12)
63 // Temperature unit selector
64 .child(
65 "unit_row",
66 Stack::horizontal()
67 .spacing(8)
68 .child("label", Label::new("Unit:").width(100))
69 .child(
70 "celsius_btn",
71 Button::new("°C")
72 .variant("secondary")
73 .on_click("set_celsius")
74 .width(60),
75 )
76 .child(
77 "fahrenheit_btn",
78 Button::new("°F")
79 .variant("secondary")
80 .on_click("set_fahrenheit")
81 .width(60),
82 ),
83 )
84 // Alert threshold
85 .child(
86 "threshold_row",
87 Stack::vertical()
88 .spacing(8)
89 .child("threshold_label", Label::new("Alert Threshold"))
90 .child(
91 "threshold_slider",
92 Slider::new()
93 .min(0.0)
94 .max(100.0)
95 .step(1.0)
96 .value(30.0)
97 .on_change("on_threshold_change")
98 .bind_value("settings.alert_threshold"),
99 ),
100 )
101 // Enable alerts switch
102 .child(
103 "alerts_switch",
104 Switch::new()
105 .label("Enable High Temperature Alerts")
106 .checked(true)
107 .on_click("toggle_alerts")
108 .bind_checked("settings.alerts_enabled"),
109 ),
110 )
111 // History chart placeholder
112 .child(
113 "history",
114 Panel::new()
115 .padding(12)
116 .bg_color("theme.surface")
117 .border(1)
118 .height(200)
119 .child(
120 "chart_label",
121 Label::new("Temperature History").weight("bold"),
122 ),
123 ),
124 )
125 .build()
126}Sourcepub fn bind_checked(self, path: impl Into<String>) -> Self
pub fn bind_checked(self, path: impl Into<String>) -> Self
Bind the checked state to a data path
Examples found in repository?
examples/simple_plugin.rs (line 108)
10fn build_temperature_monitor() -> PluginValue {
11 Panel::new()
12 .padding(20)
13 .border(1)
14 .border_color("theme.border")
15 .shadow("md")
16 .width(350)
17 .child(
18 "header",
19 Stack::vertical()
20 .spacing(4)
21 .child(
22 "title",
23 Label::new("Temperature Monitor").size("xl").weight("bold"),
24 )
25 .child(
26 "subtitle",
27 Label::new("Real-time sensor readings")
28 .size("sm")
29 .color("theme.muted"),
30 ),
31 )
32 .child(
33 "controls",
34 Stack::vertical()
35 .spacing(16)
36 // Temperature display
37 .child(
38 "temp_display",
39 Panel::new()
40 .padding(16)
41 .bg_color("theme.surface")
42 .border(1)
43 .child(
44 "content",
45 Stack::vertical()
46 .spacing(8)
47 .align("center")
48 .child("label", Label::new("Current Temperature"))
49 .child(
50 "value",
51 Label::new("--°C")
52 .size("xl")
53 .weight("bold")
54 .bind_text("data.temperature.display"),
55 ),
56 ),
57 )
58 // Settings
59 .child(
60 "settings",
61 Stack::vertical()
62 .spacing(12)
63 // Temperature unit selector
64 .child(
65 "unit_row",
66 Stack::horizontal()
67 .spacing(8)
68 .child("label", Label::new("Unit:").width(100))
69 .child(
70 "celsius_btn",
71 Button::new("°C")
72 .variant("secondary")
73 .on_click("set_celsius")
74 .width(60),
75 )
76 .child(
77 "fahrenheit_btn",
78 Button::new("°F")
79 .variant("secondary")
80 .on_click("set_fahrenheit")
81 .width(60),
82 ),
83 )
84 // Alert threshold
85 .child(
86 "threshold_row",
87 Stack::vertical()
88 .spacing(8)
89 .child("threshold_label", Label::new("Alert Threshold"))
90 .child(
91 "threshold_slider",
92 Slider::new()
93 .min(0.0)
94 .max(100.0)
95 .step(1.0)
96 .value(30.0)
97 .on_change("on_threshold_change")
98 .bind_value("settings.alert_threshold"),
99 ),
100 )
101 // Enable alerts switch
102 .child(
103 "alerts_switch",
104 Switch::new()
105 .label("Enable High Temperature Alerts")
106 .checked(true)
107 .on_click("toggle_alerts")
108 .bind_checked("settings.alerts_enabled"),
109 ),
110 )
111 // History chart placeholder
112 .child(
113 "history",
114 Panel::new()
115 .padding(12)
116 .bg_color("theme.surface")
117 .border(1)
118 .height(200)
119 .child(
120 "chart_label",
121 Label::new("Temperature History").weight("bold"),
122 ),
123 ),
124 )
125 .build()
126}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Switch
impl RefUnwindSafe for Switch
impl Send for Switch
impl Sync for Switch
impl Unpin for Switch
impl UnsafeUnpin for Switch
impl UnwindSafe for Switch
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more