|
11 | 11 |
|
12 | 12 | use std::collections::HashSet; |
13 | 13 |
|
| 14 | +use heck::{ToPascalCase, ToShoutySnakeCase}; |
14 | 15 | use proc_macro2::TokenStream; |
15 | 16 | use quote::{quote, ToTokens}; |
16 | 17 |
|
@@ -45,6 +46,7 @@ pub fn make_enum_definition_with( |
45 | 46 | // Things needed for the type definition |
46 | 47 | let derives = enum_.derives(); |
47 | 48 | let enum_doc = make_enum_doc(enum_); |
| 49 | + let enum_hint_string = make_enum_hint_string(enum_); |
48 | 50 | let name = &enum_.name; |
49 | 51 |
|
50 | 52 | // Values |
@@ -152,6 +154,13 @@ pub fn make_enum_definition_with( |
152 | 154 | } |
153 | 155 |
|
154 | 156 | #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 | + } |
155 | 164 | } |
156 | 165 |
|
157 | 166 | impl crate::registry::property::Export for #name {} |
@@ -505,6 +514,23 @@ fn make_enum_doc(enum_: &Enum) -> Vec<String> { |
505 | 514 |
|
506 | 515 | docs |
507 | 516 | } |
| 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 | +} |
508 | 534 |
|
509 | 535 | /// Creates a definition for `enumerator` of the type `enum_type`. |
510 | 536 | /// |
|
0 commit comments