Merge pull request #91188 from YeldhamDev/love_fixing_other_peoples_regressions

Fix `TabContainer` regressions related to switching tabs in certain cases
This commit is contained in:
Rémi Verschelde 2024-05-02 12:46:39 +02:00
commit 098a4e945e
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -147,9 +147,7 @@ void TabContainer::_notification(int p_what) {
if (get_tab_count() > 0) { if (get_tab_count() > 0) {
_refresh_tab_names(); _refresh_tab_names();
} }
} break;
case NOTIFICATION_POST_ENTER_TREE: {
if (setup_current_tab >= -1) { if (setup_current_tab >= -1) {
set_current_tab(setup_current_tab); set_current_tab(setup_current_tab);
setup_current_tab = -2; setup_current_tab = -2;
@ -191,6 +189,25 @@ void TabContainer::_notification(int p_what) {
} }
} break; } break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible() || setup_current_tab > -2) {
return;
}
updating_visibility = true;
// As the visibility change notification will be triggered for all children soon after,
// 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();
for (int i = 0; i < controls.size(); i++) {
controls[i]->set_visible(i == current);
}
updating_visibility = false;
} break;
case NOTIFICATION_TRANSLATION_CHANGED: case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
@ -611,6 +628,7 @@ void TabContainer::set_current_tab(int p_current) {
setup_current_tab = p_current; setup_current_tab = p_current;
return; return;
} }
tab_bar->set_current_tab(p_current); tab_bar->set_current_tab(p_current);
} }