From b7028e5f9486754a4735d925f74bc03ff3258c87 Mon Sep 17 00:00:00 2001 From: jsjtxietian Date: Sun, 18 Feb 2024 12:54:51 +0800 Subject: [PATCH] Tweak property order in the inspector for TabBar --- scene/gui/tab_bar.cpp | 16 +++++++++++++--- scene/gui/tab_bar.h | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp index bb787a742ae..f87bccdfe7e 100644 --- a/scene/gui/tab_bar.cpp +++ b/scene/gui/tab_bar.cpp @@ -635,6 +635,13 @@ void TabBar::set_tab_count(int p_count) { } } + if (!initialized) { + if (queued_current != current) { + current = queued_current; + } + initialized = true; + } + queue_redraw(); update_minimum_size(); notify_property_list_changed(); @@ -649,6 +656,10 @@ void TabBar::set_current_tab(int p_current) { // An index of -1 is only valid if deselecting is enabled or there are no valid tabs. ERR_FAIL_COND_MSG(!_can_deselect(), "Cannot deselect tabs, deselection is not enabled."); } else { + if (!initialized && p_current >= get_tab_count()) { + queued_current = p_current; + return; + } ERR_FAIL_INDEX(p_current, get_tab_count()); } @@ -1825,9 +1836,6 @@ void TabBar::_bind_methods() { ADD_SIGNAL(MethodInfo("tab_hovered", PropertyInfo(Variant::INT, "tab"))); ADD_SIGNAL(MethodInfo("active_tab_rearranged", PropertyInfo(Variant::INT, "idx_to"))); - // "current_tab" property must come after "tab_count", otherwise the property isn't loaded correctly. - ADD_ARRAY_COUNT("Tabs", "tab_count", "set_tab_count", "get_tab_count", "tab_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1"), "set_current_tab", "get_current_tab"); ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_alignment", "get_tab_alignment"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_tabs"), "set_clip_tabs", "get_clip_tabs"); @@ -1840,6 +1848,8 @@ void TabBar::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "select_with_rmb"), "set_select_with_rmb", "get_select_with_rmb"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_enabled"), "set_deselect_enabled", "get_deselect_enabled"); + ADD_ARRAY_COUNT("Tabs", "tab_count", "set_tab_count", "get_tab_count", "tab_"); + BIND_ENUM_CONSTANT(ALIGNMENT_LEFT); BIND_ENUM_CONSTANT(ALIGNMENT_CENTER); BIND_ENUM_CONSTANT(ALIGNMENT_RIGHT); diff --git a/scene/gui/tab_bar.h b/scene/gui/tab_bar.h index 444c7372204..65a1d5bd4fb 100644 --- a/scene/gui/tab_bar.h +++ b/scene/gui/tab_bar.h @@ -108,6 +108,9 @@ private: bool scroll_to_selected = true; int tabs_rearrange_group = -1; + bool initialized = false; + int queued_current = -1; + const float DEFAULT_GAMEPAD_EVENT_DELAY_MS = 0.5; const float GAMEPAD_EVENT_REPEAT_RATE_MS = 1.0 / 20; float gamepad_event_delay_ms = DEFAULT_GAMEPAD_EVENT_DELAY_MS;