nemo_plugin/
components.rs1use crate::builder::{Builder, LayoutBuilder};
4use nemo_plugin_api::PluginValue;
5
6pub struct Label(LayoutBuilder);
8
9impl Label {
10 pub fn new(text: impl Into<String>) -> Self {
12 Self(LayoutBuilder::new("label").attr("text", PluginValue::String(text.into())))
13 }
14
15 pub fn text(mut self, text: impl Into<String>) -> Self {
17 self.0 = self.0.attr("text", PluginValue::String(text.into()));
18 self
19 }
20
21 pub fn size(mut self, size: impl Into<String>) -> Self {
23 self.0 = self.0.attr("size", PluginValue::String(size.into()));
24 self
25 }
26
27 pub fn color(mut self, color: impl Into<String>) -> Self {
29 self.0 = self.0.attr("color", PluginValue::String(color.into()));
30 self
31 }
32
33 pub fn weight(mut self, weight: impl Into<String>) -> Self {
35 self.0 = self.0.attr("weight", PluginValue::String(weight.into()));
36 self
37 }
38
39 pub fn bind_text(mut self, path: impl Into<String>) -> Self {
41 self.0 = self.0.bind("text", path);
42 self
43 }
44
45 pub fn width(mut self, width: i64) -> Self {
47 self.0 = self.0.width(width);
48 self
49 }
50
51 pub fn height(mut self, height: i64) -> Self {
53 self.0 = self.0.height(height);
54 self
55 }
56}
57
58impl Builder for Label {
59 fn build(self) -> PluginValue {
60 self.0.build()
61 }
62}
63
64pub struct Input(LayoutBuilder);
66
67impl Input {
68 pub fn new() -> Self {
70 Self(LayoutBuilder::new("input"))
71 }
72
73 pub fn value(mut self, value: impl Into<String>) -> Self {
75 self.0 = self.0.attr("value", PluginValue::String(value.into()));
76 self
77 }
78
79 pub fn placeholder(mut self, placeholder: impl Into<String>) -> Self {
81 self.0 = self
82 .0
83 .attr("placeholder", PluginValue::String(placeholder.into()));
84 self
85 }
86
87 pub fn on_change(mut self, handler: impl Into<String>) -> Self {
89 self.0 = self.0.on("change", handler);
90 self
91 }
92
93 pub fn on_submit(mut self, handler: impl Into<String>) -> Self {
95 self.0 = self.0.on("submit", handler);
96 self
97 }
98
99 pub fn bind_value(mut self, path: impl Into<String>) -> Self {
101 self.0 = self.0.bind("value", path);
102 self
103 }
104
105 pub fn width(mut self, width: i64) -> Self {
107 self.0 = self.0.width(width);
108 self
109 }
110
111 pub fn disabled(mut self, disabled: bool) -> Self {
113 self.0 = self.0.attr("disabled", PluginValue::Bool(disabled));
114 self
115 }
116}
117
118impl Default for Input {
119 fn default() -> Self {
120 Self::new()
121 }
122}
123
124impl Builder for Input {
125 fn build(self) -> PluginValue {
126 self.0.build()
127 }
128}
129
130pub struct Button(LayoutBuilder);
132
133impl Button {
134 pub fn new(label: impl Into<String>) -> Self {
136 Self(LayoutBuilder::new("button").attr("label", PluginValue::String(label.into())))
137 }
138
139 pub fn label(mut self, label: impl Into<String>) -> Self {
141 self.0 = self.0.attr("label", PluginValue::String(label.into()));
142 self
143 }
144
145 pub fn variant(mut self, variant: impl Into<String>) -> Self {
147 self.0 = self.0.attr("variant", PluginValue::String(variant.into()));
148 self
149 }
150
151 pub fn on_click(mut self, handler: impl Into<String>) -> Self {
153 self.0 = self.0.on("click", handler);
154 self
155 }
156
157 pub fn disabled(mut self, disabled: bool) -> Self {
159 self.0 = self.0.attr("disabled", PluginValue::Bool(disabled));
160 self
161 }
162
163 pub fn width(mut self, width: i64) -> Self {
165 self.0 = self.0.width(width);
166 self
167 }
168}
169
170impl Builder for Button {
171 fn build(self) -> PluginValue {
172 self.0.build()
173 }
174}
175
176pub struct Switch(LayoutBuilder);
178
179impl Switch {
180 pub fn new() -> Self {
182 Self(LayoutBuilder::new("switch"))
183 }
184
185 pub fn label(mut self, label: impl Into<String>) -> Self {
187 self.0 = self.0.attr("label", PluginValue::String(label.into()));
188 self
189 }
190
191 pub fn checked(mut self, checked: bool) -> Self {
193 self.0 = self.0.attr("checked", PluginValue::Bool(checked));
194 self
195 }
196
197 pub fn on_click(mut self, handler: impl Into<String>) -> Self {
199 self.0 = self.0.on("click", handler);
200 self
201 }
202
203 pub fn bind_checked(mut self, path: impl Into<String>) -> Self {
205 self.0 = self.0.bind("checked", path);
206 self
207 }
208
209 pub fn disabled(mut self, disabled: bool) -> Self {
211 self.0 = self.0.attr("disabled", PluginValue::Bool(disabled));
212 self
213 }
214}
215
216impl Default for Switch {
217 fn default() -> Self {
218 Self::new()
219 }
220}
221
222impl Builder for Switch {
223 fn build(self) -> PluginValue {
224 self.0.build()
225 }
226}
227
228pub struct Slider(LayoutBuilder);
230
231impl Slider {
232 pub fn new() -> Self {
234 Self(LayoutBuilder::new("slider"))
235 }
236
237 pub fn value(mut self, value: f64) -> Self {
239 self.0 = self.0.attr("value", PluginValue::Float(value));
240 self
241 }
242
243 pub fn min(mut self, min: f64) -> Self {
245 self.0 = self.0.attr("min", PluginValue::Float(min));
246 self
247 }
248
249 pub fn max(mut self, max: f64) -> Self {
251 self.0 = self.0.attr("max", PluginValue::Float(max));
252 self
253 }
254
255 pub fn step(mut self, step: f64) -> Self {
257 self.0 = self.0.attr("step", PluginValue::Float(step));
258 self
259 }
260
261 pub fn on_change(mut self, handler: impl Into<String>) -> Self {
263 self.0 = self.0.on("change", handler);
264 self
265 }
266
267 pub fn bind_value(mut self, path: impl Into<String>) -> Self {
269 self.0 = self.0.bind("value", path);
270 self
271 }
272}
273
274impl Default for Slider {
275 fn default() -> Self {
276 Self::new()
277 }
278}
279
280impl Builder for Slider {
281 fn build(self) -> PluginValue {
282 self.0.build()
283 }
284}
285
286pub struct Image(LayoutBuilder);
288
289impl Image {
290 pub fn new(src: impl Into<String>) -> Self {
292 Self(LayoutBuilder::new("image").attr("src", PluginValue::String(src.into())))
293 }
294
295 pub fn src(mut self, src: impl Into<String>) -> Self {
297 self.0 = self.0.attr("src", PluginValue::String(src.into()));
298 self
299 }
300
301 pub fn alt(mut self, alt: impl Into<String>) -> Self {
303 self.0 = self.0.attr("alt", PluginValue::String(alt.into()));
304 self
305 }
306
307 pub fn width(mut self, width: i64) -> Self {
309 self.0 = self.0.width(width);
310 self
311 }
312
313 pub fn height(mut self, height: i64) -> Self {
315 self.0 = self.0.height(height);
316 self
317 }
318}
319
320impl Builder for Image {
321 fn build(self) -> PluginValue {
322 self.0.build()
323 }
324}