Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch theme editor items from ThemeDB #84763

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions editor/plugins/theme_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2373,18 +2373,23 @@ void ThemeTypeEditor::_update_type_list_debounced() {
update_debounce_timer->start();
}

HashMap<StringName, bool> ThemeTypeEditor::_get_type_items(String p_type_name, void (Theme::*get_list_func)(const StringName &, List<StringName> *) const, bool include_default) {
HashMap<StringName, bool> ThemeTypeEditor::_get_type_items(String p_type_name, Theme::DataType p_type, bool p_include_default) {
HashMap<StringName, bool> items;
List<StringName> names;

if (include_default) {
if (p_include_default) {
names.clear();
String default_type = p_type_name;
if (edited_theme->get_type_variation_base(p_type_name) != StringName()) {
default_type = edited_theme->get_type_variation_base(p_type_name);
}

(ThemeDB::get_singleton()->get_default_theme().operator->()->*get_list_func)(default_type, &names);
List<ThemeDB::ThemeItemBind> theme_binds;
ThemeDB::get_singleton()->get_class_items(default_type, &theme_binds, true, p_type);
for (const ThemeDB::ThemeItemBind &E : theme_binds) {
names.push_back(E.item_name);
}

names.sort_custom<StringName::AlphCompare>();
for (const StringName &E : names) {
items[E] = false;
Expand All @@ -2393,7 +2398,7 @@ HashMap<StringName, bool> ThemeTypeEditor::_get_type_items(String p_type_name, v

{
names.clear();
(edited_theme.operator->()->*get_list_func)(p_type_name, &names);
edited_theme->get_theme_item_list(p_type, p_type_name, &names);
names.sort_custom<StringName::AlphCompare>();
for (const StringName &E : names) {
items[E] = true;
Expand Down Expand Up @@ -2499,7 +2504,7 @@ void ThemeTypeEditor::_update_type_items() {
color_items_list->remove_child(node);
}

HashMap<StringName, bool> color_items = _get_type_items(edited_type, &Theme::get_color_list, show_default);
HashMap<StringName, bool> color_items = _get_type_items(edited_type, Theme::DATA_TYPE_COLOR, show_default);
for (const KeyValue<StringName, bool> &E : color_items) {
HBoxContainer *item_control = _create_property_control(Theme::DATA_TYPE_COLOR, E.key, E.value);
ColorPickerButton *item_editor = memnew(ColorPickerButton);
Expand Down Expand Up @@ -2528,7 +2533,7 @@ void ThemeTypeEditor::_update_type_items() {
constant_items_list->remove_child(node);
}

HashMap<StringName, bool> constant_items = _get_type_items(edited_type, &Theme::get_constant_list, show_default);
HashMap<StringName, bool> constant_items = _get_type_items(edited_type, Theme::DATA_TYPE_CONSTANT, show_default);
for (const KeyValue<StringName, bool> &E : constant_items) {
HBoxContainer *item_control = _create_property_control(Theme::DATA_TYPE_CONSTANT, E.key, E.value);
SpinBox *item_editor = memnew(SpinBox);
Expand Down Expand Up @@ -2561,7 +2566,7 @@ void ThemeTypeEditor::_update_type_items() {
font_items_list->remove_child(node);
}

HashMap<StringName, bool> font_items = _get_type_items(edited_type, &Theme::get_font_list, show_default);
HashMap<StringName, bool> font_items = _get_type_items(edited_type, Theme::DATA_TYPE_FONT, show_default);
for (const KeyValue<StringName, bool> &E : font_items) {
HBoxContainer *item_control = _create_property_control(Theme::DATA_TYPE_FONT, E.key, E.value);
EditorResourcePicker *item_editor = memnew(EditorResourcePicker);
Expand Down Expand Up @@ -2599,7 +2604,7 @@ void ThemeTypeEditor::_update_type_items() {
font_size_items_list->remove_child(node);
}

HashMap<StringName, bool> font_size_items = _get_type_items(edited_type, &Theme::get_font_size_list, show_default);
HashMap<StringName, bool> font_size_items = _get_type_items(edited_type, Theme::DATA_TYPE_FONT_SIZE, show_default);
for (const KeyValue<StringName, bool> &E : font_size_items) {
HBoxContainer *item_control = _create_property_control(Theme::DATA_TYPE_FONT_SIZE, E.key, E.value);
SpinBox *item_editor = memnew(SpinBox);
Expand Down Expand Up @@ -2632,7 +2637,7 @@ void ThemeTypeEditor::_update_type_items() {
icon_items_list->remove_child(node);
}

HashMap<StringName, bool> icon_items = _get_type_items(edited_type, &Theme::get_icon_list, show_default);
HashMap<StringName, bool> icon_items = _get_type_items(edited_type, Theme::DATA_TYPE_ICON, show_default);
for (const KeyValue<StringName, bool> &E : icon_items) {
HBoxContainer *item_control = _create_property_control(Theme::DATA_TYPE_ICON, E.key, E.value);
EditorResourcePicker *item_editor = memnew(EditorResourcePicker);
Expand Down Expand Up @@ -2700,7 +2705,7 @@ void ThemeTypeEditor::_update_type_items() {
stylebox_items_list->add_child(memnew(HSeparator));
}

HashMap<StringName, bool> stylebox_items = _get_type_items(edited_type, &Theme::get_stylebox_list, show_default);
HashMap<StringName, bool> stylebox_items = _get_type_items(edited_type, Theme::DATA_TYPE_STYLEBOX, show_default);
for (const KeyValue<StringName, bool> &E : stylebox_items) {
if (leading_stylebox.pinned && leading_stylebox.item_name == E.key) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/theme_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class ThemeTypeEditor : public MarginContainer {
VBoxContainer *_create_item_list(Theme::DataType p_data_type);
void _update_type_list();
void _update_type_list_debounced();
HashMap<StringName, bool> _get_type_items(String p_type_name, void (Theme::*get_list_func)(const StringName &, List<StringName> *) const, bool include_default);
HashMap<StringName, bool> _get_type_items(String p_type_name, Theme::DataType p_type, bool p_include_default);
HBoxContainer *_create_property_control(Theme::DataType p_data_type, String p_item_name, bool p_editable);
void _add_focusable(Control *p_control);
void _update_type_items();
Expand Down
5 changes: 4 additions & 1 deletion scene/theme/theme_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void ThemeDB::update_class_instance_items(Node *p_instance) {
}
}

void ThemeDB::get_class_items(const StringName &p_class_name, List<ThemeItemBind> *r_list, bool p_include_inherited) {
void ThemeDB::get_class_items(const StringName &p_class_name, List<ThemeItemBind> *r_list, bool p_include_inherited, Theme::DataType p_filter_type) {
List<StringName> class_hierarchy;
StringName class_name = p_class_name;
while (class_name != StringName()) {
Expand All @@ -386,6 +386,9 @@ void ThemeDB::get_class_items(const StringName &p_class_name, List<ThemeItemBind
HashMap<StringName, List<ThemeItemBind>>::Iterator E = theme_item_binds_list.find(theme_type);
if (E) {
for (const ThemeItemBind &F : E->value) {
if (p_filter_type != Theme::DATA_TYPE_MAX && F.data_type != p_filter_type) {
continue;
}
if (inherited_props.has(F.item_name)) {
continue; // Skip inherited properties.
}
Expand Down
2 changes: 1 addition & 1 deletion scene/theme/theme_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class ThemeDB : public Object {
void bind_class_external_item(Theme::DataType p_data_type, const StringName &p_class_name, const StringName &p_prop_name, const StringName &p_item_name, const StringName &p_type_name, ThemeItemSetter p_setter);
void update_class_instance_items(Node *p_instance);

void get_class_items(const StringName &p_class_name, List<ThemeItemBind> *r_list, bool p_include_inherited = false);
void get_class_items(const StringName &p_class_name, List<ThemeItemBind> *r_list, bool p_include_inherited = false, Theme::DataType p_filter_type = Theme::DATA_TYPE_MAX);

// Memory management, reference, and initialization.

Expand Down
Loading