diff options
author | kit <kitbdev@gmail.com> | 2024-09-20 15:40:55 -0400 |
---|---|---|
committer | kit <kitbdev@gmail.com> | 2024-09-20 18:49:46 -0400 |
commit | f2f34e9c50906596cc9eb340cf708ac0103ca8c8 (patch) | |
tree | 30b9f56b288c64c2232857c73b06a38d88e272f8 /scene | |
parent | 2be730a05b7ff221b89c967981f7caee6e164ef0 (diff) | |
download | redot-engine-f2f34e9c50906596cc9eb340cf708ac0103ca8c8.tar.gz |
Fix TabBar initialization issue and add tests
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/tab_bar.cpp | 15 | ||||
-rw-r--r-- | scene/gui/tab_bar.h | 4 | ||||
-rw-r--r-- | scene/gui/tab_container.cpp | 4 |
3 files changed, 17 insertions, 6 deletions
diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp index 90bb0799b1..6cc7ec3bd5 100644 --- a/scene/gui/tab_bar.cpp +++ b/scene/gui/tab_bar.cpp @@ -354,6 +354,8 @@ void TabBar::_notification(int p_what) { if (scroll_to_selected) { ensure_tab_visible(current); } + // Set initialized even if no tabs were set. + initialized = true; } break; case NOTIFICATION_INTERNAL_PROCESS: { @@ -655,10 +657,10 @@ void TabBar::set_tab_count(int p_count) { } if (!initialized) { - if (queued_current != current) { - current = queued_current; - } initialized = true; + if (queued_current != CURRENT_TAB_UNINITIALIZED && queued_current != current) { + set_current_tab(queued_current); + } } queue_redraw(); @@ -740,6 +742,13 @@ bool TabBar::select_next_available() { return false; } +void TabBar::set_tab_offset(int p_offset) { + ERR_FAIL_INDEX(p_offset, tabs.size()); + offset = p_offset; + _update_cache(); + queue_redraw(); +} + int TabBar::get_tab_offset() const { return offset; } diff --git a/scene/gui/tab_bar.h b/scene/gui/tab_bar.h index d62b39ae16..f5ae75de51 100644 --- a/scene/gui/tab_bar.h +++ b/scene/gui/tab_bar.h @@ -117,8 +117,9 @@ private: bool scroll_to_selected = true; int tabs_rearrange_group = -1; + static const int CURRENT_TAB_UNINITIALIZED = -2; bool initialized = false; - int queued_current = -1; + int queued_current = CURRENT_TAB_UNINITIALIZED; const float DEFAULT_GAMEPAD_EVENT_DELAY_MS = 0.5; const float GAMEPAD_EVENT_REPEAT_RATE_MS = 1.0 / 20; @@ -249,6 +250,7 @@ public: bool select_previous_available(); bool select_next_available(); + void set_tab_offset(int p_offset); int get_tab_offset() const; bool get_offset_buttons_visible() const; diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index eb9616c939..33e72428cf 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -190,7 +190,7 @@ void TabContainer::_notification(int p_what) { } break; case NOTIFICATION_VISIBILITY_CHANGED: { - if (!is_visible() || setup_current_tab > -2) { + if (!is_visible()) { return; } @@ -200,7 +200,7 @@ void TabContainer::_notification(int p_what) { // beat it to the punch and make sure that the correct node is the only one visible first. // Otherwise, it can prevent a tab change done right before this container was made visible. Vector<Control *> controls = _get_tab_controls(); - int current = get_current_tab(); + int current = setup_current_tab > -2 ? setup_current_tab : get_current_tab(); for (int i = 0; i < controls.size(); i++) { controls[i]->set_visible(i == current); } |