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

Defer tab_changed signal when removing children from TabContainer nodes #63176

Closed
Closed
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
14 changes: 8 additions & 6 deletions scene/gui/tab_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ Vector<Control *> TabContainer::_get_tab_controls() const {
Vector<Control *> controls;
for (int i = 0; i < get_child_count(); i++) {
Control *control = Object::cast_to<Control>(get_child(i));
if (!control || control->is_set_as_top_level() || control == tab_bar || control == child_removing) {
if (!control || control->is_set_as_top_level() || control == tab_bar) {
continue;
}

Expand Down Expand Up @@ -582,12 +582,12 @@ void TabContainer::remove_child_notify(Node *p_child) {
return;
}

int idx = get_tab_idx_from_control(c);
bool is_current_tab = p_child == get_current_tab_control();

// Before this, the tab control has not changed; after this, the tab control has changed.
child_removing = p_child;
tab_bar->remove_tab(idx);
child_removing = nullptr;
// Stop the `TabBar` from firing the `tab_changed` signal, as the child hasn't been removed yet. Call it deferred below instead.
tab_bar->set_block_signals(true);
tab_bar->remove_tab(get_tab_idx_from_control(c));
tab_bar->set_block_signals(false);

_update_margins();
if (get_tab_count() == 0) {
Expand All @@ -600,6 +600,8 @@ void TabContainer::remove_child_notify(Node *p_child) {
// TabBar won't emit the "tab_changed" signal when not inside the tree.
if (!is_inside_tree()) {
call_deferred("_repaint");
} else if (tab_bar->get_tab_count() > 0 && is_current_tab) {
tab_bar->call_deferred(SNAME("emit_signal"), SNAME("tab_changed"), tab_bar->get_current_tab());
}
}

Expand Down
1 change: 0 additions & 1 deletion scene/gui/tab_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class TabContainer : public Container {
bool drag_to_rearrange_enabled = false;
bool use_hidden_tabs_for_min_size = false;
bool theme_changing = false;
Node *child_removing = nullptr;

struct ThemeCache {
int side_margin = 0;
Expand Down