Improve theme editor responsiveness

This commit is contained in:
TsFreddie 2024-08-08 09:12:51 +08:00
parent 4bef4d9808
commit 748c88f194
No known key found for this signature in database
GPG Key ID: 3054B1FC80F9AF6F
2 changed files with 21 additions and 12 deletions

View File

@ -2304,27 +2304,20 @@ VBoxContainer *ThemeTypeEditor::_create_item_list(Theme::DataType p_data_type) {
}
void ThemeTypeEditor::_update_type_list() {
ERR_FAIL_COND(edited_theme.is_null());
if (updating) {
return;
}
updating = true;
Control *focused = get_viewport()->gui_get_focus_owner();
bool is_internal = focused == this;
if (focused) {
if (focusables.has(focused)) {
// If focus is currently on one of the internal property editors, don't update.
updating = false;
return;
}
Node *focus_parent = focused->get_parent();
while (focus_parent) {
Control *c = Object::cast_to<Control>(focus_parent);
is_internal |= c == this;
if (c && focusables.has(c)) {
// If focus is currently on one of the internal property editors, don't update.
updating = false;
return;
}
@ -2332,6 +2325,21 @@ void ThemeTypeEditor::_update_type_list() {
}
}
if (is_internal) {
_update_type_list_internal();
} else {
_update_type_list_debounced();
}
}
void ThemeTypeEditor::_update_type_list_internal() {
ERR_FAIL_COND(edited_theme.is_null());
if (updating) {
return;
}
updating = true;
List<StringName> theme_types;
edited_theme->get_type_list(&theme_types);
theme_types.sort_custom<StringName::AlphCompare>();
@ -3382,12 +3390,12 @@ void ThemeTypeEditor::_bind_methods() {
void ThemeTypeEditor::set_edited_theme(const Ref<Theme> &p_theme) {
if (edited_theme.is_valid()) {
edited_theme->disconnect_changed(callable_mp(this, &ThemeTypeEditor::_update_type_list_debounced));
edited_theme->disconnect_changed(callable_mp(this, &ThemeTypeEditor::_update_type_list));
}
edited_theme = p_theme;
if (edited_theme.is_valid()) {
edited_theme->connect_changed(callable_mp(this, &ThemeTypeEditor::_update_type_list_debounced));
edited_theme->connect_changed(callable_mp(this, &ThemeTypeEditor::_update_type_list));
_update_type_list();
}
@ -3526,7 +3534,7 @@ ThemeTypeEditor::ThemeTypeEditor() {
update_debounce_timer = memnew(Timer);
update_debounce_timer->set_one_shot(true);
update_debounce_timer->set_wait_time(0.5);
update_debounce_timer->connect("timeout", callable_mp(this, &ThemeTypeEditor::_update_type_list));
update_debounce_timer->connect("timeout", callable_mp(this, &ThemeTypeEditor::_update_type_list_internal));
add_child(update_debounce_timer);
}

View File

@ -372,6 +372,7 @@ class ThemeTypeEditor : public MarginContainer {
VBoxContainer *_create_item_list(Theme::DataType p_data_type);
void _update_type_list();
void _update_type_list_internal();
void _update_type_list_debounced();
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);