Refresh TextLine buffer when moving tab

This commit is contained in:
gongpha 2020-12-12 23:41:51 +07:00
parent 0762484473
commit 0394ff3c99
2 changed files with 22 additions and 48 deletions

View File

@ -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) {

View File

@ -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;