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
use ;
use Any;
/// Used to define a state of a [`widget`].
///
/// The state holds the logic of a widget which makes it interactive.
/// The state of a widget is made of a struct which implements this trait with its fields and its methods.
/// A state of a widget is represented by the current values of its properties.
/// Each state has to implement this trait.
/// Each state has to derive or implement the [Default](https://doc.rust-lang.org/std/default/trait.Default.html) and the [`AsAny`] traits.
/// A state is operating on the properties (components) of the widget, its parent or children, or the state's fields.
/// It is not mandatory to have a state for a widget (in this case it will be static).
///
/// # Example
/// ```
/// use orbtk::prelude::*;
///
/// #[derive(Default, AsAny)]
/// struct MyState {
/// count: usize
/// }
///
/// impl State for MyState {
/// fn init(&mut self, _registry: &mut Registry, _ctx: &mut Context) {
/// self.count = 42;
/// println!("MyState initialized.");
/// }
///
/// fn update(&mut self, _registry: &mut Registry, _ctx: &mut Context) {
/// self.count += 1;
/// println("MyState updated.");
/// }
///
/// fn update_post_layout(&mut self, _registry: &mut Registry, _ctx: &mut Context) {
/// println("MyState updated after layout is calculated.");
/// }
/// }
///
/// widget!(MyWidget<MyState>)
/// ```
///
/// [`widget`]: ./trait.Widget.html
/// [`AsAny`]: ./trait.AsAny.html