Skip to content

Commit db95d32

Browse files
committed
feat: impl crate::registry::property::Var::var_hint for all global enums
1 parent 430cc6c commit db95d32

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

godot-codegen/src/generator/enums.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1212
use std::collections::HashSet;
1313

14+
use heck::{ToPascalCase, ToShoutySnakeCase};
1415
use proc_macro2::TokenStream;
1516
use 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
@@ -152,6 +154,13 @@ pub fn make_enum_definition_with(
152154
}
153155

154156
#var_trait_set_property
157+
158+
fn var_hint() -> crate::meta::PropertyHintInfo{
159+
crate::meta::PropertyHintInfo{
160+
hint: crate::global::PropertyHint::ENUM,
161+
hint_string: #enum_hint_string.into(),
162+
}
163+
}
155164
}
156165

157166
impl crate::registry::property::Export for #name {}
@@ -505,6 +514,23 @@ fn make_enum_doc(enum_: &Enum) -> Vec<String> {
505514

506515
docs
507516
}
517+
/// Returns the hint string for the given enum.
518+
///
519+
/// Separate with commas, and remove the `<ENUM_NAME>_` prefix (if possible).
520+
/// e.g.: "Left,Center,Right,Fill"
521+
fn make_enum_hint_string(enum_: &Enum) -> String {
522+
let upper_cast_enum_name = enum_.godot_name.to_shouty_snake_case() + "_";
523+
enum_.enumerators
524+
.iter()
525+
.map(|enumerator| {
526+
enumerator.godot_name
527+
.clone()
528+
.trim_start_matches(upper_cast_enum_name.as_str())
529+
.to_pascal_case()
530+
})
531+
.collect::<Vec<String>>()
532+
.join(",")
533+
}
508534

509535
/// Creates a definition for `enumerator` of the type `enum_type`.
510536
///

0 commit comments

Comments
 (0)