euv_ui/component/toggle_group/view/struct.rs
1use super::*;
2
3/// One entry of the `euv_toggle_group` control.
4///
5/// Carries the machine value written into the selection signal, the label
6/// the user reads, and whether the entry can be picked at all.
7#[derive(Clone, Copy, CustomDebug, Data, Default, New)]
8pub struct EuvToggleGroupItem {
9 /// The machine value written into the selection signal when picked.
10 #[get(type(copy))]
11 pub value: &'static str,
12 /// The display label shown on the entry.
13 #[get(type(copy))]
14 pub label: &'static str,
15 /// Whether the entry is disabled.
16 #[get(type(copy))]
17 pub disabled: bool,
18}
19
20/// Props for the `euv_toggle_group` component.
21///
22/// The selection lives in a caller-owned `Signal<Vec<String>>` so the
23/// control takes part in two-way binding with the rest of the page. A
24/// single-selection group keeps one value in it; a multiple-selection
25/// group keeps every picked value.
26#[derive(Clone, CustomDebug, Default)]
27pub struct EuvToggleGroupProps {
28 /// The entries rendered in the control, in display order.
29 pub items: Vec<EuvToggleGroupItem>,
30 /// The signal holding the selected values.
31 pub values: Signal<Vec<String>>,
32 /// Whether more than one entry can be selected at a time.
33 pub multiple: bool,
34 /// Whether a single-selection group can be emptied by picking the
35 /// selected entry again.
36 pub collapsible: bool,
37 /// The visual variant of every entry.
38 pub variant: EuvToggleVariant,
39 /// The control size of every entry.
40 pub size: EuvToggleSize,
41 /// Optional callback receiving the selected values.
42 #[debug(skip)]
43 pub on_change: Option<Rc<dyn Fn(Vec<String>)>>,
44}
45
46/// The settings one entry of a toggle group is drawn with.
47///
48/// The entry carries everything the row needs, so the row is drawn by
49/// one call and the group keeps the shape of its own data.
50pub(crate) struct ToggleGroupEntry {
51 /// The entry the row stands for.
52 pub(crate) item: EuvToggleGroupItem,
53 /// Whether the entry is pressed.
54 pub(crate) is_pressed: bool,
55 /// The values the group has selected.
56 pub(crate) values: Signal<Vec<String>>,
57 /// Whether the group selects more than one entry.
58 pub(crate) multiple: bool,
59 /// Whether selecting an entry deselects the others.
60 pub(crate) collapsible: bool,
61 /// The visual variant of the row.
62 pub(crate) variant: EuvToggleVariant,
63 /// The control size of the row.
64 pub(crate) size: EuvToggleSize,
65 /// The value whose entry currently owns the roving tab stop.
66 pub(crate) focus_value: Signal<String>,
67 /// The callback fired when the selection changes.
68 pub(crate) on_change: Option<Rc<dyn Fn(Vec<String>)>>,
69}