Skip to content

Fix: TabBar/TabContainer can't start with all tabs deselected #108255

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

thygrrr
Copy link
Contributor

@thygrrr thygrrr commented Jul 3, 2025

TabBars and TabContainers were unable to start with no tabs selected, and couldn't properly retain their current tab value of "-1", also across editor restarts.

Fix for Issue:

#108223

Cause

As the tabs were added to a TabBar (or children to a TabContainer) as the scene was set up, a bug in TabBar would always select tab index 0, even if deselection was enabled.

Repro (also in linked issue):

image

Before fix:

image

Fixed via:

A missing check for deselect_enabled was added in TabBar.cpp on the code path when a first tab is added to an empty bar.

After fix:

image

Tests:

  • Modified 2 Test cases in [TabBar].
  • Added 1 Test case in [TabBar].

Verified on Windows only via manual testing and
./bin/godot.windows.editor.x86_64.console.exe --test --test-case="*[TabBar]*"

@thygrrr thygrrr requested review from a team as code owners July 3, 2025 21:17
@Chaosus Chaosus added this to the 4.5 milestone Jul 4, 2025
@thygrrr thygrrr changed the title TabBar current tab remains -1 when adding first tab on deselect_enabl… Fix: TabBar/TabContainer can't start with all tabs deselected Jul 4, 2025
@AThousandShips AThousandShips added the cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release label Jul 4, 2025
@@ -1266,7 +1266,7 @@ void TabBar::add_tab(const String &p_str, const Ref<Texture2D> &p_icon) {
queue_redraw();
update_minimum_size();

if (tabs.size() == 1) {
if (tabs.size() == 1 && !deselect_enabled) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (tabs.size() == 1 && !deselect_enabled) {
if (!deselect_enabled && tabs.size() == 1) {

Cheaper checks should be performed first.

Comment on lines +112 to +135
tab_bar->add_tab("tab2");
CHECK(tab_bar->get_tab_count() == 3);
CHECK(tab_bar->get_current_tab() == -1);
CHECK(tab_bar->get_previous_tab() == -1);
SIGNAL_CHECK_FALSE("tab_selected");
SIGNAL_CHECK_FALSE("tab_changed");

CHECK(tab_bar->get_tab_title(0) == "tab0");
CHECK(tab_bar->get_tab_tooltip(0) == "");
CHECK(tab_bar->get_tab_text_direction(0) == Control::TEXT_DIRECTION_INHERITED);
CHECK_FALSE(tab_bar->is_tab_disabled(0));
CHECK_FALSE(tab_bar->is_tab_hidden(0));

CHECK(tab_bar->get_tab_title(1) == "tab1");
CHECK(tab_bar->get_tab_tooltip(1) == "");
CHECK(tab_bar->get_tab_text_direction(1) == Control::TEXT_DIRECTION_INHERITED);
CHECK_FALSE(tab_bar->is_tab_disabled(1));
CHECK_FALSE(tab_bar->is_tab_hidden(1));

CHECK(tab_bar->get_tab_title(2) == "tab2");
CHECK(tab_bar->get_tab_tooltip(2) == "");
CHECK(tab_bar->get_tab_text_direction(2) == Control::TEXT_DIRECTION_INHERITED);
CHECK_FALSE(tab_bar->is_tab_disabled(2));
CHECK_FALSE(tab_bar->is_tab_hidden(2));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks are redundant, already covered by previous subcase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release topic:gui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TabContainer selects first tab (0) when current_tab == -1 and does not persist value of -1
4 participants