diff options
Diffstat (limited to 'scene/gui/tab_container.cpp')
-rw-r--r-- | scene/gui/tab_container.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 1697e743be..84a62c71c2 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -209,7 +209,7 @@ void TabContainer::_on_theme_changed() { tab_bar->add_theme_color_override(SNAME("font_outline_color"), get_theme_color(SNAME("font_outline_color"))); tab_bar->add_theme_font_override(SNAME("font"), get_theme_font(SNAME("font"))); tab_bar->add_theme_constant_override(SNAME("font_size"), get_theme_constant(SNAME("font_size"))); - tab_bar->add_theme_constant_override(SNAME("icon_separation"), get_theme_constant(SNAME("icon_separation"))); + tab_bar->add_theme_constant_override(SNAME("hseparation"), get_theme_constant(SNAME("icon_separation"))); tab_bar->add_theme_constant_override(SNAME("outline_size"), get_theme_constant(SNAME("outline_size"))); _update_margins(); @@ -472,6 +472,10 @@ void TabContainer::_on_tab_selected(int p_tab) { emit_signal(SNAME("tab_selected"), p_tab); } +void TabContainer::_on_tab_button_pressed(int p_tab) { + emit_signal(SNAME("tab_button_pressed"), p_tab); +} + void TabContainer::_refresh_tab_names() { Vector<Control *> controls = _get_tab_controls(); for (int i = 0; i < controls.size(); i++) { @@ -497,6 +501,9 @@ void TabContainer::add_child_notify(Node *p_child) { tab_bar->add_tab(p_child->get_name()); _update_margins(); + if (get_tab_count() == 1) { + update(); + } p_child->connect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names)); @@ -545,6 +552,9 @@ void TabContainer::remove_child_notify(Node *p_child) { tab_bar->remove_tab(get_tab_idx_from_control(c)); _update_margins(); + if (get_tab_count() == 0) { + update(); + } if (p_child->has_meta("_tab_name")) { p_child->remove_meta("_tab_name"); @@ -727,6 +737,17 @@ bool TabContainer::is_tab_hidden(int p_tab) const { return tab_bar->is_tab_hidden(p_tab); } +void TabContainer::set_tab_button_icon(int p_tab, const Ref<Texture2D> &p_icon) { + tab_bar->set_tab_button_icon(p_tab, p_icon); + + _update_margins(); + _repaint(); +} + +Ref<Texture2D> TabContainer::get_tab_button_icon(int p_tab) const { + return tab_bar->get_tab_button_icon(p_tab); +} + void TabContainer::get_translatable_strings(List<String> *p_strings) const { Vector<Control *> controls = _get_tab_controls(); for (int i = 0; i < controls.size(); i++) { @@ -871,6 +892,8 @@ void TabContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("is_tab_disabled", "tab_idx"), &TabContainer::is_tab_disabled); ClassDB::bind_method(D_METHOD("set_tab_hidden", "tab_idx", "hidden"), &TabContainer::set_tab_hidden); ClassDB::bind_method(D_METHOD("is_tab_hidden", "tab_idx"), &TabContainer::is_tab_hidden); + ClassDB::bind_method(D_METHOD("set_tab_button_icon", "tab_idx", "icon"), &TabContainer::set_tab_button_icon); + ClassDB::bind_method(D_METHOD("get_tab_button_icon", "tab_idx"), &TabContainer::get_tab_button_icon); ClassDB::bind_method(D_METHOD("get_tab_idx_at_point", "point"), &TabContainer::get_tab_idx_at_point); ClassDB::bind_method(D_METHOD("get_tab_idx_from_control", "control"), &TabContainer::get_tab_idx_from_control); ClassDB::bind_method(D_METHOD("set_popup", "popup"), &TabContainer::set_popup); @@ -890,6 +913,7 @@ void TabContainer::_bind_methods() { ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab"))); ADD_SIGNAL(MethodInfo("tab_selected", PropertyInfo(Variant::INT, "tab"))); + ADD_SIGNAL(MethodInfo("tab_button_pressed", PropertyInfo(Variant::INT, "tab"))); ADD_SIGNAL(MethodInfo("pre_popup_pressed")); ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_alignment", "get_tab_alignment"); @@ -909,6 +933,7 @@ TabContainer::TabContainer() { tab_bar->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE); tab_bar->connect("tab_changed", callable_mp(this, &TabContainer::_on_tab_changed)); tab_bar->connect("tab_selected", callable_mp(this, &TabContainer::_on_tab_selected)); + tab_bar->connect("tab_button_pressed", callable_mp(this, &TabContainer::_on_tab_button_pressed)); connect("mouse_exited", callable_mp(this, &TabContainer::_on_mouse_exited)); } |