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
pub mod autocomplete;
pub mod button;
pub mod checkbox;
pub mod compare_times;
pub mod containers;
pub mod dropdown;
pub mod fan_chart;
pub mod filler;
pub mod just_draw;
pub mod line_plot;
pub mod menu;
pub mod persistent_split;
pub mod scatter_plot;
pub mod slider;
pub mod spinner;
pub mod text_box;
use crate::{EventCtx, GfxCtx, ScreenDims, ScreenPt};
pub trait WidgetImpl: downcast_rs::Downcast {
fn get_dims(&self) -> ScreenDims;
fn set_pos(&mut self, top_left: ScreenPt);
fn event(&mut self, ctx: &mut EventCtx, output: &mut WidgetOutput);
fn draw(&self, g: &mut GfxCtx);
fn can_restore(&self) -> bool {
false
}
fn restore(&mut self, _: &mut EventCtx, _prev: &Box<dyn WidgetImpl>) {
unreachable!()
}
}
#[derive(Debug, PartialEq)]
pub enum Outcome {
Clicked(String),
Changed,
Nothing,
}
pub struct WidgetOutput {
pub redo_layout: bool,
pub outcome: Outcome,
}
impl WidgetOutput {
pub fn new() -> WidgetOutput {
WidgetOutput {
redo_layout: false,
outcome: Outcome::Nothing,
}
}
}
downcast_rs::impl_downcast!(WidgetImpl);