@@ -169,6 +169,59 @@ use crate::registry::property::{BuiltinExport, Export, Var};
169
169
/// }
170
170
/// ```
171
171
///
172
+ ///
173
+ /// # Custom getters and setters for `OnEditor`
174
+ ///
175
+ /// Custom setters and/or getters for `OnEditor` are declared as for any other `#[var]`.
176
+ /// Use the default `OnEditor<T>` implementation to set/retrieve the value.
177
+ ///
178
+ /// ```
179
+ /// # use godot::prelude::*;
180
+ /// #[derive(GodotClass)]
181
+ /// #[class(init)]
182
+ /// struct MyStruct {
183
+ /// #[var(get = get_my_node, set = set_my_node)]
184
+ /// my_node: OnEditor<Gd<Node>>,
185
+ /// #[var(get = get_my_value, set = set_my_value)]
186
+ /// #[init(sentinel = -1)]
187
+ /// my_value: OnEditor<i32>,
188
+ /// }
189
+ ///
190
+ /// #[godot_api]
191
+ /// impl MyStruct {
192
+ /// #[func]
193
+ /// pub fn get_my_node(&self) -> Option<Gd<Node>> {
194
+ /// // Write your logic in between here...
195
+ /// let ret = self.my_node.get_property();
196
+ /// // ...and there.
197
+ /// ret
198
+ /// }
199
+ ///
200
+ /// #[func]
201
+ /// pub fn set_my_node(&mut self, value: Option<Gd<Node>>) {
202
+ /// self.my_node.set_property(value);
203
+ /// }
204
+ ///
205
+ /// #[func]
206
+ /// pub fn get_my_value(&self) -> i32 {
207
+ /// self.my_value.get_property()
208
+ /// }
209
+ ///
210
+ /// #[func]
211
+ /// pub fn set_my_value(&mut self, value: i32) {
212
+ /// if value == 13 {
213
+ /// godot_warn!("13 is unlucky number.");
214
+ /// return
215
+ /// }
216
+ ///
217
+ /// self.my_value.set_property(value);
218
+ /// }
219
+ /// }
220
+ /// ```
221
+ ///
222
+ /// See also: [Register properties -- `#[var]`](../register/derive.GodotClass.html#register-properties--var)
223
+ ///
224
+ ///
172
225
/// # Using `OnEditor` with `#[class(tool)]`
173
226
///
174
227
/// When used with `#[class(tool)]`, the before-ready checks are omitted.
0 commit comments