@@ -139,9 +139,9 @@ use crate::util::{bail, ident, KvParser};
139
139
/// (fields annotated with `@export`). In the gdext API, these two concepts are represented with `#[var]` and `#[export]` attributes respectively,
140
140
/// which in turn are backed by the [`Var`](../register/property/trait.Var.html) and [`Export`](../register/property/trait.Export.html) traits.
141
141
///
142
- /// ## Property registration
142
+ /// ## Register properties -- `#[var]`
143
143
///
144
- /// To create a property, you can use the `#[var]` annotation:
144
+ /// To create a property, you can use the `#[var]` annotation, which supports types implementing [`Var`](../register/property/trait.Var.html).
145
145
///
146
146
/// ```
147
147
/// # use godot::prelude::*;
@@ -207,9 +207,10 @@ use crate::util::{bail, ident, KvParser};
207
207
/// }
208
208
/// ```
209
209
///
210
- /// ## Property exports
210
+ /// ## Export properties -- `#[export]`
211
211
///
212
- /// For exporting properties to the editor, you can use the `#[export]` attribute:
212
+ /// To export properties to the editor, you can use the `#[export]` attribute, which supports types implementing
213
+ /// [`Export`](../register/property/trait.Export.html):
213
214
///
214
215
/// ```
215
216
/// # use godot::prelude::*;
@@ -221,19 +222,21 @@ use crate::util::{bail, ident, KvParser};
221
222
/// }
222
223
/// ```
223
224
///
224
- /// If you don't also include a `#[var]` attribute, then a default one will be generated.
225
- /// `#[export]` also supports all of GDScript's annotations, in a slightly different format. The format is
225
+ /// If you don't include an additional `#[var]` attribute, then a default one will be generated.
226
+ ///
227
+ /// `#[export]` also supports all of [GDScript's annotations][gdscript-annotations], in a slightly different format. The format is
226
228
/// translated from an annotation by following these four rules:
227
229
///
228
- /// - `@export` becomes `#[export]`
229
- /// - `@export_{name}` becomes `#[export(name)]`
230
- /// - `@export_{name}(elem1, ...)` becomes `#[export(name = (elem1, ...))]`
231
- /// - `@export_{flags/enum}("elem1", "elem2:key2", ...)`
232
- /// becomes
233
- /// `#[export(flags/enum = (elem1, elem2 = key2, ...))]`
230
+ /// [gdscript-annotations]: https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_exports.html
234
231
///
232
+ /// | GDScript annotation | Rust attribute |
233
+ /// |---------------------------------------------|-------------------------------------------------|
234
+ /// | `@export` | `#[export]` |
235
+ /// | `@export_key` | `#[export(key)]` |
236
+ /// | `@export_key(elem1, ...)` | `#[export(key = (elem1, ...))]` |
237
+ /// | `@export_flags("elem1", "elem2:val2", ...)`<br>`@export_enum("elem1", "elem2:val2", ...)` | `#[export(flags = (elem1, elem2 = val2, ...))]`<br>`#[export(enum = (elem1, elem2 = val2, ...))]` |
235
238
///
236
- /// As an example of some different export attributes:
239
+ /// As an example of different export attributes:
237
240
///
238
241
/// ```
239
242
/// # use godot::prelude::*;
@@ -279,9 +282,8 @@ use crate::util::{bail, ident, KvParser};
279
282
///
280
283
/// ```
281
284
///
282
- /// Most values in expressions like `key = value`, can be an arbitrary expression that evaluates to the
283
- /// right value. Meaning you can use constants or variables, as well as any other rust syntax you'd like in
284
- /// the export attributes.
285
+ /// Most values in syntax such as `key = value` can be arbitrary expressions. For example, you can use constants, function calls or
286
+ /// other Rust expressions that are valid in that context.
285
287
///
286
288
/// ```
287
289
/// # use godot::prelude::*;
@@ -298,18 +300,24 @@ use crate::util::{bail, ident, KvParser};
298
300
/// }
299
301
/// ```
300
302
///
301
- /// You can specify custom property hints, hint strings, and usage flags in a `#[var]` attribute using the
302
- /// `hint`, `hint_string`, and `usage_flags` keys in the attribute. These are constants in the `PropertyHint`
303
- /// and `PropertyUsageFlags` enums, respectively.
303
+ /// ## Low-level property hints and usage
304
304
///
305
- /// ```
305
+ /// You can specify custom property hints, hint strings, and usage flags in a `#[var]` attribute using the `hint`, `hint_string`
306
+ /// and `usage_flags` keys in the attribute. Hint and usage flags are constants in the [`PropertyHint`] and [`PropertyUsageFlags`] enums,
307
+ /// while hint strings are dependent on the hint, property type and context. Using these low-level keys is rarely necessary, as most common
308
+ /// combinations are covered by `#[var]` and `#[export]` already.
309
+ ///
310
+ /// [`PropertyHint`]: ../global/struct.PropertyHint.html
311
+ /// [`PropertyUsageFlags`]: ../global/struct.PropertyUsageFlags.html
312
+ ///
313
+ /// ```no_run
306
314
/// # use godot::prelude::*;
307
315
/// #[derive(GodotClass)]
308
316
/// # #[class(init)]
309
317
/// struct MyStruct {
310
- /// // Treated as an enum with two values: "One" and "Two"
311
- /// // Displayed in the editor
312
- /// // Treated as read-only by the editor
318
+ /// // Treated as an enum with two values: "One" and "Two",
319
+ /// // displayed in the editor,
320
+ /// // treated as read-only by the editor.
313
321
/// #[var(
314
322
/// hint = ENUM,
315
323
/// hint_string = "One,Two",
@@ -319,9 +327,10 @@ use crate::util::{bail, ident, KvParser};
319
327
/// }
320
328
/// ```
321
329
///
330
+ ///
322
331
/// # Further class customization
323
332
///
324
- /// ## Running code in the editor
333
+ /// ## Running code in the editor (tool)
325
334
///
326
335
/// If you annotate a class with `#[class(tool)]`, its lifecycle methods (`ready()`, `process()` etc.) will be invoked in the editor. This
327
336
/// is useful for writing custom editor plugins, as opposed to classes running simply in-game.
0 commit comments