summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/editor_node.cpp38
-rw-r--r--editor/editor_node.h3
-rw-r--r--scene/gui/tabs.cpp161
-rw-r--r--scene/gui/tabs.h7
4 files changed, 145 insertions, 64 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 777aedefd2..0ba121d62f 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -141,7 +141,25 @@ void EditorNode::_update_scene_tabs() {
}
scene_tabs->set_current_tab(editor_data.get_edited_scene());
- scene_tabs->ensure_tab_visible(editor_data.get_edited_scene());
+
+ int current = editor_data.get_edited_scene();
+ if (scene_tabs->get_offset_buttons_visible()) {
+ // move add button to fixed position on the tabbar
+ if (scene_tab_add->get_parent() == scene_tabs) {
+ 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);
+ }
+ } else {
+ // move add button to after last tab
+ if (scene_tab_add->get_parent() == tabbar_container) {
+ tabbar_container->remove_child(scene_tab_add);
+ scene_tabs->add_child(scene_tab_add);
+ }
+ Rect2 last_tab = scene_tabs->get_tab_rect(scene_tabs->get_tab_count() - 1);
+ scene_tab_add->set_position(Point2(last_tab.get_position().x + last_tab.get_size().x + 3, last_tab.get_position().y));
+ }
}
void EditorNode::_update_title() {
@@ -327,6 +345,7 @@ void EditorNode::_notification(int p_what) {
prev_scene->set_icon(gui_base->get_icon("PrevScene", "EditorIcons"));
distraction_free->set_icon(gui_base->get_icon("DistractionFree", "EditorIcons"));
+ scene_tab_add->set_icon(gui_base->get_icon("Add", "EditorIcons"));
resource_new_button->set_icon(gui_base->get_icon("New", "EditorIcons"));
resource_load_button->set_icon(gui_base->get_icon("Load", "EditorIcons"));
@@ -344,6 +363,9 @@ void EditorNode::_notification(int p_what) {
dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons"));
update_menu->set_icon(gui_base->get_icon("Progress1", "EditorIcons"));
}
+ if (p_what = Control::NOTIFICATION_RESIZED) {
+ _update_scene_tabs();
+ }
}
void EditorNode::_fs_changed() {
@@ -1759,6 +1781,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
int idx = editor_data.add_edited_scene(-1);
_scene_tab_changed(idx);
editor_data.clear_editor_states();
+ _update_scene_tabs();
} break;
case FILE_NEW_INHERITED_SCENE:
@@ -3897,6 +3920,7 @@ void EditorNode::_scene_tab_closed(int p_tab) {
} else {
_discard_changes();
}
+ _update_scene_tabs();
}
void EditorNode::_scene_tab_hover(int p_tab) {
@@ -4863,20 +4887,28 @@ EditorNode::EditorNode() {
scene_tabs->connect("mouse_exited", this, "_scene_tab_exit");
scene_tabs->connect("gui_input", this, "_scene_tab_input");
scene_tabs->connect("reposition_active_tab_request", this, "_reposition_active_tab");
+ scene_tabs->connect("resized", this, "_update_scene_tabs");
- HBoxContainer *tabbar_container = memnew(HBoxContainer);
+ tabbar_container = memnew(HBoxContainer);
scene_tabs->set_h_size_flags(Control::SIZE_EXPAND_FILL);
srt->add_child(tabbar_container);
tabbar_container->add_child(scene_tabs);
distraction_free = memnew(ToolButton);
- tabbar_container->add_child(distraction_free);
distraction_free->set_shortcut(ED_SHORTCUT("editor/distraction_free_mode", TTR("Distraction Free Mode"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F11));
distraction_free->set_tooltip(TTR("Toggle distraction-free mode."));
distraction_free->connect("pressed", this, "_toggle_distraction_free_mode");
distraction_free->set_icon(gui_base->get_icon("DistractionFree", "EditorIcons"));
distraction_free->set_toggle_mode(true);
+ scene_tab_add = memnew(ToolButton);
+ 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_icon("Add", "EditorIcons"));
+ scene_tab_add->add_color_override("icon_color_normal", Color(0.6f, 0.6f, 0.6f, 0.8f));
+ scene_tab_add->connect("pressed", this, "_menu_option", make_binds(FILE_NEW_SCENE));
+
scene_root_parent = memnew(PanelContainer);
scene_root_parent->set_custom_minimum_size(Size2(0, 80) * EDSCALE);
scene_root_parent->add_style_override("panel", gui_base->get_stylebox("Content", "EditorStyles"));
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 54cb414835..a2b4a0a049 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -344,7 +344,10 @@ private:
int dock_popup_selected;
Timer *dock_drag_timer;
bool docks_visible;
+
+ HBoxContainer *tabbar_container;
ToolButton *distraction_free;
+ ToolButton *scene_tab_add;
bool scene_distraction;
bool script_distraction;
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 49823e18fc..1fb0f84223 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -142,91 +142,107 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> mb = p_event;
- if (rb_pressing && mb.is_valid() &&
- !mb->is_pressed() &&
- mb->get_button_index() == BUTTON_LEFT) {
+ if (mb.is_valid()) {
- if (rb_hover != -1) {
- //pressed
- emit_signal("right_button_pressed", rb_hover);
+ if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP && !mb->get_command()) {
+
+ if (scrolling_enabled && buttons_visible) {
+ if (offset > 0) {
+ offset--;
+ update();
+ }
+ }
}
- rb_pressing = false;
- update();
- }
+ if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN && !mb->get_command()) {
+ if (scrolling_enabled && buttons_visible) {
+ if (missing_right) {
+ offset++;
+ update();
+ }
+ }
+ }
+
+ if (rb_pressing && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
- if (cb_pressing && mb.is_valid() &&
- !mb->is_pressed() &&
- mb->get_button_index() == BUTTON_LEFT) {
+ if (rb_hover != -1) {
+ //pressed
+ emit_signal("right_button_pressed", rb_hover);
+ }
- if (cb_hover != -1) {
- //pressed
- emit_signal("tab_close", cb_hover);
+ rb_pressing = false;
+ update();
}
- cb_pressing = false;
- update();
- }
+ if (cb_pressing && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
- if (mb.is_valid() &&
- mb->is_pressed() &&
- mb->get_button_index() == BUTTON_LEFT) {
+ if (cb_hover != -1) {
+ //pressed
+ emit_signal("tab_close", cb_hover);
+ }
- // clicks
- Point2 pos(mb->get_position().x, mb->get_position().y);
+ cb_pressing = false;
+ update();
+ }
- if (buttons_visible) {
+ if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
- Ref<Texture> incr = get_icon("increment");
- Ref<Texture> decr = get_icon("decrement");
+ // clicks
+ Point2 pos(mb->get_position().x, mb->get_position().y);
- int limit = get_size().width - incr->get_width() - decr->get_width();
+ if (buttons_visible) {
- if (pos.x > limit + decr->get_width()) {
- if (missing_right) {
- offset++;
- update();
- }
- return;
- } else if (pos.x > limit) {
- if (offset > 0) {
- offset--;
- update();
+ Ref<Texture> incr = get_icon("increment");
+ Ref<Texture> decr = get_icon("decrement");
+
+ int limit = get_size().width - incr->get_width() - decr->get_width();
+
+ if (pos.x > limit + decr->get_width()) {
+ if (missing_right) {
+ offset++;
+ update();
+ }
+ return;
+ } else if (pos.x > limit) {
+ if (offset > 0) {
+ offset--;
+ update();
+ }
+ return;
}
- return;
}
- }
- int found = -1;
- for (int i = 0; i < tabs.size(); i++) {
+ int found = -1;
+ for (int i = 0; i < tabs.size(); i++) {
- if (i < offset)
- continue;
+ if (i < offset)
+ continue;
- if (tabs[i].rb_rect.has_point(pos)) {
- rb_pressing = true;
- update();
- return;
- }
+ if (tabs[i].rb_rect.has_point(pos)) {
+ rb_pressing = true;
+ update();
+ return;
+ }
- if (tabs[i].cb_rect.has_point(pos)) {
- cb_pressing = true;
- update();
- return;
- }
+ if (tabs[i].cb_rect.has_point(pos)) {
+ cb_pressing = true;
+ update();
+ return;
+ }
- if (pos.x >= tabs[i].ofs_cache && pos.x < tabs[i].ofs_cache + tabs[i].size_cache) {
- if (!tabs[i].disabled) {
- found = i;
+ if (pos.x >= tabs[i].ofs_cache && pos.x < tabs[i].ofs_cache + tabs[i].size_cache) {
+ if (!tabs[i].disabled) {
+ found = i;
+ }
+ break;
}
- break;
}
- }
- if (found != -1) {
+ if (found != -1) {
- set_current_tab(found);
- emit_signal("tab_clicked", found);
+ set_current_tab(found);
+ emit_signal("tab_clicked", found);
+ }
}
}
}
@@ -440,6 +456,14 @@ int Tabs::get_hovered_tab() const {
return hover;
}
+int Tabs::get_tab_offset() const {
+ return offset;
+}
+
+bool Tabs::get_offset_buttons_visible() const {
+ return buttons_visible;
+}
+
void Tabs::set_tab_title(int p_tab, const String &p_title) {
ERR_FAIL_INDEX(p_tab, tabs.size());
@@ -484,6 +508,7 @@ void Tabs::set_tab_right_button(int p_tab, const Ref<Texture> &p_right_button) {
ERR_FAIL_INDEX(p_tab, tabs.size());
tabs[p_tab].right_button = p_right_button;
+ _update_cache();
update();
minimum_size_changed();
}
@@ -783,6 +808,14 @@ void Tabs::set_min_width(int p_width) {
min_width = p_width;
}
+void Tabs::set_scrolling_enabled(bool p_enabled) {
+ scrolling_enabled = p_enabled;
+}
+
+bool Tabs::get_scrolling_enabled() const {
+ return scrolling_enabled;
+}
+
void Tabs::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &Tabs::_gui_input);
@@ -799,11 +832,15 @@ void Tabs::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_tab", "title", "icon"), &Tabs::add_tab, DEFVAL(""), DEFVAL(Ref<Texture>()));
ClassDB::bind_method(D_METHOD("set_tab_align", "align"), &Tabs::set_tab_align);
ClassDB::bind_method(D_METHOD("get_tab_align"), &Tabs::get_tab_align);
+ ClassDB::bind_method(D_METHOD("get_tab_offset"), &Tabs::get_tab_offset);
+ ClassDB::bind_method(D_METHOD("get_offset_buttons_visible"), &Tabs::get_offset_buttons_visible);
ClassDB::bind_method(D_METHOD("ensure_tab_visible", "idx"), &Tabs::ensure_tab_visible);
ClassDB::bind_method(D_METHOD("get_tab_rect", "tab_idx"), &Tabs::get_tab_rect);
ClassDB::bind_method(D_METHOD("move_tab", "from", "to"), &Tabs::move_tab);
ClassDB::bind_method(D_METHOD("set_tab_close_display_policy", "policy"), &Tabs::set_tab_close_display_policy);
ClassDB::bind_method(D_METHOD("get_tab_close_display_policy"), &Tabs::get_tab_close_display_policy);
+ ClassDB::bind_method(D_METHOD("set_scrolling_enabled", "enabled"), &Tabs::set_scrolling_enabled);
+ ClassDB::bind_method(D_METHOD("get_scrolling_enabled"), &Tabs::get_scrolling_enabled);
ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab")));
ADD_SIGNAL(MethodInfo("right_button_pressed", PropertyInfo(Variant::INT, "tab")));
@@ -814,6 +851,7 @@ void Tabs::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), "set_current_tab", "get_current_tab");
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "tab_close_display_policy", PROPERTY_HINT_ENUM, "Show Never,Show Active Only,Show Always"), "set_tab_close_display_policy", "get_tab_close_display_policy");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scrolling_enabled"), "set_scrolling_enabled", "get_scrolling_enabled");
BIND_ENUM_CONSTANT(ALIGN_LEFT);
BIND_ENUM_CONSTANT(ALIGN_CENTER);
@@ -841,4 +879,5 @@ Tabs::Tabs() {
max_drawn_tab = 0;
min_width = 0;
+ scrolling_enabled = true;
}
diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h
index 73fa40bbb8..4eb6be3435 100644
--- a/scene/gui/tabs.h
+++ b/scene/gui/tabs.h
@@ -88,6 +88,7 @@ private:
int hover; // hovered tab
int min_width;
+ bool scrolling_enabled;
int get_tab_width(int p_idx) const;
void _ensure_no_over_offset();
@@ -131,10 +132,16 @@ public:
int get_current_tab() const;
int get_hovered_tab() const;
+ int get_tab_offset() const;
+ bool get_offset_buttons_visible() const;
+
void remove_tab(int p_idx);
void clear_tabs();
+ void set_scrolling_enabled(bool p_enabled);
+ bool get_scrolling_enabled() const;
+
void ensure_tab_visible(int p_idx);
void set_min_width(int p_width);