Skip to content

Commit ef4ad67

Browse files
committed
Improve #[var] docs
1 parent 4a8e299 commit ef4ad67

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

godot-macros/src/class/data_models/field_export.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ impl ExportType {
548548
}
549549
}
550550

551+
/// Returns a `PropertyUsageFlags` identifier if this export type has a _usage_.
551552
pub fn to_export_usage(&self) -> Option<Ident> {
552553
match self {
553554
Self::Storage => Some(ident("STORAGE")),

godot-macros/src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ use crate::util::{bail, ident, KvParser};
139139
/// (fields annotated with `@export`). In the gdext API, these two concepts are represented with `#[var]` and `#[export]` attributes respectively,
140140
/// which in turn are backed by the [`Var`](../register/property/trait.Var.html) and [`Export`](../register/property/trait.Export.html) traits.
141141
///
142-
/// ## Property registration
142+
/// ## Register properties with `#[var]`
143143
///
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).
145145
///
146146
/// ```
147147
/// # use godot::prelude::*;
@@ -207,9 +207,18 @@ use crate::util::{bail, ident, KvParser};
207207
/// }
208208
/// ```
209209
///
210-
/// ## Property exports
210+
/// You can additionally provide low-level configuration of a property with the keys `hint`, `hint_string` and `usage_flags`.
211+
/// This is typically not necessary, but exists for full flexibility. These keys can be combined, but the combination must be
212+
/// meaningful in Godot, and godot-rust should generally cover known useful combinations in higher-level APIs.
211213
///
212-
/// For exporting properties to the editor, you can use the `#[export]` attribute:
214+
/// - `#[var(hint = ENUM)]` denoting a constant from [`PropertyHint`](../global/struct.PropertyHint.html),
215+
/// - `#[var(hint_string = "one,two")]` providing a hint string for the property, which is interpreted by Godot depending on hint and context.
216+
/// - `#[var(usage_flags = [EDITOR, READ_ONLY])]` providing a list of [`PropertyUsageFlags`](../global/struct.PropertyUsageFlags.html).
217+
///
218+
/// ## Export properties with `#[export]`
219+
///
220+
/// To export properties to the editor, you can use the `#[export]` attribute, which supports types implementing
221+
/// [`Export`](../register/property/trait.Export.html):
213222
///
214223
/// ```
215224
/// # use godot::prelude::*;

0 commit comments

Comments
 (0)