pub struct Button(/* private fields */);Expand description
Builder for a Button component
Implementations§
Source§impl Button
impl Button
Sourcepub fn new(label: impl Into<String>) -> Self
pub fn new(label: impl Into<String>) -> Self
Create a new button with label
Examples found in repository?
examples/simple_plugin.rs (line 71)
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}
127
128/// Build a control panel with multiple inputs
129fn build_control_panel() -> PluginValue {
130 Panel::new()
131 .padding(16)
132 .border(2)
133 .border_color("theme.primary")
134 .child(
135 "form",
136 Stack::vertical()
137 .spacing(12)
138 .child("title", Label::new("Device Control Panel").size("lg"))
139 // Using the helper function for input rows
140 .child(
141 "name_row",
142 containers::input_row(
143 "Device Name",
144 Some(120),
145 Input::new()
146 .placeholder("Enter device name")
147 .on_change("on_name_change"),
148 Some(8),
149 ),
150 )
151 .child(
152 "id_row",
153 containers::input_row(
154 "Device ID",
155 Some(120),
156 Input::new()
157 .placeholder("Auto-generated")
158 .disabled(true)
159 .bind_value("device.id"),
160 Some(8),
161 ),
162 )
163 // Action buttons
164 .child(
165 "actions",
166 Stack::horizontal()
167 .spacing(8)
168 .justify("end")
169 .child(
170 "save_btn",
171 Button::new("Save")
172 .variant("primary")
173 .on_click("save_settings"),
174 )
175 .child(
176 "reset_btn",
177 Button::new("Reset")
178 .variant("secondary")
179 .on_click("reset_settings"),
180 )
181 .child(
182 "delete_btn",
183 Button::new("Delete")
184 .variant("danger")
185 .on_click("delete_device"),
186 ),
187 ),
188 )
189 .build()
190}Sourcepub fn variant(self, variant: impl Into<String>) -> Self
pub fn variant(self, variant: impl Into<String>) -> Self
Set the button variant (primary, secondary, danger, etc.)
Examples found in repository?
examples/simple_plugin.rs (line 72)
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}
127
128/// Build a control panel with multiple inputs
129fn build_control_panel() -> PluginValue {
130 Panel::new()
131 .padding(16)
132 .border(2)
133 .border_color("theme.primary")
134 .child(
135 "form",
136 Stack::vertical()
137 .spacing(12)
138 .child("title", Label::new("Device Control Panel").size("lg"))
139 // Using the helper function for input rows
140 .child(
141 "name_row",
142 containers::input_row(
143 "Device Name",
144 Some(120),
145 Input::new()
146 .placeholder("Enter device name")
147 .on_change("on_name_change"),
148 Some(8),
149 ),
150 )
151 .child(
152 "id_row",
153 containers::input_row(
154 "Device ID",
155 Some(120),
156 Input::new()
157 .placeholder("Auto-generated")
158 .disabled(true)
159 .bind_value("device.id"),
160 Some(8),
161 ),
162 )
163 // Action buttons
164 .child(
165 "actions",
166 Stack::horizontal()
167 .spacing(8)
168 .justify("end")
169 .child(
170 "save_btn",
171 Button::new("Save")
172 .variant("primary")
173 .on_click("save_settings"),
174 )
175 .child(
176 "reset_btn",
177 Button::new("Reset")
178 .variant("secondary")
179 .on_click("reset_settings"),
180 )
181 .child(
182 "delete_btn",
183 Button::new("Delete")
184 .variant("danger")
185 .on_click("delete_device"),
186 ),
187 ),
188 )
189 .build()
190}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 73)
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}
127
128/// Build a control panel with multiple inputs
129fn build_control_panel() -> PluginValue {
130 Panel::new()
131 .padding(16)
132 .border(2)
133 .border_color("theme.primary")
134 .child(
135 "form",
136 Stack::vertical()
137 .spacing(12)
138 .child("title", Label::new("Device Control Panel").size("lg"))
139 // Using the helper function for input rows
140 .child(
141 "name_row",
142 containers::input_row(
143 "Device Name",
144 Some(120),
145 Input::new()
146 .placeholder("Enter device name")
147 .on_change("on_name_change"),
148 Some(8),
149 ),
150 )
151 .child(
152 "id_row",
153 containers::input_row(
154 "Device ID",
155 Some(120),
156 Input::new()
157 .placeholder("Auto-generated")
158 .disabled(true)
159 .bind_value("device.id"),
160 Some(8),
161 ),
162 )
163 // Action buttons
164 .child(
165 "actions",
166 Stack::horizontal()
167 .spacing(8)
168 .justify("end")
169 .child(
170 "save_btn",
171 Button::new("Save")
172 .variant("primary")
173 .on_click("save_settings"),
174 )
175 .child(
176 "reset_btn",
177 Button::new("Reset")
178 .variant("secondary")
179 .on_click("reset_settings"),
180 )
181 .child(
182 "delete_btn",
183 Button::new("Delete")
184 .variant("danger")
185 .on_click("delete_device"),
186 ),
187 ),
188 )
189 .build()
190}Sourcepub fn width(self, width: i64) -> Self
pub fn width(self, width: i64) -> Self
Set width
Examples found in repository?
examples/simple_plugin.rs (line 74)
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 Button
impl RefUnwindSafe for Button
impl Send for Button
impl Sync for Button
impl Unpin for Button
impl UnsafeUnpin for Button
impl UnwindSafe for Button
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