Skip to content
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

Fix TabBar initialization issue and add tests #97255

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions scene/gui/tab_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion scene/gui/tab_bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ class TabBar : public Control {
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;
Expand Down Expand Up @@ -249,6 +250,7 @@ class TabBar : public Control {
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;

Expand Down
4 changes: 2 additions & 2 deletions scene/gui/tab_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
Expand Down
Loading
Loading