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
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
//! Implementation of the `paws::build!` macro.
// used in doc comments
use crateUi;
/// Convenience macro for `push`ing and `pop`ping groups automatically.
///
/// Since it can be quite annoying to have to call [`Ui::push`] and [`Ui::pop`] manually, this macro aims to solve that
/// by offloading the work to the Rust compiler. It also helps show how groups are nested, further aiding readability.
///
/// # Syntax
///
/// The syntax for using this macro is:
/// ```
/// # use paws::{Ui, NoRenderer, Layout};
/// # struct Window;
/// # impl Window {
/// # fn begin(&mut self, _ui: &mut Ui<NoRenderer>, (): ()) {}
/// # fn end(&mut self) {}
/// # }
/// # let mut ui = Ui::new(NoRenderer);
/// # ui.root((800.0, 600.0), Layout::Freeform);
/// # let mut element = Window;
/// # let args = ();
/// paws::build! {
/// group ui => ((800.0, 600.0), Layout::Freeform) { }
/// process element, &mut ui => (args) { }
/// // or any old statement
/// }
/// ```
///
/// ## `group`
///
/// `group`'s primary use case is for pushing and popping UI groups. A `group` is transformed like so:
/// ```ignore
/// paws::build! {
/// group ui => ((300.0, 300.0), Layout::Freeform) {
/// println!("hi!");
/// }
/// }
/// // becomes
/// ui.push((300.0, 300.0), Layout::Freeform);
/// {
/// println!("hi!");
/// }
/// ui.pop();
/// ```
///
/// This module's examples use a real `Ui`, but `group` will work with anything that implements methods called `push`
/// and `pop`, so you can even use it with `Vec<T>` (although that doesn't mean you should):
/// ```
/// let mut stack: Vec<i32> = Vec::new();
/// paws::build! {
/// group stack => (3) {
/// assert_eq!(*stack.last().unwrap(), 3);
/// }
/// }
/// ```
///
/// ## `process`
///
/// `process`'s primary use case is for user elements that may nest other groups, like panels, menus, windows, etc.
/// Contrary to `group`, this will call methods called `begin` and `end`, as they better signify what is actually done.
/// Here's an example of how one might implement a window:
/// ```
/// # use paws::{Ui, NoRenderer, Layout};
/// use paws::Vector;
///
/// // of course, your window will contain actual data like its position, maybe also size, etc.
/// struct Window;
///
/// impl Window {
/// // for this example though, the size of the window will be defined by the caller.
/// fn begin(&mut self, _ui: &mut Ui<NoRenderer>, _size: impl Into<Vector>, _title: &str) {}
/// fn end(&mut self) {}
/// }
/// # let mut ui = Ui::new(NoRenderer);
/// # ui.root((800.0, 600.0), Layout::Freeform);
///
/// let mut window = Window;
/// paws::build! {
/// process window, &mut ui => ((300.0, 500.0), "Hello, world") {
/// // draw stuff inside the window
/// }
/// }
/// ```
///
/// The reason why the element comes before the UI instance is to aid readability. In this case, it's clear that which
/// element is being processed is more important than the UI instance that's being used, as there's usually only one
/// of the latter, while there may be many other elements present.
///
/// A `process` is transformed just like a `group`, with a few key differences:
/// ```ignore
/// paws::build! {
/// process window, &mut ui => ((300.0, 500.0), "Hello, world") {
/// println!("inside the window!");
/// }
/// }
/// // becomes
/// window.begin(&mut ui, (300.0, 500.0), "Hello, world");
/// {
/// println!("inside the window!");
/// }
/// window.end();
/// ```
///
/// The first, probably most noticable difference, is that the method names are `begin` and `end`, instead of `push` and
/// `pop`, as previously mentioned. The second difference is that `begin` receives the UI instance before all other
/// parameters.
;
=> ;
=> ;
}