diff options
author | jsjtxietian <jsjtxietian@outlook.com> | 2024-02-18 12:54:51 +0800 |
---|---|---|
committer | jsjtxietian <jsjtxietian@outlook.com> | 2024-02-18 12:54:51 +0800 |
commit | b7028e5f9486754a4735d925f74bc03ff3258c87 (patch) | |
tree | 43017860c27b05cbe1d937d0a7c526282803132b | |
parent | 8f0c20ee8d5564d4a8131deb4d5341b60edbcff8 (diff) | |
download | redot-engine-b7028e5f9486754a4735d925f74bc03ff3258c87.tar.gz |
Tweak property order in the inspector for TabBar
-rw-r--r-- | scene/gui/tab_bar.cpp | 16 | ||||
-rw-r--r-- | 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 bb787a742a..f87bccdfe7 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 444c737220..65a1d5bd4f 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; |