1111
1212use std:: collections:: HashSet ;
1313
14+ use heck:: ToPascalCase ;
1415use proc_macro2:: TokenStream ;
1516use quote:: { quote, ToTokens } ;
1617
@@ -45,6 +46,7 @@ pub fn make_enum_definition_with(
4546 // Things needed for the type definition
4647 let derives = enum_. derives ( ) ;
4748 let enum_doc = make_enum_doc ( enum_) ;
49+ let enum_hint_string = make_enum_hint_string ( enum_) ;
4850 let name = & enum_. name ;
4951
5052 // Values
@@ -105,9 +107,28 @@ pub fn make_enum_definition_with(
105107
106108 // Trait implementations.
107109 let engine_trait_impl = make_enum_engine_trait_impl ( enum_, enum_bitmask. as_ref ( ) ) ;
110+ let property_hint = if enum_. is_bitfield {
111+ quote ! { crate :: global:: PropertyHint :: FLAGS }
112+ } else {
113+ quote ! { crate :: global:: PropertyHint :: ENUM }
114+ } ;
108115 let index_enum_impl = make_enum_index_impl ( enum_) ;
109116 let bitwise_impls = make_enum_bitwise_operators ( enum_, enum_bitmask. as_ref ( ) ) ;
110117
118+ let var_trait_set_property = if enum_. is_exhaustive {
119+ quote ! {
120+ fn set_property( & mut self , value: Self :: Via ) {
121+ * self = <Self as #engine_trait>:: from_ord( value) ;
122+ }
123+ }
124+ } else {
125+ quote ! {
126+ fn set_property( & mut self , value: Self :: Via ) {
127+ self . ord = value;
128+ }
129+ }
130+ } ;
131+
111132 quote ! {
112133 #engine_trait_impl
113134 #index_enum_impl
@@ -131,6 +152,23 @@ pub fn make_enum_definition_with(
131152 . ok_or_else( || crate :: meta:: error:: FromGodotError :: InvalidEnum . into_error( via) )
132153 }
133154 }
155+
156+ impl crate :: registry:: property:: Var for #name {
157+ fn get_property( & self ) -> Self :: Via {
158+ <Self as #engine_trait>:: ord( * self )
159+ }
160+
161+ #var_trait_set_property
162+
163+ fn var_hint( ) -> crate :: meta:: PropertyHintInfo {
164+ crate :: meta:: PropertyHintInfo {
165+ hint: #property_hint,
166+ hint_string: crate :: builtin:: GString :: from( #enum_hint_string) ,
167+ }
168+ }
169+ }
170+
171+ impl crate :: registry:: property:: Export for #name { }
134172 }
135173 } ) ;
136174
@@ -481,6 +519,18 @@ fn make_enum_doc(enum_: &Enum) -> Vec<String> {
481519
482520 docs
483521}
522+ /// Returns the hint string for the given enum.
523+ ///
524+ /// Separate with commas, and remove the `<ENUM_NAME>_` prefix (if possible).
525+ /// e.g.: "Left,Center,Right,Fill"
526+ fn make_enum_hint_string ( enum_ : & Enum ) -> String {
527+ enum_
528+ . enumerators
529+ . iter ( )
530+ . map ( |enumerator| enumerator. name . to_string ( ) . to_pascal_case ( ) )
531+ . collect :: < Vec < String > > ( )
532+ . join ( "," )
533+ }
484534
485535/// Creates a definition for `enumerator` of the type `enum_type`.
486536///
0 commit comments