Skip to content

Commit

Permalink
Defer tab_changed signal when removing children from TabContainer
Browse files Browse the repository at this point in the history
… nodes
  • Loading branch information
YeldhamDev committed Oct 24, 2022
1 parent 040f49e commit e35f2e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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

0 comments on commit e35f2e7

Please sign in to comment.