-
-
Notifications
You must be signed in to change notification settings - Fork 263
Description
Background
When building custom controls with gdext, I try to wrap built-in Godot nodes and want to forward some of their properties directly, without introducing a backing field.
Concrete example:
#[derive(GodotClass)]
#[class(base = Control, tool)]
struct LLabel {
#[base]
base: Base<Control>,
inner_label: Gd<Label>,
#[export]
#[var(get = get_text, set = g_set_text)]
text: PhantomVar<GString>,
#[export]
#[var(get = get_vertical_alignment, set = set_vertical_alignment)]
vertical_alignment: PhantomVar<godot::global::VerticalAlignment>,
}text: PhantomVar<GString> works perfectly, this is exactly where it excels.
However, VerticalAlignment gets stuck. This is because PhantomVar requires it to be GodotType+Var, and #[export] further requires it to be Export.
I'm a complete beginner with gdext, so I've thought a lot about this. Within the existing framework, I either have to use i32 and manually handle the conversion in the setter, or write a new VerticalAlignment, plus other supporting code.
The former results in a poor user experience on the editor side, while the latter requires me to violate the DRY (Don't Repeat Yourself) principle.
I've already tried modifying the gdext code to achieve this, but before that, given my beginner background, do any experts have a more elegant solution to suggest?