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
//! Checkboxes and switches.
use mitsuami_core::{Element, ElementBuilder, EventValue, NodeId, Prop, Tweak, Ui, UiEvent, View, WidgetKind};
use mitsuami_reactive::{IntoValue, Signal};
pub struct Checkbox(Element);
widget!(Checkbox);
toggle!(Checkbox);
impl Checkbox {
pub fn new(label: impl IntoValue<String>) -> Checkbox {
let mut element = Element::new(WidgetKind::Checkbox);
element.prop(label.into_value(), Prop::Label);
Checkbox(element)
}
/// Shows the mixed state, whatever `checked` says: some of what the box
/// stands for is checked, as in a "Select all" box. A click leaves it,
/// checked or not as the platform decides (AppKit checks it, GTK flips
/// `checked`), and reports that with `on_change`: work out `mixed`
/// again from there.
pub fn mixed(mut self, mixed: impl IntoValue<bool>) -> Checkbox {
self.0.prop(mixed.into_value(), Prop::Mixed);
self
}
/// Raw platform settings, past the semantic ones: see [`Tweak`].
pub fn native(mut self, tweak: Tweak<Checkbox>) -> Checkbox {
tweak.apply(&mut self.0);
self
}
}
/// On/off switch. Most platforms draw no caption; the label is its
/// accessible name.
pub struct Switch(Element);
widget!(Switch);
toggle!(Switch);
impl Switch {
pub fn new(label: impl IntoValue<String>) -> Switch {
let mut element = Element::new(WidgetKind::Switch);
element.prop(label.into_value(), Prop::Label);
Switch(element)
}
/// Raw platform settings: see [`Tweak`]. Switches have no semantic
/// options past `checked`: what the platforms offer (sizes, GTK's
/// delayed state, WinUI's on and off text) is each one's own.
pub fn native(mut self, tweak: Tweak<Switch>) -> Switch {
tweak.apply(&mut self.0);
self
}
}
text_tag!(Checkbox, Label);
text_tag!(Switch, Label);