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
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
use FromStr;
use derive_for_enum;
use quote;
use derive_for_struct;
use Data;
pub
compile_error!;
/// Generates the immediate gui (ImGui or egui) representation for a
/// struct or an enum.
///
/// # Options
///
/// It is possible to configure the code generation with the use of the
/// [`#[imgui_presentation]`] procedural macro attribute, which has the
/// following options implemented:
///
/// - `readonly` makes a struct or a field have only immutable
/// presentation.
/// - `skip` skips the code generation for this field.
/// - `rename` renames a struct or a field in the generated
/// presentation code.
/// - `format` (only for scalars) allows to set custom display format.
/// - `tooltip` changes the hint text for a field or a struct.
/// - `button` allows to generated custom buttons, can only be
/// specified on a struct/enum.
/// - `backend` allows a struct or enum to specify the backend it needs.
/// only the chosen backend code will be derived.
///
/// # Examples
///
/// ## Readonly
///
/// To make a whole struct read-only (so not render it allowing to
/// change the values) just use the `readonly` attribute:
///
/// ```rust,ignore
/// #[derive(ImguiPresentation)]
/// #[imgui_presentation(readonly)]
/// pub struct A {
/// field: i32,
/// }
/// ```
///
/// To make a field read-only, it is allowed to specify the `readonly`
/// attribute on a field:
///
/// ```rust,ignore
/// #[derive(ImguiPresentation)]
/// pub struct A {
/// #[imgui_presentation(readonly)]
/// read_only_field: i32,
/// ordinary_field: i32,
/// }
/// ```
///
/// ## Skip
///
/// To skip generating a Imgui UI element for a field, use the `skip`
/// attribute:
///
/// ```rust,ignore
/// #[derive(ImguiPresentation)]
/// pub struct A {
/// #[imgui_presentation(skip)]
/// skipped_field: i32,
/// ordinary_field: i32,
/// }
/// ```
///
/// ## Rename
///
/// The code generator cannot make assumptions as to how it is the best
/// to name the user structure, and so just uses its full name. If a
/// more human-readable name is required, one can always specify the
/// name to appear in Imgui using the `rename` attribute:
///
/// ```rust,ignore
/// #[derive(ImguiPresentation)]
/// #[imgui_presentation(rename = "A great struct")]
/// pub struct A {
/// field: i32,
/// }
/// ```
///
/// The same goes for the fields:
///
/// ```rust,ignore
/// #[derive(ImguiPresentation)]
/// #[imgui_presentation(rename = "A great struct")]
/// pub struct A {
/// #[imgui_presentation(rename = "A great field of a great struct")]
/// field: i32,
/// }
/// ```
///
/// ## Tooltip
///
/// The code generator grabs the doc-comment an enum, structure or a
/// field is annotated with and creates a tooltip for this field with
/// the text from that doc-comment. If the tooltip should be changed,
/// the `tooltip` attribute can be used for structs, enums and fields:
///
/// ```rust,ignore
/// // This is a struct with a tooltip from the doc-comment:
///
/// /// This is a great struct.
/// #[derive(ImguiPresentation)]
/// pub struct A {
/// field: i32,
/// }
/// ```
///
/// To change the tooltip text from `"This is a great struct"`, we use
/// the `tooltip` attribute as follows:
///
/// ```rust,ignore
/// #[imgui_presentation(tooltip = "This is not a great struct.")]
/// #[derive(ImguiPresentation)]
/// pub struct A {
/// field: i32,
/// }
/// ```
///
/// The same goes for the enums, struct and enum fields.
///
/// ## Buttons
///
/// Buttons are specified once per attribute string, in the format of:
///
/// ```ignore,no_run
/// button(<"button title"> : <"method name to call">)
/// ```
///
/// ```rust,ignore
/// #[derive(ImguiPresentation)]
/// #[imgui_presentation(button("Hello world": "hello_world"))]
/// #[imgui_presentation(button("Bye world": "bye"))]
/// pub struct A {
/// }
///
/// impl A {
/// fn hello_world(&mut self) {
/// println!("The \"Hello world\" button was pressed.");
/// }
///
/// fn bye(&mut self) {
/// println!("The \"Bye world\" button was pressed.");
/// }
/// }
/// ```
///
/// ## Backends
///
/// To specify a backend for the code generation for a struct, use the
/// `backend` attribute:
///
/// ```rust,ignore
/// #[derive(ImguiPresentation)]
/// #[imgui_presentation(backend = "imgui")]
/// pub struct A {
/// }
/// ```
///
/// Usually, the backend specification isn't required, as only
/// one of the backends is built due to only one being selected as a
/// crate feature. However, by default, both are generated as both
/// features are the default ones, and if the default features aren't
/// disabled for the crate, the compiler will always try to generate the
/// code for both the backends even if only one is actually being used.
/// For that reason, to direct the derive macro to generate the code
/// for a struct or an enum for only one backend out of others which are
/// also available, the `backend` attribute should be used. If it is
/// known in advance that only one backend will be used, just disable
/// the default features for this crate and specify the ones you need.
///
/// ## Tuple structs
///
/// The tuple structs are supported exactly the same way as the ordinary
/// structs, except for the field names, which:
///
/// 1. In case there is only one field (`struct.0`), is prefixed with
/// the struct type.
/// 2. In case there are more fields, prefixed with their order numbers.
///
/// ## Enums
///
/// Only simple enums with simple variants are supported. Such enums
/// appear as a ComboBox which allows to select a new value from a set
/// of available variants of the enum, for example:
///
/// ```rust,ignore
/// /// The languages the engine supports.
/// #[derive(
/// Default,
/// ImguiPresentation,
/// )]
/// pub enum Language {
/// /// English language.
/// #[default]
/// English,
/// /// Dutch language.
/// Dutch,
/// }
///