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
/// Macro to create environment for testing a single aspect.
///
/// ```
/// use sketchbook::aspects::update;
///
/// use sketchbook::derive_sketch;
/// use macro_rules_attribute::apply;
/// use sketchbook::aspects::update::SketchExt;
/// mod single_aspect {
/// use sketchbook::aspects::update;
/// use sketchbook::aspects::update::*;
///
/// sketchbook::env_for_aspect!(update);
///
/// sketchbook::compose! {
/// pub enum Events {
/// #[part]
/// Aspect(update::Event),
/// }
/// }
///
/// sketchbook::compose! {
/// #[derive(Default)]
/// pub struct Page {
/// #[part]
/// pub aspect: update::EnvData<EnvSpecificMarker>,
/// }
/// }
///
/// impl update::EnvSpecific for EnvSpecificMarker {
/// type Time = i16;
/// type Duration = i16;
/// type Num = f32;
///
/// fn default_update_rate() -> Self::Num {
/// 30.0
/// }
///
/// fn zero_duration() -> Self::Duration {
/// 0
/// }
///
/// fn duration_between(start: &Self::Time, end: &Self::Time) -> Self::Duration {
/// end - start
/// }
/// }
///
/// impl update::EnvPageExt<EnvSpecificMarker> for Page {
/// fn get_time(&mut self) -> update::TimeFor<EnvSpecificMarker> {
/// 0
/// }
/// }
/// }
///
/// #[apply(derive_sketch)]
/// #[sketch(env=single_aspect, aspects=(update))]
/// struct App {
/// #[page]
/// page: single_aspect::Page,
/// }
///
/// impl update::Handlers for App {
/// fn update(&mut self, delta_t: i16) {
/// println!("Update state, time since last update: {}", delta_t);
/// }
/// }
/// ```
=> ;
}
pub use env_for_aspect;