Skip to main content

Switch

Struct Switch 

Source
pub struct Switch(/* private fields */);
Expand description

Builder for a Switch/Toggle component

Implementations§

Source§

impl Switch

Source

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}
Source

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}
Source

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}
Source

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}
Source

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}
Source

pub fn disabled(self, disabled: bool) -> Self

Set whether the switch is disabled

Trait Implementations§

Source§

impl Builder for Switch

Source§

fn build(self) -> PluginValue

Convert this builder to a PluginValue
Source§

impl Default for Switch

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.