diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_node.cpp | 70 | ||||
-rw-r--r-- | editor/editor_node.h | 1 |
2 files changed, 41 insertions, 30 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 076a774efa..716d4a50c3 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -312,7 +312,7 @@ void EditorNode::_update_scene_tabs() { DisplayServer::get_singleton()->global_menu_clear("_dock"); } - // Get all scene names, which may be ambiguous + // Get all scene names, which may be ambiguous. Vector<String> disambiguated_scene_names; Vector<String> full_path_names; for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { @@ -349,34 +349,35 @@ void EditorNode::_update_scene_tabs() { DisplayServer::get_singleton()->global_menu_add_item("_dock", TTR("New Window"), callable_mp(this, &EditorNode::_global_menu_new_window)); } - scene_tabs->set_current_tab(editor_data.get_edited_scene()); + if (scene_tabs->get_tab_count() > 0) { + scene_tabs->set_current_tab(editor_data.get_edited_scene()); + } if (scene_tabs->get_offset_buttons_visible()) { - // move add button to fixed position on the tabbar + // Move the add button to a fixed position. if (scene_tab_add->get_parent() == scene_tabs) { - if (scene_tabs->is_layout_rtl()) { - scene_tab_add->set_position(Point2(tabbar_container->get_size().x - scene_tab_add->get_size().x, 0)); - } else { - scene_tab_add->set_position(Point2(0, 0)); - } scene_tabs->remove_child(scene_tab_add); - tabbar_container->add_child(scene_tab_add); - tabbar_container->move_child(scene_tab_add, 1); + scene_tab_add_ph->add_child(scene_tab_add); + scene_tab_add->set_position(Point2()); } } else { - // move add button to after last tab - if (scene_tab_add->get_parent() == tabbar_container) { - tabbar_container->remove_child(scene_tab_add); + // Move the add button to be after the last tab. + if (scene_tab_add->get_parent() == scene_tab_add_ph) { + scene_tab_add_ph->remove_child(scene_tab_add); scene_tabs->add_child(scene_tab_add); } - Rect2 last_tab = Rect2(); - if (scene_tabs->get_tab_count() != 0) { - last_tab = scene_tabs->get_tab_rect(scene_tabs->get_tab_count() - 1); + + if (scene_tabs->get_tab_count() == 0) { + scene_tab_add->set_position(Point2()); + return; } + + Rect2 last_tab = scene_tabs->get_tab_rect(scene_tabs->get_tab_count() - 1); + int hsep = scene_tabs->get_theme_constant(SNAME("hseparation")); if (scene_tabs->is_layout_rtl()) { - scene_tab_add->set_position(Point2(last_tab.get_position().x - scene_tab_add->get_size().x - 3, last_tab.get_position().y)); + scene_tab_add->set_position(Point2(last_tab.position.x - scene_tab_add->get_size().x - hsep, last_tab.position.y)); } else { - scene_tab_add->set_position(Point2(last_tab.get_position().x + last_tab.get_size().x + 3, last_tab.get_position().y)); + scene_tab_add->set_position(Point2(last_tab.position.x + last_tab.size.width + hsep, last_tab.position.y)); } } } @@ -624,6 +625,10 @@ void EditorNode::_notification(int p_what) { editor_data.clear_edited_scenes(); } break; + case Control::NOTIFICATION_THEME_CHANGED: { + scene_tab_add_ph->set_custom_minimum_size(scene_tab_add->get_minimum_size()); + } break; + case NOTIFICATION_READY: { { _initializing_addons = true; @@ -6227,6 +6232,9 @@ EditorNode::EditorNode() { tab_preview->set_position(Point2(2, 2) * EDSCALE); tab_preview_panel->add_child(tab_preview); + tabbar_container = memnew(HBoxContainer); + srt->add_child(tabbar_container); + scene_tabs = memnew(TabBar); scene_tabs->add_theme_style_override("tab_selected", gui_base->get_theme_stylebox(SNAME("SceneTabFG"), SNAME("EditorStyles"))); scene_tabs->add_theme_style_override("tab_unselected", gui_base->get_theme_stylebox(SNAME("SceneTabBG"), SNAME("EditorStyles"))); @@ -6244,16 +6252,26 @@ EditorNode::EditorNode() { scene_tabs->connect("gui_input", callable_mp(this, &EditorNode::_scene_tab_input)); scene_tabs->connect("active_tab_rearranged", callable_mp(this, &EditorNode::_reposition_active_tab)); scene_tabs->connect("resized", callable_mp(this, &EditorNode::_update_scene_tabs)); - - tabbar_container = memnew(HBoxContainer); scene_tabs->set_h_size_flags(Control::SIZE_EXPAND_FILL); + tabbar_container->add_child(scene_tabs); scene_tabs_context_menu = memnew(PopupMenu); tabbar_container->add_child(scene_tabs_context_menu); scene_tabs_context_menu->connect("id_pressed", callable_mp(this, &EditorNode::_menu_option)); - srt->add_child(tabbar_container); - tabbar_container->add_child(scene_tabs); + scene_tab_add = memnew(Button); + scene_tab_add->set_flat(true); + scene_tab_add->set_tooltip(TTR("Add a new scene.")); + scene_tab_add->set_icon(gui_base->get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); + scene_tab_add->add_theme_color_override("icon_normal_color", Color(0.6f, 0.6f, 0.6f, 0.8f)); + scene_tabs->add_child(scene_tab_add); + scene_tab_add->connect("pressed", callable_mp(this, &EditorNode::_menu_option), make_binds(FILE_NEW_SCENE)); + + scene_tab_add_ph = memnew(Control); + scene_tab_add_ph->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); + scene_tab_add_ph->set_custom_minimum_size(scene_tab_add->get_minimum_size()); + tabbar_container->add_child(scene_tab_add_ph); + distraction_free = memnew(Button); distraction_free->set_flat(true); ED_SHORTCUT_AND_COMMAND("editor/distraction_free_mode", TTR("Distraction Free Mode"), KeyModifierMask::CMD | KeyModifierMask::SHIFT | Key::F11); @@ -6263,15 +6281,7 @@ EditorNode::EditorNode() { distraction_free->connect("pressed", callable_mp(this, &EditorNode::_toggle_distraction_free_mode)); distraction_free->set_icon(gui_base->get_theme_icon(SNAME("DistractionFree"), SNAME("EditorIcons"))); distraction_free->set_toggle_mode(true); - - scene_tab_add = memnew(Button); - scene_tab_add->set_flat(true); - tabbar_container->add_child(scene_tab_add); tabbar_container->add_child(distraction_free); - scene_tab_add->set_tooltip(TTR("Add a new scene.")); - scene_tab_add->set_icon(gui_base->get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); - scene_tab_add->add_theme_color_override("icon_normal_color", Color(0.6f, 0.6f, 0.6f, 0.8f)); - scene_tab_add->connect("pressed", callable_mp(this, &EditorNode::_menu_option), make_binds(FILE_NEW_SCENE)); scene_root_parent = memnew(PanelContainer); scene_root_parent->set_custom_minimum_size(Size2(0, 80) * EDSCALE); diff --git a/editor/editor_node.h b/editor/editor_node.h index 5c013a18d9..8d322a1bfd 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -384,6 +384,7 @@ private: HBoxContainer *tabbar_container; Button *distraction_free; Button *scene_tab_add; + Control *scene_tab_add_ph; bool scene_distraction; bool script_distraction; |