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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use crate::;
use ;
/// A label is a non-interactive toolbar item that displays text on the top or bottom part of a window.
///
/// Toolbar labels are used to show information to the user, such as status indicators, counters,
/// or other text that doesn't require user interaction. Unlike buttons or checkboxes, labels don't
/// generate events when clicked.
///
/// # Example
///
/// The following example creates a window with labels that display numbers in different formats,
/// which can be toggled using checkboxes:
///
/// ```rust, no_run
/// use appcui::prelude::*;
///
/// #[Window(events = ButtonEvents+CheckBoxEvents)]
/// struct NumberFormatsWindow {
/// increase_button: Handle<Button>,
/// decimal_label: Handle<toolbar::Label>,
/// hex_label: Handle<toolbar::Label>,
/// binary_label: Handle<toolbar::Label>,
/// show_decimal: Handle<CheckBox>,
/// show_hex: Handle<CheckBox>,
/// show_binary: Handle<CheckBox>,
/// number: u32,
/// }
///
/// impl NumberFormatsWindow {
/// fn new() -> Self {
/// let mut win = NumberFormatsWindow {
/// base: window!("'Number Formats',a:c,w:40,h:10"),
/// increase_button: Handle::None,
/// decimal_label: Handle::None,
/// hex_label: Handle::None,
/// binary_label: Handle::None,
/// show_decimal: Handle::None,
/// show_hex: Handle::None,
/// show_binary: Handle::None,
/// number: 42,
/// };
///
/// // Add the increase button
/// win.increase_button = win.add(button!("'Increase',w:15,a:l"));
///
/// // Add checkboxes to control visibility
/// win.show_decimal = win.add(checkbox!("'Show decimal',x:20,y:2,w:16,checked:true"));
/// win.show_hex = win.add(checkbox!("'Show hex',x:20,y:4,w:16,checked:true"));
/// win.show_binary = win.add(checkbox!("'Show binary',x:20,y:6,w:16,checked:true"));
///
/// // Create toolbar groups
/// let bottom_group = win.toolbar().create_group(toolbar::GroupPosition::BottomLeft);
/// let top_group = win.toolbar().create_group(toolbar::GroupPosition::TopRight);
///
/// // Add toolbar labels
/// win.decimal_label = win.toolbar().add(bottom_group, toolbar::Label::new("Dec:42"));
/// win.hex_label = win.toolbar().add(bottom_group, toolbar::Label::new("Hex:2A"));
/// win.binary_label = win.toolbar().add(top_group, toolbar::Label::new("Bin:101010"));
///
/// win
/// }
///
/// fn update_labels(&mut self) {
/// // Update all labels with the current number in different formats
/// let h = self.decimal_label;
/// let number = self.number;
/// if let Some(label) = self.toolbar().get_mut(h) {
/// label.set_content(&format!("Dec:{}", number));
/// }
/// let h = self.hex_label;
/// if let Some(label) = self.toolbar().get_mut(h) {
/// label.set_content(&format!("Hex:{:X}", number));
/// }
/// let h = self.binary_label;
/// if let Some(label) = self.toolbar().get_mut(h) {
/// label.set_content(&format!("Bin:{:b}", number));
/// }
/// }
/// }
///
/// impl ButtonEvents for NumberFormatsWindow {
/// fn on_pressed(&mut self, _handle: Handle<Button>) -> EventProcessStatus {
/// self.number += 1;
/// self.update_labels();
/// EventProcessStatus::Processed
/// }
/// }
///
/// impl CheckBoxEvents for NumberFormatsWindow {
/// fn on_status_changed(&mut self, handle: Handle<CheckBox>, checked: bool) -> EventProcessStatus {
/// if handle == self.show_decimal {
/// if let Some(label) = self.toolbar().get_mut(handle) {
/// label.set_visible(checked);
/// }
/// } else if handle == self.show_hex {
/// if let Some(label) = self.toolbar().get_mut(handle) {
/// label.set_visible(checked);
/// }
/// } else if handle == self.show_binary {
/// if let Some(label) = self.toolbar().get_mut(handle) {
/// label.set_visible(checked);
/// }
/// }
/// EventProcessStatus::Processed
/// }
/// }
///
/// fn main() -> Result<(), appcui::system::Error> {
/// let mut app = App::new().build()?;
/// app.add_window(NumberFormatsWindow::new());
/// app.run();
/// Ok(())
/// }
/// ```
add_to_toolbar_impl!;