diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2020-12-21 00:26:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-21 00:26:08 +0100 |
commit | f7ddcbf446e88b155f1172d94d30a7974e67e8a8 (patch) | |
tree | 2f3a4ae40e8f9fa3b9b6720aa8e42670bc608aa9 | |
parent | 153c132a7e7e7cea00c420b93257f3ebd56cf2dc (diff) | |
parent | 0394ff3c998f40c40206a8eda610cebdcca9e162 (diff) |
Merge pull request #44328 from gongpha/tabs-label-incorrect
Refresh TextLine buffer when moving a tab
-rw-r--r-- | scene/gui/tab_container.cpp | 68 | ||||
-rw-r--r-- | scene/gui/tab_container.h | 2 |
2 files changed, 22 insertions, 48 deletions
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 01c1a15b79..809b4ffd64 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -568,16 +568,12 @@ void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, in text_buf[p_index]->draw(canvas, text_pos, p_font_color); } -void TabContainer::_on_theme_changed() { - if (!_theme_changing) { - return; - } - +void TabContainer::_refresh_texts() { text_buf.clear(); + Vector<Control *> tabs = _get_tabs(); bool rtl = is_layout_rtl(); Ref<Font> font = get_theme_font("font"); int font_size = get_theme_font_size("font_size"); - Vector<Control *> tabs = _get_tabs(); for (int i = 0; i < tabs.size(); i++) { Control *control = Object::cast_to<Control>(tabs[i]); String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); @@ -587,6 +583,14 @@ void TabContainer::_on_theme_changed() { name->add_string(text, font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); text_buf.push_back(name); } +} + +void TabContainer::_on_theme_changed() { + if (!_theme_changing) { + return; + } + + _refresh_texts(); minimum_size_changed(); if (get_tab_count() > 0) { @@ -679,21 +683,7 @@ Vector<Control *> TabContainer::_get_tabs() const { } void TabContainer::_child_renamed_callback() { - text_buf.clear(); - Vector<Control *> tabs = _get_tabs(); - bool rtl = is_layout_rtl(); - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); - for (int i = 0; i < tabs.size(); i++) { - Control *control = Object::cast_to<Control>(tabs[i]); - String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); - Ref<TextLine> name; - name.instance(); - name->set_direction(rtl ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); - name->add_string(text, font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); - text_buf.push_back(name); - } - + _refresh_texts(); update(); } @@ -708,20 +698,8 @@ void TabContainer::add_child_notify(Node *p_child) { return; } - text_buf.clear(); Vector<Control *> tabs = _get_tabs(); - bool rtl = is_layout_rtl(); - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); - for (int i = 0; i < tabs.size(); i++) { - Control *control = Object::cast_to<Control>(tabs[i]); - String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); - Ref<TextLine> name; - name.instance(); - name->set_direction(rtl ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); - name->add_string(text, font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); - text_buf.push_back(name); - } + _refresh_texts(); bool first = false; @@ -743,7 +721,6 @@ void TabContainer::add_child_notify(Node *p_child) { 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))); - update(); p_child->connect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback)); if (first && is_inside_tree()) { @@ -751,6 +728,13 @@ void TabContainer::add_child_notify(Node *p_child) { } } +void TabContainer::move_child_notify(Node *p_child) { + Container::move_child_notify(p_child); + call_deferred("_update_current_tab"); + _refresh_texts(); + update(); +} + int TabContainer::get_tab_count() const { return _get_tabs().size(); } @@ -813,20 +797,8 @@ void TabContainer::remove_child_notify(Node *p_child) { } void TabContainer::_update_current_tab() { - text_buf.clear(); Vector<Control *> tabs = _get_tabs(); - bool rtl = is_layout_rtl(); - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); - for (int i = 0; i < tabs.size(); i++) { - Control *control = Object::cast_to<Control>(tabs[i]); - String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); - Ref<TextLine> name; - name.instance(); - name->set_direction(rtl ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); - name->add_string(text, font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); - text_buf.push_back(name); - } + _refresh_texts(); int tc = tabs.size(); if (current >= tc) { diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h index 91153e5fc3..9ff56afe6e 100644 --- a/scene/gui/tab_container.h +++ b/scene/gui/tab_container.h @@ -73,12 +73,14 @@ private: void _on_mouse_exited(); void _update_current_tab(); void _draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, int p_index, float p_x); + void _refresh_texts(); protected: void _child_renamed_callback(); void _gui_input(const Ref<InputEvent> &p_event); void _notification(int p_what); virtual void add_child_notify(Node *p_child) override; + virtual void move_child_notify(Node *p_child) override; virtual void remove_child_notify(Node *p_child) override; Variant get_drag_data(const Point2 &p_point) override; |