Skip to content

Commit 552a85e

Browse files
committed
Add OnEditor<T>, remove impl<T> Export for Gd<T> and DynGd<T, D>
- Rearrange the code; move implementations for `OnEditor<Gd<T>>` and `OnEditor<DynGd<D, T>>` to their associated files (`gd.rs` and `dyn_gd.rs`). - Inform user about available use cases for `OnEditor<T>` in associated docs - Clean up the API – don't allow to create initialized `OnEditor<T>` value, delegate initialization to `init(...)` method, limit usage of `uninit` to Directly Exportable GodotTypes.
1 parent d6c4652 commit 552a85e

File tree

8 files changed

+213
-165
lines changed

8 files changed

+213
-165
lines changed

godot-core/src/builtin/collections/array.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::meta::{
1616
CowArg, FromGodot, GodotConvert, GodotFfiVariant, GodotType, ParamType, PropertyHintInfo,
1717
RefArg, ToGodot,
1818
};
19-
use crate::obj::{bounds, Bounds, Gd, GodotClass};
19+
use crate::obj::{bounds, Bounds, DynGd, Gd, GodotClass};
2020
use crate::registry::property::{Export, Var};
2121
use godot_ffi as sys;
2222
use sys::{ffi_methods, interface_fn, GodotFfi};
@@ -1114,6 +1114,21 @@ where
11141114
}
11151115
}
11161116

1117+
impl<T: GodotClass, D> Export for Array<DynGd<T, D>>
1118+
where
1119+
T: GodotClass + Bounds<Exportable = bounds::Yes>,
1120+
D: ?Sized + 'static,
1121+
{
1122+
fn export_hint() -> PropertyHintInfo {
1123+
PropertyHintInfo::export_array_element::<DynGd<T, D>>()
1124+
}
1125+
1126+
#[doc(hidden)]
1127+
fn as_node_class() -> Option<ClassName> {
1128+
PropertyHintInfo::object_as_node_class::<T>()
1129+
}
1130+
}
1131+
11171132
impl<T: ArrayElement> Default for Array<T> {
11181133
#[inline]
11191134
fn default() -> Self {

godot-core/src/obj/dyn_gd.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,6 @@ where
495495
}
496496
}
497497

498-
#[doc(hidden)]
499498
#[allow(clippy::derivable_impls)]
500499
impl<T, D> Default for OnEditor<DynGd<T, D>>
501500
where
@@ -506,6 +505,7 @@ where
506505
OnEditor::null()
507506
}
508507
}
508+
509509
impl<T, D> Export for Option<DynGd<T, D>>
510510
where
511511
T: GodotClass + Bounds<Exportable = bounds::Yes>,
@@ -517,6 +517,46 @@ where
517517
..PropertyHintInfo::export_gd::<T>()
518518
}
519519
}
520+
521+
fn as_node_class() -> Option<ClassName> {
522+
PropertyHintInfo::object_as_node_class::<T>()
523+
}
524+
}
525+
526+
impl<T, D> GodotConvert for OnEditor<DynGd<T, D>>
527+
where
528+
T: GodotClass,
529+
D: ?Sized,
530+
{
531+
type Via = Option<<DynGd<T, D> as GodotConvert>::Via>;
532+
}
533+
534+
impl<T, D> Var for OnEditor<DynGd<T, D>>
535+
where
536+
T: GodotClass,
537+
D: ?Sized + 'static,
538+
{
539+
fn get_property(&self) -> Self::Via {
540+
OnEditor::<DynGd<T, D>>::get_property_inner(self)
541+
}
542+
543+
fn set_property(&mut self, value: Self::Via) {
544+
OnEditor::<DynGd<T, D>>::set_property_inner(self, value)
545+
}
546+
}
547+
548+
impl<T, D> Export for OnEditor<DynGd<T, D>>
549+
where
550+
OnEditor<DynGd<T, D>>: Var,
551+
T: GodotClass + Bounds<Exportable = bounds::Yes>,
552+
D: ?Sized + 'static,
553+
{
554+
fn export_hint() -> PropertyHintInfo {
555+
PropertyHintInfo {
556+
hint_string: get_dyn_property_hint_string::<D>(),
557+
..PropertyHintInfo::export_gd::<T>()
558+
}
559+
}
520560
fn as_node_class() -> Option<ClassName> {
521561
PropertyHintInfo::object_as_node_class::<T>()
522562
}

godot-core/src/obj/gd.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,14 +917,49 @@ where
917917
}
918918
}
919919

920-
#[doc(hidden)]
921920
#[allow(clippy::derivable_impls)]
922921
impl<T: GodotClass> Default for OnEditor<Gd<T>> {
923922
fn default() -> Self {
924923
OnEditor::null()
925924
}
926925
}
927926

927+
impl<T: GodotClass> GodotConvert for OnEditor<Gd<T>>
928+
where
929+
Option<<Gd<T> as GodotConvert>::Via>: GodotType,
930+
{
931+
type Via = Option<<Gd<T> as GodotConvert>::Via>;
932+
}
933+
934+
impl<T> Var for OnEditor<Gd<T>>
935+
where
936+
T: GodotClass,
937+
OnEditor<Gd<T>>: GodotConvert<Via = Option<<Gd<T> as GodotConvert>::Via>>,
938+
{
939+
fn get_property(&self) -> Self::Via {
940+
OnEditor::<Gd<T>>::get_property_inner(self)
941+
}
942+
943+
fn set_property(&mut self, value: Self::Via) {
944+
OnEditor::<Gd<T>>::set_property_inner(self, value)
945+
}
946+
}
947+
948+
impl<T> Export for OnEditor<Gd<T>>
949+
where
950+
T: GodotClass + Bounds<Exportable = bounds::Yes>,
951+
OnEditor<Gd<T>>: Var,
952+
{
953+
fn export_hint() -> PropertyHintInfo {
954+
PropertyHintInfo::export_gd::<T>()
955+
}
956+
957+
#[doc(hidden)]
958+
fn as_node_class() -> Option<ClassName> {
959+
PropertyHintInfo::object_as_node_class::<T>()
960+
}
961+
}
962+
928963
impl<T: GodotClass> PartialEq for Gd<T> {
929964
/// ⚠️ Returns whether two `Gd` pointers point to the same object.
930965
///

0 commit comments

Comments
 (0)