diff options
Diffstat (limited to 'scene/gui/tab_container.cpp')
-rw-r--r-- | scene/gui/tab_container.cpp | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 9953637e4f..102fe18502 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -138,6 +138,13 @@ void TabContainer::gui_input(const Ref<InputEvent> &p_event) { void TabContainer::_notification(int p_what) { switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + // If some nodes happen to be renamed outside the tree, the tab names need to be updated manually. + if (get_tab_count() > 0) { + _refresh_tab_names(); + } + } break; + case NOTIFICATION_READY: case NOTIFICATION_RESIZED: { _update_margins(); @@ -394,7 +401,10 @@ void TabContainer::_drop_data_fw(const Point2 &p_point, const Variant &p_data, C } move_child(get_tab_control(tab_from_id), get_tab_control(hover_now)->get_index(false)); - set_current_tab(hover_now); + if (!is_tab_disabled(hover_now)) { + set_current_tab(hover_now); + } + } else if (get_tabs_rearrange_group() != -1) { // Drag and drop between TabContainers. Node *from_node = get_node(from_path); @@ -409,8 +419,9 @@ void TabContainer::_drop_data_fw(const Point2 &p_point, const Variant &p_data, C } move_child(moving_tabc, get_tab_control(hover_now)->get_index(false)); - - set_current_tab(hover_now); + if (!is_tab_disabled(hover_now)) { + set_current_tab(hover_now); + } } } } @@ -430,12 +441,11 @@ void TabContainer::_on_tab_selected(int p_tab) { emit_signal(SNAME("tab_selected"), p_tab); } -void TabContainer::_child_renamed_callback() { +void TabContainer::_refresh_tab_names() { Vector<Control *> controls = _get_tab_controls(); for (int i = 0; i < controls.size(); i++) { if (!controls[i]->has_meta("_tab_name") && String(controls[i]->get_name()) != get_tab_title(i)) { tab_bar->set_tab_title(i, controls[i]->get_name()); - return; } } } @@ -457,7 +467,7 @@ void TabContainer::add_child_notify(Node *p_child) { _update_margins(); - p_child->connect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback)); + p_child->connect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names)); // TabBar won't emit the "tab_changed" signal when not inside the tree. if (!is_inside_tree()) { @@ -508,7 +518,7 @@ void TabContainer::remove_child_notify(Node *p_child) { if (p_child->has_meta("_tab_name")) { p_child->remove_meta("_tab_name"); } - p_child->disconnect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback)); + p_child->disconnect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names)); // TabBar won't emit the "tab_changed" signal when not inside the tree. if (!is_inside_tree()) { @@ -635,6 +645,11 @@ void TabContainer::set_tab_title(int p_tab, const String &p_title) { tab_bar->set_tab_title(p_tab, p_title); child->set_meta("_tab_name", p_title); } + + _update_margins(); + if (!get_clip_tabs()) { + update_minimum_size(); + } } String TabContainer::get_tab_title(int p_tab) const { @@ -643,6 +658,9 @@ String TabContainer::get_tab_title(int p_tab) const { void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) { tab_bar->set_tab_icon(p_tab, p_icon); + + _update_margins(); + _repaint(); } Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const { @@ -651,6 +669,11 @@ Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const { void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) { tab_bar->set_tab_disabled(p_tab, p_disabled); + + _update_margins(); + if (!get_clip_tabs()) { + update_minimum_size(); + } } bool TabContainer::is_tab_disabled(int p_tab) const { @@ -663,6 +686,11 @@ void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) { tab_bar->set_tab_hidden(p_tab, p_hidden); child->hide(); + + _update_margins(); + if (!get_clip_tabs()) { + update_minimum_size(); + } } bool TabContainer::is_tab_hidden(int p_tab) const { @@ -735,7 +763,9 @@ void TabContainer::set_popup(Node *p_popup) { if (had_popup != bool(popup)) { update(); _update_margins(); - update_minimum_size(); + if (!get_clip_tabs()) { + update_minimum_size(); + } } } @@ -838,6 +868,7 @@ void TabContainer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tabs_visible"), "set_tabs_visible", "are_tabs_visible"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "all_tabs_in_front"), "set_all_tabs_in_front", "is_all_tabs_in_front"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "drag_to_rearrange_enabled"), "set_drag_to_rearrange_enabled", "get_drag_to_rearrange_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "tabs_rearrange_group"), "set_tabs_rearrange_group", "get_tabs_rearrange_group"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_hidden_tabs_for_min_size"), "set_use_hidden_tabs_for_min_size", "get_use_hidden_tabs_for_min_size"); } |