Struct pushrod::core::widget_store::WidgetStore

source ·
pub struct WidgetStore {
    pub widgets: Vec<WidgetContainer>,
    pub layout_managers: Vec<LayoutManagerContainer>,
}
Expand description

This is the WidgetStore, which contains a list of Widget objects for a GUI window.

Fields§

§widgets: Vec<WidgetContainer>§layout_managers: Vec<LayoutManagerContainer>

Implementations§

source§

impl WidgetStore

source

pub fn new() -> Self

Constructor, creates a new WidgetStore, assigning a top-level CanvasWidget as the very top-level widget. All Widget objects added will be a parent to this Widget, which is stored at ID 0. If this Widget object ever becomes invalidated, the entire window is force refreshed.

source

pub fn invalidate_all_widgets(&mut self)

Invalidates all Widgets in the GUI stack, forcing a redraw.

Examples found in repository?
examples/simple.rs (line 92)
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
    fn widget_clicked(&mut self, widget_id: i32, button: Button, widget_store: &mut WidgetStore) {
        match button {
            Button::Mouse(mouse_button) => {
                if mouse_button != MouseButton::Left {
                    return;
                }
            }
            _ => (),
        }

        match widget_store.get_name_for_widget_id(widget_id) {
            "BoxInLayoutWidgetButton1" => {
                let state = widget_store
                    .get_widget_for_name("BoxInLayoutWidget1")
                    .borrow_mut()
                    .config()
                    .get_toggle(CONFIG_WIDGET_HIDDEN);
                let button_text = if state == true {
                    String::from("Hide")
                } else {
                    String::from("Show")
                };

                widget_store
                    .get_widget_for_name("BoxInLayoutWidgetButton1")
                    .borrow_mut()
                    .set_config(CONFIG_DISPLAY_TEXT, Config::Text(button_text));

                widget_store
                    .get_widget_for_name("BoxInLayoutWidget1")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_HIDDEN, !state);

                widget_store.invalidate_all_widgets();
            }

            "BoxInLayoutWidgetButton2" => {
                let state = widget_store
                    .get_widget_for_name("BoxInLayoutWidget2")
                    .borrow_mut()
                    .config()
                    .get_toggle(CONFIG_WIDGET_DISABLED);
                let button_text = if state == true {
                    String::from("Disable")
                } else {
                    String::from("Enable")
                };

                widget_store
                    .get_widget_for_name("BoxInLayoutWidgetButton2")
                    .borrow_mut()
                    .set_config(CONFIG_DISPLAY_TEXT, Config::Text(button_text));

                widget_store
                    .get_widget_for_name("BoxInLayoutWidget2")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store
                    .get_widget_for_name("MiniBox1")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store
                    .get_widget_for_name("MiniBox2")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store
                    .get_widget_for_name("MiniBox3")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store
                    .get_widget_for_name("MiniBox4")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store.invalidate_all_widgets();
            }

            "BoxInLayoutWidgetButton3" => {
                widget_store
                    .get_widget_for_name("BoxInLayoutWidget3")
                    .borrow_mut()
                    .set_config(
                        CONFIG_MAIN_COLOR,
                        Config::Color([
                            (rand::random::<u8>() as f32 / 255.0),
                            (rand::random::<u8>() as f32 / 255.0),
                            (rand::random::<u8>() as f32 / 255.0),
                            1.0,
                        ]),
                    );
            }

            "RandomColorButton2" => match button {
                Button::Mouse(mouse_button) => {
                    if mouse_button == MouseButton::Left {
                        widget_store
                            .get_widget_for_name("ProgressWidget")
                            .borrow_mut()
                            .set_config(
                                CONFIG_SECONDARY_COLOR,
                                Config::Color([
                                    (rand::random::<u8>() as f32 / 255.0),
                                    (rand::random::<u8>() as f32 / 255.0),
                                    (rand::random::<u8>() as f32 / 255.0),
                                    1.0,
                                ]),
                            );
                    }
                }
                _ => (),
            },

            _ => (),
        }
    }
source

pub fn needs_repaint(&mut self) -> bool

Indicates whether or not a widget in the store has been invalidated.

source

pub fn add_widget(&mut self, name: &str, widget: Box<dyn Widget>) -> i32

Adds a Widget to the stack by name.

source

pub fn add_widget_to_parent( &mut self, name: &str, widget: Box<dyn Widget>, parent_id: i32, ) -> i32

Adds a Widget object to the parent specified by ID.

source

pub fn add_widget_to_layout_manager( &mut self, name: &str, widget: Box<dyn Widget>, manager_id: i32, position: Point, ) -> i32

source

pub fn get_parent_of(&mut self, widget_id: i32) -> i32

Gets the parent of the child Widget by ID. If the child has no assigned parent, the top-level CanvasWidget is returned (ID 0).

source

pub fn get_children_of(&self, parent_id: i32) -> Vec<i32>

Returns a list of the children that are owned by a parent ID. Does not return a list of siblings, only the first-level children.

source

pub fn get_widget_id_for_point(&mut self, point: Point) -> i32

Gets a Widget by ID for a point in the screen. If the GUI object is hidden or disabled, the ID is not returned. If no widget is found under the point specified, an ID of -1 is returned.

source

pub fn get_name_for_widget_id(&mut self, widget_id: i32) -> &str

Returns the name of the Widget by specified ID.

Examples found in repository?
examples/simple.rs (line 69)
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
    fn widget_clicked(&mut self, widget_id: i32, button: Button, widget_store: &mut WidgetStore) {
        match button {
            Button::Mouse(mouse_button) => {
                if mouse_button != MouseButton::Left {
                    return;
                }
            }
            _ => (),
        }

        match widget_store.get_name_for_widget_id(widget_id) {
            "BoxInLayoutWidgetButton1" => {
                let state = widget_store
                    .get_widget_for_name("BoxInLayoutWidget1")
                    .borrow_mut()
                    .config()
                    .get_toggle(CONFIG_WIDGET_HIDDEN);
                let button_text = if state == true {
                    String::from("Hide")
                } else {
                    String::from("Show")
                };

                widget_store
                    .get_widget_for_name("BoxInLayoutWidgetButton1")
                    .borrow_mut()
                    .set_config(CONFIG_DISPLAY_TEXT, Config::Text(button_text));

                widget_store
                    .get_widget_for_name("BoxInLayoutWidget1")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_HIDDEN, !state);

                widget_store.invalidate_all_widgets();
            }

            "BoxInLayoutWidgetButton2" => {
                let state = widget_store
                    .get_widget_for_name("BoxInLayoutWidget2")
                    .borrow_mut()
                    .config()
                    .get_toggle(CONFIG_WIDGET_DISABLED);
                let button_text = if state == true {
                    String::from("Disable")
                } else {
                    String::from("Enable")
                };

                widget_store
                    .get_widget_for_name("BoxInLayoutWidgetButton2")
                    .borrow_mut()
                    .set_config(CONFIG_DISPLAY_TEXT, Config::Text(button_text));

                widget_store
                    .get_widget_for_name("BoxInLayoutWidget2")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store
                    .get_widget_for_name("MiniBox1")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store
                    .get_widget_for_name("MiniBox2")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store
                    .get_widget_for_name("MiniBox3")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store
                    .get_widget_for_name("MiniBox4")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store.invalidate_all_widgets();
            }

            "BoxInLayoutWidgetButton3" => {
                widget_store
                    .get_widget_for_name("BoxInLayoutWidget3")
                    .borrow_mut()
                    .set_config(
                        CONFIG_MAIN_COLOR,
                        Config::Color([
                            (rand::random::<u8>() as f32 / 255.0),
                            (rand::random::<u8>() as f32 / 255.0),
                            (rand::random::<u8>() as f32 / 255.0),
                            1.0,
                        ]),
                    );
            }

            "RandomColorButton2" => match button {
                Button::Mouse(mouse_button) => {
                    if mouse_button == MouseButton::Left {
                        widget_store
                            .get_widget_for_name("ProgressWidget")
                            .borrow_mut()
                            .set_config(
                                CONFIG_SECONDARY_COLOR,
                                Config::Color([
                                    (rand::random::<u8>() as f32 / 255.0),
                                    (rand::random::<u8>() as f32 / 255.0),
                                    (rand::random::<u8>() as f32 / 255.0),
                                    1.0,
                                ]),
                            );
                    }
                }
                _ => (),
            },

            _ => (),
        }
    }

    fn timer_triggered(&mut self, widget_id: i32, widget_store: &mut WidgetStore) {
        match widget_store.get_name_for_widget_id(widget_id) {
            "HelloWorldTimer" => {
                if self.manipulated_color == 1 {
                    if self.color_direction == 1 {
                        if self.red_value == 255 {
                            self.color_direction = -1;
                        }
                    } else {
                        if self.red_value == 0 {
                            self.color_direction = 1;
                            self.manipulated_color = 2;
                        }
                    }

                    self.red_value += self.color_direction;
                } else if self.manipulated_color == 2 {
                    if self.color_direction == 1 {
                        if self.green_value == 255 {
                            self.color_direction = -1;
                        }
                    } else {
                        if self.green_value == 0 {
                            self.color_direction = 1;
                            self.manipulated_color = 3;
                        }
                    }

                    self.green_value += self.color_direction;
                } else if self.manipulated_color == 3 {
                    if self.color_direction == 1 {
                        if self.blue_value == 255 {
                            self.color_direction = -1;
                        }
                    } else {
                        if self.blue_value == 0 {
                            self.color_direction = 1;
                            self.manipulated_color = 1;
                        }
                    }

                    self.blue_value += self.color_direction;
                }

                widget_store
                    .get_widget_for_name("TextWidget")
                    .borrow_mut()
                    .set_color(
                        CONFIG_TEXT_COLOR,
                        [
                            (self.red_value as f32 / 255.0),
                            (self.green_value as f32 / 255.0),
                            (self.blue_value as f32 / 255.0),
                            1.0,
                        ],
                    );
            }

            "TimerWidget1" => {
                if self.animated {
                    self.progress += 1;

                    if self.progress > 100 {
                        self.progress = 0;
                    }

                    widget_store
                        .get_widget_for_name("ProgressWidget")
                        .borrow_mut()
                        .set_config(CONFIG_PROGRESS, Config::Numeric(self.progress as u64));

                    widget_store
                        .get_widget_for_name("ProgressText1")
                        .borrow_mut()
                        .set_text(CONFIG_DISPLAY_TEXT, format!("{} %", self.progress));
                }
            }

            _ => {}
        };
    }

    fn mouse_entered(&mut self, widget_id: i32, widget_store: &mut WidgetStore) {
        // When a mouse enters a widget, the ID will get modified; modify the debug widget
        // with the ID that was specified.
        let widget_name = String::from(widget_store.get_name_for_widget_id(widget_id));
        let widget_point = widget_store
            .get_widget_for_id(widget_id)
            .borrow_mut()
            .config()
            .get_point(CONFIG_ORIGIN);
        let widget_size = widget_store
            .get_widget_for_id(widget_id)
            .borrow_mut()
            .config()
            .get_size(CONFIG_BODY_SIZE);

        widget_store
            .get_widget_for_name("DebugText1")
            .borrow_mut()
            .set_config(
                CONFIG_DISPLAY_TEXT,
                Config::Text(format!("Current Widget: {} ({})", widget_id, widget_name)).clone(),
            );

        widget_store
            .get_widget_for_name("DebugText2")
            .borrow_mut()
            .set_config(
                CONFIG_DISPLAY_TEXT,
                Config::Text(format!(
                    "Dimensions: x={} y={} w={} h={}",
                    widget_point.x, widget_point.y, widget_size.w, widget_size.h
                ))
                .clone(),
            );
    }

    fn widget_selected(
        &mut self,
        widget_id: i32,
        _button: Button,
        selected: bool,
        widget_store: &mut WidgetStore,
    ) {
        match widget_store.get_name_for_widget_id(widget_id) {
            "AnimateButton1" => {
                self.animated = selected;
            }

            "DebugCheck1" => {
                widget_store
                    .get_widget_for_name("DebugText1")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_HIDDEN, !selected);
                widget_store
                    .get_widget_for_name("DebugText2")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_HIDDEN, !selected);
            }
            _ => (),
        }
    }

    fn widget_moved(&mut self, widget_id: i32, point: Point, widget_store: &mut WidgetStore) {
        match widget_store.get_name_for_widget_id(widget_id) {
            "BoxInLayoutWidget3" => {
                eprintln!("Reposition text inside BoxInLayoutWidget1");

                widget_store
                    .get_widget_for_name("LeftJustifiedText")
                    .borrow_mut()
                    .set_point(CONFIG_ORIGIN, point.x + 16, point.y + 10);

                widget_store
                    .get_widget_for_name("CenterJustifiedText")
                    .borrow_mut()
                    .set_point(CONFIG_ORIGIN, point.x + 16, point.y + 100 - 24);

                widget_store
                    .get_widget_for_name("RightJustifiedText")
                    .borrow_mut()
                    .set_point(CONFIG_ORIGIN, point.x + 16, point.y + 200 - 54);

                let layout_size2 = widget_store
                    .get_widget_for_name("BoxInLayoutWidget2")
                    .borrow_mut()
                    .config()
                    .get_size(CONFIG_BODY_SIZE);

                eprintln!("Reposition text inside BoxInLayoutWidget2");

                let box2_point = widget_store
                    .get_widget_for_name("BoxInLayoutWidget2")
                    .borrow_mut()
                    .config()
                    .get_point(CONFIG_ORIGIN);

                widget_store
                    .get_widget_for_name("MiniBox1")
                    .borrow_mut()
                    .set_point(CONFIG_ORIGIN, box2_point.x + 10, box2_point.y + 10);

                widget_store
                    .get_widget_for_name("MiniBox2")
                    .borrow_mut()
                    .set_point(
                        CONFIG_ORIGIN,
                        box2_point.x + (layout_size2.w / 2) + 4,
                        box2_point.y + 10,
                    );

                widget_store
                    .get_widget_for_name("MiniBox3")
                    .borrow_mut()
                    .set_point(
                        CONFIG_ORIGIN,
                        box2_point.x + 10,
                        box2_point.y + (layout_size2.h / 2) + 4,
                    );

                widget_store
                    .get_widget_for_name("MiniBox4")
                    .borrow_mut()
                    .set_point(
                        CONFIG_ORIGIN,
                        box2_point.x + (layout_size2.w / 2) + 4,
                        box2_point.y + (layout_size2.h / 2) + 4,
                    );
            }
            _ => (),
        }
    }

    fn widget_resized(&mut self, widget_id: i32, _size: Size, widget_store: &mut WidgetStore) {
        match widget_store.get_name_for_widget_id(widget_id) {
            "BoxInLayoutWidget3" => {
                let layout_size = widget_store
                    .get_widget_for_name("BoxInLayoutWidget1")
                    .borrow_mut()
                    .config()
                    .get_size(CONFIG_BODY_SIZE);

                eprintln!("Resize text inside BoxInLayoutWidget1");

                widget_store
                    .get_widget_for_name("LeftJustifiedText")
                    .borrow_mut()
                    .set_size(CONFIG_BODY_SIZE, layout_size.w - 32, 32);

                widget_store
                    .get_widget_for_name("CenterJustifiedText")
                    .borrow_mut()
                    .set_size(CONFIG_BODY_SIZE, layout_size.w - 32, 32);

                widget_store
                    .get_widget_for_name("RightJustifiedText")
                    .borrow_mut()
                    .set_size(CONFIG_BODY_SIZE, layout_size.w - 32, 32);

                let layout_size2 = widget_store
                    .get_widget_for_name("BoxInLayoutWidget2")
                    .borrow_mut()
                    .config()
                    .get_size(CONFIG_BODY_SIZE);

                eprintln!("Resize boxes inside BoxInLayoutWidget2: {:?}", layout_size2);

                widget_store
                    .get_widget_for_name("MiniBox1")
                    .borrow_mut()
                    .set_size(
                        CONFIG_BODY_SIZE,
                        (layout_size2.w / 2) - 12,
                        (layout_size2.h / 2) - 12,
                    );

                widget_store
                    .get_widget_for_name("MiniBox2")
                    .borrow_mut()
                    .set_size(
                        CONFIG_BODY_SIZE,
                        (layout_size2.w / 2) - 12,
                        (layout_size2.h / 2) - 12,
                    );

                widget_store
                    .get_widget_for_name("MiniBox3")
                    .borrow_mut()
                    .set_size(
                        CONFIG_BODY_SIZE,
                        (layout_size2.w / 2) - 12,
                        (layout_size2.h / 2) - 12,
                    );

                widget_store
                    .get_widget_for_name("MiniBox4")
                    .borrow_mut()
                    .set_size(
                        CONFIG_BODY_SIZE,
                        (layout_size2.w / 2) - 12,
                        (layout_size2.h / 2) - 12,
                    );
            }
            _ => (),
        }
    }
source

pub fn get_widget_id_for_name(&mut self, name: &str) -> i32

Retrieves a widget ID for the name specified. Returns top-level CanvasWidget ID if not found.

source

pub fn get_widget_for_name(&mut self, name: &str) -> &RefCell<Box<dyn Widget>>

Retrieves a reference to a Widget by its name. Returns the top-level CanvasWidget object if not found.

Examples found in repository?
examples/simple.rs (line 72)
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
    fn widget_clicked(&mut self, widget_id: i32, button: Button, widget_store: &mut WidgetStore) {
        match button {
            Button::Mouse(mouse_button) => {
                if mouse_button != MouseButton::Left {
                    return;
                }
            }
            _ => (),
        }

        match widget_store.get_name_for_widget_id(widget_id) {
            "BoxInLayoutWidgetButton1" => {
                let state = widget_store
                    .get_widget_for_name("BoxInLayoutWidget1")
                    .borrow_mut()
                    .config()
                    .get_toggle(CONFIG_WIDGET_HIDDEN);
                let button_text = if state == true {
                    String::from("Hide")
                } else {
                    String::from("Show")
                };

                widget_store
                    .get_widget_for_name("BoxInLayoutWidgetButton1")
                    .borrow_mut()
                    .set_config(CONFIG_DISPLAY_TEXT, Config::Text(button_text));

                widget_store
                    .get_widget_for_name("BoxInLayoutWidget1")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_HIDDEN, !state);

                widget_store.invalidate_all_widgets();
            }

            "BoxInLayoutWidgetButton2" => {
                let state = widget_store
                    .get_widget_for_name("BoxInLayoutWidget2")
                    .borrow_mut()
                    .config()
                    .get_toggle(CONFIG_WIDGET_DISABLED);
                let button_text = if state == true {
                    String::from("Disable")
                } else {
                    String::from("Enable")
                };

                widget_store
                    .get_widget_for_name("BoxInLayoutWidgetButton2")
                    .borrow_mut()
                    .set_config(CONFIG_DISPLAY_TEXT, Config::Text(button_text));

                widget_store
                    .get_widget_for_name("BoxInLayoutWidget2")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store
                    .get_widget_for_name("MiniBox1")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store
                    .get_widget_for_name("MiniBox2")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store
                    .get_widget_for_name("MiniBox3")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store
                    .get_widget_for_name("MiniBox4")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_DISABLED, !state);

                widget_store.invalidate_all_widgets();
            }

            "BoxInLayoutWidgetButton3" => {
                widget_store
                    .get_widget_for_name("BoxInLayoutWidget3")
                    .borrow_mut()
                    .set_config(
                        CONFIG_MAIN_COLOR,
                        Config::Color([
                            (rand::random::<u8>() as f32 / 255.0),
                            (rand::random::<u8>() as f32 / 255.0),
                            (rand::random::<u8>() as f32 / 255.0),
                            1.0,
                        ]),
                    );
            }

            "RandomColorButton2" => match button {
                Button::Mouse(mouse_button) => {
                    if mouse_button == MouseButton::Left {
                        widget_store
                            .get_widget_for_name("ProgressWidget")
                            .borrow_mut()
                            .set_config(
                                CONFIG_SECONDARY_COLOR,
                                Config::Color([
                                    (rand::random::<u8>() as f32 / 255.0),
                                    (rand::random::<u8>() as f32 / 255.0),
                                    (rand::random::<u8>() as f32 / 255.0),
                                    1.0,
                                ]),
                            );
                    }
                }
                _ => (),
            },

            _ => (),
        }
    }

    fn timer_triggered(&mut self, widget_id: i32, widget_store: &mut WidgetStore) {
        match widget_store.get_name_for_widget_id(widget_id) {
            "HelloWorldTimer" => {
                if self.manipulated_color == 1 {
                    if self.color_direction == 1 {
                        if self.red_value == 255 {
                            self.color_direction = -1;
                        }
                    } else {
                        if self.red_value == 0 {
                            self.color_direction = 1;
                            self.manipulated_color = 2;
                        }
                    }

                    self.red_value += self.color_direction;
                } else if self.manipulated_color == 2 {
                    if self.color_direction == 1 {
                        if self.green_value == 255 {
                            self.color_direction = -1;
                        }
                    } else {
                        if self.green_value == 0 {
                            self.color_direction = 1;
                            self.manipulated_color = 3;
                        }
                    }

                    self.green_value += self.color_direction;
                } else if self.manipulated_color == 3 {
                    if self.color_direction == 1 {
                        if self.blue_value == 255 {
                            self.color_direction = -1;
                        }
                    } else {
                        if self.blue_value == 0 {
                            self.color_direction = 1;
                            self.manipulated_color = 1;
                        }
                    }

                    self.blue_value += self.color_direction;
                }

                widget_store
                    .get_widget_for_name("TextWidget")
                    .borrow_mut()
                    .set_color(
                        CONFIG_TEXT_COLOR,
                        [
                            (self.red_value as f32 / 255.0),
                            (self.green_value as f32 / 255.0),
                            (self.blue_value as f32 / 255.0),
                            1.0,
                        ],
                    );
            }

            "TimerWidget1" => {
                if self.animated {
                    self.progress += 1;

                    if self.progress > 100 {
                        self.progress = 0;
                    }

                    widget_store
                        .get_widget_for_name("ProgressWidget")
                        .borrow_mut()
                        .set_config(CONFIG_PROGRESS, Config::Numeric(self.progress as u64));

                    widget_store
                        .get_widget_for_name("ProgressText1")
                        .borrow_mut()
                        .set_text(CONFIG_DISPLAY_TEXT, format!("{} %", self.progress));
                }
            }

            _ => {}
        };
    }

    fn mouse_entered(&mut self, widget_id: i32, widget_store: &mut WidgetStore) {
        // When a mouse enters a widget, the ID will get modified; modify the debug widget
        // with the ID that was specified.
        let widget_name = String::from(widget_store.get_name_for_widget_id(widget_id));
        let widget_point = widget_store
            .get_widget_for_id(widget_id)
            .borrow_mut()
            .config()
            .get_point(CONFIG_ORIGIN);
        let widget_size = widget_store
            .get_widget_for_id(widget_id)
            .borrow_mut()
            .config()
            .get_size(CONFIG_BODY_SIZE);

        widget_store
            .get_widget_for_name("DebugText1")
            .borrow_mut()
            .set_config(
                CONFIG_DISPLAY_TEXT,
                Config::Text(format!("Current Widget: {} ({})", widget_id, widget_name)).clone(),
            );

        widget_store
            .get_widget_for_name("DebugText2")
            .borrow_mut()
            .set_config(
                CONFIG_DISPLAY_TEXT,
                Config::Text(format!(
                    "Dimensions: x={} y={} w={} h={}",
                    widget_point.x, widget_point.y, widget_size.w, widget_size.h
                ))
                .clone(),
            );
    }

    fn widget_selected(
        &mut self,
        widget_id: i32,
        _button: Button,
        selected: bool,
        widget_store: &mut WidgetStore,
    ) {
        match widget_store.get_name_for_widget_id(widget_id) {
            "AnimateButton1" => {
                self.animated = selected;
            }

            "DebugCheck1" => {
                widget_store
                    .get_widget_for_name("DebugText1")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_HIDDEN, !selected);
                widget_store
                    .get_widget_for_name("DebugText2")
                    .borrow_mut()
                    .set_toggle(CONFIG_WIDGET_HIDDEN, !selected);
            }
            _ => (),
        }
    }

    fn widget_moved(&mut self, widget_id: i32, point: Point, widget_store: &mut WidgetStore) {
        match widget_store.get_name_for_widget_id(widget_id) {
            "BoxInLayoutWidget3" => {
                eprintln!("Reposition text inside BoxInLayoutWidget1");

                widget_store
                    .get_widget_for_name("LeftJustifiedText")
                    .borrow_mut()
                    .set_point(CONFIG_ORIGIN, point.x + 16, point.y + 10);

                widget_store
                    .get_widget_for_name("CenterJustifiedText")
                    .borrow_mut()
                    .set_point(CONFIG_ORIGIN, point.x + 16, point.y + 100 - 24);

                widget_store
                    .get_widget_for_name("RightJustifiedText")
                    .borrow_mut()
                    .set_point(CONFIG_ORIGIN, point.x + 16, point.y + 200 - 54);

                let layout_size2 = widget_store
                    .get_widget_for_name("BoxInLayoutWidget2")
                    .borrow_mut()
                    .config()
                    .get_size(CONFIG_BODY_SIZE);

                eprintln!("Reposition text inside BoxInLayoutWidget2");

                let box2_point = widget_store
                    .get_widget_for_name("BoxInLayoutWidget2")
                    .borrow_mut()
                    .config()
                    .get_point(CONFIG_ORIGIN);

                widget_store
                    .get_widget_for_name("MiniBox1")
                    .borrow_mut()
                    .set_point(CONFIG_ORIGIN, box2_point.x + 10, box2_point.y + 10);

                widget_store
                    .get_widget_for_name("MiniBox2")
                    .borrow_mut()
                    .set_point(
                        CONFIG_ORIGIN,
                        box2_point.x + (layout_size2.w / 2) + 4,
                        box2_point.y + 10,
                    );

                widget_store
                    .get_widget_for_name("MiniBox3")
                    .borrow_mut()
                    .set_point(
                        CONFIG_ORIGIN,
                        box2_point.x + 10,
                        box2_point.y + (layout_size2.h / 2) + 4,
                    );

                widget_store
                    .get_widget_for_name("MiniBox4")
                    .borrow_mut()
                    .set_point(
                        CONFIG_ORIGIN,
                        box2_point.x + (layout_size2.w / 2) + 4,
                        box2_point.y + (layout_size2.h / 2) + 4,
                    );
            }
            _ => (),
        }
    }

    fn widget_resized(&mut self, widget_id: i32, _size: Size, widget_store: &mut WidgetStore) {
        match widget_store.get_name_for_widget_id(widget_id) {
            "BoxInLayoutWidget3" => {
                let layout_size = widget_store
                    .get_widget_for_name("BoxInLayoutWidget1")
                    .borrow_mut()
                    .config()
                    .get_size(CONFIG_BODY_SIZE);

                eprintln!("Resize text inside BoxInLayoutWidget1");

                widget_store
                    .get_widget_for_name("LeftJustifiedText")
                    .borrow_mut()
                    .set_size(CONFIG_BODY_SIZE, layout_size.w - 32, 32);

                widget_store
                    .get_widget_for_name("CenterJustifiedText")
                    .borrow_mut()
                    .set_size(CONFIG_BODY_SIZE, layout_size.w - 32, 32);

                widget_store
                    .get_widget_for_name("RightJustifiedText")
                    .borrow_mut()
                    .set_size(CONFIG_BODY_SIZE, layout_size.w - 32, 32);

                let layout_size2 = widget_store
                    .get_widget_for_name("BoxInLayoutWidget2")
                    .borrow_mut()
                    .config()
                    .get_size(CONFIG_BODY_SIZE);

                eprintln!("Resize boxes inside BoxInLayoutWidget2: {:?}", layout_size2);

                widget_store
                    .get_widget_for_name("MiniBox1")
                    .borrow_mut()
                    .set_size(
                        CONFIG_BODY_SIZE,
                        (layout_size2.w / 2) - 12,
                        (layout_size2.h / 2) - 12,
                    );

                widget_store
                    .get_widget_for_name("MiniBox2")
                    .borrow_mut()
                    .set_size(
                        CONFIG_BODY_SIZE,
                        (layout_size2.w / 2) - 12,
                        (layout_size2.h / 2) - 12,
                    );

                widget_store
                    .get_widget_for_name("MiniBox3")
                    .borrow_mut()
                    .set_size(
                        CONFIG_BODY_SIZE,
                        (layout_size2.w / 2) - 12,
                        (layout_size2.h / 2) - 12,
                    );

                widget_store
                    .get_widget_for_name("MiniBox4")
                    .borrow_mut()
                    .set_size(
                        CONFIG_BODY_SIZE,
                        (layout_size2.w / 2) - 12,
                        (layout_size2.h / 2) - 12,
                    );
            }
            _ => (),
        }
    }
source

pub fn get_widget_for_id(&mut self, id: i32) -> &RefCell<Box<dyn Widget>>

Retrieves a Widget by its ID.

Examples found in repository?
examples/simple.rs (line 266)
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
    fn mouse_entered(&mut self, widget_id: i32, widget_store: &mut WidgetStore) {
        // When a mouse enters a widget, the ID will get modified; modify the debug widget
        // with the ID that was specified.
        let widget_name = String::from(widget_store.get_name_for_widget_id(widget_id));
        let widget_point = widget_store
            .get_widget_for_id(widget_id)
            .borrow_mut()
            .config()
            .get_point(CONFIG_ORIGIN);
        let widget_size = widget_store
            .get_widget_for_id(widget_id)
            .borrow_mut()
            .config()
            .get_size(CONFIG_BODY_SIZE);

        widget_store
            .get_widget_for_name("DebugText1")
            .borrow_mut()
            .set_config(
                CONFIG_DISPLAY_TEXT,
                Config::Text(format!("Current Widget: {} ({})", widget_id, widget_name)).clone(),
            );

        widget_store
            .get_widget_for_name("DebugText2")
            .borrow_mut()
            .set_config(
                CONFIG_DISPLAY_TEXT,
                Config::Text(format!(
                    "Dimensions: x={} y={} w={} h={}",
                    widget_point.x, widget_point.y, widget_size.w, widget_size.h
                ))
                .clone(),
            );
    }
source

pub fn handle_event( &mut self, widget_id: i32, event: CallbackEvent, ) -> Option<CallbackEvent>

Handles a specific event generated by the OS or the GUI interaction.

source

pub fn inject_event(&mut self, event: CallbackEvent)

Injects an event to all widgets, allowing them to exhibit custom event handling behavior if required. This is usually used in cases where special triggering needs to take place, like an indication of a timeout or transient error.

source

pub fn add_layout_manager(&mut self, manager: Box<dyn LayoutManager>) -> i32

source

pub fn do_layout_for_manager(&mut self, manager_id: i32)

source

pub fn resize_layout_managers(&mut self, _w: u32, _h: u32)

source

pub fn set_hidden(&mut self, widget_id: i32, state: bool)

Sets the hidden toggle for a parent, and all of its children.

source

pub fn draw( &mut self, widget_id: i32, c: Context, g: &mut GlGraphics, original_fbo: GLuint, )

Draws a Widget by ID, and any children contained in that Widget. Submitting a draw request from ID 0 will redraw the entire screen.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> SetParameter for T

source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.