From cb119e349a02c63746b86ad1cb280db259f3bdd3 Mon Sep 17 00:00:00 2001 From: Lisandro Lorea Date: Sat, 13 Jun 2020 19:15:47 -0300 Subject: [PATCH] Fix TabContainer emitting spurious tab_selected signals when a theme is changed - The repaint code was moved outside of set_current_tab() and to a "_repaint()" private function - _on_theme_changed() will now only call _repaint() and update() This means _on_theme_changed() will do only what it needs (repainting the TabContainer to account for the new theme) fixes #39498 (cherry picked from commit 5123006f06e235637b8b1d9faca92eecab476eee) --- scene/gui/tab_container.cpp | 44 +++++++++++++++++++++---------------- scene/gui/tab_container.h | 1 + 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index d4217838a10..b179fa02530 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -438,7 +438,30 @@ void TabContainer::_notification(int p_what) { void TabContainer::_on_theme_changed() { if (get_tab_count() > 0) { - set_current_tab(get_current_tab()); + _repaint(); + update(); + } +} + +void TabContainer::_repaint() { + Ref sb = get_stylebox("panel"); + Vector tabs = _get_tabs(); + for (int i = 0; i < tabs.size(); i++) { + Control *c = tabs[i]; + if (i == current) { + c->show(); + c->set_anchors_and_margins_preset(Control::PRESET_WIDE); + if (tabs_visible) { + c->set_margin(MARGIN_TOP, _get_top_margin()); + } + c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP))); + c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT))); + c->set_margin(Margin(MARGIN_RIGHT), c->get_margin(Margin(MARGIN_RIGHT)) - sb->get_margin(Margin(MARGIN_RIGHT))); + c->set_margin(Margin(MARGIN_BOTTOM), c->get_margin(Margin(MARGIN_BOTTOM)) - sb->get_margin(Margin(MARGIN_BOTTOM))); + + } else { + c->hide(); + } } } @@ -554,24 +577,7 @@ void TabContainer::set_current_tab(int p_current) { int pending_previous = current; current = p_current; - Ref sb = get_stylebox("panel"); - Vector tabs = _get_tabs(); - for (int i = 0; i < tabs.size(); i++) { - - Control *c = tabs[i]; - if (i == current) { - c->show(); - c->set_anchors_and_margins_preset(Control::PRESET_WIDE); - if (tabs_visible) - c->set_margin(MARGIN_TOP, _get_top_margin()); - c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP))); - c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT))); - c->set_margin(Margin(MARGIN_RIGHT), c->get_margin(Margin(MARGIN_RIGHT)) - sb->get_margin(Margin(MARGIN_RIGHT))); - c->set_margin(Margin(MARGIN_BOTTOM), c->get_margin(Margin(MARGIN_BOTTOM)) - sb->get_margin(Margin(MARGIN_BOTTOM))); - - } else - c->hide(); - } + _repaint(); _change_notify("current_tab"); diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h index c5a9045ca61..77da35d877c 100644 --- a/scene/gui/tab_container.h +++ b/scene/gui/tab_container.h @@ -66,6 +66,7 @@ private: Vector _get_tabs() const; int _get_tab_width(int p_index) const; void _on_theme_changed(); + void _repaint(); void _on_mouse_exited(); void _update_current_tab();