summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/control.cpp106
-rw-r--r--scene/gui/control.h24
-rw-r--r--scene/gui/file_dialog.cpp5
-rw-r--r--scene/gui/graph_edit.cpp22
-rw-r--r--scene/gui/graph_edit.h1
-rw-r--r--scene/gui/item_list.cpp12
-rw-r--r--scene/gui/line_edit.cpp3
-rw-r--r--scene/gui/rich_text_label.cpp36
-rw-r--r--scene/gui/rich_text_label.h3
-rw-r--r--scene/gui/scroll_container.cpp11
-rw-r--r--scene/gui/tabs.cpp161
-rw-r--r--scene/gui/tabs.h7
-rw-r--r--scene/gui/text_edit.cpp672
-rw-r--r--scene/gui/text_edit.h42
-rw-r--r--scene/gui/tree.cpp38
15 files changed, 926 insertions, 217 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 3976a2ad48..adca78d1d4 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -45,7 +45,7 @@
#endif
#include <stdio.h>
-Variant Control::edit_get_state() const {
+Dictionary Control::_edit_get_state() const {
Dictionary s;
s["rect"] = get_rect();
@@ -59,22 +59,78 @@ Variant Control::edit_get_state() const {
s["anchors"] = anchors;
return s;
}
-void Control::edit_set_state(const Variant &p_state) {
+void Control::_edit_set_state(const Dictionary &p_state) {
- Dictionary s = p_state;
+ Dictionary state = p_state;
- Rect2 state = s["rect"];
- set_position(state.position);
- set_size(state.size);
- set_rotation(s["rotation"]);
- set_scale(s["scale"]);
- Array anchors = s["anchors"];
+ Rect2 rect = state["rect"];
+ set_position(rect.position);
+ set_size(rect.size);
+ set_rotation(state["rotation"]);
+ set_scale(state["scale"]);
+ Array anchors = state["anchors"];
set_anchor(MARGIN_LEFT, anchors[0]);
set_anchor(MARGIN_TOP, anchors[1]);
set_anchor(MARGIN_RIGHT, anchors[2]);
set_anchor(MARGIN_BOTTOM, anchors[3]);
}
+void Control::_edit_set_position(const Point2 &p_position) {
+ set_position(p_position);
+};
+
+Point2 Control::_edit_get_position() const {
+ return get_position();
+};
+
+void Control::_edit_set_rect(const Rect2 &p_edit_rect) {
+
+ Transform2D xform = _get_internal_transform();
+
+ Vector2 new_pos = xform.basis_xform(p_edit_rect.position);
+
+ Vector2 pos = get_position() + new_pos;
+
+ Rect2 new_rect = get_rect();
+ new_rect.position = pos.snapped(Vector2(1, 1));
+ new_rect.size = p_edit_rect.size.snapped(Vector2(1, 1));
+
+ set_position(new_rect.position);
+ set_size(new_rect.size);
+}
+
+Rect2 Control::_edit_get_rect() const {
+ return Rect2(Point2(), get_size());
+}
+
+bool Control::_edit_use_rect() const {
+ return true;
+}
+
+void Control::_edit_set_rotation(float p_rotation) {
+ set_rotation(p_rotation);
+}
+
+float Control::_edit_get_rotation() const {
+ return get_rotation();
+}
+
+bool Control::_edit_use_rotation() const {
+ return true;
+}
+
+void Control::_edit_set_pivot(const Point2 &p_pivot) {
+ set_pivot_offset(p_pivot);
+}
+
+Point2 Control::_edit_get_pivot() const {
+ return get_pivot_offset();
+}
+
+bool Control::_edit_use_pivot() const {
+ return true;
+}
+
void Control::set_custom_minimum_size(const Size2 &p_custom) {
if (p_custom == data.custom_minimum_size)
@@ -96,7 +152,7 @@ Size2 Control::get_combined_minimum_size() const {
return minsize;
}
-Size2 Control::edit_get_minimum_size() const {
+Size2 Control::_edit_get_minimum_size() const {
return get_combined_minimum_size();
}
@@ -110,23 +166,6 @@ Transform2D Control::_get_internal_transform() const {
return offset.affine_inverse() * (rot_scale * offset);
}
-void Control::edit_set_rect(const Rect2 &p_edit_rect) {
-
- Transform2D xform = _get_internal_transform();
-
- // xform[2] += get_position();
-
- Vector2 new_pos = xform.basis_xform(p_edit_rect.position);
-
- Vector2 pos = get_position() + new_pos;
-
- Rect2 new_rect = get_rect();
- new_rect.position = pos.snapped(Vector2(1, 1));
- new_rect.size = p_edit_rect.size.snapped(Vector2(1, 1));
-
- set_position(new_rect.position);
- set_size(new_rect.size);
-}
bool Control::_set(const StringName &p_name, const Variant &p_value) {
@@ -1210,7 +1249,7 @@ Size2 Control::get_parent_area_size() const {
if (data.parent_canvas_item) {
- parent_size = data.parent_canvas_item->get_item_rect().size;
+ parent_size = data.parent_canvas_item->_edit_get_rect().size;
} else {
parent_size = get_viewport()->get_visible_rect().size;
@@ -1289,7 +1328,7 @@ float Control::_get_parent_range(int p_idx) const {
}
if (data.parent_canvas_item) {
- return data.parent_canvas_item->get_item_rect().size[p_idx & 1];
+ return data.parent_canvas_item->_edit_get_rect().size[p_idx & 1];
} else {
return get_viewport()->get_visible_rect().size[p_idx & 1];
}
@@ -1751,11 +1790,6 @@ Rect2 Control::get_rect() const {
return Rect2(get_position(), get_size());
}
-Rect2 Control::get_item_rect() const {
-
- return Rect2(Point2(), get_size());
-}
-
void Control::add_icon_override(const StringName &p_name, const Ref<Texture> &p_icon) {
ERR_FAIL_COND(p_icon.is_null());
@@ -2254,7 +2288,7 @@ Control *Control::_get_focus_neighbour(Margin p_margin, int p_count) {
Point2 points[4];
Transform2D xform = get_global_transform();
- Rect2 rect = get_item_rect();
+ Rect2 rect = _edit_get_rect();
points[0] = xform.xform(rect.position);
points[1] = xform.xform(rect.position + Point2(rect.size.x, 0));
@@ -2313,7 +2347,7 @@ void Control::_window_find_focus_neighbour(const Vector2 &p_dir, Node *p_at, con
Point2 points[4];
Transform2D xform = c->get_global_transform();
- Rect2 rect = c->get_item_rect();
+ Rect2 rect = c->_edit_get_rect();
points[0] = xform.xform(rect.position);
points[1] = xform.xform(rect.position + Point2(rect.size.x, 0));
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 94c484ca50..92d1c969fc 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -271,10 +271,25 @@ public:
};
- virtual Variant edit_get_state() const;
- virtual void edit_set_state(const Variant &p_state);
- virtual void edit_set_rect(const Rect2 &p_edit_rect);
- virtual Size2 edit_get_minimum_size() const;
+ virtual Dictionary _edit_get_state() const;
+ virtual void _edit_set_state(const Dictionary &p_state);
+
+ virtual void _edit_set_position(const Point2 &p_position);
+ virtual Point2 _edit_get_position() const;
+
+ virtual void _edit_set_rect(const Rect2 &p_edit_rect);
+ virtual Rect2 _edit_get_rect() const;
+ virtual bool _edit_use_rect() const;
+
+ virtual void _edit_set_rotation(float p_rotation);
+ virtual float _edit_get_rotation() const;
+ virtual bool _edit_use_rotation() const;
+
+ virtual void _edit_set_pivot(const Point2 &p_pivot);
+ virtual Point2 _edit_get_pivot() const;
+ virtual bool _edit_use_pivot() const;
+
+ virtual Size2 _edit_get_minimum_size() const;
void accept_event();
@@ -427,7 +442,6 @@ public:
CursorShape get_default_cursor_shape() const;
virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const;
- virtual Rect2 get_item_rect() const;
virtual Transform2D get_transform() const;
bool is_toplevel_control() const;
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 6ade4fcc38..6aba535572 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -323,6 +323,9 @@ void FileDialog::update_file_list() {
while ((item = dir_access->get_next(&isdir)) != "") {
+ if (item == ".")
+ continue;
+
ishidden = dir_access->current_is_hidden();
if (show_hidden || !ishidden) {
@@ -344,7 +347,7 @@ void FileDialog::update_file_list() {
while (!dirs.empty()) {
String &dir_name = dirs.front()->get();
TreeItem *ti = tree->create_item(root);
- ti->set_text(0, dir_name + "/");
+ ti->set_text(0, dir_name);
ti->set_icon(0, folder);
Dictionary d;
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 946a8c47a3..da52fb39e0 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -964,6 +964,19 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
emit_signal("delete_nodes_request");
accept_event();
}
+
+ Ref<InputEventMagnifyGesture> magnify_gesture = p_ev;
+ if (magnify_gesture.is_valid()) {
+
+ set_zoom_custom(zoom * magnify_gesture->get_factor(), magnify_gesture->get_position());
+ }
+
+ Ref<InputEventPanGesture> pan_gesture = p_ev;
+ if (pan_gesture.is_valid()) {
+
+ h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8);
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
+ }
}
void GraphEdit::clear_connections() {
@@ -975,6 +988,11 @@ void GraphEdit::clear_connections() {
void GraphEdit::set_zoom(float p_zoom) {
+ set_zoom_custom(p_zoom, get_size() / 2);
+}
+
+void GraphEdit::set_zoom_custom(float p_zoom, const Vector2 &p_center) {
+
p_zoom = CLAMP(p_zoom, MIN_ZOOM, MAX_ZOOM);
if (zoom == p_zoom)
return;
@@ -982,7 +1000,7 @@ void GraphEdit::set_zoom(float p_zoom) {
zoom_minus->set_disabled(zoom == MIN_ZOOM);
zoom_plus->set_disabled(zoom == MAX_ZOOM);
- Vector2 sbofs = (Vector2(h_scroll->get_value(), v_scroll->get_value()) + get_size() / 2) / zoom;
+ Vector2 sbofs = (Vector2(h_scroll->get_value(), v_scroll->get_value()) + p_center) / zoom;
zoom = p_zoom;
top_layer->update();
@@ -992,7 +1010,7 @@ void GraphEdit::set_zoom(float p_zoom) {
if (is_visible_in_tree()) {
- Vector2 ofs = sbofs * zoom - get_size() / 2;
+ Vector2 ofs = sbofs * zoom - p_center;
h_scroll->set_value(ofs.x);
v_scroll->set_value(ofs.y);
}
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index 4656b50133..e8e530848d 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -179,6 +179,7 @@ public:
bool is_valid_connection_type(int p_type, int p_with_type) const;
void set_zoom(float p_zoom);
+ void set_zoom_custom(float p_zoom, const Vector2 &p_center);
float get_zoom() const;
GraphEditFilter *get_top_layer() const { return top_layer; }
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index e9e9dcc859..51ab49e643 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -525,6 +525,11 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
return;
}
+ if (mb->get_button_index() == BUTTON_RIGHT) {
+ emit_signal("rmb_clicked", mb->get_position());
+
+ return;
+ }
}
if (mb.is_valid() && mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
@@ -708,6 +713,12 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
}
}
}
+
+ Ref<InputEventPanGesture> pan_gesture = p_event;
+ if (pan_gesture.is_valid()) {
+
+ scroll_bar->set_value(scroll_bar->get_value() + scroll_bar->get_page() * pan_gesture->get_delta().y / 8);
+ }
}
void ItemList::ensure_current_is_visible() {
@@ -1397,6 +1408,7 @@ void ItemList::_bind_methods() {
ADD_SIGNAL(MethodInfo("item_rmb_selected", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::VECTOR2, "at_position")));
ADD_SIGNAL(MethodInfo("multi_selected", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "selected")));
ADD_SIGNAL(MethodInfo("item_activated", PropertyInfo(Variant::INT, "index")));
+ ADD_SIGNAL(MethodInfo("rmb_clicked", PropertyInfo(Variant::VECTOR2, "at_position")));
GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000);
}
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 5d3e5ec0e8..f7bf1cd9ea 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -1309,6 +1309,7 @@ void LineEdit::set_expand_to_text_length(bool p_enabled) {
expand_to_text_length = p_enabled;
minimum_size_changed();
+ set_window_pos(0);
}
bool LineEdit::get_expand_to_text_length() const {
@@ -1428,7 +1429,7 @@ void LineEdit::_bind_methods() {
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "max_length"), "set_max_length", "get_max_length");
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable");
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "secret"), "set_secret", "is_secret");
- ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "expand_to_len"), "set_expand_to_text_length", "get_expand_to_text_length");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "expand_to_text_length"), "set_expand_to_text_length", "get_expand_to_text_length");
ADD_PROPERTY(PropertyInfo(Variant::INT, "focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_focus_mode", "get_focus_mode");
ADD_GROUP("Placeholder", "placeholder_");
ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "placeholder_text"), "set_placeholder", "get_placeholder");
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 798acb9d52..124c268c8a 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -817,6 +817,16 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
}
+ Ref<InputEventPanGesture> pan_gesture = p_event;
+ if (pan_gesture.is_valid()) {
+
+ if (scroll_active)
+
+ vscroll->set_value(vscroll->get_value() + vscroll->get_page() * pan_gesture->get_delta().y * 0.5 / 8);
+
+ return;
+ }
+
Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
@@ -877,11 +887,13 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
if (main->first_invalid_line < main->lines.size())
return;
+ int line = 0;
+ Item *item = NULL;
+ bool outside;
+ _find_click(main, m->get_position(), &item, &line, &outside);
+
if (selection.click) {
- int line = 0;
- Item *item = NULL;
- _find_click(main, m->get_position(), &item, &line);
if (!item)
return; // do not update
@@ -912,6 +924,22 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
selection.active = true;
update();
}
+
+ Variant meta;
+ if (item && !outside && _find_meta(item, &meta)) {
+ if (meta_hovering != item) {
+ if (meta_hovering) {
+ emit_signal("meta_hover_ended", current_meta);
+ }
+ meta_hovering = static_cast<ItemMeta *>(item);
+ current_meta = meta;
+ emit_signal("meta_hover_started", meta);
+ }
+ } else if (meta_hovering) {
+ emit_signal("meta_hover_ended", current_meta);
+ meta_hovering = NULL;
+ current_meta = false;
+ }
}
}
@@ -1968,6 +1996,8 @@ void RichTextLabel::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color");
ADD_SIGNAL(MethodInfo("meta_clicked", PropertyInfo(Variant::NIL, "meta", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT)));
+ ADD_SIGNAL(MethodInfo("meta_hover_started", PropertyInfo(Variant::NIL, "meta", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT)));
+ ADD_SIGNAL(MethodInfo("meta_hover_ended", PropertyInfo(Variant::NIL, "meta", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT)));
BIND_ENUM_CONSTANT(ALIGN_LEFT);
BIND_ENUM_CONSTANT(ALIGN_CENTER);
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index f9e37b1094..1096e3f650 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -225,6 +225,9 @@ private:
Align default_align;
+ ItemMeta *meta_hovering;
+ Variant current_meta;
+
void _invalidate_current_line(ItemFrame *p_frame);
void _validate_line_caches(ItemFrame *p_frame);
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index 9022d67a4a..a71a1c5f92 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -180,6 +180,17 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
time_since_motion = 0;
}
}
+
+ Ref<InputEventPanGesture> pan_gesture = p_gui_input;
+ if (pan_gesture.is_valid()) {
+
+ if (h_scroll->is_visible_in_tree()) {
+ h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8);
+ }
+ if (v_scroll->is_visible_in_tree()) {
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
+ }
+ }
}
void ScrollContainer::_update_scrollbar_position() {
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);
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 1b87771fd4..69dc7b21fe 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -274,6 +274,7 @@ void TextEdit::Text::insert(int p_at, const String &p_text) {
Line line;
line.marked = false;
line.breakpoint = false;
+ line.hidden = false;
line.width_cache = -1;
line.data = p_text;
text.insert(p_at, line);
@@ -297,9 +298,11 @@ void TextEdit::_update_scrollbars() {
int hscroll_rows = ((hmin.height - 1) / get_row_height()) + 1;
int visible_rows = get_visible_rows();
- int total_rows = text.size();
+ int num_rows = MAX(visible_rows, num_lines_from(CLAMP(cursor.line_ofs, 0, text.size() - 1), MIN(visible_rows, text.size() - 1 - cursor.line_ofs)));
+
+ int total_rows = (is_hiding_enabled() ? get_total_unhidden_rows() : text.size());
if (scroll_past_end_of_file_enabled) {
- total_rows += get_visible_rows() - 1;
+ total_rows += visible_rows - 1;
}
int vscroll_pixels = v_scroll->get_combined_minimum_size().width;
@@ -313,6 +316,10 @@ void TextEdit::_update_scrollbars() {
total_width += cache.breakpoint_gutter_width;
}
+ if (draw_fold_gutter) {
+ total_width += cache.fold_gutter_width;
+ }
+
bool use_hscroll = true;
bool use_vscroll = true;
@@ -347,12 +354,11 @@ void TextEdit::_update_scrollbars() {
v_scroll->set_step(1);
}
- if (fabs(v_scroll->get_value() - (double)cursor.line_ofs) >= 1) {
- v_scroll->set_value(cursor.line_ofs);
- }
-
+ update_line_scroll_pos();
} else {
cursor.line_ofs = 0;
+ line_scroll_pos = 0;
+ v_scroll->set_value(0);
v_scroll->hide();
}
@@ -551,6 +557,13 @@ void TextEdit::_notification(int p_what) {
cache.breakpoint_gutter_width = 0;
}
+ if (draw_fold_gutter) {
+ fold_gutter_width = (get_row_height() * 55) / 100;
+ cache.fold_gutter_width = fold_gutter_width;
+ } else {
+ cache.fold_gutter_width = 0;
+ }
+
int line_number_char_count = 0;
{
@@ -573,7 +586,7 @@ void TextEdit::_notification(int p_what) {
RID ci = get_canvas_item();
VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
- int xmargin_beg = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width;
+ int xmargin_beg = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width;
int xmargin_end = cache.size.width - cache.style_normal->get_margin(MARGIN_RIGHT);
//let's do it easy for now:
cache.style_normal->draw(ci, Rect2(Point2(), cache.size));
@@ -780,10 +793,22 @@ void TextEdit::_notification(int p_what) {
String highlighted_text = get_selection_text();
String line_num_padding = line_numbers_zero_padded ? "0" : " ";
+ update_line_scroll_pos();
+ int line = cursor.line_ofs - 1;
for (int i = 0; i < visible_rows; i++) {
- int line = i + cursor.line_ofs;
+ line++;
+
+ if (line < 0 || line >= (int)text.size())
+ continue;
+
+ while (is_line_hidden(line)) {
+ line++;
+ if (line < 0 || line >= (int)text.size()) {
+ break;
+ }
+ }
if (line < 0 || line >= (int)text.size())
continue;
@@ -794,7 +819,7 @@ void TextEdit::_notification(int p_what) {
int char_ofs = 0;
int ofs_y = (i * get_row_height() + cache.line_spacing / 2);
if (smooth_scroll_enabled) {
- ofs_y -= (v_scroll->get_value() - cursor.line_ofs) * get_row_height();
+ ofs_y -= (v_scroll->get_value() - get_line_scroll_pos()) * get_row_height();
}
bool prev_is_char = false;
@@ -857,6 +882,21 @@ void TextEdit::_notification(int p_what) {
}
}
+ // draw fold markers
+ if (draw_fold_gutter) {
+ int horizontal_gap = (cache.fold_gutter_width * 30) / 100;
+ int gutter_left = cache.style_normal->get_margin(MARGIN_LEFT) + cache.breakpoint_gutter_width + cache.line_number_w;
+ if (is_folded(line)) {
+ int xofs = horizontal_gap - (cache.can_fold_icon->get_width()) / 2;
+ int yofs = (get_row_height() - cache.folded_icon->get_height()) / 2;
+ cache.folded_icon->draw(ci, Point2(gutter_left + xofs, ofs_y + yofs), Color(0.8f, 0.8f, 0.8f, 0.8f));
+ } else if (can_fold(line)) {
+ int xofs = -cache.can_fold_icon->get_width() / 2 - horizontal_gap + 3;
+ int yofs = (get_row_height() - cache.can_fold_icon->get_height()) / 2;
+ cache.can_fold_icon->draw(ci, Point2(gutter_left + xofs, ofs_y + yofs), Color(0.8f, 0.8f, 0.8f, 0.8f));
+ }
+ }
+
if (cache.line_number_w) {
String fc = String::num(line + 1);
while (fc.length() < line_number_char_count) {
@@ -1196,6 +1236,12 @@ void TextEdit::_notification(int p_what) {
}
char_ofs += char_w;
+
+ if (j == str.length() - 1 && is_folded(line)) {
+ int yofs = (get_row_height() - cache.folded_eol_icon->get_height()) / 2;
+ int xofs = cache.folded_eol_icon->get_width() / 2;
+ cache.folded_eol_icon->draw(ci, Point2(char_ofs + char_margin + xofs, ofs_y + yofs), Color(1, 1, 1, 1));
+ }
}
if (cursor.column == str.length() && cursor.line == line && (char_ofs + char_margin) >= xmargin_beg) {
@@ -1538,6 +1584,12 @@ void TextEdit::backspace_at_cursor() {
int prev_line = cursor.column ? cursor.line : cursor.line - 1;
int prev_column = cursor.column ? (cursor.column - 1) : (text[cursor.line - 1].length());
+
+ if (is_line_hidden(cursor.line))
+ set_line_as_hidden(prev_line, true);
+ if (is_line_set_as_breakpoint(cursor.line))
+ set_line_as_breakpoint(prev_line, true);
+
if (auto_brace_completion_enabled &&
cursor.column > 0 &&
_is_pair_left_symbol(text[cursor.line][cursor.column - 1])) {
@@ -1577,7 +1629,7 @@ void TextEdit::backspace_at_cursor() {
}
}
- cursor_set_line(prev_line);
+ cursor_set_line(prev_line, true, true);
cursor_set_column(prev_column);
}
@@ -1651,10 +1703,18 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
float rows = p_mouse.y;
rows -= cache.style_normal->get_margin(MARGIN_TOP);
rows /= get_row_height();
- int row = cursor.line_ofs + (rows + (v_scroll->get_value() - cursor.line_ofs));
+ int lsp = get_line_scroll_pos(true);
+ int row = cursor.line_ofs + (rows + (v_scroll->get_value() - lsp));
+
+ if (is_hiding_enabled()) {
+ // row will be offset by the hidden rows
+ int f_ofs = num_lines_from(CLAMP(cursor.line_ofs, 0, text.size() - 1), MIN(rows + 1, text.size() - cursor.line_ofs)) - 1;
+ row = cursor.line_ofs + (f_ofs + (v_scroll->get_value() - lsp));
+ row = CLAMP(row, 0, text.size() - num_lines_from(text.size() - 1, -1));
+ }
if (row < 0)
- row = 0;
+ row = 0; //todo
int col = 0;
@@ -1664,7 +1724,7 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
col = text[row].size();
} else {
- col = p_mouse.x - (cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width);
+ col = p_mouse.x - (cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width);
col += cursor.x_ofs;
col = get_char_pos_for(col, get_line(row));
}
@@ -1717,43 +1777,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (mb->is_pressed()) {
if (mb->get_button_index() == BUTTON_WHEEL_UP && !mb->get_command()) {
- if (scrolling) {
- target_v_scroll = (target_v_scroll - (3 * mb->get_factor()));
- } else {
- target_v_scroll = (v_scroll->get_value() - (3 * mb->get_factor()));
- }
-
- if (smooth_scroll_enabled) {
- if (target_v_scroll <= 0) {
- target_v_scroll = 0;
- }
- scrolling = true;
- set_physics_process(true);
- } else {
- v_scroll->set_value(target_v_scroll);
- }
+ _scroll_up(3 * mb->get_factor());
}
if (mb->get_button_index() == BUTTON_WHEEL_DOWN && !mb->get_command()) {
- if (scrolling) {
- target_v_scroll = (target_v_scroll + (3 * mb->get_factor()));
- } else {
- target_v_scroll = (v_scroll->get_value() + (3 * mb->get_factor()));
- }
-
- if (smooth_scroll_enabled) {
- int max_v_scroll = get_line_count() - 1;
- if (!scroll_past_end_of_file_enabled) {
- max_v_scroll -= get_visible_rows() - 1;
- }
-
- if (target_v_scroll > max_v_scroll) {
- target_v_scroll = max_v_scroll;
- }
- scrolling = true;
- set_physics_process(true);
- } else {
- v_scroll->set_value(target_v_scroll);
- }
+ _scroll_down(3 * mb->get_factor());
}
if (mb->get_button_index() == BUTTON_WHEEL_LEFT) {
h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor()));
@@ -1766,6 +1793,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_reset_caret_blink_timer();
int row, col;
+ update_line_scroll_pos();
_get_mouse_pos(Point2i(mb->get_position().x, mb->get_position().y), row, col);
if (mb->get_command() && highlighted_word != String()) {
@@ -1784,10 +1812,35 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
+ // toggle fold on gutter click if can
+ if (draw_fold_gutter) {
+
+ int left_margin = cache.style_normal->get_margin(MARGIN_LEFT);
+ int gutter_left = left_margin + cache.breakpoint_gutter_width + cache.line_number_w;
+ if (mb->get_position().x > gutter_left - 6 && mb->get_position().x <= gutter_left + cache.fold_gutter_width - 3) {
+ if (is_folded(row)) {
+ unfold_line(row);
+ } else if (can_fold(row)) {
+ fold_line(row);
+ }
+ return;
+ }
+ }
+
+ // unfold on folded icon click
+ if (is_folded(row)) {
+ int line_width = text.get_line_width(row);
+ line_width += cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width - cursor.x_ofs;
+ if (mb->get_position().x > line_width - 3 && mb->get_position().x <= line_width + cache.folded_eol_icon->get_width() + 3) {
+ unfold_line(row);
+ return;
+ }
+ }
+
int prev_col = cursor.column;
int prev_line = cursor.line;
- cursor_set_line(row);
+ cursor_set_line(row, true, false);
cursor_set_column(col);
if (mb->get_shift() && (cursor.column != prev_col || cursor.line != prev_line)) {
@@ -1884,6 +1937,19 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
+ const Ref<InputEventPanGesture> pan_gesture = p_gui_input;
+ if (pan_gesture.is_valid()) {
+
+ const real_t delta = pan_gesture->get_delta().y;
+ if (delta < 0) {
+ _scroll_up(-delta);
+ } else {
+ _scroll_down(delta);
+ }
+ h_scroll->set_value(h_scroll->get_value() + pan_gesture->get_delta().x * 100);
+ return;
+ }
+
Ref<InputEventMouseMotion> mm = p_gui_input;
if (mm.is_valid()) {
@@ -2026,22 +2092,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
return;
}
- if (k->get_scancode() == KEY_DOWN) {
-
- if (completion_index < completion_options.size() - 1) {
- completion_index++;
- completion_current = completion_options[completion_index];
- update();
- }
- accept_event();
- return;
- }
-
if (k->get_scancode() == KEY_KP_ENTER || k->get_scancode() == KEY_ENTER || k->get_scancode() == KEY_TAB) {
_confirm_completion();
accept_event();
- emit_signal("request_completion");
return;
}
@@ -2191,7 +2245,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
selection.active = false;
update();
_remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
- cursor_set_line(selection.from_line);
+ cursor_set_line(selection.from_line, true, false);
cursor_set_column(selection.from_column);
update();
}
@@ -2241,6 +2295,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
+ if (is_folded(cursor.line))
+ unfold_line(cursor.line);
+
bool brace_indent = false;
// no need to indent if we are going upwards.
@@ -2391,6 +2448,8 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_column(column);
} else {
+ if (cursor.line > 0 && is_line_hidden(cursor.line - 1))
+ unfold_line(cursor.line - 1);
backspace_at_cursor();
}
@@ -2449,7 +2508,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} else if (cursor.column == 0) {
if (cursor.line > 0) {
- cursor_set_line(cursor.line - 1);
+ cursor_set_line(cursor.line - num_lines_from(CLAMP(cursor.line - 1, 0, text.size() - 1), -1));
cursor_set_column(text[cursor.line].length());
}
} else {
@@ -2512,7 +2571,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
} else if (cursor.column == text[cursor.line].length()) {
if (cursor.line < text.size() - 1) {
- cursor_set_line(cursor.line + 1);
+ cursor_set_line(cursor_get_line() + num_lines_from(CLAMP(cursor.line + 1, 0, text.size() - 1), 1), true, false);
cursor_set_column(0);
}
} else {
@@ -2553,7 +2612,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
cursor_set_line(0);
else
#endif
- cursor_set_line(cursor_get_line() - 1);
+ cursor_set_line(cursor_get_line() - num_lines_from(CLAMP(cursor.line - 1, 0, text.size() - 1), -1));
if (k->get_shift())
_post_shift_selection();
@@ -2587,10 +2646,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (k->get_command())
- cursor_set_line(text.size() - 1);
+ cursor_set_line(text.size() - 1, true, false);
else
#endif
- cursor_set_line(cursor_get_line() + 1);
+ cursor_set_line(cursor_get_line() + num_lines_from(CLAMP(cursor.line + 1, 0, text.size() - 1), 1), true, false);
if (k->get_shift())
_post_shift_selection();
@@ -2737,7 +2796,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (k->get_shift())
_pre_shift_selection();
- cursor_set_line(text.size() - 1);
+ cursor_set_line(text.size() - 1, true, false);
if (k->get_shift())
_post_shift_selection();
@@ -2752,7 +2811,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_pre_shift_selection();
if (k->get_command())
- cursor_set_line(text.size() - 1);
+ cursor_set_line(text.size() - 1, true, false);
cursor_set_column(text[cursor.line].length());
if (k->get_shift())
@@ -2777,7 +2836,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (k->get_shift())
_pre_shift_selection();
- cursor_set_line(cursor_get_line() - get_visible_rows());
+ cursor_set_line(cursor_get_line() - num_lines_from(cursor.line, -get_visible_rows()), true, false);
if (k->get_shift())
_post_shift_selection();
@@ -2798,7 +2857,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (k->get_shift())
_pre_shift_selection();
- cursor_set_line(cursor_get_line() + get_visible_rows());
+ cursor_set_line(cursor_get_line() + num_lines_from(cursor.line, get_visible_rows()), true, false);
if (k->get_shift())
_post_shift_selection();
@@ -2984,6 +3043,50 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
+void TextEdit::_scroll_up(real_t p_delta) {
+
+ if (scrolling) {
+ target_v_scroll = (target_v_scroll - p_delta);
+ } else {
+ target_v_scroll = (v_scroll->get_value() - p_delta);
+ }
+
+ if (smooth_scroll_enabled) {
+ if (target_v_scroll <= 0) {
+ target_v_scroll = 0;
+ }
+ scrolling = true;
+ set_physics_process(true);
+ } else {
+ v_scroll->set_value(target_v_scroll);
+ }
+}
+
+void TextEdit::_scroll_down(real_t p_delta) {
+
+ if (scrolling) {
+ target_v_scroll = (target_v_scroll + p_delta);
+ } else {
+ target_v_scroll = (v_scroll->get_value() + p_delta);
+ }
+
+ if (smooth_scroll_enabled) {
+ int max_v_scroll = get_total_unhidden_rows();
+ if (!scroll_past_end_of_file_enabled) {
+ max_v_scroll -= get_visible_rows();
+ max_v_scroll = CLAMP(max_v_scroll, 0, get_total_unhidden_rows());
+ }
+
+ if (target_v_scroll > max_v_scroll) {
+ target_v_scroll = max_v_scroll;
+ }
+ scrolling = true;
+ set_physics_process(true);
+ } else {
+ v_scroll->set_value(target_v_scroll);
+ }
+}
+
void TextEdit::_pre_shift_selection() {
if (!selection.active || selection.selecting_mode == Selection::MODE_NONE) {
@@ -3016,8 +3119,9 @@ void TextEdit::_scroll_lines_up() {
}
// adjust the cursor
- if (cursor_get_line() >= (get_visible_rows() + get_v_scroll()) && !selection.active) {
- cursor_set_line((get_visible_rows() + get_v_scroll()) - 1, false);
+ int num_lines = num_lines_from(CLAMP(cursor.line_ofs, 0, text.size() - 1), get_visible_rows()) - 1;
+ if (cursor.line >= cursor.line_ofs + num_lines && !selection.active) {
+ cursor_set_line(cursor.line_ofs + num_lines, false, false);
}
}
@@ -3025,9 +3129,10 @@ void TextEdit::_scroll_lines_down() {
scrolling = false;
// calculate the maximum vertical scroll position
- int max_v_scroll = get_line_count() - 1;
+ int max_v_scroll = get_total_unhidden_rows();
if (!scroll_past_end_of_file_enabled) {
- max_v_scroll -= get_visible_rows() - 1;
+ max_v_scroll -= get_visible_rows();
+ max_v_scroll = CLAMP(max_v_scroll, 0, get_total_unhidden_rows());
}
// adjust the vertical scroll
@@ -3036,8 +3141,8 @@ void TextEdit::_scroll_lines_down() {
}
// adjust the cursor
- if ((cursor_get_line()) <= get_v_scroll() - 1 && !selection.active) {
- cursor_set_line(get_v_scroll(), false);
+ if (cursor.line <= cursor.line_ofs - 1 && !selection.active) {
+ cursor_set_line(cursor.line_ofs, false, false);
}
}
@@ -3082,6 +3187,15 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
}
}
+ // if we are just making a new empty line, reset breakpoints and hidden status
+ if (p_char == 0 && p_text.replace("\r", "") == "\n") {
+
+ text.set_breakpoint(p_line + 1, text.is_breakpoint(p_line));
+ text.set_hidden(p_line + 1, text.is_hidden(p_line));
+ text.set_breakpoint(p_line, false);
+ text.set_hidden(p_line, false);
+ }
+
r_end_line = p_line + substrings.size() - 1;
r_end_column = text[r_end_line].length() - postinsert_text.length();
@@ -3280,6 +3394,7 @@ Size2 TextEdit::get_minimum_size() const {
return cache.style_normal->get_minimum_size();
}
+
int TextEdit::get_visible_rows() const {
int total = cache.size.height;
@@ -3287,31 +3402,81 @@ int TextEdit::get_visible_rows() const {
total /= get_row_height();
return total;
}
+
+int TextEdit::get_total_unhidden_rows() const {
+ if (!is_hiding_enabled())
+ return text.size();
+
+ int total_unhidden = 0;
+ for (int i = 0; i < text.size(); i++) {
+ if (!text.is_hidden(i))
+ total_unhidden++;
+ }
+ return total_unhidden;
+}
+
+double TextEdit::get_line_scroll_pos(bool p_recalculate) const {
+
+ if (!is_hiding_enabled())
+ return cursor.line_ofs;
+ if (!p_recalculate)
+ return line_scroll_pos;
+
+ // count num unhidden lines to the cursor line ofs
+ double new_line_scroll_pos = 0;
+ int to = CLAMP(cursor.line_ofs, 0, text.size() - 1);
+ for (int i = 0; i < to; i++) {
+ if (!text.is_hidden(i))
+ new_line_scroll_pos++;
+ }
+ return new_line_scroll_pos;
+}
+
+void TextEdit::update_line_scroll_pos() {
+
+ if (!is_hiding_enabled()) {
+ line_scroll_pos = cursor.line_ofs;
+ return;
+ }
+
+ // count num unhidden lines to the cursor line ofs
+ double new_line_scroll_pos = 0;
+ int to = CLAMP(cursor.line_ofs, 0, text.size() - 1);
+ for (int i = 0; i < to; i++) {
+ if (!text.is_hidden(i))
+ new_line_scroll_pos++;
+ }
+ line_scroll_pos = new_line_scroll_pos;
+}
+
void TextEdit::adjust_viewport_to_cursor() {
scrolling = false;
- if (cursor.line_ofs > cursor.line)
+ if (cursor.line_ofs > cursor.line) {
cursor.line_ofs = cursor.line;
+ }
- int visible_width = cache.size.width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width;
+ int visible_width = cache.size.width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width;
if (v_scroll->is_visible_in_tree())
visible_width -= v_scroll->get_combined_minimum_size().width;
visible_width -= 20; // give it a little more space
- //printf("rowofs %i, visrows %i, cursor.line %i\n",cursor.line_ofs,get_visible_rows(),cursor.line);
-
int visible_rows = get_visible_rows();
if (h_scroll->is_visible_in_tree())
visible_rows -= ((h_scroll->get_combined_minimum_size().height - 1) / get_row_height());
+ int num_rows = num_lines_from(CLAMP(cursor.line_ofs, 0, text.size() - 1), MIN(visible_rows, text.size() - 1 - cursor.line_ofs));
- if (cursor.line >= (cursor.line_ofs + visible_rows))
- cursor.line_ofs = cursor.line - visible_rows;
- if (cursor.line < cursor.line_ofs)
+ // if the cursor is off the screen
+ if (cursor.line >= (cursor.line_ofs + MAX(num_rows, visible_rows))) {
+ cursor.line_ofs = cursor.line - (num_lines_from(CLAMP(cursor.line, 0, text.size() - 1), -visible_rows) - 1);
+ }
+ if (cursor.line < cursor.line_ofs) {
cursor.line_ofs = cursor.line;
+ }
- if (cursor.line_ofs + visible_rows > text.size() && !scroll_past_end_of_file_enabled) {
- cursor.line_ofs = text.size() - visible_rows;
- v_scroll->set_value(text.size() - visible_rows);
+ // fixes deleting lines from moving the line ofs in a bad way
+ if (!scroll_past_end_of_file_enabled && get_total_unhidden_rows() > visible_rows && num_rows < visible_rows) {
+ cursor.line_ofs = text.size() - 1 - (num_lines_from(text.size() - 1, -visible_rows) - 1);
}
int cursor_x = get_column_x_offset(cursor.column, text[cursor.line]);
@@ -3322,6 +3487,11 @@ void TextEdit::adjust_viewport_to_cursor() {
if (cursor_x < cursor.x_ofs)
cursor.x_ofs = cursor_x;
+ update_line_scroll_pos();
+ if (get_line_scroll_pos() == 0)
+ v_scroll->set_value(0);
+ else
+ v_scroll->set_value(get_line_scroll_pos() + 1);
update();
/*
get_range()->set_max(text.size());
@@ -3338,7 +3508,10 @@ void TextEdit::center_viewport_to_cursor() {
if (cursor.line_ofs > cursor.line)
cursor.line_ofs = cursor.line;
- int visible_width = cache.size.width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width;
+ if (is_line_hidden(cursor.line))
+ unfold_line(cursor.line);
+
+ int visible_width = cache.size.width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width;
if (v_scroll->is_visible_in_tree())
visible_width -= v_scroll->get_combined_minimum_size().width;
visible_width -= 20; // give it a little more space
@@ -3347,9 +3520,8 @@ void TextEdit::center_viewport_to_cursor() {
if (h_scroll->is_visible_in_tree())
visible_rows -= ((h_scroll->get_combined_minimum_size().height - 1) / get_row_height());
- int max_ofs = text.size() - (scroll_past_end_of_file_enabled ? 1 : visible_rows);
- cursor.line_ofs = CLAMP(cursor.line - (visible_rows / 2), 0, max_ofs);
-
+ int max_ofs = text.size() - (scroll_past_end_of_file_enabled ? 1 : num_lines_from(text.size() - 1, -visible_rows));
+ cursor.line_ofs = CLAMP(cursor.line - num_lines_from(cursor.line - visible_rows / 2, -visible_rows / 2), 0, max_ofs);
int cursor_x = get_column_x_offset(cursor.column, text[cursor.line]);
if (cursor_x > (cursor.x_ofs + visible_width))
@@ -3358,6 +3530,9 @@ void TextEdit::center_viewport_to_cursor() {
if (cursor_x < cursor.x_ofs)
cursor.x_ofs = cursor_x;
+ update_line_scroll_pos();
+ v_scroll->set_value(get_line_scroll_pos());
+
update();
}
@@ -3382,7 +3557,7 @@ void TextEdit::cursor_set_column(int p_col, bool p_adjust_viewport) {
}
}
-void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport) {
+void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport, bool p_can_be_hidden) {
if (setting_row)
return;
@@ -3394,6 +3569,21 @@ void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport) {
if (p_row >= (int)text.size())
p_row = (int)text.size() - 1;
+ if (!p_can_be_hidden) {
+ if (is_line_hidden(CLAMP(p_row, 0, text.size() - 1))) {
+ int move_down = num_lines_from(p_row, 1) - 1;
+ if (p_row + move_down <= text.size() - 1 && !is_line_hidden(p_row + move_down)) {
+ p_row += move_down;
+ } else {
+ int move_up = num_lines_from(p_row, -1) - 1;
+ if (p_row - move_up > 0 && !is_line_hidden(p_row - move_up)) {
+ p_row -= move_up;
+ } else {
+ WARN_PRINTS(("Cursor set to hidden line " + itos(p_row) + " and there are no nonhidden lines."));
+ }
+ }
+ }
+ }
cursor.line = p_row;
cursor.column = get_char_pos_for(cursor.last_fit_x, get_line(cursor.line));
@@ -3463,8 +3653,11 @@ void TextEdit::_scroll_moved(double p_to_val) {
if (h_scroll->is_visible_in_tree())
cursor.x_ofs = h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
- cursor.line_ofs = v_scroll->get_value();
+ if (v_scroll->is_visible_in_tree()) {
+ double val = v_scroll->get_value();
+ cursor.line_ofs = num_lines_from(0, (int)floor(val)) - 1;
+ line_scroll_pos = (int)floor(val);
+ }
update();
}
@@ -3553,10 +3746,43 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
if (highlighted_word != String())
return CURSOR_POINTING_HAND;
- int gutter = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width;
- if ((completion_active && completion_rect.has_point(p_pos)) || p_pos.x < gutter) {
+ int gutter = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width;
+ if ((completion_active && completion_rect.has_point(p_pos))) {
+ return CURSOR_ARROW;
+ }
+ if (p_pos.x < gutter) {
+
+ int row, col;
+ _get_mouse_pos(p_pos, row, col);
+ int left_margin = cache.style_normal->get_margin(MARGIN_LEFT);
+
+ // breakpoint icon
+ if (draw_breakpoint_gutter && p_pos.x > left_margin && p_pos.x <= left_margin + cache.breakpoint_gutter_width + 3) {
+ return CURSOR_POINTING_HAND;
+ }
+
+ // fold icon
+ int gutter_left = left_margin + cache.breakpoint_gutter_width + cache.line_number_w;
+ if (draw_fold_gutter && p_pos.x > gutter_left - 6 && p_pos.x <= gutter_left + cache.fold_gutter_width - 3) {
+ if (is_folded(row) || can_fold(row))
+ return CURSOR_POINTING_HAND;
+ else
+ return CURSOR_ARROW;
+ }
return CURSOR_ARROW;
+ } else {
+ int row, col;
+ _get_mouse_pos(p_pos, row, col);
+ // eol fold icon
+ if (is_folded(row)) {
+ int line_width = text.get_line_width(row);
+ line_width += cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width - cursor.x_ofs;
+ if (p_pos.x > line_width - 3 && p_pos.x <= line_width + cache.folded_eol_icon->get_width() + 3) {
+ return CURSOR_POINTING_HAND;
+ }
+ }
}
+
return CURSOR_IBEAM;
}
@@ -3570,6 +3796,7 @@ void TextEdit::set_text(String p_text) {
cursor.line = 0;
cursor.x_ofs = 0;
cursor.line_ofs = 0;
+ line_scroll_pos = 0;
cursor.last_fit_x = 0;
cursor_set_line(0);
cursor_set_column(0);
@@ -3655,6 +3882,7 @@ void TextEdit::_clear() {
cursor.line = 0;
cursor.x_ofs = 0;
cursor.line_ofs = 0;
+ line_scroll_pos = 0;
cursor.last_fit_x = 0;
}
@@ -3733,6 +3961,9 @@ void TextEdit::_update_caches() {
cache.line_spacing = get_constant("line_spacing");
cache.row_height = cache.font->get_height() + cache.line_spacing;
cache.tab_icon = get_icon("tab");
+ cache.folded_icon = get_icon("GuiTreeArrowRight", "EditorIcons");
+ cache.can_fold_icon = get_icon("GuiTreeArrowDown", "EditorIcons");
+ cache.folded_eol_icon = get_icon("GuiEllipsis", "EditorIcons");
text.set_font(cache.font);
}
@@ -4179,6 +4410,198 @@ void TextEdit::get_breakpoints(List<int> *p_breakpoints) const {
}
}
+void TextEdit::set_line_as_hidden(int p_line, bool p_hidden) {
+
+ ERR_FAIL_INDEX(p_line, text.size());
+ if (is_hiding_enabled() || !p_hidden)
+ text.set_hidden(p_line, p_hidden);
+ update();
+}
+
+bool TextEdit::is_line_hidden(int p_line) const {
+
+ ERR_FAIL_INDEX_V(p_line, text.size(), false);
+ return text.is_hidden(p_line);
+}
+
+void TextEdit::fold_all_lines() {
+
+ for (int i = 0; i < text.size(); i++) {
+ fold_line(i);
+ }
+ _update_scrollbars();
+ update();
+}
+
+void TextEdit::unhide_all_lines() {
+
+ for (int i = 0; i < text.size(); i++) {
+ text.set_hidden(i, false);
+ }
+ _update_scrollbars();
+ update();
+}
+
+int TextEdit::num_lines_from(int p_line_from, int unhidden_amount) const {
+
+ // returns the number of hidden and unhidden lines from p_line_from to p_line_from + amount of visible lines
+ ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(unhidden_amount));
+
+ if (!is_hiding_enabled())
+ return unhidden_amount;
+ int num_visible = 0;
+ int num_total = 0;
+ if (unhidden_amount >= 0) {
+ for (int i = p_line_from; i < text.size(); i++) {
+ num_total++;
+ if (!is_line_hidden(i))
+ num_visible++;
+ if (num_visible >= unhidden_amount)
+ break;
+ }
+ } else {
+ unhidden_amount = ABS(unhidden_amount);
+ for (int i = p_line_from; i >= 0; i--) {
+ num_total++;
+ if (!is_line_hidden(i))
+ num_visible++;
+ if (num_visible >= unhidden_amount)
+ break;
+ }
+ }
+ return num_total;
+}
+
+int TextEdit::get_whitespace_level(int p_line) const {
+
+ ERR_FAIL_INDEX_V(p_line, text.size(), 0);
+
+ // counts number of tabs and spaces before line starts
+ int whitespace_count = 0;
+ int line_length = text[p_line].size();
+ for (int i = 0; i < line_length - 1; i++) {
+ if (text[p_line][i] == '\t') {
+ whitespace_count++;
+ } else if (text[p_line][i] == ' ') {
+ whitespace_count++;
+ } else if (text[p_line][i] == '#') {
+ break;
+ } else {
+ break;
+ }
+ }
+ return whitespace_count;
+}
+
+bool TextEdit::can_fold(int p_line) const {
+
+ ERR_FAIL_INDEX_V(p_line, text.size(), false);
+ if (!is_hiding_enabled())
+ return false;
+ if (p_line + 1 >= text.size())
+ return false;
+ if (text[p_line].size() == 0)
+ return false;
+ if (is_folded(p_line))
+ return false;
+ if (is_line_hidden(p_line))
+ return false;
+
+ int start_indent = get_whitespace_level(p_line);
+
+ for (int i = p_line + 1; i < text.size(); i++) {
+ if (text[i].size() == 0)
+ continue;
+ int next_indent = get_whitespace_level(i);
+ if (next_indent > start_indent)
+ return true;
+ else
+ return false;
+ }
+
+ return false;
+}
+
+bool TextEdit::is_folded(int p_line) const {
+
+ ERR_FAIL_INDEX_V(p_line, text.size(), false);
+ if (p_line + 1 >= text.size() - 1)
+ return false;
+ if (!is_line_hidden(p_line) && is_line_hidden(p_line + 1))
+ return true;
+ return false;
+}
+
+void TextEdit::fold_line(int p_line) {
+
+ ERR_FAIL_INDEX(p_line, text.size());
+ if (!is_hiding_enabled())
+ return;
+ if (!can_fold(p_line))
+ return;
+
+ // hide lines below this one
+ int start_indent = get_whitespace_level(p_line);
+ for (int i = p_line + 1; i < text.size(); i++) {
+ int cur_indent = get_whitespace_level(i);
+ if (text[i].size() == 0 || cur_indent > start_indent) {
+ set_line_as_hidden(i, true);
+ } else {
+ // exclude trailing empty lines
+ for (int trail_i = i - 1; trail_i > p_line; trail_i--) {
+ if (text[trail_i].size() == 0)
+ set_line_as_hidden(trail_i, false);
+ else
+ break;
+ }
+ break;
+ }
+ }
+
+ // fix selection
+ if (is_selection_active()) {
+ if (is_line_hidden(selection.from_line) && is_line_hidden(selection.to_line)) {
+ deselect();
+ } else if (is_line_hidden(selection.from_line)) {
+ select(p_line, 9999, selection.to_line, selection.to_column);
+ } else if (is_line_hidden(selection.to_line)) {
+ select(selection.from_line, selection.from_column, p_line, 9999);
+ }
+ }
+
+ // reset cursor
+ if (is_line_hidden(cursor.line)) {
+ cursor_set_line(p_line, false, false);
+ cursor_set_column(get_line(p_line).length(), false);
+ }
+ _update_scrollbars();
+ update();
+}
+
+void TextEdit::unfold_line(int p_line) {
+
+ ERR_FAIL_INDEX(p_line, text.size());
+
+ if (!is_folded(p_line) && !is_line_hidden(p_line))
+ return;
+ int fold_start = p_line;
+ for (fold_start = p_line; fold_start > 0; fold_start--) {
+ if (is_folded(fold_start))
+ break;
+ }
+ fold_start = is_folded(fold_start) ? fold_start : p_line;
+
+ for (int i = fold_start + 1; i < text.size(); i++) {
+ if (is_line_hidden(i)) {
+ set_line_as_hidden(i, false);
+ } else {
+ break;
+ }
+ }
+ _update_scrollbars();
+ update();
+}
+
int TextEdit::get_line_count() const {
return text.size();
@@ -4405,12 +4828,14 @@ void TextEdit::set_v_scroll(int p_scroll) {
p_scroll = 0;
}
if (!scroll_past_end_of_file_enabled) {
- if (p_scroll + get_visible_rows() > get_line_count()) {
- p_scroll = get_line_count() - get_visible_rows();
+ if (p_scroll + get_visible_rows() > get_total_unhidden_rows()) {
+ int num_rows = num_lines_from(CLAMP(p_scroll, 0, text.size() - 1), MIN(get_visible_rows(), text.size() - 1 - p_scroll));
+ p_scroll = text.size() - num_rows;
}
}
v_scroll->set_value(p_scroll);
- cursor.line_ofs = p_scroll;
+ cursor.line_ofs = num_lines_from(0, p_scroll);
+ line_scroll_pos = p_scroll;
}
int TextEdit::get_h_scroll() const {
@@ -4772,7 +5197,7 @@ void TextEdit::set_line(int line, String new_text) {
void TextEdit::insert_at(const String &p_text, int at) {
cursor_set_column(0);
- cursor_set_line(at);
+ cursor_set_line(at, false, true);
_insert_text(at, 0, p_text + "\n");
}
@@ -4820,6 +5245,35 @@ int TextEdit::get_breakpoint_gutter_width() const {
return cache.breakpoint_gutter_width;
}
+void TextEdit::set_draw_fold_gutter(bool p_draw) {
+ draw_fold_gutter = p_draw;
+ update();
+}
+
+bool TextEdit::is_drawing_fold_gutter() const {
+ return draw_fold_gutter;
+}
+
+void TextEdit::set_fold_gutter_width(int p_gutter_width) {
+ fold_gutter_width = p_gutter_width;
+ update();
+}
+
+int TextEdit::get_fold_gutter_width() const {
+ return cache.fold_gutter_width;
+}
+
+void TextEdit::set_hiding_enabled(int p_enabled) {
+ if (!p_enabled)
+ unhide_all_lines();
+ hiding_enabled = p_enabled;
+ update();
+}
+
+int TextEdit::is_hiding_enabled() const {
+ return hiding_enabled;
+}
+
void TextEdit::set_highlight_current_line(bool p_enabled) {
highlight_current_line = p_enabled;
update();
@@ -4914,7 +5368,7 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_line", "line"), &TextEdit::get_line);
ClassDB::bind_method(D_METHOD("cursor_set_column", "column", "adjust_viewport"), &TextEdit::cursor_set_column, DEFVAL(true));
- ClassDB::bind_method(D_METHOD("cursor_set_line", "line", "adjust_viewport"), &TextEdit::cursor_set_line, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("cursor_set_line", "line", "adjust_viewport", "can_be_hidden"), &TextEdit::cursor_set_line, DEFVAL(true), DEFVAL(true));
ClassDB::bind_method(D_METHOD("cursor_get_column"), &TextEdit::cursor_get_column);
ClassDB::bind_method(D_METHOD("cursor_get_line"), &TextEdit::cursor_get_line);
@@ -4955,6 +5409,17 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_show_line_numbers", "enable"), &TextEdit::set_show_line_numbers);
ClassDB::bind_method(D_METHOD("is_show_line_numbers_enabled"), &TextEdit::is_show_line_numbers_enabled);
+ ClassDB::bind_method(D_METHOD("set_hiding_enabled", "enable"), &TextEdit::set_hiding_enabled);
+ ClassDB::bind_method(D_METHOD("is_hiding_enabled"), &TextEdit::is_hiding_enabled);
+ ClassDB::bind_method(D_METHOD("set_line_as_hidden", "line", "enable"), &TextEdit::set_line_as_hidden);
+ ClassDB::bind_method(D_METHOD("is_line_hidden"), &TextEdit::is_line_hidden);
+ ClassDB::bind_method(D_METHOD("fold_all_lines"), &TextEdit::fold_all_lines);
+ ClassDB::bind_method(D_METHOD("unhide_all_lines"), &TextEdit::unhide_all_lines);
+ ClassDB::bind_method(D_METHOD("fold_line", "line"), &TextEdit::fold_line);
+ ClassDB::bind_method(D_METHOD("unfold_line", "line"), &TextEdit::unfold_line);
+ ClassDB::bind_method(D_METHOD("can_fold", "line"), &TextEdit::can_fold);
+ ClassDB::bind_method(D_METHOD("is_folded", "line"), &TextEdit::is_folded);
+
ClassDB::bind_method(D_METHOD("set_highlight_all_occurrences", "enable"), &TextEdit::set_highlight_all_occurrences);
ClassDB::bind_method(D_METHOD("is_highlight_all_occurrences_enabled"), &TextEdit::is_highlight_all_occurrences_enabled);
@@ -4988,6 +5453,7 @@ void TextEdit::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "context_menu_enabled"), "set_context_menu_enabled", "is_context_menu_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_scrolling"), "set_smooth_scroll_enable", "is_smooth_scroll_enabled");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "v_scroll_speed"), "set_v_scroll_speed", "get_v_scroll_speed");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hiding_enabled"), "set_hiding_enabled", "is_hiding_enabled");
ADD_GROUP("Caret", "caret_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_block_mode"), "cursor_set_block_mode", "cursor_is_block_mode");
@@ -5029,6 +5495,8 @@ TextEdit::TextEdit() {
cache.line_number_w = 1;
cache.breakpoint_gutter_width = 0;
breakpoint_gutter_width = 0;
+ cache.fold_gutter_width = 0;
+ fold_gutter_width = 0;
indent_size = 4;
text.set_indent_size(indent_size);
@@ -5098,6 +5566,8 @@ TextEdit::TextEdit() {
line_length_guideline = false;
line_length_guideline_col = 80;
draw_breakpoint_gutter = false;
+ draw_fold_gutter = false;
+ hiding_enabled = false;
next_operation_is_complex = false;
scroll_past_end_of_file_enabled = false;
auto_brace_completion_enabled = false;
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 50f005ed6a..bb9ca87d06 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -73,6 +73,9 @@ class TextEdit : public Control {
struct Cache {
Ref<Texture> tab_icon;
+ Ref<Texture> can_fold_icon;
+ Ref<Texture> folded_icon;
+ Ref<Texture> folded_eol_icon;
Ref<StyleBox> style_normal;
Ref<StyleBox> style_focus;
Ref<Font> font;
@@ -105,6 +108,7 @@ class TextEdit : public Control {
int line_spacing;
int line_number_w;
int breakpoint_gutter_width;
+ int fold_gutter_width;
Size2 size;
} cache;
@@ -136,6 +140,7 @@ class TextEdit : public Control {
int width_cache : 24;
bool marked : 1;
bool breakpoint : 1;
+ bool hidden : 1;
Map<int, ColorRegionInfo> region_info;
String data;
};
@@ -160,6 +165,8 @@ class TextEdit : public Control {
bool is_marked(int p_line) const { return text[p_line].marked; }
void set_breakpoint(int p_line, bool p_breakpoint) { text[p_line].breakpoint = p_breakpoint; }
bool is_breakpoint(int p_line) const { return text[p_line].breakpoint; }
+ void set_hidden(int p_line, bool p_hidden) { text[p_line].hidden = p_hidden; }
+ bool is_hidden(int p_line) const { return text[p_line].hidden; }
void insert(int p_at, const String &p_text);
void remove(int p_at);
int size() const { return text.size(); }
@@ -251,6 +258,9 @@ class TextEdit : public Control {
int line_length_guideline_col;
bool draw_breakpoint_gutter;
int breakpoint_gutter_width;
+ bool draw_fold_gutter;
+ int fold_gutter_width;
+ bool hiding_enabled;
bool highlight_all_occurrences;
bool scroll_past_end_of_file_enabled;
@@ -293,9 +303,14 @@ class TextEdit : public Control {
int search_result_line;
int search_result_col;
+ double line_scroll_pos;
+
bool context_menu_enabled;
int get_visible_rows() const;
+ int get_total_unhidden_rows() const;
+ double get_line_scroll_pos(bool p_recalculate = false) const;
+ void update_line_scroll_pos();
int get_char_count();
@@ -303,6 +318,7 @@ class TextEdit : public Control {
int get_column_x_offset(int p_char, String p_str);
void adjust_viewport_to_cursor();
+ double get_scroll_line_diff() const;
void _scroll_moved(double);
void _update_scrollbars();
void _v_scroll_input();
@@ -312,6 +328,9 @@ class TextEdit : public Control {
void _update_selection_mode_word();
void _update_selection_mode_line();
+ void _scroll_up(real_t p_delta);
+ void _scroll_down(real_t p_delta);
+
void _pre_shift_selection();
void _post_shift_selection();
@@ -405,6 +424,18 @@ public:
void set_line_as_breakpoint(int p_line, bool p_breakpoint);
bool is_line_set_as_breakpoint(int p_line) const;
void get_breakpoints(List<int> *p_breakpoints) const;
+
+ void set_line_as_hidden(int p_line, bool p_hidden);
+ bool is_line_hidden(int p_line) const;
+ void fold_all_lines();
+ void unhide_all_lines();
+ int num_lines_from(int p_line_from, int unhidden_amount) const;
+ int get_whitespace_level(int p_line) const;
+ bool can_fold(int p_line) const;
+ bool is_folded(int p_line) const;
+ void fold_line(int p_line);
+ void unfold_line(int p_line);
+
String get_text();
String get_line(int line) const;
void set_line(int line, String new_text);
@@ -433,7 +464,7 @@ public:
void center_viewport_to_cursor();
void cursor_set_column(int p_col, bool p_adjust_viewport = true);
- void cursor_set_line(int p_row, bool p_adjust_viewport = true);
+ void cursor_set_line(int p_row, bool p_adjust_viewport = true, bool p_can_be_hidden = true);
int cursor_get_column() const;
int cursor_get_line() const;
@@ -538,6 +569,15 @@ public:
void set_breakpoint_gutter_width(int p_gutter_width);
int get_breakpoint_gutter_width() const;
+ void set_draw_fold_gutter(bool p_draw);
+ bool is_drawing_fold_gutter() const;
+
+ void set_fold_gutter_width(int p_gutter_width);
+ int get_fold_gutter_width() const;
+
+ void set_hiding_enabled(int p_enabled);
+ int is_hiding_enabled() const;
+
void set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata);
void set_completion(bool p_enabled, const Vector<String> &p_prefixes);
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index f2e5919b5f..9213296c55 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -28,6 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "tree.h"
+#include <limits.h>
#include "os/input.h"
#include "os/keyboard.h"
@@ -154,8 +155,17 @@ void TreeItem::set_text(int p_column, String p_text) {
if (cells[p_column].mode == TreeItem::CELL_MODE_RANGE || cells[p_column].mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) {
- cells[p_column].min = 0;
- cells[p_column].max = p_text.get_slice_count(",");
+ Vector<String> strings = p_text.split(",");
+ cells[p_column].min = INT_MAX;
+ cells[p_column].max = INT_MIN;
+ for (int i = 0; i < strings.size(); i++) {
+ int value = i;
+ if (!strings[i].get_slicec(':', 1).empty()) {
+ value = strings[i].get_slicec(':', 1).to_int();
+ }
+ cells[p_column].min = MIN(cells[p_column].min, value);
+ cells[p_column].max = MAX(cells[p_column].max, value);
+ }
cells[p_column].step = 0;
}
_changed_notify(p_column);
@@ -1231,8 +1241,18 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
int option = (int)p_item->cells[i].val;
- String s = p_item->cells[i].text;
- s = s.get_slicec(',', option);
+ String s = RTR("(Other)");
+ Vector<String> strings = p_item->cells[i].text.split(",");
+ for (int i = 0; i < strings.size(); i++) {
+ int value = i;
+ if (!strings[i].get_slicec(':', 1).empty()) {
+ value = strings[i].get_slicec(':', 1).to_int();
+ }
+ if (option == value) {
+ s = strings[i].get_slicec(':', 0);
+ break;
+ }
+ }
if (p_item->cells[i].suffix != String())
s += " " + p_item->cells[i].suffix;
@@ -1776,7 +1796,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
for (int i = 0; i < c.text.get_slice_count(","); i++) {
String s = c.text.get_slicec(',', i);
- popup_menu->add_item(s, i);
+ popup_menu->add_item(s.get_slicec(':', 0), s.get_slicec(':', 1).empty() ? i : s.get_slicec(':', 1).to_int());
}
popup_menu->set_size(Size2(col_width, 0));
@@ -2592,6 +2612,12 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
} break;
}
}
+
+ Ref<InputEventPanGesture> pan_gesture = p_event;
+ if (pan_gesture.is_valid()) {
+
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
+ }
}
bool Tree::edit_selected() {
@@ -2634,7 +2660,7 @@ bool Tree::edit_selected() {
for (int i = 0; i < c.text.get_slice_count(","); i++) {
String s = c.text.get_slicec(',', i);
- popup_menu->add_item(s, i);
+ popup_menu->add_item(s.get_slicec(':', 0), s.get_slicec(':', 1).empty() ? i : s.get_slicec(':', 1).to_int());
}
popup_menu->set_size(Size2(rect.size.width, 0));