summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/base_button.cpp24
-rw-r--r--scene/gui/base_button.h7
-rw-r--r--scene/gui/box_container.cpp4
-rw-r--r--scene/gui/check_box.cpp18
-rw-r--r--scene/gui/code_edit.cpp557
-rw-r--r--scene/gui/code_edit.h35
-rw-r--r--scene/gui/color_picker.cpp218
-rw-r--r--scene/gui/color_picker.h39
-rw-r--r--scene/gui/control.cpp182
-rw-r--r--scene/gui/control.h26
-rw-r--r--scene/gui/dialogs.cpp6
-rw-r--r--scene/gui/file_dialog.cpp15
-rw-r--r--scene/gui/file_dialog.h2
-rw-r--r--scene/gui/gradient_edit.cpp11
-rw-r--r--scene/gui/gradient_edit.h6
-rw-r--r--scene/gui/graph_edit.cpp653
-rw-r--r--scene/gui/graph_edit.h37
-rw-r--r--scene/gui/graph_node.cpp4
-rw-r--r--scene/gui/graph_node.h2
-rw-r--r--scene/gui/item_list.cpp44
-rw-r--r--scene/gui/item_list.h7
-rw-r--r--scene/gui/label.cpp249
-rw-r--r--scene/gui/line_edit.cpp38
-rw-r--r--scene/gui/line_edit.h4
-rw-r--r--scene/gui/link_button.cpp16
-rw-r--r--scene/gui/link_button.h1
-rw-r--r--scene/gui/menu_button.cpp11
-rw-r--r--scene/gui/menu_button.h4
-rw-r--r--scene/gui/option_button.cpp2
-rw-r--r--scene/gui/option_button.h4
-rw-r--r--scene/gui/popup.cpp2
-rw-r--r--scene/gui/popup.h2
-rw-r--r--scene/gui/popup_menu.cpp28
-rw-r--r--scene/gui/popup_menu.h8
-rw-r--r--scene/gui/rich_text_effect.cpp29
-rw-r--r--scene/gui/rich_text_effect.h38
-rw-r--r--scene/gui/rich_text_label.cpp49
-rw-r--r--scene/gui/rich_text_label.h8
-rw-r--r--scene/gui/scroll_bar.cpp3
-rw-r--r--scene/gui/scroll_bar.h2
-rw-r--r--scene/gui/scroll_container.cpp10
-rw-r--r--scene/gui/scroll_container.h2
-rw-r--r--scene/gui/shortcut.cpp70
-rw-r--r--scene/gui/shortcut.h54
-rw-r--r--scene/gui/slider.cpp3
-rw-r--r--scene/gui/slider.h2
-rw-r--r--scene/gui/spin_box.cpp8
-rw-r--r--scene/gui/spin_box.h2
-rw-r--r--scene/gui/split_container.cpp4
-rw-r--r--scene/gui/split_container.h2
-rw-r--r--scene/gui/subviewport_container.cpp10
-rw-r--r--scene/gui/subviewport_container.h4
-rw-r--r--scene/gui/tab_container.cpp92
-rw-r--r--scene/gui/tab_container.h3
-rw-r--r--scene/gui/tabs.cpp3
-rw-r--r--scene/gui/tabs.h2
-rw-r--r--scene/gui/text_edit.cpp6820
-rw-r--r--scene/gui/text_edit.h973
-rw-r--r--scene/gui/texture_progress_bar.cpp57
-rw-r--r--scene/gui/texture_progress_bar.h4
-rw-r--r--scene/gui/tree.cpp97
-rw-r--r--scene/gui/tree.h11
-rw-r--r--scene/gui/video_player.cpp5
63 files changed, 5954 insertions, 4679 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 82f4a216b8..bef1011364 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -52,7 +52,7 @@ void BaseButton::_unpress_group() {
}
}
-void BaseButton::_gui_input(Ref<InputEvent> p_event) {
+void BaseButton::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
if (status.disabled) { // no interaction with disabled button
@@ -121,17 +121,13 @@ void BaseButton::_notification(int p_what) {
}
void BaseButton::_pressed() {
- if (get_script_instance()) {
- get_script_instance()->call(SceneStringNames::get_singleton()->_pressed);
- }
+ GDVIRTUAL_CALL(_pressed);
pressed();
emit_signal(SNAME("pressed"));
}
void BaseButton::_toggled(bool p_pressed) {
- if (get_script_instance()) {
- get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, p_pressed);
- }
+ GDVIRTUAL_CALL(_toggled, p_pressed);
toggled(p_pressed);
emit_signal(SNAME("toggled"), p_pressed);
}
@@ -145,7 +141,11 @@ void BaseButton::on_action_event(Ref<InputEvent> p_event) {
if (status.press_attempt && status.pressing_inside) {
if (toggle_mode) {
- if ((p_event->is_pressed() && action_mode == ACTION_MODE_BUTTON_PRESS) || (!p_event->is_pressed() && action_mode == ACTION_MODE_BUTTON_RELEASE)) {
+ bool is_pressed = p_event->is_pressed();
+ if (Object::cast_to<InputEventShortcut>(*p_event)) {
+ is_pressed = false;
+ }
+ if ((is_pressed && action_mode == ACTION_MODE_BUTTON_PRESS) || (!is_pressed && action_mode == ACTION_MODE_BUTTON_RELEASE)) {
if (action_mode == ACTION_MODE_BUTTON_PRESS) {
status.press_attempt = false;
status.pressing_inside = false;
@@ -338,7 +338,7 @@ Ref<Shortcut> BaseButton::get_shortcut() const {
return shortcut;
}
-void BaseButton::_unhandled_key_input(Ref<InputEvent> p_event) {
+void BaseButton::unhandled_key_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
if (!_is_focus_owner_in_shorcut_context()) {
@@ -407,8 +407,6 @@ bool BaseButton::_is_focus_owner_in_shorcut_context() const {
}
void BaseButton::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &BaseButton::_gui_input);
- ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &BaseButton::_unhandled_key_input);
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &BaseButton::set_pressed);
ClassDB::bind_method(D_METHOD("is_pressed"), &BaseButton::is_pressed);
ClassDB::bind_method(D_METHOD("set_pressed_no_signal", "pressed"), &BaseButton::set_pressed_no_signal);
@@ -436,8 +434,8 @@ void BaseButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_shortcut_context", "node"), &BaseButton::set_shortcut_context);
ClassDB::bind_method(D_METHOD("get_shortcut_context"), &BaseButton::get_shortcut_context);
- BIND_VMETHOD(MethodInfo("_pressed"));
- BIND_VMETHOD(MethodInfo("_toggled", PropertyInfo(Variant::BOOL, "button_pressed")));
+ GDVIRTUAL_BIND(_pressed);
+ GDVIRTUAL_BIND(_toggled, "button_pressed");
ADD_SIGNAL(MethodInfo("pressed"));
ADD_SIGNAL(MethodInfo("button_up"));
diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h
index d86b35daf0..cd6e78464f 100644
--- a/scene/gui/base_button.h
+++ b/scene/gui/base_button.h
@@ -75,12 +75,15 @@ protected:
virtual void pressed();
virtual void toggled(bool p_pressed);
static void _bind_methods();
- virtual void _gui_input(Ref<InputEvent> p_event);
- virtual void _unhandled_key_input(Ref<InputEvent> p_event);
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
+ virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override;
void _notification(int p_what);
bool _is_focus_owner_in_shorcut_context() const;
+ GDVIRTUAL0(_pressed)
+ GDVIRTUAL1(_toggled, bool)
+
public:
enum DrawMode {
DRAW_NORMAL,
diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp
index a2f1d2b15a..cf2df4e1a2 100644
--- a/scene/gui/box_container.cpp
+++ b/scene/gui/box_container.cpp
@@ -351,11 +351,11 @@ MarginContainer *VBoxContainer::add_margin_child(const String &p_label, Control
Label *l = memnew(Label);
l->set_theme_type_variation("HeaderSmall");
l->set_text(p_label);
- add_child(l);
+ add_child(l, false, INTERNAL_MODE_FRONT);
MarginContainer *mc = memnew(MarginContainer);
mc->add_theme_constant_override("margin_left", 0);
mc->add_child(p_control);
- add_child(mc);
+ add_child(mc, false, INTERNAL_MODE_FRONT);
if (p_expand) {
mc->set_v_size_flags(SIZE_EXPAND_FILL);
}
diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp
index d93107df2d..411fb2e1f0 100644
--- a/scene/gui/check_box.cpp
+++ b/scene/gui/check_box.cpp
@@ -34,11 +34,13 @@
Size2 CheckBox::get_icon_size() const {
Ref<Texture2D> checked = Control::get_theme_icon(SNAME("checked"));
- Ref<Texture2D> checked_disabled = Control::get_theme_icon(SNAME("checked_disabled"));
Ref<Texture2D> unchecked = Control::get_theme_icon(SNAME("unchecked"));
- Ref<Texture2D> unchecked_disabled = Control::get_theme_icon(SNAME("unchecked_disabled"));
Ref<Texture2D> radio_checked = Control::get_theme_icon(SNAME("radio_checked"));
Ref<Texture2D> radio_unchecked = Control::get_theme_icon(SNAME("radio_unchecked"));
+ Ref<Texture2D> checked_disabled = Control::get_theme_icon(SNAME("checked_disabled"));
+ Ref<Texture2D> unchecked_disabled = Control::get_theme_icon(SNAME("unchecked_disabled"));
+ Ref<Texture2D> radio_checked_disabled = Control::get_theme_icon(SNAME("radio_checked_disabled"));
+ Ref<Texture2D> radio_unchecked_disabled = Control::get_theme_icon(SNAME("radio_unchecked_disabled"));
Size2 tex_size = Size2(0, 0);
if (!checked.is_null()) {
@@ -53,6 +55,18 @@ Size2 CheckBox::get_icon_size() const {
if (!radio_unchecked.is_null()) {
tex_size = Size2(MAX(tex_size.width, radio_unchecked->get_width()), MAX(tex_size.height, radio_unchecked->get_height()));
}
+ if (!checked_disabled.is_null()) {
+ tex_size = Size2(MAX(tex_size.width, checked_disabled->get_width()), MAX(tex_size.height, checked_disabled->get_height()));
+ }
+ if (!unchecked_disabled.is_null()) {
+ tex_size = Size2(MAX(tex_size.width, unchecked_disabled->get_width()), MAX(tex_size.height, unchecked_disabled->get_height()));
+ }
+ if (!radio_checked_disabled.is_null()) {
+ tex_size = Size2(MAX(tex_size.width, radio_checked_disabled->get_width()), MAX(tex_size.height, radio_checked_disabled->get_height()));
+ }
+ if (!radio_unchecked_disabled.is_null()) {
+ tex_size = Size2(MAX(tex_size.width, radio_unchecked_disabled->get_width()), MAX(tex_size.height, radio_unchecked_disabled->get_height()));
+ }
return tex_size;
}
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index 32922f609d..d05762b6c0 100644
--- a/scene/gui/code_edit.cpp
+++ b/scene/gui/code_edit.cpp
@@ -46,9 +46,16 @@ void CodeEdit::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED:
case NOTIFICATION_ENTER_TREE: {
- set_gutter_width(main_gutter, get_row_height());
- set_gutter_width(line_number_gutter, (line_number_digits + 1) * cache.font->get_char_size('0', 0, cache.font_size).width);
- set_gutter_width(fold_gutter, get_row_height() / 1.2);
+ style_normal = get_theme_stylebox(SNAME("normal"));
+
+ font = get_theme_font(SNAME("font"));
+ font_size = get_theme_font_size(SNAME("font_size"));
+
+ line_spacing = get_theme_constant(SNAME("line_spacing"));
+
+ set_gutter_width(main_gutter, get_line_height());
+ set_gutter_width(line_number_gutter, (line_number_digits + 1) * font->get_char_size('0', 0, font_size).width);
+ set_gutter_width(fold_gutter, get_line_height() / 1.2);
breakpoint_color = get_theme_color(SNAME("breakpoint_color"));
breakpoint_icon = get_theme_icon(SNAME("breakpoint"));
@@ -65,7 +72,7 @@ void CodeEdit::_notification(int p_what) {
can_fold_icon = get_theme_icon(SNAME("can_fold"));
folded_icon = get_theme_icon(SNAME("folded"));
- code_completion_max_width = get_theme_constant(SNAME("completion_max_width")) * cache.font->get_char_size('x').x;
+ code_completion_max_width = get_theme_constant(SNAME("completion_max_width"));
code_completion_max_lines = get_theme_constant(SNAME("completion_lines"));
code_completion_scroll_width = get_theme_constant(SNAME("completion_scroll_width"));
code_completion_scroll_color = get_theme_color(SNAME("completion_scroll_color"));
@@ -80,12 +87,12 @@ void CodeEdit::_notification(int p_what) {
const Size2 size = get_size();
const bool caret_visible = is_caret_visible();
const bool rtl = is_layout_rtl();
- const int row_height = get_row_height();
+ const int row_height = get_line_height();
if (line_length_guideline_columns.size() > 0) {
- const int xmargin_beg = cache.style_normal->get_margin(SIDE_LEFT) + get_total_gutter_width();
- const int xmargin_end = size.width - cache.style_normal->get_margin(SIDE_RIGHT) - (is_drawing_minimap() ? get_minimap_width() : 0);
- const int char_size = (int)cache.font->get_char_size('0', 0, cache.font_size).width;
+ const int xmargin_beg = style_normal->get_margin(SIDE_LEFT) + get_total_gutter_width();
+ const int xmargin_end = size.width - style_normal->get_margin(SIDE_RIGHT) - (is_drawing_minimap() ? get_minimap_width() : 0);
+ const int char_size = (int)font->get_char_size('0', 0, font_size).width;
for (int i = 0; i < line_length_guideline_columns.size(); i++) {
const int xoffset = xmargin_beg + char_size * (int)line_length_guideline_columns[i] - get_h_scroll();
@@ -115,14 +122,14 @@ void CodeEdit::_notification(int p_what) {
const Point2 caret_pos = get_caret_draw_pos();
const int total_height = csb->get_minimum_size().y + code_completion_rect.size.height;
if (caret_pos.y + row_height + total_height > get_size().height) {
- code_completion_rect.position.y = (caret_pos.y - total_height - row_height) + cache.line_spacing;
+ code_completion_rect.position.y = (caret_pos.y - total_height - row_height) + line_spacing;
} else {
- code_completion_rect.position.y = caret_pos.y + (cache.line_spacing / 2.0f);
+ code_completion_rect.position.y = caret_pos.y + (line_spacing / 2.0f);
code_completion_below = true;
}
const int scroll_width = code_completion_options_count > code_completion_max_lines ? code_completion_scroll_width : 0;
- const int code_completion_base_width = cache.font->get_string_size(code_completion_base).width;
+ const int code_completion_base_width = font->get_string_size(code_completion_base).width;
if (caret_pos.x - code_completion_base_width + code_completion_rect.size.width + scroll_width > get_size().width) {
code_completion_rect.position.x = get_size().width - code_completion_rect.size.width - scroll_width;
} else {
@@ -144,7 +151,7 @@ void CodeEdit::_notification(int p_what) {
Ref<TextLine> tl;
tl.instantiate();
- tl->add_string(code_completion_options[l].display, cache.font, cache.font_size);
+ tl->add_string(code_completion_options[l].display, font, font_size);
int yofs = (row_height - tl->get_size().y) / 2;
Point2 title_pos(code_completion_rect.position.x, code_completion_rect.position.y + i * row_height + yofs);
@@ -183,8 +190,7 @@ void CodeEdit::_notification(int p_what) {
/* Code hint */
if (caret_visible && code_hint != "" && (!code_completion_active || (code_completion_below != code_hint_draw_below))) {
- const Ref<Font> font = cache.font;
- const int font_height = font->get_height(cache.font_size);
+ const int font_height = font->get_height(font_size);
Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel"), SNAME("TooltipPanel"));
Color font_color = get_theme_color(SNAME("font_color"), SNAME("TooltipLabel"));
@@ -193,37 +199,37 @@ void CodeEdit::_notification(int p_what) {
int max_width = 0;
for (int i = 0; i < line_count; i++) {
- max_width = MAX(max_width, font->get_string_size(code_hint_lines[i], cache.font_size).x);
+ max_width = MAX(max_width, font->get_string_size(code_hint_lines[i], font_size).x);
}
- Size2 minsize = sb->get_minimum_size() + Size2(max_width, line_count * font_height + (cache.line_spacing * line_count - 1));
+ Size2 minsize = sb->get_minimum_size() + Size2(max_width, line_count * font_height + (line_spacing * line_count - 1));
- int offset = font->get_string_size(code_hint_lines[0].substr(0, code_hint_lines[0].find(String::chr(0xFFFF))), cache.font_size).x;
+ int offset = font->get_string_size(code_hint_lines[0].substr(0, code_hint_lines[0].find(String::chr(0xFFFF))), font_size).x;
if (code_hint_xpos == -0xFFFF) {
code_hint_xpos = get_caret_draw_pos().x - offset;
}
Point2 hint_ofs = Vector2(code_hint_xpos, get_caret_draw_pos().y);
if (code_hint_draw_below) {
- hint_ofs.y += cache.line_spacing / 2.0f;
+ hint_ofs.y += line_spacing / 2.0f;
} else {
- hint_ofs.y -= (minsize.y + row_height) - cache.line_spacing;
+ hint_ofs.y -= (minsize.y + row_height) - line_spacing;
}
draw_style_box(sb, Rect2(hint_ofs, minsize));
- int line_spacing = 0;
+ int yofs = 0;
for (int i = 0; i < line_count; i++) {
const String &line = code_hint_lines[i];
int begin = 0;
int end = 0;
if (line.find(String::chr(0xFFFF)) != -1) {
- begin = font->get_string_size(line.substr(0, line.find(String::chr(0xFFFF))), cache.font_size).x;
- end = font->get_string_size(line.substr(0, line.rfind(String::chr(0xFFFF))), cache.font_size).x;
+ begin = font->get_string_size(line.substr(0, line.find(String::chr(0xFFFF))), font_size).x;
+ end = font->get_string_size(line.substr(0, line.rfind(String::chr(0xFFFF))), font_size).x;
}
- Point2 round_ofs = hint_ofs + sb->get_offset() + Vector2(0, font->get_ascent() + font_height * i + line_spacing);
+ Point2 round_ofs = hint_ofs + sb->get_offset() + Vector2(0, font->get_ascent() + font_height * i + yofs);
round_ofs = round_ofs.round();
- draw_string(font, round_ofs, line.replace(String::chr(0xFFFF), ""), HALIGN_LEFT, -1, cache.font_size, font_color);
+ draw_string(font, round_ofs, line.replace(String::chr(0xFFFF), ""), HALIGN_LEFT, -1, font_size, font_color);
if (end > 0) {
// Draw an underline for the currently edited function parameter.
const Vector2 b = hint_ofs + sb->get_offset() + Vector2(begin, font_height + font_height * i + line_spacing);
@@ -235,14 +241,14 @@ void CodeEdit::_notification(int p_what) {
Vector2(end - begin, font_height));
draw_rect(highlight_rect, font_color * Color(1, 1, 1, 0.2));
}
- line_spacing += cache.line_spacing;
+ yofs += line_spacing;
}
}
} break;
}
}
-void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
+void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
Ref<InputEventMouseButton> mb = p_gui_input;
if (mb.is_valid()) {
@@ -270,7 +276,7 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
} break;
case MOUSE_BUTTON_LEFT: {
- code_completion_current_selected = CLAMP(code_completion_line_ofs + (mb->get_position().y - code_completion_rect.position.y) / get_row_height(), 0, code_completion_options.size() - 1);
+ code_completion_current_selected = CLAMP(code_completion_line_ofs + (mb->get_position().y - code_completion_rect.position.y) / get_line_height(), 0, code_completion_options.size() - 1);
if (mb->is_double_click()) {
confirm_code_completion();
}
@@ -290,14 +296,15 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
mpos.x = get_size().x - mpos.x;
}
- int line, col;
- _get_mouse_pos(Point2i(mpos.x, mpos.y), line, col);
+ Point2i pos = get_line_column_at_pos(Point2i(mpos.x, mpos.y));
+ int line = pos.y;
+ int col = pos.x;
if (mb->get_button_index() == MOUSE_BUTTON_LEFT) {
if (is_line_folded(line)) {
- int wrap_index = get_line_wrap_index_at_col(line, col);
- if (wrap_index == times_line_wraps(line)) {
- int eol_icon_width = cache.folded_eol_icon->get_width();
+ int wrap_index = get_line_wrap_index_at_column(line, col);
+ if (wrap_index == get_line_wrap_count(line)) {
+ int eol_icon_width = folded_eol_icon->get_width();
int left_margin = get_total_gutter_width() + eol_icon_width + get_line_width(line, wrap_index) - get_h_scroll();
if (mpos.x > left_margin && mpos.x <= left_margin + eol_icon_width + 3) {
unfold_line(line);
@@ -313,8 +320,10 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (is_layout_rtl()) {
mpos.x = get_size().x - mpos.x;
}
- int line, col;
- _get_mouse_pos(Point2i(mpos.x, mpos.y), line, col);
+
+ Point2i pos = get_line_column_at_pos(Point2i(mpos.x, mpos.y));
+ int line = pos.y;
+ int col = pos.x;
emit_signal(SNAME("symbol_lookup"), symbol_lookup_word, line, col);
return;
@@ -345,7 +354,7 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
Ref<InputEventKey> k = p_gui_input;
bool update_code_completion = false;
if (!k.is_valid()) {
- TextEdit::_gui_input(p_gui_input);
+ TextEdit::gui_input(p_gui_input);
return;
}
@@ -357,7 +366,7 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
#endif
if (symbol_lookup_on_click_enabled) {
if (k->is_pressed() && !is_dragging_cursor()) {
- symbol_lookup_new_word = get_word_at_pos(_get_local_mouse_pos());
+ symbol_lookup_new_word = get_word_at_pos(get_local_mouse_pos());
if (symbol_lookup_new_word != symbol_lookup_word) {
emit_signal(SNAME("symbol_validate"), symbol_lookup_new_word);
}
@@ -441,7 +450,7 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
if (k->is_action("ui_text_backspace", true)) {
backspace();
- _filter_code_completion_candidates();
+ _filter_code_completion_candidates_impl();
accept_event();
return;
}
@@ -510,10 +519,10 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
set_code_hint("");
}
- TextEdit::_gui_input(p_gui_input);
+ TextEdit::gui_input(p_gui_input);
if (update_code_completion) {
- _filter_code_completion_candidates();
+ _filter_code_completion_candidates_impl();
}
}
@@ -523,17 +532,18 @@ Control::CursorShape CodeEdit::get_cursor_shape(const Point2 &p_pos) const {
return CURSOR_POINTING_HAND;
}
- if ((code_completion_active && code_completion_rect.has_point(p_pos)) || (is_readonly() && (!is_selecting_enabled() || get_line_count() == 0))) {
+ if ((code_completion_active && code_completion_rect.has_point(p_pos)) || (!is_editable() && (!is_selecting_enabled() || get_line_count() == 0))) {
return CURSOR_ARROW;
}
- int line, col;
- _get_mouse_pos(p_pos, line, col);
+ Point2i pos = get_line_column_at_pos(p_pos);
+ int line = pos.y;
+ int col = pos.x;
if (is_line_folded(line)) {
- int wrap_index = get_line_wrap_index_at_col(line, col);
- if (wrap_index == times_line_wraps(line)) {
- int eol_icon_width = cache.folded_eol_icon->get_width();
+ int wrap_index = get_line_wrap_index_at_column(line, col);
+ if (wrap_index == get_line_wrap_count(line)) {
+ int eol_icon_width = folded_eol_icon->get_width();
int left_margin = get_total_gutter_width() + eol_icon_width + get_line_width(line, wrap_index) - get_h_scroll();
if (p_pos.x > left_margin && p_pos.x <= left_margin + eol_icon_width + 3) {
return CURSOR_POINTING_HAND;
@@ -544,58 +554,118 @@ Control::CursorShape CodeEdit::get_cursor_shape(const Point2 &p_pos) const {
return TextEdit::get_cursor_shape(p_pos);
}
-void CodeEdit::handle_unicode_input(uint32_t p_unicode) {
- bool had_selection = is_selection_active();
+/* Text manipulation */
+
+// Overridable actions
+void CodeEdit::_handle_unicode_input_internal(const uint32_t p_unicode) {
+ bool had_selection = has_selection();
if (had_selection) {
begin_complex_operation();
delete_selection();
}
- // Remove the old character if in insert mode and no selection.
- if (is_insert_mode() && !had_selection) {
+ // Remove the old character if in overtype mode and no selection.
+ if (is_overtype_mode_enabled() && !had_selection) {
begin_complex_operation();
- // Make sure we don't try and remove empty space.
- if (cursor_get_column() < get_line(cursor_get_line()).length()) {
- _remove_text(cursor_get_line(), cursor_get_column(), cursor_get_line(), cursor_get_column() + 1);
+ /* Make sure we don't try and remove empty space. */
+ if (get_caret_column() < get_line(get_caret_line()).length()) {
+ remove_text(get_caret_line(), get_caret_column(), get_caret_line(), get_caret_column() + 1);
}
}
const char32_t chr[2] = { (char32_t)p_unicode, 0 };
if (auto_brace_completion_enabled) {
- int cl = cursor_get_line();
- int cc = cursor_get_column();
+ int cl = get_caret_line();
+ int cc = get_caret_column();
int caret_move_offset = 1;
int post_brace_pair = cc < get_line(cl).length() ? _get_auto_brace_pair_close_at_pos(cl, cc) : -1;
if (has_string_delimiter(chr) && cc > 0 && _is_char(get_line(cl)[cc - 1]) && post_brace_pair == -1) {
- insert_text_at_cursor(chr);
+ insert_text_at_caret(chr);
} else if (cc < get_line(cl).length() && _is_char(get_line(cl)[cc])) {
- insert_text_at_cursor(chr);
+ insert_text_at_caret(chr);
} else if (post_brace_pair != -1 && auto_brace_completion_pairs[post_brace_pair].close_key[0] == chr[0]) {
caret_move_offset = auto_brace_completion_pairs[post_brace_pair].close_key.length();
} else if (is_in_comment(cl, cc) != -1 || (is_in_string(cl, cc) != -1 && has_string_delimiter(chr))) {
- insert_text_at_cursor(chr);
+ insert_text_at_caret(chr);
} else {
- insert_text_at_cursor(chr);
+ insert_text_at_caret(chr);
int pre_brace_pair = _get_auto_brace_pair_open_at_pos(cl, cc + 1);
if (pre_brace_pair != -1) {
- insert_text_at_cursor(auto_brace_completion_pairs[pre_brace_pair].close_key);
+ insert_text_at_caret(auto_brace_completion_pairs[pre_brace_pair].close_key);
}
}
- cursor_set_column(cc + caret_move_offset);
+ set_caret_column(cc + caret_move_offset);
} else {
- insert_text_at_cursor(chr);
+ insert_text_at_caret(chr);
}
- if ((is_insert_mode() && !had_selection) || (had_selection)) {
+ if ((is_overtype_mode_enabled() && !had_selection) || (had_selection)) {
end_complex_operation();
}
}
+void CodeEdit::_backspace_internal() {
+ if (!is_editable()) {
+ return;
+ }
+
+ int cc = get_caret_column();
+ int cl = get_caret_line();
+
+ if (cc == 0 && cl == 0) {
+ return;
+ }
+
+ if (has_selection()) {
+ delete_selection();
+ return;
+ }
+
+ if (cl > 0 && _is_line_hidden(cl - 1)) {
+ unfold_line(get_caret_line() - 1);
+ }
+
+ int prev_line = cc ? cl : cl - 1;
+ int prev_column = cc ? (cc - 1) : (get_line(cl - 1).length());
+
+ merge_gutters(prev_line, cl);
+
+ if (auto_brace_completion_enabled && cc > 0) {
+ int idx = _get_auto_brace_pair_open_at_pos(cl, cc);
+ if (idx != -1) {
+ prev_column = cc - auto_brace_completion_pairs[idx].open_key.length();
+
+ if (_get_auto_brace_pair_close_at_pos(cl, cc) == idx) {
+ remove_text(prev_line, prev_column, cl, cc + auto_brace_completion_pairs[idx].close_key.length());
+ } else {
+ remove_text(prev_line, prev_column, cl, cc);
+ }
+ set_caret_line(prev_line, false, true);
+ set_caret_column(prev_column);
+ return;
+ }
+ }
+
+ // For space indentation we need to do a simple unindent if there are no chars to the left, acting in the
+ // same way as tabs.
+ if (indent_using_spaces && cc != 0) {
+ if (get_first_non_whitespace_column(cl) > cc) {
+ prev_column = cc - _calculate_spaces_till_next_left_indent(cc);
+ prev_line = cl;
+ }
+ }
+
+ remove_text(prev_line, prev_column, cl, cc);
+
+ set_caret_line(prev_line, false, true);
+ set_caret_column(prev_column);
+}
+
/* Indent management */
void CodeEdit::set_indent_size(const int p_size) {
ERR_FAIL_COND_MSG(p_size <= 0, "Indend size must be greater than 0.");
@@ -654,28 +724,28 @@ TypedArray<String> CodeEdit::get_auto_indent_prefixes() const {
}
void CodeEdit::do_indent() {
- if (is_readonly()) {
+ if (!is_editable()) {
return;
}
- if (is_selection_active()) {
+ if (has_selection()) {
indent_lines();
return;
}
if (!indent_using_spaces) {
- insert_text_at_cursor("\t");
+ insert_text_at_caret("\t");
return;
}
- int spaces_to_add = _calculate_spaces_till_next_right_indent(cursor_get_column());
+ int spaces_to_add = _calculate_spaces_till_next_right_indent(get_caret_column());
if (spaces_to_add > 0) {
- insert_text_at_cursor(String(" ").repeat(spaces_to_add));
+ insert_text_at_caret(String(" ").repeat(spaces_to_add));
}
}
void CodeEdit::indent_lines() {
- if (is_readonly()) {
+ if (!is_editable()) {
return;
}
@@ -685,9 +755,9 @@ void CodeEdit::indent_lines() {
/* Default is 1 for tab indentation. */
int selection_offset = 1;
- int start_line = cursor_get_line();
+ int start_line = get_caret_line();
int end_line = start_line;
- if (is_selection_active()) {
+ if (has_selection()) {
start_line = get_selection_from_line();
end_line = get_selection_to_line();
@@ -700,7 +770,7 @@ void CodeEdit::indent_lines() {
for (int i = start_line; i <= end_line; i++) {
const String line_text = get_line(i);
- if (line_text.size() == 0 && is_selection_active()) {
+ if (line_text.size() == 0 && has_selection()) {
continue;
}
@@ -717,32 +787,32 @@ void CodeEdit::indent_lines() {
}
/* Fix selection and caret being off after shifting selection right.*/
- if (is_selection_active()) {
+ if (has_selection()) {
select(start_line, get_selection_from_column() + selection_offset, get_selection_to_line(), get_selection_to_column() + selection_offset);
}
- cursor_set_column(cursor_get_column() + selection_offset, false);
+ set_caret_column(get_caret_column() + selection_offset, false);
end_complex_operation();
}
void CodeEdit::do_unindent() {
- if (is_readonly()) {
+ if (!is_editable()) {
return;
}
- int cc = cursor_get_column();
+ int cc = get_caret_column();
- if (is_selection_active() || cc <= 0) {
+ if (has_selection() || cc <= 0) {
unindent_lines();
return;
}
- int cl = cursor_get_line();
+ int cl = get_caret_line();
const String &line = get_line(cl);
if (line[cc - 1] == '\t') {
- _remove_text(cl, cc - 1, cl, cc);
- cursor_set_column(MAX(0, cc - 1));
+ remove_text(cl, cc - 1, cl, cc);
+ set_caret_column(MAX(0, cc - 1));
return;
}
@@ -758,13 +828,13 @@ void CodeEdit::do_unindent() {
break;
}
}
- _remove_text(cl, cc - spaces_to_remove, cl, cc);
- cursor_set_column(MAX(0, cc - spaces_to_remove));
+ remove_text(cl, cc - spaces_to_remove, cl, cc);
+ set_caret_column(MAX(0, cc - spaces_to_remove));
}
}
void CodeEdit::unindent_lines() {
- if (is_readonly()) {
+ if (!is_editable()) {
return;
}
@@ -775,11 +845,11 @@ void CodeEdit::unindent_lines() {
/* therefore we just remember initial values and at the end of the operation offset them by number of removed characters. */
int removed_characters = 0;
int initial_selection_end_column = 0;
- int initial_cursor_column = cursor_get_column();
+ int initial_cursor_column = get_caret_column();
- int start_line = cursor_get_line();
+ int start_line = get_caret_line();
int end_line = start_line;
- if (is_selection_active()) {
+ if (has_selection()) {
start_line = get_selection_from_line();
end_line = get_selection_to_line();
@@ -822,7 +892,7 @@ void CodeEdit::unindent_lines() {
}
}
- if (is_selection_active()) {
+ if (has_selection()) {
/* Fix selection being off by one on the first line. */
if (first_line_edited) {
select(get_selection_from_line(), get_selection_from_column() - removed_characters, get_selection_to_line(), initial_selection_end_column);
@@ -833,7 +903,7 @@ void CodeEdit::unindent_lines() {
select(get_selection_from_line(), get_selection_from_column(), get_selection_to_line(), initial_selection_end_column - removed_characters);
}
}
- cursor_set_column(initial_cursor_column - removed_characters, false);
+ set_caret_column(initial_cursor_column - removed_characters, false);
end_complex_operation();
}
@@ -851,12 +921,12 @@ int CodeEdit::_calculate_spaces_till_next_right_indent(int p_column) const {
}
void CodeEdit::_new_line(bool p_split_current_line, bool p_above) {
- if (is_readonly()) {
+ if (!is_editable()) {
return;
}
- const int cc = cursor_get_column();
- const int cl = cursor_get_line();
+ const int cc = get_caret_column();
+ const int cl = get_caret_line();
const String line = get_line(cl);
String ins = "\n";
@@ -932,86 +1002,29 @@ void CodeEdit::_new_line(bool p_split_current_line, bool p_above) {
if (!p_split_current_line) {
if (p_above) {
if (cl > 0) {
- cursor_set_line(cl - 1, false);
- cursor_set_column(get_line(cursor_get_line()).length());
+ set_caret_line(cl - 1, false);
+ set_caret_column(get_line(get_caret_line()).length());
} else {
- cursor_set_column(0);
+ set_caret_column(0);
first_line = true;
}
} else {
- cursor_set_column(line.length());
+ set_caret_column(line.length());
}
}
- insert_text_at_cursor(ins);
+ insert_text_at_caret(ins);
if (first_line) {
- cursor_set_line(0);
+ set_caret_line(0);
} else if (brace_indent) {
- cursor_set_line(cursor_get_line() - 1, false);
- cursor_set_column(get_line(cursor_get_line()).length());
+ set_caret_line(get_caret_line() - 1, false);
+ set_caret_column(get_line(get_caret_line()).length());
}
end_complex_operation();
}
-void CodeEdit::backspace() {
- if (is_readonly()) {
- return;
- }
-
- int cc = cursor_get_column();
- int cl = cursor_get_line();
-
- if (cc == 0 && cl == 0) {
- return;
- }
-
- if (is_selection_active()) {
- delete_selection();
- return;
- }
-
- if (cl > 0 && is_line_hidden(cl - 1)) {
- unfold_line(cursor_get_line() - 1);
- }
-
- int prev_line = cc ? cl : cl - 1;
- int prev_column = cc ? (cc - 1) : (get_line(cl - 1).length());
-
- merge_gutters(cl, prev_line);
-
- if (auto_brace_completion_enabled && cc > 0) {
- int idx = _get_auto_brace_pair_open_at_pos(cl, cc);
- if (idx != -1) {
- prev_column = cc - auto_brace_completion_pairs[idx].open_key.length();
-
- if (_get_auto_brace_pair_close_at_pos(cl, cc) == idx) {
- _remove_text(prev_line, prev_column, cl, cc + auto_brace_completion_pairs[idx].close_key.length());
- } else {
- _remove_text(prev_line, prev_column, cl, cc);
- }
- cursor_set_line(prev_line, false, true);
- cursor_set_column(prev_column);
- return;
- }
- }
-
- /* For space indentation we need to do a simple unindent if there are no chars to the left, acting in the */
- /* same way as tabs. */
- if (indent_using_spaces && cc != 0) {
- if (get_first_non_whitespace_column(cl) > cc) {
- prev_column = cc - _calculate_spaces_till_next_left_indent(cc);
- prev_line = cl;
- }
- }
-
- _remove_text(prev_line, prev_column, cl, cc);
-
- cursor_set_line(prev_line, false, true);
- cursor_set_column(prev_column);
-}
-
/* Auto brace completion */
void CodeEdit::set_auto_brace_completion_enabled(bool p_enabled) {
auto_brace_completion_enabled = p_enabled;
@@ -1165,6 +1178,8 @@ void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2
// Breakpoints
void CodeEdit::set_line_as_breakpoint(int p_line, bool p_breakpointed) {
+ ERR_FAIL_INDEX(p_line, get_line_count());
+
int mask = get_line_gutter_metadata(p_line, main_gutter);
set_line_gutter_metadata(p_line, main_gutter, p_breakpointed ? mask | MAIN_GUTTER_BREAKPOINT : mask & ~MAIN_GUTTER_BREAKPOINT);
if (p_breakpointed) {
@@ -1278,8 +1293,8 @@ void CodeEdit::_line_number_draw_callback(int p_line, int p_gutter, const Rect2
String fc = TS->format_number(String::num(p_line + 1).lpad(line_number_digits, line_number_padding));
Ref<TextLine> tl;
tl.instantiate();
- tl->add_string(fc, cache.font, cache.font_size);
- int yofs = p_region.position.y + (get_row_height() - tl->get_size().y) / 2;
+ tl->add_string(fc, font, font_size);
+ int yofs = p_region.position.y + (get_line_height() - tl->get_size().y) / 2;
Color number_color = get_line_gutter_item_color(p_line, line_number_gutter);
if (number_color == Color(1, 1, 1)) {
number_color = line_number_color;
@@ -1319,7 +1334,7 @@ void CodeEdit::_fold_gutter_draw_callback(int p_line, int p_gutter, Rect2 p_regi
/* Line Folding */
void CodeEdit::set_line_folding_enabled(bool p_enabled) {
line_folding_enabled = p_enabled;
- set_hiding_enabled(p_enabled);
+ _set_hiding_enabled(p_enabled);
}
bool CodeEdit::is_line_folding_enabled() const {
@@ -1336,7 +1351,7 @@ bool CodeEdit::can_fold_line(int p_line) const {
return false;
}
- if (is_line_hidden(p_line) || is_line_folded(p_line)) {
+ if (_is_line_hidden(p_line) || is_line_folded(p_line)) {
return false;
}
@@ -1385,7 +1400,8 @@ void CodeEdit::fold_line(int p_line) {
}
/* Find the last line to be hidden. */
- int end_line = get_line_count();
+ const int line_count = get_line_count() - 1;
+ int end_line = line_count;
int in_comment = is_in_comment(p_line);
int in_string = (in_comment == -1) ? is_in_string(p_line) : -1;
@@ -1393,7 +1409,7 @@ void CodeEdit::fold_line(int p_line) {
end_line = get_delimiter_end_position(p_line, get_line(p_line).size() - 1).y;
/* End line is the same therefore we have a block. */
if (end_line == p_line) {
- for (int i = p_line + 1; i < get_line_count(); i++) {
+ for (int i = p_line + 1; i <= line_count; i++) {
if ((in_string != -1 && is_in_string(i) == -1) || (in_comment != -1 && is_in_comment(i) == -1)) {
end_line = i - 1;
break;
@@ -1402,45 +1418,58 @@ void CodeEdit::fold_line(int p_line) {
}
} else {
int start_indent = get_indent_level(p_line);
- for (int i = p_line + 1; i < get_line_count(); i++) {
+ for (int i = p_line + 1; i <= line_count; i++) {
if (get_line(p_line).strip_edges().size() == 0 || is_in_string(i) != -1 || is_in_comment(i) != -1) {
end_line = i;
continue;
}
- if (get_indent_level(i) <= start_indent && get_line(i).strip_edges().size() != 0) {
+ if (i == line_count) {
+ /* Do not fold empty last line of script if any */
+ end_line = i;
+ if (get_line(i).strip_edges().size() == 0) {
+ end_line--;
+ }
+ break;
+ }
+
+ if ((get_indent_level(i) <= start_indent && get_line(i).strip_edges().size() != 0)) {
+ /* Keep an empty line unfolded if any */
end_line = i - 1;
+ if (get_line(i - 1).strip_edges().size() == 0 && i - 2 > p_line) {
+ end_line = i - 2;
+ }
break;
}
}
}
for (int i = p_line + 1; i <= end_line; i++) {
- set_line_as_hidden(i, true);
+ _set_line_as_hidden(i, true);
}
/* Fix selection. */
- if (is_selection_active()) {
- if (is_line_hidden(get_selection_from_line()) && is_line_hidden(get_selection_to_line())) {
+ if (has_selection()) {
+ if (_is_line_hidden(get_selection_from_line()) && _is_line_hidden(get_selection_to_line())) {
deselect();
- } else if (is_line_hidden(get_selection_from_line())) {
+ } else if (_is_line_hidden(get_selection_from_line())) {
select(p_line, 9999, get_selection_to_line(), get_selection_to_column());
- } else if (is_line_hidden(get_selection_to_line())) {
+ } else if (_is_line_hidden(get_selection_to_line())) {
select(get_selection_from_line(), get_selection_from_column(), p_line, 9999);
}
}
/* Reset caret. */
- if (is_line_hidden(cursor_get_line())) {
- cursor_set_line(p_line, false, false);
- cursor_set_column(get_line(p_line).length(), false);
+ if (_is_line_hidden(get_caret_line())) {
+ set_caret_line(p_line, false, false);
+ set_caret_column(get_line(p_line).length(), false);
}
update();
}
void CodeEdit::unfold_line(int p_line) {
ERR_FAIL_INDEX(p_line, get_line_count());
- if (!is_line_folded(p_line) && !is_line_hidden(p_line)) {
+ if (!is_line_folded(p_line) && !_is_line_hidden(p_line)) {
return;
}
@@ -1453,10 +1482,10 @@ void CodeEdit::unfold_line(int p_line) {
fold_start = is_line_folded(fold_start) ? fold_start : p_line;
for (int i = fold_start + 1; i < get_line_count(); i++) {
- if (!is_line_hidden(i)) {
+ if (!_is_line_hidden(i)) {
break;
}
- set_line_as_hidden(i, false);
+ _set_line_as_hidden(i, false);
}
update();
}
@@ -1469,7 +1498,7 @@ void CodeEdit::fold_all_lines() {
}
void CodeEdit::unfold_all_lines() {
- unhide_all_lines();
+ _unhide_all_lines();
}
void CodeEdit::toggle_foldable_line(int p_line) {
@@ -1483,7 +1512,7 @@ void CodeEdit::toggle_foldable_line(int p_line) {
bool CodeEdit::is_line_folded(int p_line) const {
ERR_FAIL_INDEX_V(p_line, get_line_count(), false);
- return p_line + 1 < get_line_count() && !is_line_hidden(p_line) && is_line_hidden(p_line + 1);
+ return p_line + 1 < get_line_count() && !_is_line_hidden(p_line) && _is_line_hidden(p_line + 1);
}
TypedArray<int> CodeEdit::get_folded_lines() const {
@@ -1707,11 +1736,11 @@ String CodeEdit::get_text_for_code_completion() const {
for (int i = 0; i < text_size; i++) {
String line = get_line(i);
- if (i == cursor_get_line()) {
- completion_text += line.substr(0, cursor_get_column());
+ if (i == get_caret_line()) {
+ completion_text += line.substr(0, get_caret_column());
/* Not unicode, represents the caret. */
completion_text += String::chr(0xFFFF);
- completion_text += line.substr(cursor_get_column(), line.size());
+ completion_text += line.substr(get_caret_column(), line.size());
} else {
completion_text += line;
}
@@ -1724,9 +1753,7 @@ String CodeEdit::get_text_for_code_completion() const {
}
void CodeEdit::request_code_completion(bool p_force) {
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_request_code_completion")) {
- si->call("_request_code_completion", p_force);
+ if (GDVIRTUAL_CALL(_request_code_completion, p_force)) {
return;
}
@@ -1758,10 +1785,10 @@ void CodeEdit::request_code_completion(bool p_force) {
return;
}
- String line = get_line(cursor_get_line());
- int ofs = CLAMP(cursor_get_column(), 0, line.length());
+ String line = get_line(get_caret_line());
+ int ofs = CLAMP(get_caret_column(), 0, line.length());
- if (ofs > 0 && (is_in_string(cursor_get_line(), ofs) != -1 || _is_char(line[ofs - 1]) || code_completion_prefixes.has(String::chr(line[ofs - 1])))) {
+ if (ofs > 0 && (is_in_string(get_caret_line(), ofs) != -1 || _is_char(line[ofs - 1]) || code_completion_prefixes.has(String::chr(line[ofs - 1])))) {
emit_signal(SNAME("request_code_completion"));
} else if (ofs > 1 && line[ofs - 1] == ' ' && code_completion_prefixes.has(String::chr(line[ofs - 2]))) {
emit_signal(SNAME("request_code_completion"));
@@ -1783,7 +1810,7 @@ void CodeEdit::update_code_completion_options(bool p_forced) {
code_completion_forced = p_forced;
code_completion_option_sources = code_completion_option_submitted;
code_completion_option_submitted.clear();
- _filter_code_completion_candidates();
+ _filter_code_completion_candidates_impl();
}
TypedArray<Dictionary> CodeEdit::get_code_completion_options() const {
@@ -1836,18 +1863,17 @@ void CodeEdit::set_code_completion_selected_index(int p_index) {
}
void CodeEdit::confirm_code_completion(bool p_replace) {
- if (is_readonly() || !code_completion_active) {
+ if (!is_editable() || !code_completion_active) {
return;
}
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_confirm_code_completion")) {
- si->call("_confirm_code_completion", p_replace);
+ if (GDVIRTUAL_CALL(_confirm_code_completion, p_replace)) {
return;
}
+
begin_complex_operation();
- int caret_line = cursor_get_line();
+ int caret_line = get_caret_line();
const String &insert_text = code_completion_options[code_completion_current_selected].insert_text;
const String &display_text = code_completion_options[code_completion_current_selected].display;
@@ -1855,7 +1881,7 @@ void CodeEdit::confirm_code_completion(bool p_replace) {
if (p_replace) {
/* Find end of current section */
const String line = get_line(caret_line);
- int caret_col = cursor_get_column();
+ int caret_col = get_caret_column();
int caret_remove_line = caret_line;
bool merge_text = true;
@@ -1878,13 +1904,13 @@ void CodeEdit::confirm_code_completion(bool p_replace) {
}
/* Replace. */
- _remove_text(caret_line, cursor_get_column() - code_completion_base.length(), caret_remove_line, caret_col);
- cursor_set_column(cursor_get_column() - code_completion_base.length(), false);
- insert_text_at_cursor(insert_text);
+ remove_text(caret_line, get_caret_column() - code_completion_base.length(), caret_remove_line, caret_col);
+ set_caret_column(get_caret_column() - code_completion_base.length(), false);
+ insert_text_at_caret(insert_text);
} else {
/* Get first non-matching char. */
const String line = get_line(caret_line);
- int caret_col = cursor_get_column();
+ int caret_col = get_caret_column();
int matching_chars = code_completion_base.length();
for (; matching_chars <= insert_text.length(); matching_chars++) {
if (caret_col >= line.length() || line[caret_col] != insert_text[matching_chars]) {
@@ -1894,41 +1920,41 @@ void CodeEdit::confirm_code_completion(bool p_replace) {
}
/* Remove base completion text. */
- _remove_text(caret_line, cursor_get_column() - code_completion_base.length(), caret_line, cursor_get_column());
- cursor_set_column(cursor_get_column() - code_completion_base.length(), false);
+ remove_text(caret_line, get_caret_column() - code_completion_base.length(), caret_line, get_caret_column());
+ set_caret_column(get_caret_column() - code_completion_base.length(), false);
/* Merge with text. */
- insert_text_at_cursor(insert_text.substr(0, code_completion_base.length()));
- cursor_set_column(caret_col, false);
- insert_text_at_cursor(insert_text.substr(matching_chars));
+ insert_text_at_caret(insert_text.substr(0, code_completion_base.length()));
+ set_caret_column(caret_col, false);
+ insert_text_at_caret(insert_text.substr(matching_chars));
}
/* Handle merging of symbols eg strings, brackets. */
const String line = get_line(caret_line);
- char32_t next_char = line[cursor_get_column()];
+ char32_t next_char = line[get_caret_column()];
char32_t last_completion_char = insert_text[insert_text.length() - 1];
char32_t last_completion_char_display = display_text[display_text.length() - 1];
- int pre_brace_pair = cursor_get_column() > 0 ? _get_auto_brace_pair_open_at_pos(caret_line, cursor_get_column()) : -1;
- int post_brace_pair = cursor_get_column() < get_line(caret_line).length() ? _get_auto_brace_pair_close_at_pos(caret_line, cursor_get_column()) : -1;
+ int pre_brace_pair = get_caret_column() > 0 ? _get_auto_brace_pair_open_at_pos(caret_line, get_caret_column()) : -1;
+ int post_brace_pair = get_caret_column() < get_line(caret_line).length() ? _get_auto_brace_pair_close_at_pos(caret_line, get_caret_column()) : -1;
if (post_brace_pair != -1 && (last_completion_char == next_char || last_completion_char_display == next_char)) {
- _remove_text(caret_line, cursor_get_column(), caret_line, cursor_get_column() + 1);
+ remove_text(caret_line, get_caret_column(), caret_line, get_caret_column() + 1);
}
if (pre_brace_pair != -1 && pre_brace_pair != post_brace_pair && (last_completion_char == next_char || last_completion_char_display == next_char)) {
- _remove_text(caret_line, cursor_get_column(), caret_line, cursor_get_column() + 1);
+ remove_text(caret_line, get_caret_column(), caret_line, get_caret_column() + 1);
} else if (auto_brace_completion_enabled && pre_brace_pair != -1 && post_brace_pair == -1) {
- insert_text_at_cursor(auto_brace_completion_pairs[pre_brace_pair].close_key);
- cursor_set_column(cursor_get_column() - auto_brace_completion_pairs[pre_brace_pair].close_key.length());
+ insert_text_at_caret(auto_brace_completion_pairs[pre_brace_pair].close_key);
+ set_caret_column(get_caret_column() - auto_brace_completion_pairs[pre_brace_pair].close_key.length());
}
- if (pre_brace_pair == -1 && post_brace_pair == -1 && cursor_get_column() > 0 && cursor_get_column() < get_line(caret_line).length()) {
- pre_brace_pair = _get_auto_brace_pair_open_at_pos(caret_line, cursor_get_column() + 1);
- if (pre_brace_pair == _get_auto_brace_pair_close_at_pos(caret_line, cursor_get_column() - 1)) {
- _remove_text(caret_line, cursor_get_column() - 2, caret_line, cursor_get_column());
- if (_get_auto_brace_pair_close_at_pos(caret_line, cursor_get_column() - 1) != pre_brace_pair) {
- cursor_set_column(cursor_get_column() - 1);
+ if (pre_brace_pair == -1 && post_brace_pair == -1 && get_caret_column() > 0 && get_caret_column() < get_line(caret_line).length()) {
+ pre_brace_pair = _get_auto_brace_pair_open_at_pos(caret_line, get_caret_column() + 1);
+ if (pre_brace_pair != -1 && pre_brace_pair == _get_auto_brace_pair_close_at_pos(caret_line, get_caret_column() - 1)) {
+ remove_text(caret_line, get_caret_column() - 2, caret_line, get_caret_column());
+ if (_get_auto_brace_pair_close_at_pos(caret_line, get_caret_column() - 1) != pre_brace_pair) {
+ set_caret_column(get_caret_column() - 1);
}
}
}
@@ -1971,9 +1997,11 @@ bool CodeEdit::is_symbol_lookup_on_click_enabled() const {
}
String CodeEdit::get_text_for_symbol_lookup() {
- int line, col;
- Point2i mp = _get_local_mouse_pos();
- _get_mouse_pos(mp, line, col);
+ Point2i mp = get_local_mouse_pos();
+
+ Point2i pos = get_line_column_at_pos(mp);
+ int line = pos.y;
+ int col = pos.x;
StringBuilder lookup_text;
const int text_size = get_line_count();
@@ -2162,9 +2190,10 @@ void CodeEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_code_comletion_prefixes"), &CodeEdit::get_code_completion_prefixes);
// Overridable
- BIND_VMETHOD(MethodInfo("_confirm_code_completion", PropertyInfo(Variant::BOOL, "replace")));
- BIND_VMETHOD(MethodInfo("_request_code_completion", PropertyInfo(Variant::BOOL, "force")));
- BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_filter_code_completion_candidates", PropertyInfo(Variant::ARRAY, "candidates")));
+
+ GDVIRTUAL_BIND(_confirm_code_completion, "replace")
+ GDVIRTUAL_BIND(_request_code_completion, "force")
+ GDVIRTUAL_BIND(_filter_code_completion_candidates, "candidates")
/* Line length guidelines */
ClassDB::bind_method(D_METHOD("set_line_length_guidelines", "guideline_columns"), &CodeEdit::set_line_length_guidelines);
@@ -2289,8 +2318,8 @@ void CodeEdit::_gutter_clicked(int p_line, int p_gutter) {
if (p_gutter == line_number_gutter) {
set_selection_mode(TextEdit::SelectionMode::SELECTION_MODE_LINE, p_line, 0);
select(p_line, 0, p_line + 1, 0);
- cursor_set_line(p_line + 1);
- cursor_set_column(0);
+ set_caret_line(p_line + 1);
+ set_caret_column(0);
return;
}
@@ -2633,9 +2662,10 @@ TypedArray<String> CodeEdit::_get_delimiters(DelimiterType p_type) const {
}
/* Code Completion */
-void CodeEdit::_filter_code_completion_candidates() {
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_filter_code_completion_candidates")) {
+void CodeEdit::_filter_code_completion_candidates_impl() {
+ int line_height = get_line_height();
+
+ if (GDVIRTUAL_IS_OVERRIDDEN(_filter_code_completion_candidates)) {
code_completion_options.clear();
code_completion_base = "";
@@ -2655,7 +2685,9 @@ void CodeEdit::_filter_code_completion_candidates() {
i++;
}
- TypedArray<Dictionary> completion_options = si->call("_filter_code_completion_candidates", completion_options_sources);
+ Array completion_options;
+
+ GDVIRTUAL_CALL(_filter_code_completion_candidates, completion_options_sources, completion_options);
/* No options to complete, cancel. */
if (completion_options.size() == 0) {
@@ -2674,19 +2706,24 @@ void CodeEdit::_filter_code_completion_candidates() {
option.icon = completion_options[i].get("icon");
option.default_value = completion_options[i].get("default_value");
- max_width = MAX(max_width, cache.font->get_string_size(option.display).width);
+ int offset = 0;
+ if (option.default_value.get_type() == Variant::COLOR) {
+ offset = line_height;
+ }
+
+ max_width = MAX(max_width, font->get_string_size(option.display, font_size).width + offset);
code_completion_options.push_back(option);
}
- code_completion_longest_line = MIN(max_width, code_completion_max_width);
+ code_completion_longest_line = MIN(max_width, code_completion_max_width * font_size);
code_completion_current_selected = 0;
code_completion_active = true;
update();
return;
}
- const int caret_line = cursor_get_line();
- const int caret_column = cursor_get_column();
+ const int caret_line = get_caret_line();
+ const int caret_column = get_caret_column();
const String line = get_line(caret_line);
if (caret_column > 0 && line[caret_column - 1] == '(' && !code_completion_forced) {
@@ -2721,7 +2758,7 @@ void CodeEdit::_filter_code_completion_candidates() {
/* If we have a space, previous word might be a keyword. eg "func |". */
} else if (cofs > 0 && line[cofs - 1] == ' ') {
int ofs = cofs - 1;
- while (ofs >= 0 && line[ofs] == ' ') {
+ while (ofs > 0 && line[ofs] == ' ') {
ofs--;
}
prev_is_word = _is_char(line[ofs]);
@@ -2766,6 +2803,11 @@ void CodeEdit::_filter_code_completion_candidates() {
option.display = option.display.unquote().quote("'");
}
+ int offset = 0;
+ if (option.default_value.get_type() == Variant::COLOR) {
+ offset = line_height;
+ }
+
if (in_string != -1) {
String quote = single_quote ? "'" : "\"";
option.display = option.display.unquote().quote(quote);
@@ -2778,7 +2820,7 @@ void CodeEdit::_filter_code_completion_candidates() {
if (string_to_complete.length() == 0) {
code_completion_options.push_back(option);
- max_width = MAX(max_width, cache.font->get_string_size(option.display).width);
+ max_width = MAX(max_width, font->get_string_size(option.display, font_size).width + offset);
continue;
}
@@ -2827,7 +2869,7 @@ void CodeEdit::_filter_code_completion_candidates() {
} else {
completion_options_subseq.push_back(option);
}
- max_width = MAX(max_width, cache.font->get_string_size(option.display).width);
+ max_width = MAX(max_width, font->get_string_size(option.display, font_size).width + offset);
/* Matched the whole subsequence in s_lower. */
} else if (!*ssq_lower) {
/* Finished matching in the first s.length() characters. */
@@ -2836,7 +2878,7 @@ void CodeEdit::_filter_code_completion_candidates() {
} else {
completion_options_subseq_casei.push_back(option);
}
- max_width = MAX(max_width, cache.font->get_string_size(option.display).width);
+ max_width = MAX(max_width, font->get_string_size(option.display, font_size).width + offset);
}
}
@@ -2856,7 +2898,7 @@ void CodeEdit::_filter_code_completion_candidates() {
return;
}
- code_completion_longest_line = MIN(max_width, code_completion_max_width);
+ code_completion_longest_line = MIN(max_width, code_completion_max_width * font_size);
code_completion_current_selected = 0;
code_completion_active = true;
update();
@@ -2869,30 +2911,53 @@ void CodeEdit::_lines_edited_from(int p_from_line, int p_to_line) {
return;
}
+ lines_edited_from = (lines_edited_from == -1) ? MIN(p_from_line, p_to_line) : MIN(lines_edited_from, MIN(p_from_line, p_to_line));
+ lines_edited_to = (lines_edited_to == -1) ? MAX(p_from_line, p_to_line) : MAX(lines_edited_from, MAX(p_from_line, p_to_line));
+}
+
+void CodeEdit::_text_set() {
+ lines_edited_from = 0;
+ lines_edited_to = 9999;
+ _text_changed();
+}
+
+void CodeEdit::_text_changed() {
+ if (lines_edited_from == -1) {
+ return;
+ }
+
int lc = get_line_count();
line_number_digits = 1;
while (lc /= 10) {
line_number_digits++;
}
- set_gutter_width(line_number_gutter, (line_number_digits + 1) * cache.font->get_char_size('0', 0, cache.font_size).width);
- int from_line = MIN(p_from_line, p_to_line);
- int line_count = (p_to_line - p_from_line);
+ if (font.is_valid()) {
+ set_gutter_width(line_number_gutter, (line_number_digits + 1) * font->get_char_size('0', 0, font_size).width);
+ }
+
+ lc = get_line_count();
+ int line_change_size = (lines_edited_to - lines_edited_from);
List<int> breakpoints;
breakpointed_lines.get_key_list(&breakpoints);
- for (const int line : breakpoints) {
- if (line <= from_line) {
+ for (const int &line : breakpoints) {
+ if (line < lines_edited_from || (line < lc && is_line_breakpointed(line))) {
continue;
}
- breakpointed_lines.erase(line);
+ breakpointed_lines.erase(line);
emit_signal(SNAME("breakpoint_toggled"), line);
- if (line_count > 0 || line >= p_from_line) {
- emit_signal(SNAME("breakpoint_toggled"), line + line_count);
- breakpointed_lines[line + line_count] = true;
+
+ int next_line = line + line_change_size;
+ if (next_line < lc && is_line_breakpointed(next_line)) {
+ emit_signal(SNAME("breakpoint_toggled"), next_line);
+ breakpointed_lines[next_line] = true;
continue;
}
}
+
+ lines_edited_from = -1;
+ lines_edited_to = -1;
}
CodeEdit::CodeEdit() {
@@ -2946,8 +3011,10 @@ CodeEdit::CodeEdit() {
gutter_idx++;
connect("lines_edited_from", callable_mp(this, &CodeEdit::_lines_edited_from));
- connect("gutter_clicked", callable_mp(this, &CodeEdit::_gutter_clicked));
+ connect("text_set", callable_mp(this, &CodeEdit::_text_set));
+ connect("text_changed", callable_mp(this, &CodeEdit::_text_changed));
+ connect("gutter_clicked", callable_mp(this, &CodeEdit::_gutter_clicked));
connect("gutter_added", callable_mp(this, &CodeEdit::_update_gutter_indexes));
connect("gutter_removed", callable_mp(this, &CodeEdit::_update_gutter_indexes));
_update_gutter_indexes();
diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h
index 72fdc6e787..4fbb5194e6 100644
--- a/scene/gui/code_edit.h
+++ b/scene/gui/code_edit.h
@@ -219,9 +219,7 @@ private:
List<ScriptCodeCompletionOption> code_completion_option_sources;
String code_completion_base;
- void _filter_code_completion_candidates();
-
- void _lines_edited_from(int p_from_line, int p_to_line);
+ void _filter_code_completion_candidates_impl();
/* Line length guidelines */
TypedArray<int> line_length_guideline_columns;
@@ -233,16 +231,41 @@ private:
String symbol_lookup_new_word = "";
String symbol_lookup_word = "";
+ /* Visual */
+ Ref<StyleBox> style_normal;
+
+ Ref<Font> font;
+ int font_size = 16;
+
+ int line_spacing = 1;
+
+ /* Callbacks */
+ int lines_edited_from = -1;
+ int lines_edited_to = -1;
+
+ void _lines_edited_from(int p_from_line, int p_to_line);
+ void _text_set();
+ void _text_changed();
+
protected:
- void _gui_input(const Ref<InputEvent> &p_gui_input) override;
+ void gui_input(const Ref<InputEvent> &p_gui_input) override;
void _notification(int p_what);
static void _bind_methods();
+ /* Text manipulation */
+
+ // Overridable actions
+ virtual void _handle_unicode_input_internal(const uint32_t p_unicode) override;
+ virtual void _backspace_internal() override;
+
+ GDVIRTUAL1(_confirm_code_completion, bool)
+ GDVIRTUAL1(_request_code_completion, bool)
+ GDVIRTUAL1RC(Array, _filter_code_completion_candidates, TypedArray<Dictionary>)
+
public:
/* General overrides */
virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override;
- virtual void handle_unicode_input(uint32_t p_unicode) override;
/* Indent management */
void set_indent_size(const int p_size);
@@ -263,8 +286,6 @@ public:
void indent_lines();
void unindent_lines();
- virtual void backspace() override;
-
/* Auto brace completion */
void set_auto_brace_completion_enabled(bool p_enabled);
bool is_auto_brace_completion_enabled() const;
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 261480bcdd..1afb0b8e9d 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -46,13 +46,13 @@ void ColorPicker::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
btn_pick->set_icon(get_theme_icon(SNAME("screen_picker"), SNAME("ColorPicker")));
- bt_add_preset->set_icon(get_theme_icon(SNAME("add_preset")));
-
+ btn_add_preset->set_icon(get_theme_icon(SNAME("add_preset")));
+ _update_presets();
_update_controls();
} break;
case NOTIFICATION_ENTER_TREE: {
btn_pick->set_icon(get_theme_icon(SNAME("screen_picker"), SNAME("ColorPicker")));
- bt_add_preset->set_icon(get_theme_icon(SNAME("add_preset")));
+ btn_add_preset->set_icon(get_theme_icon(SNAME("add_preset")));
_update_controls();
_update_color();
@@ -69,7 +69,6 @@ void ColorPicker::_notification(int p_what) {
for (int i = 0; i < preset_cache.size(); i++) {
presets.push_back(preset_cache[i]);
}
- preset->update();
}
#endif
} break;
@@ -98,6 +97,8 @@ Ref<Shader> ColorPicker::circle_shader;
void ColorPicker::init_shaders() {
wheel_shader.instantiate();
wheel_shader->set_code(R"(
+// ColorPicker wheel shader.
+
shader_type canvas_item;
void fragment() {
@@ -120,6 +121,8 @@ void fragment() {
circle_shader.instantiate();
circle_shader->set_code(R"(
+// ColorPicker circle shader.
+
shader_type canvas_item;
uniform float v = 1.0;
@@ -372,22 +375,23 @@ void ColorPicker::_update_color(bool p_update_sliders) {
}
void ColorPicker::_update_presets() {
- return;
- //presets should be shown using buttons or something else, this method is not a good idea
-
- presets_per_row = 10;
- Size2 size = bt_add_preset->get_size();
- Size2 preset_size = Size2(MIN(size.width * presets.size(), presets_per_row * size.width), size.height * (Math::ceil((float)presets.size() / presets_per_row)));
- preset->set_custom_minimum_size(preset_size);
- preset_container->set_custom_minimum_size(preset_size);
- preset->draw_rect(Rect2(Point2(), preset_size), Color(1, 1, 1, 0));
-
- for (int i = 0; i < presets.size(); i++) {
- int x = (i % presets_per_row) * size.width;
- int y = (Math::floor((float)i / presets_per_row)) * size.height;
- preset->draw_rect(Rect2(Point2(x, y), size), presets[i]);
+ int preset_size = _get_preset_size();
+ // Only update the preset button size if it has changed.
+ if (preset_size != prev_preset_size) {
+ prev_preset_size = preset_size;
+ btn_add_preset->set_custom_minimum_size(Size2(preset_size, preset_size));
+ for (int i = 1; i < preset_container->get_child_count(); i++) {
+ ColorPresetButton *cpb = Object::cast_to<ColorPresetButton>(preset_container->get_child(i));
+ cpb->set_custom_minimum_size(Size2(preset_size, preset_size));
+ }
+ }
+ // Only load preset buttons when the only child is the add-preset button.
+ if (preset_container->get_child_count() == 1) {
+ for (int i = 0; i < preset_cache.size(); i++) {
+ _add_preset_button(preset_size, preset_cache[i]);
+ }
+ _notification(NOTIFICATION_VISIBILITY_CHANGED);
}
- _notification(NOTIFICATION_VISIBILITY_CHANGED);
}
void ColorPicker::_text_type_toggled() {
@@ -422,14 +426,37 @@ ColorPicker::PickerShapeType ColorPicker::get_picker_shape() const {
return picker_type;
}
+inline int ColorPicker::_get_preset_size() {
+ return (int(get_minimum_size().width) - (preset_container->get_theme_constant(SNAME("hseparation")) * (preset_column_count - 1))) / preset_column_count;
+}
+
+void ColorPicker::_add_preset_button(int p_size, const Color &p_color) {
+ ColorPresetButton *btn_preset = memnew(ColorPresetButton(p_color));
+ btn_preset->set_preset_color(p_color);
+ btn_preset->set_custom_minimum_size(Size2(p_size, p_size));
+ btn_preset->connect("gui_input", callable_mp(this, &ColorPicker::_preset_input), varray(p_color));
+ btn_preset->set_tooltip(vformat(RTR("Color: #%s\nLMB: Apply color\nRMB: Remove preset"), p_color.to_html(p_color.a < 1)));
+ preset_container->add_child(btn_preset);
+}
+
void ColorPicker::add_preset(const Color &p_color) {
if (presets.find(p_color)) {
presets.move_to_back(presets.find(p_color));
+
+ // Find button to move to the end.
+ for (int i = 1; i < preset_container->get_child_count(); i++) {
+ ColorPresetButton *current_btn = Object::cast_to<ColorPresetButton>(preset_container->get_child(i));
+ if (current_btn && p_color == current_btn->get_preset_color()) {
+ preset_container->move_child(current_btn, preset_container->get_child_count() - 1);
+ break;
+ }
+ }
} else {
presets.push_back(p_color);
preset_cache.push_back(p_color);
+
+ _add_preset_button(_get_preset_size(), p_color);
}
- preset->update();
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
@@ -443,7 +470,15 @@ void ColorPicker::erase_preset(const Color &p_color) {
if (presets.find(p_color)) {
presets.erase(presets.find(p_color));
preset_cache.erase(preset_cache.find(p_color));
- preset->update();
+
+ // Find preset button to remove.
+ for (int i = 1; i < preset_container->get_child_count(); i++) {
+ ColorPresetButton *current_btn = Object::cast_to<ColorPresetButton>(preset_container->get_child(i));
+ if (current_btn && p_color == current_btn->get_preset_color()) {
+ current_btn->queue_delete();
+ break;
+ }
+ }
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
@@ -560,7 +595,7 @@ void ColorPicker::_sample_draw() {
const Rect2 rect_old = Rect2(Point2(), Size2(sample->get_size().width * 0.5, sample->get_size().height * 0.95));
if (display_old_color && old_color.a < 1.0) {
- sample->draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPicker")), rect_old, true);
+ sample->draw_texture_rect(get_theme_icon(SNAME("sample_bg"), SNAME("ColorPicker")), rect_old, true);
}
sample->draw_rect(rect_old, old_color);
@@ -574,7 +609,7 @@ void ColorPicker::_sample_draw() {
}
if (color.a < 1.0) {
- sample->draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPicker")), rect_new, true);
+ sample->draw_texture_rect(get_theme_icon(SNAME("sample_bg"), SNAME("ColorPicker")), rect_new, true);
}
sample->draw_rect(rect_new, color);
@@ -734,7 +769,7 @@ void ColorPicker::_slider_draw(int p_which) {
#endif
if (p_which == 3) {
- scroll[p_which]->draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPicker")), Rect2(Point2(0, margin), Size2(size.x, margin)), true);
+ scroll[p_which]->draw_texture_rect(get_theme_icon(SNAME("sample_bg"), SNAME("ColorPicker")), Rect2(Point2(0, margin), Size2(size.x, margin)), true);
left_color = color;
left_color.a = 0;
@@ -932,43 +967,19 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) {
}
}
-void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) {
+void ColorPicker::_preset_input(const Ref<InputEvent> &p_event, const Color &p_color) {
Ref<InputEventMouseButton> bev = p_event;
if (bev.is_valid()) {
- int index = 0;
if (bev->is_pressed() && bev->get_button_index() == MOUSE_BUTTON_LEFT) {
- for (int i = 0; i < presets.size(); i++) {
- int x = (i % presets_per_row) * bt_add_preset->get_size().x;
- int y = (Math::floor((float)i / presets_per_row)) * bt_add_preset->get_size().y;
- if (bev->get_position().x > x && bev->get_position().x < x + preset->get_size().x && bev->get_position().y > y && bev->get_position().y < y + preset->get_size().y) {
- index = i;
- }
- }
- set_pick_color(presets[index]);
+ set_pick_color(p_color);
_update_color();
- emit_signal(SNAME("color_changed"), color);
+ emit_signal(SNAME("color_changed"), p_color);
} else if (bev->is_pressed() && bev->get_button_index() == MOUSE_BUTTON_RIGHT && presets_enabled) {
- index = bev->get_position().x / (preset->get_size().x / presets.size());
- Color clicked_preset = presets[index];
- erase_preset(clicked_preset);
- emit_signal(SNAME("preset_removed"), clicked_preset);
- bt_add_preset->show();
+ erase_preset(p_color);
+ emit_signal(SNAME("preset_removed"), p_color);
}
}
-
- Ref<InputEventMouseMotion> mev = p_event;
-
- if (mev.is_valid()) {
- int index = mev->get_position().x * presets.size();
- if (preset->get_size().x != 0) {
- index /= preset->get_size().x;
- }
- if (index < 0 || index >= presets.size()) {
- return;
- }
- preset->set_tooltip(vformat(RTR("Color: #%s\nLMB: Set color\nRMB: Remove preset"), presets[index].to_html(presets[index].a < 1)));
- }
}
void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) {
@@ -1064,11 +1075,11 @@ void ColorPicker::_html_focus_exit() {
void ColorPicker::set_presets_enabled(bool p_enabled) {
presets_enabled = p_enabled;
if (!p_enabled) {
- bt_add_preset->set_disabled(true);
- bt_add_preset->set_focus_mode(FOCUS_NONE);
+ btn_add_preset->set_disabled(true);
+ btn_add_preset->set_focus_mode(FOCUS_NONE);
} else {
- bt_add_preset->set_disabled(false);
- bt_add_preset->set_focus_mode(FOCUS_ALL);
+ btn_add_preset->set_disabled(false);
+ btn_add_preset->set_focus_mode(FOCUS_ALL);
}
}
@@ -1080,7 +1091,6 @@ void ColorPicker::set_presets_visible(bool p_visible) {
presets_visible = p_visible;
preset_separator->set_visible(p_visible);
preset_container->set_visible(p_visible);
- preset_container2->set_visible(p_visible);
}
bool ColorPicker::are_presets_visible() const {
@@ -1129,7 +1139,7 @@ void ColorPicker::_bind_methods() {
ColorPicker::ColorPicker() :
BoxContainer(true) {
HBoxContainer *hb_edit = memnew(HBoxContainer);
- add_child(hb_edit);
+ add_child(hb_edit, false, INTERNAL_MODE_FRONT);
hb_edit->set_v_size_flags(SIZE_EXPAND_FILL);
hb_edit->add_child(uv_edit);
@@ -1141,7 +1151,7 @@ ColorPicker::ColorPicker() :
uv_edit->connect("draw", callable_mp(this, &ColorPicker::_hsv_draw), make_binds(0, uv_edit));
HBoxContainer *hb_smpl = memnew(HBoxContainer);
- add_child(hb_smpl);
+ add_child(hb_smpl, false, INTERNAL_MODE_FRONT);
hb_smpl->add_child(sample);
sample->set_h_size_flags(SIZE_EXPAND_FILL);
@@ -1155,12 +1165,12 @@ ColorPicker::ColorPicker() :
btn_pick->connect("pressed", callable_mp(this, &ColorPicker::_screen_pick_pressed));
VBoxContainer *vbl = memnew(VBoxContainer);
- add_child(vbl);
+ add_child(vbl, false, INTERNAL_MODE_FRONT);
- add_child(memnew(HSeparator));
+ add_child(memnew(HSeparator), false, INTERNAL_MODE_FRONT);
VBoxContainer *vbr = memnew(VBoxContainer);
- add_child(vbr);
+ add_child(vbr, false, INTERNAL_MODE_FRONT);
vbr->set_h_size_flags(SIZE_EXPAND_FILL);
for (int i = 0; i < 4; i++) {
@@ -1263,20 +1273,16 @@ ColorPicker::ColorPicker() :
set_pick_color(Color(1, 1, 1));
- add_child(preset_separator);
+ add_child(preset_separator, false, INTERNAL_MODE_FRONT);
preset_container->set_h_size_flags(SIZE_EXPAND_FILL);
- add_child(preset_container);
+ preset_container->set_columns(preset_column_count);
+ add_child(preset_container, false, INTERNAL_MODE_FRONT);
- preset_container->add_child(preset);
- preset->connect("gui_input", callable_mp(this, &ColorPicker::_preset_input));
- preset->connect("draw", callable_mp(this, &ColorPicker::_update_presets));
-
- preset_container2->set_h_size_flags(SIZE_EXPAND_FILL);
- add_child(preset_container2);
- preset_container2->add_child(bt_add_preset);
- bt_add_preset->set_tooltip(RTR("Add current color as a preset."));
- bt_add_preset->connect("pressed", callable_mp(this, &ColorPicker::_add_preset_pressed));
+ btn_add_preset->set_icon_align(Button::ALIGN_CENTER);
+ btn_add_preset->set_tooltip(RTR("Add current color as a preset."));
+ btn_add_preset->connect("pressed", callable_mp(this, &ColorPicker::_add_preset_pressed));
+ preset_container->add_child(btn_add_preset);
}
/////////////////
@@ -1303,6 +1309,7 @@ void ColorPickerButton::pressed() {
_update_picker();
popup->set_as_minsize();
+ picker->_update_presets();
Rect2i usable_rect = popup->get_usable_parent_rect();
//let's try different positions to see which one we can use
@@ -1398,7 +1405,7 @@ void ColorPickerButton::_update_picker() {
picker = memnew(ColorPicker);
picker->set_anchors_and_offsets_preset(PRESET_WIDE);
popup->add_child(picker);
- add_child(popup);
+ add_child(popup, false, INTERNAL_MODE_FRONT);
picker->connect("color_changed", callable_mp(this, &ColorPickerButton::_color_changed));
popup->connect("about_to_popup", callable_mp(this, &ColorPickerButton::_about_to_popup));
popup->connect("popup_hide", callable_mp(this, &ColorPickerButton::_modal_closed));
@@ -1428,3 +1435,64 @@ void ColorPickerButton::_bind_methods() {
ColorPickerButton::ColorPickerButton() {
set_toggle_mode(true);
}
+
+/////////////////
+
+void ColorPresetButton::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ const Rect2 r = Rect2(Point2(0, 0), get_size());
+ Ref<StyleBox> sb_raw = get_theme_stylebox(SNAME("preset_fg"), SNAME("ColorPresetButton"))->duplicate();
+ Ref<StyleBoxFlat> sb_flat = sb_raw;
+ Ref<StyleBoxTexture> sb_texture = sb_raw;
+
+ if (sb_flat.is_valid()) {
+ if (preset_color.a < 1) {
+ // Draw a background pattern when the color is transparent.
+ sb_flat->set_bg_color(Color(1, 1, 1));
+ sb_flat->draw(get_canvas_item(), r);
+
+ Rect2 bg_texture_rect = r.grow_side(SIDE_LEFT, -sb_flat->get_margin(SIDE_LEFT));
+ bg_texture_rect = bg_texture_rect.grow_side(SIDE_RIGHT, -sb_flat->get_margin(SIDE_RIGHT));
+ bg_texture_rect = bg_texture_rect.grow_side(SIDE_TOP, -sb_flat->get_margin(SIDE_TOP));
+ bg_texture_rect = bg_texture_rect.grow_side(SIDE_BOTTOM, -sb_flat->get_margin(SIDE_BOTTOM));
+
+ draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPresetButton")), bg_texture_rect, true);
+ sb_flat->set_bg_color(preset_color);
+ }
+ sb_flat->set_bg_color(preset_color);
+ sb_flat->draw(get_canvas_item(), r);
+ } else if (sb_texture.is_valid()) {
+ if (preset_color.a < 1) {
+ // Draw a background pattern when the color is transparent.
+ bool use_tile_texture = (sb_texture->get_h_axis_stretch_mode() == StyleBoxTexture::AxisStretchMode::AXIS_STRETCH_MODE_TILE) || (sb_texture->get_h_axis_stretch_mode() == StyleBoxTexture::AxisStretchMode::AXIS_STRETCH_MODE_TILE_FIT);
+ draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPresetButton")), r, use_tile_texture);
+ }
+ sb_texture->set_modulate(preset_color);
+ sb_texture->draw(get_canvas_item(), r);
+ } else {
+ WARN_PRINT("Unsupported StyleBox used for ColorPresetButton. Use StyleBoxFlat or StyleBoxTexture instead.");
+ }
+ if (preset_color.r > 1 || preset_color.g > 1 || preset_color.b > 1) {
+ // Draw an indicator to denote that the color is "overbright" and can't be displayed accurately in the preview
+ draw_texture(Control::get_theme_icon(SNAME("overbright_indicator"), SNAME("ColorPresetButton")), Vector2(0, 0));
+ }
+
+ } break;
+ }
+}
+
+void ColorPresetButton::set_preset_color(const Color &p_color) {
+ preset_color = p_color;
+}
+
+Color ColorPresetButton::get_preset_color() const {
+ return preset_color;
+}
+
+ColorPresetButton::ColorPresetButton(Color p_color) {
+ preset_color = p_color;
+}
+
+ColorPresetButton::~ColorPresetButton() {
+}
diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h
index 60da3957aa..67ca007eb5 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -35,6 +35,7 @@
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/check_button.h"
+#include "scene/gui/grid_container.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/popup.h"
@@ -43,6 +44,22 @@
#include "scene/gui/spin_box.h"
#include "scene/gui/texture_rect.h"
+class ColorPresetButton : public BaseButton {
+ GDCLASS(ColorPresetButton, BaseButton);
+
+ Color preset_color;
+
+protected:
+ void _notification(int);
+
+public:
+ void set_preset_color(const Color &p_color);
+ Color get_preset_color() const;
+
+ ColorPresetButton(Color p_color);
+ ~ColorPresetButton();
+};
+
class ColorPicker : public BoxContainer {
GDCLASS(ColorPicker, BoxContainer);
@@ -69,12 +86,9 @@ private:
Control *wheel = memnew(Control);
Control *wheel_uv = memnew(Control);
TextureRect *sample = memnew(TextureRect);
- TextureRect *preset = memnew(TextureRect);
- HBoxContainer *preset_container = memnew(HBoxContainer);
- HBoxContainer *preset_container2 = memnew(HBoxContainer);
+ GridContainer *preset_container = memnew(GridContainer);
HSeparator *preset_separator = memnew(HSeparator);
- Button *bt_add_preset = memnew(Button);
- List<Color> presets;
+ Button *btn_add_preset = memnew(Button);
Button *btn_pick = memnew(Button);
CheckButton *btn_hsv = memnew(CheckButton);
CheckButton *btn_raw = memnew(CheckButton);
@@ -83,14 +97,19 @@ private:
Label *labels[4];
Button *text_type = memnew(Button);
LineEdit *c_text = memnew(LineEdit);
+
bool edit_alpha = true;
Size2i ms;
bool text_is_constructor = false;
- int presets_per_row = 0;
PickerShapeType picker_type = SHAPE_HSV_WHEEL;
+ const int preset_column_count = 9;
+ int prev_preset_size = 0;
+ List<Color> presets;
+
Color color;
Color old_color;
+
bool display_old_color = false;
bool raw_mode_enabled = false;
bool hsv_mode_enabled = false;
@@ -100,6 +119,7 @@ private:
bool spinning = false;
bool presets_enabled = true;
bool presets_visible = true;
+
float h = 0.0;
float s = 0.0;
float v = 0.0;
@@ -109,7 +129,6 @@ private:
void _value_changed(double);
void _update_controls();
void _update_color(bool p_update_sliders = true);
- void _update_presets();
void _update_text_value();
void _text_type_toggled();
void _sample_input(const Ref<InputEvent> &p_event);
@@ -119,7 +138,7 @@ private:
void _uv_input(const Ref<InputEvent> &p_event, Control *c);
void _w_input(const Ref<InputEvent> &p_event);
- void _preset_input(const Ref<InputEvent> &p_event);
+ void _preset_input(const Ref<InputEvent> &p_event, const Color &p_color);
void _screen_input(const Ref<InputEvent> &p_event);
void _add_preset_pressed();
void _screen_pick_pressed();
@@ -127,6 +146,9 @@ private:
void _focus_exit();
void _html_focus_exit();
+ inline int _get_preset_size();
+ void _add_preset_button(int p_size, const Color &p_color);
+
protected:
void _notification(int);
static void _bind_methods();
@@ -152,6 +174,7 @@ public:
void add_preset(const Color &p_color);
void erase_preset(const Color &p_color);
PackedColorArray get_presets() const;
+ void _update_presets();
void set_hsv_mode(bool p_enabled);
bool is_hsv_mode() const;
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index a2e6872da6..81411d5844 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -30,6 +30,7 @@
#include "control.h"
+#include "container.h"
#include "core/config/project_settings.h"
#include "core/math/geometry_2d.h"
#include "core/object/message_queue.h"
@@ -168,6 +169,20 @@ Size2 Control::_edit_get_minimum_size() const {
}
#endif
+String Control::properties_managed_by_container[] = {
+ "offset_left",
+ "offset_top",
+ "offset_right",
+ "offset_bottom",
+ "anchor_left",
+ "anchor_top",
+ "anchor_right",
+ "anchor_bottom",
+ "rect_position",
+ "rect_scale",
+ "rect_size"
+};
+
void Control::accept_event() {
if (is_inside_tree()) {
get_viewport()->_gui_accept_event();
@@ -442,6 +457,20 @@ void Control::_validate_property(PropertyInfo &property) const {
property.hint_string = hint_string;
}
+ if (!Object::cast_to<Container>(get_parent())) {
+ return;
+ }
+ // Disable the property if it's managed by the parent container.
+ bool property_is_managed_by_container = false;
+ for (unsigned i = 0; i < properties_managed_by_container_count; i++) {
+ property_is_managed_by_container = properties_managed_by_container[i] == property.name;
+ if (property_is_managed_by_container) {
+ break;
+ }
+ }
+ if (property_is_managed_by_container) {
+ property.usage |= PROPERTY_USAGE_READ_ONLY;
+ }
}
Control *Control::get_parent_control() const {
@@ -730,14 +759,9 @@ Variant Control::get_drag_data(const Point2 &p_point) {
}
}
- if (get_script_instance()) {
- Variant v = p_point;
- const Variant *p = &v;
- Callable::CallError ce;
- Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_get_drag_data, &p, 1, ce);
- if (ce.error == Callable::CallError::CALL_OK) {
- return ret;
- }
+ Variant dd;
+ if (GDVIRTUAL_CALL(_get_drag_data, p_point, dd)) {
+ return dd;
}
return Variant();
@@ -752,16 +776,10 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const
}
}
- if (get_script_instance()) {
- Variant v = p_point;
- const Variant *p[2] = { &v, &p_data };
- Callable::CallError ce;
- Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_can_drop_data, p, 2, ce);
- if (ce.error == Callable::CallError::CALL_OK) {
- return ret;
- }
+ bool ret;
+ if (GDVIRTUAL_CALL(_can_drop_data, p_point, p_data, ret)) {
+ return ret;
}
-
return false;
}
@@ -775,15 +793,7 @@ void Control::drop_data(const Point2 &p_point, const Variant &p_data) {
}
}
- if (get_script_instance()) {
- Variant v = p_point;
- const Variant *p[2] = { &v, &p_data };
- Callable::CallError ce;
- Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->_drop_data, p, 2, ce);
- if (ce.error == Callable::CallError::CALL_OK) {
- return;
- }
- }
+ GDVIRTUAL_CALL(_drop_data, p_point, p_data);
}
void Control::force_drag(const Variant &p_data, Control *p_control) {
@@ -799,16 +809,26 @@ void Control::set_drag_preview(Control *p_control) {
get_viewport()->_gui_set_drag_preview(this, p_control);
}
+void Control::_call_gui_input(const Ref<InputEvent> &p_event) {
+ emit_signal(SceneStringNames::get_singleton()->gui_input, p_event); //signal should be first, so it's possible to override an event (and then accept it)
+ if (!is_inside_tree() || get_viewport()->is_input_handled()) {
+ return; //input was handled, abort
+ }
+ GDVIRTUAL_CALL(_gui_input, p_event);
+ if (!is_inside_tree() || get_viewport()->is_input_handled()) {
+ return; //input was handled, abort
+ }
+ gui_input(p_event);
+}
+void Control::gui_input(const Ref<InputEvent> &p_event) {
+}
+
Size2 Control::get_minimum_size() const {
- ScriptInstance *si = const_cast<Control *>(this)->get_script_instance();
- if (si) {
- Callable::CallError ce;
- Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, nullptr, 0, ce);
- if (ce.error == Callable::CallError::CALL_OK) {
- return s;
- }
+ Vector2 ms;
+ if (GDVIRTUAL_CALL(_get_minimum_size, ms)) {
+ return ms;
}
- return Size2();
+ return Vector2();
}
template <class T>
@@ -1686,6 +1706,17 @@ Rect2 Control::get_anchorable_rect() const {
return Rect2(Point2(), get_size());
}
+void Control::begin_bulk_theme_override() {
+ data.bulk_theme_override = true;
+}
+
+void Control::end_bulk_theme_override() {
+ ERR_FAIL_COND(!data.bulk_theme_override);
+
+ data.bulk_theme_override = false;
+ _notify_theme_changed();
+}
+
void Control::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) {
ERR_FAIL_COND(!p_icon.is_valid());
@@ -1695,7 +1726,7 @@ void Control::add_theme_icon_override(const StringName &p_name, const Ref<Textur
data.icon_override[p_name] = p_icon;
data.icon_override[p_name]->connect("changed", callable_mp(this, &Control::_override_changed), Vector<Variant>(), CONNECT_REFERENCE_COUNTED);
- notification(NOTIFICATION_THEME_CHANGED);
+ _notify_theme_changed();
}
void Control::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) {
@@ -1707,7 +1738,7 @@ void Control::add_theme_style_override(const StringName &p_name, const Ref<Style
data.style_override[p_name] = p_style;
data.style_override[p_name]->connect("changed", callable_mp(this, &Control::_override_changed), Vector<Variant>(), CONNECT_REFERENCE_COUNTED);
- notification(NOTIFICATION_THEME_CHANGED);
+ _notify_theme_changed();
}
void Control::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) {
@@ -1719,22 +1750,22 @@ void Control::add_theme_font_override(const StringName &p_name, const Ref<Font>
data.font_override[p_name] = p_font;
data.font_override[p_name]->connect("changed", callable_mp(this, &Control::_override_changed), Vector<Variant>(), CONNECT_REFERENCE_COUNTED);
- notification(NOTIFICATION_THEME_CHANGED);
+ _notify_theme_changed();
}
void Control::add_theme_font_size_override(const StringName &p_name, int p_font_size) {
data.font_size_override[p_name] = p_font_size;
- notification(NOTIFICATION_THEME_CHANGED);
+ _notify_theme_changed();
}
void Control::add_theme_color_override(const StringName &p_name, const Color &p_color) {
data.color_override[p_name] = p_color;
- notification(NOTIFICATION_THEME_CHANGED);
+ _notify_theme_changed();
}
void Control::add_theme_constant_override(const StringName &p_name, int p_constant) {
data.constant_override[p_name] = p_constant;
- notification(NOTIFICATION_THEME_CHANGED);
+ _notify_theme_changed();
}
void Control::remove_theme_icon_override(const StringName &p_name) {
@@ -1743,7 +1774,7 @@ void Control::remove_theme_icon_override(const StringName &p_name) {
}
data.icon_override.erase(p_name);
- notification(NOTIFICATION_THEME_CHANGED);
+ _notify_theme_changed();
}
void Control::remove_theme_style_override(const StringName &p_name) {
@@ -1752,7 +1783,7 @@ void Control::remove_theme_style_override(const StringName &p_name) {
}
data.style_override.erase(p_name);
- notification(NOTIFICATION_THEME_CHANGED);
+ _notify_theme_changed();
}
void Control::remove_theme_font_override(const StringName &p_name) {
@@ -1761,22 +1792,22 @@ void Control::remove_theme_font_override(const StringName &p_name) {
}
data.font_override.erase(p_name);
- notification(NOTIFICATION_THEME_CHANGED);
+ _notify_theme_changed();
}
void Control::remove_theme_font_size_override(const StringName &p_name) {
data.font_size_override.erase(p_name);
- notification(NOTIFICATION_THEME_CHANGED);
+ _notify_theme_changed();
}
void Control::remove_theme_color_override(const StringName &p_name) {
data.color_override.erase(p_name);
- notification(NOTIFICATION_THEME_CHANGED);
+ _notify_theme_changed();
}
void Control::remove_theme_constant_override(const StringName &p_name) {
data.constant_override.erase(p_name);
- notification(NOTIFICATION_THEME_CHANGED);
+ _notify_theme_changed();
}
void Control::set_focus_mode(FocusMode p_focus_mode) {
@@ -2049,6 +2080,12 @@ void Control::_theme_changed() {
_propagate_theme_changed(this, this, nullptr, false);
}
+void Control::_notify_theme_changed() {
+ if (!data.bulk_theme_override) {
+ notification(NOTIFICATION_THEME_CHANGED);
+ }
+}
+
void Control::set_theme(const Ref<Theme> &p_theme) {
if (data.theme == p_theme) {
return;
@@ -2106,8 +2143,9 @@ String Control::get_tooltip(const Point2 &p_pos) const {
}
Control *Control::make_custom_tooltip(const String &p_text) const {
- if (get_script_instance()) {
- return const_cast<Control *>(this)->call("_make_custom_tooltip", p_text);
+ Object *ret = nullptr;
+ if (GDVIRTUAL_CALL(_make_custom_tooltip, p_text, ret)) {
+ return Object::cast_to<Control>(ret);
}
return nullptr;
}
@@ -2482,14 +2520,11 @@ Vector<Vector2i> Control::structured_text_parser(StructuredTextParser p_theme_ty
}
} break;
case STRUCTURED_TEXT_CUSTOM: {
- if (get_script_instance()) {
- Variant data = get_script_instance()->call(SceneStringNames::get_singleton()->_structured_text_parser, p_args, p_text);
- if (data.get_type() == Variant::ARRAY) {
- Array _data = data;
- for (int i = 0; i < _data.size(); i++) {
- if (_data[i].get_type() == Variant::VECTOR2I) {
- ret.push_back(Vector2i(_data[i]));
- }
+ Array r;
+ if (GDVIRTUAL_CALL(_structured_text_parser, p_args, p_text, r)) {
+ for (int i = 0; i < r.size(); i++) {
+ if (r[i].get_type() == Variant::VECTOR2I) {
+ ret.push_back(Vector2i(r[i]));
}
}
}
@@ -2585,7 +2620,7 @@ bool Control::is_visibility_clip_disabled() const {
void Control::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
#ifdef TOOLS_ENABLED
- const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
+ const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
#else
const String quote_style = "\"";
#endif
@@ -2608,8 +2643,8 @@ void Control::get_argument_options(const StringName &p_function, int p_idx, List
}
sn.sort_custom<StringName::AlphCompare>();
- for (const StringName &E : sn) {
- r_options->push_back(quote_style + E + quote_style);
+ for (const StringName &name : sn) {
+ r_options->push_back(String(name).quote(quote_style));
}
}
}
@@ -2719,6 +2754,9 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_theme_type_variation", "theme_type"), &Control::set_theme_type_variation);
ClassDB::bind_method(D_METHOD("get_theme_type_variation"), &Control::get_theme_type_variation);
+ ClassDB::bind_method(D_METHOD("begin_bulk_theme_override"), &Control::begin_bulk_theme_override);
+ ClassDB::bind_method(D_METHOD("end_bulk_theme_override"), &Control::end_bulk_theme_override);
+
ClassDB::bind_method(D_METHOD("add_theme_icon_override", "name", "texture"), &Control::add_theme_icon_override);
ClassDB::bind_method(D_METHOD("add_theme_stylebox_override", "name", "stylebox"), &Control::add_theme_style_override);
ClassDB::bind_method(D_METHOD("add_theme_font_override", "name", "font"), &Control::add_theme_font_override);
@@ -2803,21 +2841,6 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Control::set_auto_translate);
ClassDB::bind_method(D_METHOD("is_auto_translating"), &Control::is_auto_translating);
- BIND_VMETHOD(MethodInfo("_structured_text_parser", PropertyInfo(Variant::ARRAY, "args"), PropertyInfo(Variant::STRING, "text")));
-
- BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
- BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_get_minimum_size"));
-
- MethodInfo get_drag_data = MethodInfo("_get_drag_data", PropertyInfo(Variant::VECTOR2, "position"));
- get_drag_data.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
- BIND_VMETHOD(get_drag_data);
-
- BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data")));
- BIND_VMETHOD(MethodInfo("_drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data")));
- BIND_VMETHOD(MethodInfo(
- PropertyInfo(Variant::OBJECT, "control", PROPERTY_HINT_RESOURCE_TYPE, "Control"),
- "_make_custom_tooltip", PropertyInfo(Variant::STRING, "for_text")));
-
ADD_GROUP("Anchor", "anchor_");
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_LEFT);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_top", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_TOP);
@@ -2974,5 +2997,14 @@ void Control::_bind_methods() {
ADD_SIGNAL(MethodInfo("minimum_size_changed"));
ADD_SIGNAL(MethodInfo("theme_changed"));
- GDVIRTUAL_BIND(_has_point);
+ GDVIRTUAL_BIND(_has_point, "position");
+ GDVIRTUAL_BIND(_structured_text_parser, "args", "text");
+ GDVIRTUAL_BIND(_get_minimum_size);
+
+ GDVIRTUAL_BIND(_get_drag_data, "at_position");
+ GDVIRTUAL_BIND(_can_drop_data, "at_position", "data");
+ GDVIRTUAL_BIND(_drop_data, "at_position", "data");
+ GDVIRTUAL_BIND(_make_custom_tooltip, "for_text");
+
+ GDVIRTUAL_BIND(_gui_input, "event");
}
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 8d669c7a6d..9cec5d6e8d 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -31,10 +31,10 @@
#ifndef CONTROL_H
#define CONTROL_H
+#include "core/input/shortcut.h"
#include "core/math/transform_2d.h"
#include "core/object/gdvirtual.gen.inc"
#include "core/templates/rid.h"
-#include "scene/gui/shortcut.h"
#include "scene/main/canvas_item.h"
#include "scene/main/node.h"
#include "scene/main/timer.h"
@@ -220,6 +220,7 @@ private:
NodePath focus_next;
NodePath focus_prev;
+ bool bulk_theme_override = false;
HashMap<StringName, Ref<Texture2D>> icon_override;
HashMap<StringName, Ref<StyleBox>> style_override;
HashMap<StringName, Ref<Font>> font_override;
@@ -229,6 +230,9 @@ private:
} data;
+ static constexpr unsigned properties_managed_by_container_count = 11;
+ static String properties_managed_by_container[properties_managed_by_container_count];
+
// used internally
Control *_find_control_at_pos(CanvasItem *p_node, const Point2 &p_pos, const Transform2D &p_xform, Transform2D &r_inv_xform);
@@ -241,6 +245,7 @@ private:
void _set_size(const Size2 &p_size);
void _theme_changed();
+ void _notify_theme_changed();
void _update_minimum_size();
@@ -261,6 +266,8 @@ private:
friend class Viewport;
+ void _call_gui_input(const Ref<InputEvent> &p_event);
+
void _update_minimum_size_cache();
friend class Window;
static void _propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_owner_window, bool p_assign = true);
@@ -270,7 +277,6 @@ private:
static bool has_theme_item_in_types(Control *p_theme_owner, Window *p_theme_owner_window, Theme::DataType p_data_type, const StringName &p_name, List<StringName> p_theme_types);
_FORCE_INLINE_ void _get_theme_type_dependencies(const StringName &p_theme_type, List<StringName> *p_list) const;
- GDVIRTUAL1RC(bool, _has_point, Vector2)
protected:
virtual void add_child_notify(Node *p_child) override;
virtual void remove_child_notify(Node *p_child) override;
@@ -289,6 +295,17 @@ protected:
//bind helpers
+ GDVIRTUAL1RC(bool, _has_point, Vector2)
+ GDVIRTUAL2RC(Array, _structured_text_parser, Array, String)
+ GDVIRTUAL0RC(Vector2, _get_minimum_size)
+
+ GDVIRTUAL1RC(Variant, _get_drag_data, Vector2)
+ GDVIRTUAL2RC(bool, _can_drop_data, Vector2, Variant)
+ GDVIRTUAL2(_drop_data, Vector2, Variant)
+ GDVIRTUAL1RC(Object *, _make_custom_tooltip, String)
+
+ GDVIRTUAL1(_gui_input, Ref<InputEvent>)
+
public:
enum {
/* NOTIFICATION_DRAW=30,
@@ -331,6 +348,8 @@ public:
virtual Size2 _edit_get_minimum_size() const override;
#endif
+ virtual void gui_input(const Ref<InputEvent> &p_event);
+
void accept_event();
virtual Size2 get_minimum_size() const;
@@ -452,6 +471,9 @@ public:
/* SKINNING */
+ void begin_bulk_theme_override();
+ void end_bulk_theme_override();
+
void add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon);
void add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style);
void add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font);
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index da858e8e83..5d98aaa698 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -319,7 +319,7 @@ AcceptDialog::AcceptDialog() {
set_clamp_to_embedder(true);
bg = memnew(Panel);
- add_child(bg);
+ add_child(bg, false, INTERNAL_MODE_FRONT);
hbc = memnew(HBoxContainer);
@@ -331,9 +331,9 @@ AcceptDialog::AcceptDialog() {
label->set_anchor(SIDE_BOTTOM, Control::ANCHOR_END);
label->set_begin(Point2(margin, margin));
label->set_end(Point2(-margin, -button_margin - 10));
- add_child(label);
+ add_child(label, false, INTERNAL_MODE_FRONT);
- add_child(hbc);
+ add_child(hbc, false, INTERNAL_MODE_FRONT);
hbc->add_spacer();
ok = memnew(Button);
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 2e4204e171..973b72973d 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -95,7 +95,7 @@ void FileDialog::_notification(int p_what) {
}
}
-void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
+void FileDialog::unhandled_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
Ref<InputEventKey> k = p_event;
@@ -854,8 +854,6 @@ void FileDialog::_update_drives() {
bool FileDialog::default_show_hidden_files = false;
void FileDialog::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_unhandled_input"), &FileDialog::_unhandled_input);
-
ClassDB::bind_method(D_METHOD("_cancel_pressed"), &FileDialog::_cancel_pressed);
ClassDB::bind_method(D_METHOD("clear_filters"), &FileDialog::clear_filters);
@@ -926,7 +924,7 @@ FileDialog::FileDialog() {
show_hidden_files = default_show_hidden_files;
vbox = memnew(VBoxContainer);
- add_child(vbox);
+ add_child(vbox, false, INTERNAL_MODE_FRONT);
vbox->connect("theme_changed", callable_mp(this, &FileDialog::_theme_changed));
mode = FILE_MODE_SAVE_FILE;
@@ -1025,8 +1023,7 @@ FileDialog::FileDialog() {
filter->connect("item_selected", callable_mp(this, &FileDialog::_filter_selected));
confirm_save = memnew(ConfirmationDialog);
- // confirm_save->set_as_top_level(true);
- add_child(confirm_save);
+ add_child(confirm_save, false, INTERNAL_MODE_FRONT);
confirm_save->connect("confirmed", callable_mp(this, &FileDialog::_save_confirm_pressed));
@@ -1038,16 +1035,16 @@ FileDialog::FileDialog() {
makedirname = memnew(LineEdit);
makedirname->set_structured_text_bidi_override(Control::STRUCTURED_TEXT_FILE);
makevb->add_margin_child(TTRC("Name:"), makedirname);
- add_child(makedialog);
+ add_child(makedialog, false, INTERNAL_MODE_FRONT);
makedialog->register_text_enter(makedirname);
makedialog->connect("confirmed", callable_mp(this, &FileDialog::_make_dir_confirm));
mkdirerr = memnew(AcceptDialog);
mkdirerr->set_text(TTRC("Could not create folder."));
- add_child(mkdirerr);
+ add_child(mkdirerr, false, INTERNAL_MODE_FRONT);
exterr = memnew(AcceptDialog);
exterr->set_text(TTRC("Must use a valid extension."));
- add_child(exterr);
+ add_child(exterr, false, INTERNAL_MODE_FRONT);
update_filters();
update_dir();
diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h
index 7fbafc4bb4..b5190bdab1 100644
--- a/scene/gui/file_dialog.h
+++ b/scene/gui/file_dialog.h
@@ -132,7 +132,7 @@ private:
void _update_drives();
- void _unhandled_input(const Ref<InputEvent> &p_event);
+ virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
bool _is_open_should_be_disabled();
diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp
index ff983f4415..56b8a936e1 100644
--- a/scene/gui/gradient_edit.cpp
+++ b/scene/gui/gradient_edit.cpp
@@ -48,7 +48,7 @@ GradientEdit::GradientEdit() {
picker = memnew(ColorPicker);
popup->add_child(picker);
- add_child(popup);
+ add_child(popup, false, INTERNAL_MODE_FRONT);
}
int GradientEdit::_get_point_from_pos(int x) {
@@ -88,7 +88,7 @@ void GradientEdit::_show_color_picker() {
GradientEdit::~GradientEdit() {
}
-void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) {
+void GradientEdit::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
Ref<InputEventKey> k = p_event;
@@ -415,7 +415,7 @@ void GradientEdit::_color_changed(const Color &p_color) {
emit_signal(SNAME("ramp_changed"));
}
-void GradientEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors) {
+void GradientEdit::set_ramp(const Vector<real_t> &p_offsets, const Vector<Color> &p_colors) {
ERR_FAIL_COND(p_offsets.size() != p_colors.size());
points.clear();
for (int i = 0; i < p_offsets.size(); i++) {
@@ -429,8 +429,8 @@ void GradientEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color>
update();
}
-Vector<float> GradientEdit::get_offsets() const {
- Vector<float> ret;
+Vector<real_t> GradientEdit::get_offsets() const {
+ Vector<real_t> ret;
for (int i = 0; i < points.size(); i++) {
ret.push_back(points[i].offset);
}
@@ -458,6 +458,5 @@ Vector<Gradient::Point> &GradientEdit::get_points() {
}
void GradientEdit::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &GradientEdit::_gui_input);
ADD_SIGNAL(MethodInfo("ramp_changed"));
}
diff --git a/scene/gui/gradient_edit.h b/scene/gui/gradient_edit.h
index 3d83a02429..a173631963 100644
--- a/scene/gui/gradient_edit.h
+++ b/scene/gui/gradient_edit.h
@@ -52,13 +52,13 @@ class GradientEdit : public Control {
void _show_color_picker();
protected:
- void _gui_input(const Ref<InputEvent> &p_event);
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
void _notification(int p_what);
static void _bind_methods();
public:
- void set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors);
- Vector<float> get_offsets() const;
+ void set_ramp(const Vector<real_t> &p_offsets, const Vector<Color> &p_colors);
+ Vector<real_t> get_offsets() const;
Vector<Color> get_colors() const;
void set_points(Vector<Gradient::Point> &p_points);
Vector<Gradient::Point> &get_points();
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 1fac2b9129..cabae9feb2 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -51,10 +51,6 @@ GraphEditFilter::GraphEditFilter(GraphEdit *p_edit) {
ge = p_edit;
}
-void GraphEditMinimap::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &GraphEditMinimap::_gui_input);
-}
-
GraphEditMinimap::GraphEditMinimap(GraphEdit *p_edit) {
ge = p_edit;
@@ -148,7 +144,7 @@ Vector2 GraphEditMinimap::_convert_to_graph_position(const Vector2 &p_position)
return graph_position;
}
-void GraphEditMinimap::_gui_input(const Ref<InputEvent> &p_ev) {
+void GraphEditMinimap::gui_input(const Ref<InputEvent> &p_ev) {
ERR_FAIL_COND(p_ev.is_null());
if (!ge->is_minimap_enabled()) {
@@ -370,7 +366,6 @@ void GraphEdit::_graph_node_raised(Node *p_gn) {
}
move_child(connections_layer, first_not_comment);
- top_layer->raise();
emit_signal(SNAME("node_selected"), p_gn);
}
@@ -450,6 +445,7 @@ void GraphEdit::_notification(int p_what) {
zoom_plus->set_icon(get_theme_icon(SNAME("more")));
snap_button->set_icon(get_theme_icon(SNAME("snap")));
minimap_button->set_icon(get_theme_icon(SNAME("minimap")));
+ layout_button->set_icon(get_theme_icon(SNAME("layout")));
}
if (p_what == NOTIFICATION_READY) {
Size2 hmin = h_scroll->get_combined_minimum_size();
@@ -519,6 +515,7 @@ void GraphEdit::_notification(int p_what) {
bool GraphEdit::_filter_input(const Point2 &p_point) {
Ref<Texture2D> port = get_theme_icon(SNAME("port"), SNAME("GraphNode"));
+ Vector2i port_size = Vector2i(port->get_width(), port->get_height());
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
@@ -528,14 +525,14 @@ bool GraphEdit::_filter_input(const Point2 &p_point) {
for (int j = 0; j < gn->get_connection_output_count(); j++) {
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
- if (is_in_hot_zone(pos / zoom, p_point / zoom)) {
+ if (is_in_hot_zone(pos / zoom, p_point / zoom, port_size, false)) {
return true;
}
}
for (int j = 0; j < gn->get_connection_input_count(); j++) {
Vector2 pos = gn->get_connection_input_position(j) + gn->get_position();
- if (is_in_hot_zone(pos / zoom, p_point / zoom)) {
+ if (is_in_hot_zone(pos / zoom, p_point / zoom, port_size, true)) {
return true;
}
}
@@ -547,8 +544,10 @@ bool GraphEdit::_filter_input(const Point2 &p_point) {
void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
Ref<InputEventMouseButton> mb = p_ev;
if (mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_LEFT && mb->is_pressed()) {
- connecting_valid = false;
Ref<Texture2D> port = get_theme_icon(SNAME("port"), SNAME("GraphNode"));
+ Vector2i port_size = Vector2i(port->get_width(), port->get_height());
+
+ connecting_valid = false;
click_pos = mb->get_position() / zoom;
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
@@ -558,7 +557,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
for (int j = 0; j < gn->get_connection_output_count(); j++) {
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
- if (is_in_hot_zone(pos / zoom, click_pos)) {
+ if (is_in_hot_zone(pos / zoom, click_pos, port_size, false)) {
if (valid_left_disconnect_types.has(gn->get_connection_output_type(j))) {
//check disconnect
for (const Connection &E : connections) {
@@ -600,7 +599,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
for (int j = 0; j < gn->get_connection_input_count(); j++) {
Vector2 pos = gn->get_connection_input_position(j) + gn->get_position();
- if (is_in_hot_zone(pos / zoom, click_pos)) {
+ if (is_in_hot_zone(pos / zoom, click_pos, port_size, true)) {
if (right_disconnects || valid_right_disconnect_types.has(gn->get_connection_input_type(j))) {
//check disconnect
for (const Connection &E : connections) {
@@ -649,10 +648,12 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
connecting_target = false;
top_layer->update();
minimap->update();
- connecting_valid = just_disconnected || click_pos.distance_to(connecting_to / zoom) > 20.0 * zoom;
+ connecting_valid = just_disconnected || click_pos.distance_to(connecting_to / zoom) > 20.0;
if (connecting_valid) {
Ref<Texture2D> port = get_theme_icon(SNAME("port"), SNAME("GraphNode"));
+ Vector2i port_size = Vector2i(port->get_width(), port->get_height());
+
Vector2 mpos = mm->get_position() / zoom;
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
@@ -664,7 +665,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
for (int j = 0; j < gn->get_connection_output_count(); j++) {
Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
int type = gn->get_connection_output_type(j);
- if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && is_in_hot_zone(pos / zoom, mpos)) {
+ if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && is_in_hot_zone(pos / zoom, mpos, port_size, false)) {
connecting_target = true;
connecting_to = pos;
connecting_target_to = gn->get_name();
@@ -676,7 +677,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
for (int j = 0; j < gn->get_connection_input_count(); j++) {
Vector2 pos = gn->get_connection_input_position(j) + gn->get_position();
int type = gn->get_connection_input_type(j);
- if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && is_in_hot_zone(pos / zoom, mpos)) {
+ if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && is_in_hot_zone(pos / zoom, mpos, port_size, true)) {
connecting_target = true;
connecting_to = pos;
connecting_target_to = gn->get_name();
@@ -747,9 +748,25 @@ bool GraphEdit::_check_clickable_control(Control *p_control, const Vector2 &pos)
}
}
-bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos) {
- if (!Rect2(pos.x - port_grab_distance_horizontal, pos.y - port_grab_distance_vertical, port_grab_distance_horizontal * 2, port_grab_distance_vertical * 2).has_point(p_mouse_pos)) {
- return false;
+bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos, const Vector2i &p_port_size, bool p_left) {
+ if (p_left) {
+ if (!Rect2(
+ pos.x - p_port_size.x / 2 - port_grab_distance_horizontal,
+ pos.y - p_port_size.y / 2 - port_grab_distance_vertical / 2,
+ p_port_size.x + port_grab_distance_horizontal,
+ p_port_size.y + port_grab_distance_vertical)
+ .has_point(p_mouse_pos)) {
+ return false;
+ }
+ } else {
+ if (!Rect2(
+ pos.x - p_port_size.x / 2,
+ pos.y - p_port_size.y / 2 - port_grab_distance_vertical / 2,
+ p_port_size.x + port_grab_distance_horizontal,
+ p_port_size.y + port_grab_distance_vertical)
+ .has_point(p_mouse_pos)) {
+ return false;
+ }
}
for (int i = 0; i < get_child_count(); i++) {
@@ -783,68 +800,36 @@ bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos) {
return true;
}
-template <class Vector2>
-static _FORCE_INLINE_ Vector2 _bezier_interp(real_t t, Vector2 start, Vector2 control_1, Vector2 control_2, Vector2 end) {
- /* Formula from Wikipedia article on Bezier curves. */
- real_t omt = (1.0 - t);
- real_t omt2 = omt * omt;
- real_t omt3 = omt2 * omt;
- real_t t2 = t * t;
- real_t t3 = t2 * t;
-
- return start * omt3 + control_1 * omt2 * t * 3.0 + control_2 * omt * t2 * 3.0 + end * t3;
-}
-
-void GraphEdit::_bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const {
- float mp = p_begin + (p_end - p_begin) * 0.5;
- Vector2 beg = _bezier_interp(p_begin, p_a, p_a + p_out, p_b + p_in, p_b);
- Vector2 mid = _bezier_interp(mp, p_a, p_a + p_out, p_b + p_in, p_b);
- Vector2 end = _bezier_interp(p_end, p_a, p_a + p_out, p_b + p_in, p_b);
-
- Vector2 na = (mid - beg).normalized();
- Vector2 nb = (end - mid).normalized();
- float dp = Math::rad2deg(Math::acos(na.dot(nb)));
-
- if (p_depth >= p_min_depth && (dp < p_tol || p_depth >= p_max_depth)) {
- points.push_back((beg + end) * 0.5);
- colors.push_back(p_color.lerp(p_to_color, mp));
- lines++;
- } else {
- _bake_segment2d(points, colors, p_begin, mp, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
- _bake_segment2d(points, colors, mp, p_end, p_a, p_out, p_b, p_in, p_depth + 1, p_min_depth, p_max_depth, p_tol, p_color, p_to_color, lines);
+PackedVector2Array GraphEdit::get_connection_line(const Vector2 &p_from, const Vector2 &p_to) {
+ Vector<Vector2> ret;
+ if (GDVIRTUAL_CALL(_get_connection_line, p_from, p_to, ret)) {
+ return ret;
}
-}
-
-void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width, float p_bezier_ratio) {
- //cubic bezier code
- float diff = p_to.x - p_from.x;
- float cp_offset;
- int cp_len = get_theme_constant(SNAME("bezier_len_pos")) * p_bezier_ratio;
- int cp_neg_len = get_theme_constant(SNAME("bezier_len_neg")) * p_bezier_ratio;
- if (diff > 0) {
- cp_offset = MIN(cp_len, diff * 0.5);
- } else {
- cp_offset = MAX(MIN(cp_len - diff, cp_neg_len), -diff * 0.5);
- }
-
- Vector2 c1 = Vector2(cp_offset * zoom, 0);
- Vector2 c2 = Vector2(-cp_offset * zoom, 0);
-
- int lines = 0;
+ Curve2D curve;
+ Vector<Color> colors;
+ curve.add_point(p_from);
+ curve.set_point_out(0, Vector2(60, 0));
+ curve.add_point(p_to);
+ curve.set_point_in(1, Vector2(-60, 0));
+ return curve.tessellate();
+}
- Vector<Point2> points;
+void GraphEdit::_draw_connection_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width, float p_zoom) {
+ Vector<Vector2> points = get_connection_line(p_from / p_zoom, p_to / p_zoom);
+ Vector<Vector2> scaled_points;
Vector<Color> colors;
- points.push_back(p_from);
- colors.push_back(p_color);
- _bake_segment2d(points, colors, 0, 1, p_from, c1, p_to, c2, 0, 3, 9, 3, p_color, p_to_color, lines);
- points.push_back(p_to);
- colors.push_back(p_to_color);
+ float length = (p_from / p_zoom).distance_to(p_to / p_zoom);
+ for (int i = 0; i < points.size(); i++) {
+ float d = (p_from / p_zoom).distance_to(points[i]) / length;
+ colors.push_back(p_color.lerp(p_to_color, d));
+ scaled_points.push_back(points[i] * p_zoom);
+ }
#ifdef TOOLS_ENABLED
- p_where->draw_polyline_colors(points, colors, Math::floor(p_width * EDSCALE), lines_antialiased);
+ p_where->draw_polyline_colors(scaled_points, colors, Math::floor(p_width * EDSCALE), lines_antialiased);
#else
- p_where->draw_polyline_colors(points, colors, p_width, lines_antialiased);
+ p_where->draw_polyline_colors(scaled_points, colors, p_width, lines_antialiased);
#endif
}
@@ -891,7 +876,7 @@ void GraphEdit::_connections_layer_draw() {
color = color.lerp(activity_color, E->get().activity);
tocolor = tocolor.lerp(activity_color, E->get().activity);
}
- _draw_cos_line(connections_layer, frompos, topos, color, tocolor, lines_thickness);
+ _draw_connection_line(connections_layer, frompos, topos, color, tocolor, lines_thickness, zoom);
}
while (to_erase.size()) {
@@ -930,7 +915,7 @@ void GraphEdit::_top_layer_draw() {
if (!connecting_out) {
SWAP(pos, topos);
}
- _draw_cos_line(top_layer, pos, topos, col, col, lines_thickness);
+ _draw_connection_line(top_layer, pos, topos, col, col, lines_thickness, zoom);
}
if (box_selecting) {
@@ -1034,7 +1019,7 @@ void GraphEdit::_minimap_draw() {
from_color = from_color.lerp(activity_color, E.activity);
to_color = to_color.lerp(activity_color, E.activity);
}
- _draw_cos_line(minimap, from_position, to_position, from_color, to_color, 1.0, 0.5);
+ _draw_connection_line(minimap, from_position, to_position, from_color, to_color, 0.1, minimap->_convert_from_graph_position(Vector2(zoom, zoom)).length());
}
// Draw the "camera" viewport.
@@ -1058,7 +1043,7 @@ void GraphEdit::set_selected(Node *p_child) {
}
}
-void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
+void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
ERR_FAIL_COND(p_ev.is_null());
Ref<InputEventMouseMotion> mm = p_ev;
@@ -1646,6 +1631,505 @@ HBoxContainer *GraphEdit::get_zoom_hbox() {
return zoom_hb;
}
+int GraphEdit::_set_operations(SET_OPERATIONS p_operation, Set<StringName> &r_u, const Set<StringName> &r_v) {
+ switch (p_operation) {
+ case GraphEdit::IS_EQUAL: {
+ for (Set<StringName>::Element *E = r_u.front(); E; E = E->next()) {
+ if (!r_v.has(E->get()))
+ return 0;
+ }
+ return r_u.size() == r_v.size();
+ } break;
+ case GraphEdit::IS_SUBSET: {
+ if (r_u.size() == r_v.size() && !r_u.size()) {
+ return 1;
+ }
+ for (Set<StringName>::Element *E = r_u.front(); E; E = E->next()) {
+ if (!r_v.has(E->get()))
+ return 0;
+ }
+ return 1;
+ } break;
+ case GraphEdit::DIFFERENCE: {
+ for (Set<StringName>::Element *E = r_u.front(); E; E = E->next()) {
+ if (r_v.has(E->get())) {
+ r_u.erase(E->get());
+ }
+ }
+ return r_u.size();
+ } break;
+ case GraphEdit::UNION: {
+ for (Set<StringName>::Element *E = r_v.front(); E; E = E->next()) {
+ if (!r_u.has(E->get())) {
+ r_u.insert(E->get());
+ }
+ }
+ return r_v.size();
+ } break;
+ default:
+ break;
+ }
+ return -1;
+}
+
+HashMap<int, Vector<StringName>> GraphEdit::_layering(const Set<StringName> &r_selected_nodes, const HashMap<StringName, Set<StringName>> &r_upper_neighbours) {
+ HashMap<int, Vector<StringName>> l;
+
+ Set<StringName> p = r_selected_nodes, q = r_selected_nodes, u, z;
+ int current_layer = 0;
+ bool selected = false;
+
+ while (!_set_operations(GraphEdit::IS_EQUAL, q, u)) {
+ _set_operations(GraphEdit::DIFFERENCE, p, u);
+ for (const Set<StringName>::Element *E = p.front(); E; E = E->next()) {
+ Set<StringName> n = r_upper_neighbours[E->get()];
+ if (_set_operations(GraphEdit::IS_SUBSET, n, z)) {
+ Vector<StringName> t;
+ t.push_back(E->get());
+ if (!l.has(current_layer)) {
+ l.set(current_layer, Vector<StringName>{});
+ }
+ selected = true;
+ t.append_array(l[current_layer]);
+ l.set(current_layer, t);
+ Set<StringName> V;
+ V.insert(E->get());
+ _set_operations(GraphEdit::UNION, u, V);
+ }
+ }
+ if (!selected) {
+ current_layer++;
+ _set_operations(GraphEdit::UNION, z, u);
+ }
+ selected = false;
+ }
+
+ return l;
+}
+
+Vector<StringName> GraphEdit::_split(const Vector<StringName> &r_layer, const HashMap<StringName, Dictionary> &r_crossings) {
+ if (!r_layer.size()) {
+ return Vector<StringName>();
+ }
+
+ StringName p = r_layer[Math::random(0, r_layer.size() - 1)];
+ Vector<StringName> left;
+ Vector<StringName> right;
+
+ for (int i = 0; i < r_layer.size(); i++) {
+ if (p != r_layer[i]) {
+ StringName q = r_layer[i];
+ int cross_pq = r_crossings[p][q];
+ int cross_qp = r_crossings[q][p];
+ if (cross_pq > cross_qp) {
+ left.push_back(q);
+ } else {
+ right.push_back(q);
+ }
+ }
+ }
+
+ left.push_back(p);
+ left.append_array(right);
+ return left;
+}
+
+void GraphEdit::_horizontal_alignment(Dictionary &r_root, Dictionary &r_align, const HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, Set<StringName>> &r_upper_neighbours, const Set<StringName> &r_selected_nodes) {
+ for (const Set<StringName>::Element *E = r_selected_nodes.front(); E; E = E->next()) {
+ r_root[E->get()] = E->get();
+ r_align[E->get()] = E->get();
+ }
+
+ if (r_layers.size() == 1) {
+ return;
+ }
+
+ for (unsigned int i = 1; i < r_layers.size(); i++) {
+ Vector<StringName> lower_layer = r_layers[i];
+ Vector<StringName> upper_layer = r_layers[i - 1];
+ int r = -1;
+
+ for (int j = 0; j < lower_layer.size(); j++) {
+ Vector<Pair<int, StringName>> up;
+ StringName current_node = lower_layer[j];
+ for (int k = 0; k < upper_layer.size(); k++) {
+ StringName adjacent_neighbour = upper_layer[k];
+ if (r_upper_neighbours[current_node].has(adjacent_neighbour)) {
+ up.push_back(Pair<int, StringName>(k, adjacent_neighbour));
+ }
+ }
+
+ int start = up.size() / 2;
+ int end = up.size() % 2 ? start : start + 1;
+ for (int p = start; p <= end; p++) {
+ StringName Align = r_align[current_node];
+ if (Align == current_node && r < up[p].first) {
+ r_align[up[p].second] = lower_layer[j];
+ r_root[current_node] = r_root[up[p].second];
+ r_align[current_node] = r_root[up[p].second];
+ r = up[p].first;
+ }
+ }
+ }
+ }
+}
+
+void GraphEdit::_crossing_minimisation(HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, Set<StringName>> &r_upper_neighbours) {
+ if (r_layers.size() == 1) {
+ return;
+ }
+
+ for (unsigned int i = 1; i < r_layers.size(); i++) {
+ Vector<StringName> upper_layer = r_layers[i - 1];
+ Vector<StringName> lower_layer = r_layers[i];
+ HashMap<StringName, Dictionary> c;
+
+ for (int j = 0; j < lower_layer.size(); j++) {
+ StringName p = lower_layer[j];
+ Dictionary d;
+
+ for (int k = 0; k < lower_layer.size(); k++) {
+ unsigned int crossings = 0;
+ StringName q = lower_layer[k];
+
+ if (j != k) {
+ for (int h = 1; h < upper_layer.size(); h++) {
+ if (r_upper_neighbours[p].has(upper_layer[h])) {
+ for (int g = 0; g < h; g++) {
+ if (r_upper_neighbours[q].has(upper_layer[g])) {
+ crossings++;
+ }
+ }
+ }
+ }
+ }
+ d[q] = crossings;
+ }
+ c.set(p, d);
+ }
+
+ r_layers.set(i, _split(lower_layer, c));
+ }
+}
+
+void GraphEdit::_calculate_inner_shifts(Dictionary &r_inner_shifts, const Dictionary &r_root, const Dictionary &r_node_names, const Dictionary &r_align, const Set<StringName> &r_block_heads, const HashMap<StringName, Pair<int, int>> &r_port_info) {
+ for (const Set<StringName>::Element *E = r_block_heads.front(); E; E = E->next()) {
+ real_t left = 0;
+ StringName u = E->get();
+ StringName v = r_align[u];
+ while (u != v && (StringName)r_root[u] != v) {
+ String _connection = String(u) + " " + String(v);
+ GraphNode *gfrom = Object::cast_to<GraphNode>(r_node_names[u]);
+ GraphNode *gto = Object::cast_to<GraphNode>(r_node_names[v]);
+
+ Pair<int, int> ports = r_port_info[_connection];
+ int pfrom = ports.first;
+ int pto = ports.second;
+ Vector2 frompos = gfrom->get_connection_output_position(pfrom);
+ Vector2 topos = gto->get_connection_input_position(pto);
+
+ real_t s = (real_t)r_inner_shifts[u] + (frompos.y - topos.y) / zoom;
+ r_inner_shifts[v] = s;
+ left = MIN(left, s);
+
+ u = v;
+ v = (StringName)r_align[v];
+ }
+
+ u = E->get();
+ do {
+ r_inner_shifts[u] = (real_t)r_inner_shifts[u] - left;
+ u = (StringName)r_align[u];
+ } while (u != E->get());
+ }
+}
+
+float GraphEdit::_calculate_threshold(StringName p_v, StringName p_w, const Dictionary &r_node_names, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_inner_shift, real_t p_current_threshold, const HashMap<StringName, Vector2> &r_node_positions) {
+#define MAX_ORDER 2147483647
+#define ORDER(node, layers) \
+ for (unsigned int i = 0; i < layers.size(); i++) { \
+ int index = layers[i].find(node); \
+ if (index > 0) { \
+ order = index; \
+ break; \
+ } \
+ order = MAX_ORDER; \
+ }
+
+ int order = MAX_ORDER;
+ float threshold = p_current_threshold;
+ if (p_v == p_w) {
+ int min_order = MAX_ORDER;
+ Connection incoming;
+ for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
+ if (E->get().to == p_w) {
+ ORDER(E->get().from, r_layers);
+ if (min_order > order) {
+ min_order = order;
+ incoming = E->get();
+ }
+ }
+ }
+
+ if (incoming.from != StringName()) {
+ GraphNode *gfrom = Object::cast_to<GraphNode>(r_node_names[incoming.from]);
+ GraphNode *gto = Object::cast_to<GraphNode>(r_node_names[p_w]);
+ Vector2 frompos = gfrom->get_connection_output_position(incoming.from_port);
+ Vector2 topos = gto->get_connection_input_position(incoming.to_port);
+
+ //If connected block node is selected, calculate thershold or add current block to list
+ if (gfrom->is_selected()) {
+ Vector2 connected_block_pos = r_node_positions[r_root[incoming.from]];
+ if (connected_block_pos.y != FLT_MAX) {
+ //Connected block is placed. Calculate threshold
+ threshold = connected_block_pos.y + (real_t)r_inner_shift[incoming.from] - (real_t)r_inner_shift[p_w] + frompos.y - topos.y;
+ }
+ }
+ }
+ }
+ if (threshold == FLT_MIN && (StringName)r_align[p_w] == p_v) {
+ //This time, pick an outgoing edge and repeat as above!
+ int min_order = MAX_ORDER;
+ Connection outgoing;
+ for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
+ if (E->get().from == p_w) {
+ ORDER(E->get().to, r_layers);
+ if (min_order > order) {
+ min_order = order;
+ outgoing = E->get();
+ }
+ }
+ }
+
+ if (outgoing.to != StringName()) {
+ GraphNode *gfrom = Object::cast_to<GraphNode>(r_node_names[p_w]);
+ GraphNode *gto = Object::cast_to<GraphNode>(r_node_names[outgoing.to]);
+ Vector2 frompos = gfrom->get_connection_output_position(outgoing.from_port);
+ Vector2 topos = gto->get_connection_input_position(outgoing.to_port);
+
+ //If connected block node is selected, calculate thershold or add current block to list
+ if (gto->is_selected()) {
+ Vector2 connected_block_pos = r_node_positions[r_root[outgoing.to]];
+ if (connected_block_pos.y != FLT_MAX) {
+ //Connected block is placed. Calculate threshold
+ threshold = connected_block_pos.y + (real_t)r_inner_shift[outgoing.to] - (real_t)r_inner_shift[p_w] + frompos.y - topos.y;
+ }
+ }
+ }
+ }
+#undef MAX_ORDER
+#undef ORDER
+ return threshold;
+}
+
+void GraphEdit::_place_block(StringName p_v, float p_delta, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_node_name, const Dictionary &r_inner_shift, Dictionary &r_sink, Dictionary &r_shift, HashMap<StringName, Vector2> &r_node_positions) {
+#define PRED(node, layers) \
+ for (unsigned int i = 0; i < layers.size(); i++) { \
+ int index = layers[i].find(node); \
+ if (index > 0) { \
+ predecessor = layers[i][index - 1]; \
+ break; \
+ } \
+ predecessor = StringName(); \
+ }
+
+ StringName predecessor;
+ StringName successor;
+ Vector2 pos = r_node_positions[p_v];
+
+ if (pos.y == FLT_MAX) {
+ pos.y = 0;
+ bool initial = false;
+ StringName w = p_v;
+ real_t threshold = FLT_MIN;
+ do {
+ PRED(w, r_layers);
+ if (predecessor != StringName()) {
+ StringName u = r_root[predecessor];
+ _place_block(u, p_delta, r_layers, r_root, r_align, r_node_name, r_inner_shift, r_sink, r_shift, r_node_positions);
+ threshold = _calculate_threshold(p_v, w, r_node_name, r_layers, r_root, r_align, r_inner_shift, threshold, r_node_positions);
+ if ((StringName)r_sink[p_v] == p_v) {
+ r_sink[p_v] = r_sink[u];
+ }
+
+ Vector2 predecessor_root_pos = r_node_positions[u];
+ Vector2 predecessor_node_size = Object::cast_to<GraphNode>(r_node_name[predecessor])->get_size();
+ if (r_sink[p_v] != r_sink[u]) {
+ real_t sc = pos.y + (real_t)r_inner_shift[w] - predecessor_root_pos.y - (real_t)r_inner_shift[predecessor] - predecessor_node_size.y - p_delta;
+ r_shift[r_sink[u]] = MIN(sc, (real_t)r_shift[r_sink[u]]);
+ } else {
+ real_t sb = predecessor_root_pos.y + (real_t)r_inner_shift[predecessor] + predecessor_node_size.y - (real_t)r_inner_shift[w] + p_delta;
+ sb = MAX(sb, threshold);
+ if (initial) {
+ pos.y = sb;
+ } else {
+ pos.y = MAX(pos.y, sb);
+ }
+ initial = false;
+ }
+ }
+ threshold = _calculate_threshold(p_v, w, r_node_name, r_layers, r_root, r_align, r_inner_shift, threshold, r_node_positions);
+ w = r_align[w];
+ } while (w != p_v);
+ r_node_positions.set(p_v, pos);
+ }
+
+#undef PRED
+}
+
+void GraphEdit::arrange_nodes() {
+ if (!arranging_graph) {
+ arranging_graph = true;
+ } else {
+ return;
+ }
+
+ Dictionary node_names;
+ Set<StringName> selected_nodes;
+
+ for (int i = get_child_count() - 1; i >= 0; i--) {
+ GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
+ if (!gn) {
+ continue;
+ }
+
+ node_names[gn->get_name()] = gn;
+ }
+
+ HashMap<StringName, Set<StringName>> upper_neighbours;
+ HashMap<StringName, Pair<int, int>> port_info;
+ Vector2 origin(FLT_MAX, FLT_MAX);
+
+ float gap_v = 100.0f;
+ float gap_h = 100.0f;
+
+ for (int i = get_child_count() - 1; i >= 0; i--) {
+ GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
+ if (!gn) {
+ continue;
+ }
+
+ if (gn->is_selected()) {
+ selected_nodes.insert(gn->get_name());
+ Set<StringName> s;
+ for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
+ GraphNode *p_from = Object::cast_to<GraphNode>(node_names[E->get().from]);
+ if (E->get().to == gn->get_name() && p_from->is_selected()) {
+ if (!s.has(p_from->get_name())) {
+ s.insert(p_from->get_name());
+ }
+ String s_connection = String(p_from->get_name()) + " " + String(E->get().to);
+ StringName _connection(s_connection);
+ Pair<int, int> ports(E->get().from_port, E->get().to_port);
+ if (port_info.has(_connection)) {
+ Pair<int, int> p_ports = port_info[_connection];
+ if (p_ports.first < ports.first) {
+ ports = p_ports;
+ }
+ }
+ port_info.set(_connection, ports);
+ }
+ }
+ upper_neighbours.set(gn->get_name(), s);
+ }
+ }
+
+ if (!selected_nodes.size()) {
+ arranging_graph = false;
+ return;
+ }
+
+ HashMap<int, Vector<StringName>> layers = _layering(selected_nodes, upper_neighbours);
+ _crossing_minimisation(layers, upper_neighbours);
+
+ Dictionary root, align, sink, shift;
+ _horizontal_alignment(root, align, layers, upper_neighbours, selected_nodes);
+
+ HashMap<StringName, Vector2> new_positions;
+ Vector2 default_position(FLT_MAX, FLT_MAX);
+ Dictionary inner_shift;
+ Set<StringName> block_heads;
+
+ for (const Set<StringName>::Element *E = selected_nodes.front(); E; E = E->next()) {
+ inner_shift[E->get()] = 0.0f;
+ sink[E->get()] = E->get();
+ shift[E->get()] = FLT_MAX;
+ new_positions.set(E->get(), default_position);
+ if ((StringName)root[E->get()] == E->get()) {
+ block_heads.insert(E->get());
+ }
+ }
+
+ _calculate_inner_shifts(inner_shift, root, node_names, align, block_heads, port_info);
+
+ for (const Set<StringName>::Element *E = block_heads.front(); E; E = E->next()) {
+ _place_block(E->get(), gap_v, layers, root, align, node_names, inner_shift, sink, shift, new_positions);
+ }
+ origin.y = Object::cast_to<GraphNode>(node_names[layers[0][0]])->get_position_offset().y - (new_positions[layers[0][0]].y + (float)inner_shift[layers[0][0]]);
+ origin.x = Object::cast_to<GraphNode>(node_names[layers[0][0]])->get_position_offset().x;
+
+ for (const Set<StringName>::Element *E = block_heads.front(); E; E = E->next()) {
+ StringName u = E->get();
+ float start_from = origin.y + new_positions[E->get()].y;
+ do {
+ Vector2 cal_pos;
+ cal_pos.y = start_from + (real_t)inner_shift[u];
+ new_positions.set(u, cal_pos);
+ u = align[u];
+ } while (u != E->get());
+ }
+
+ //Compute horizontal co-ordinates individually for layers to get uniform gap
+ float start_from = origin.x;
+ float largest_node_size = 0.0f;
+
+ for (unsigned int i = 0; i < layers.size(); i++) {
+ Vector<StringName> layer = layers[i];
+ for (int j = 0; j < layer.size(); j++) {
+ float current_node_size = Object::cast_to<GraphNode>(node_names[layer[j]])->get_size().x;
+ largest_node_size = MAX(largest_node_size, current_node_size);
+ }
+
+ for (int j = 0; j < layer.size(); j++) {
+ float current_node_size = Object::cast_to<GraphNode>(node_names[layer[j]])->get_size().x;
+ Vector2 cal_pos = new_positions[layer[j]];
+
+ if (current_node_size == largest_node_size) {
+ cal_pos.x = start_from;
+ } else {
+ float current_node_start_pos = start_from;
+ if (current_node_size < largest_node_size / 2) {
+ if (!(i || j)) {
+ start_from -= (largest_node_size - current_node_size);
+ }
+ current_node_start_pos = start_from + largest_node_size - current_node_size;
+ }
+ cal_pos.x = current_node_start_pos;
+ }
+ new_positions.set(layer[j], cal_pos);
+ }
+
+ start_from += largest_node_size + gap_h;
+ largest_node_size = 0.0f;
+ }
+
+ emit_signal("begin_node_move");
+ for (const Set<StringName>::Element *E = selected_nodes.front(); E; E = E->next()) {
+ GraphNode *gn = Object::cast_to<GraphNode>(node_names[E->get()]);
+ gn->set_drag(true);
+ Vector2 pos = (new_positions[E->get()]);
+
+ if (is_using_snap()) {
+ const int snap = get_snap();
+ pos = pos.snapped(Vector2(snap, snap));
+ }
+ gn->set_position_offset(pos);
+ gn->set_drag(false);
+ }
+ emit_signal("end_node_move");
+ arranging_graph = false;
+}
+
void GraphEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("connect_node", "from", "from_port", "to", "to_port"), &GraphEdit::connect_node);
ClassDB::bind_method(D_METHOD("is_node_connected", "from", "from_port", "to", "to_port"), &GraphEdit::is_node_connected);
@@ -1663,6 +2147,7 @@ void GraphEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_valid_connection_type", "from_type", "to_type"), &GraphEdit::add_valid_connection_type);
ClassDB::bind_method(D_METHOD("remove_valid_connection_type", "from_type", "to_type"), &GraphEdit::remove_valid_connection_type);
ClassDB::bind_method(D_METHOD("is_valid_connection_type", "from_type", "to_type"), &GraphEdit::is_valid_connection_type);
+ ClassDB::bind_method(D_METHOD("get_connection_line", "from", "to"), &GraphEdit::get_connection_line);
ClassDB::bind_method(D_METHOD("set_zoom", "zoom"), &GraphEdit::set_zoom);
ClassDB::bind_method(D_METHOD("get_zoom"), &GraphEdit::get_zoom);
@@ -1702,13 +2187,16 @@ void GraphEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_right_disconnects", "enable"), &GraphEdit::set_right_disconnects);
ClassDB::bind_method(D_METHOD("is_right_disconnects_enabled"), &GraphEdit::is_right_disconnects_enabled);
- ClassDB::bind_method(D_METHOD("_gui_input"), &GraphEdit::_gui_input);
ClassDB::bind_method(D_METHOD("_update_scroll_offset"), &GraphEdit::_update_scroll_offset);
ClassDB::bind_method(D_METHOD("get_zoom_hbox"), &GraphEdit::get_zoom_hbox);
+ ClassDB::bind_method(D_METHOD("arrange_nodes"), &GraphEdit::arrange_nodes);
+
ClassDB::bind_method(D_METHOD("set_selected", "node"), &GraphEdit::set_selected);
+ GDVIRTUAL_BIND(_get_connection_line, "from", "to")
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "right_disconnects"), "set_right_disconnects", "is_right_disconnects_enabled");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_offset"), "set_scroll_ofs", "get_scroll_ofs");
ADD_PROPERTY(PropertyInfo(Variant::INT, "snap_distance"), "set_snap", "get_snap");
@@ -1757,14 +2245,14 @@ GraphEdit::GraphEdit() {
zoom_max = (1 * Math::pow(zoom_step, 4));
top_layer = memnew(GraphEditFilter(this));
- add_child(top_layer);
+ add_child(top_layer, false, INTERNAL_MODE_BACK);
top_layer->set_mouse_filter(MOUSE_FILTER_PASS);
top_layer->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
top_layer->connect("draw", callable_mp(this, &GraphEdit::_top_layer_draw));
top_layer->connect("gui_input", callable_mp(this, &GraphEdit::_top_layer_input));
connections_layer = memnew(Control);
- add_child(connections_layer);
+ add_child(connections_layer, false, INTERNAL_MODE_FRONT);
connections_layer->connect("draw", callable_mp(this, &GraphEdit::_connections_layer_draw));
connections_layer->set_name("CLAYER");
connections_layer->set_disable_visibility_clip(true); // so it can draw freely and be offset
@@ -1851,6 +2339,13 @@ GraphEdit::GraphEdit() {
minimap_button->set_focus_mode(FOCUS_NONE);
zoom_hb->add_child(minimap_button);
+ layout_button = memnew(Button);
+ layout_button->set_flat(true);
+ zoom_hb->add_child(layout_button);
+ layout_button->set_tooltip(RTR("Arrange nodes."));
+ layout_button->connect("pressed", callable_mp(this, &GraphEdit::arrange_nodes));
+ layout_button->set_focus_mode(FOCUS_NONE);
+
Vector2 minimap_size = Vector2(240, 160);
float minimap_opacity = 0.65;
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index 5251de1722..44e50aa3c2 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -62,8 +62,6 @@ class GraphEditMinimap : public Control {
GraphEdit *ge;
protected:
- static void _bind_methods();
-
public:
GraphEditMinimap(GraphEdit *p_edit);
@@ -88,7 +86,7 @@ private:
Vector2 _convert_from_graph_position(const Vector2 &p_position);
Vector2 _convert_to_graph_position(const Vector2 &p_position);
- void _gui_input(const Ref<InputEvent> &p_ev);
+ virtual void gui_input(const Ref<InputEvent> &p_ev) override;
void _adjust_graph_scroll(const Vector2 &p_offset);
};
@@ -116,6 +114,8 @@ private:
Button *minimap_button;
+ Button *layout_button;
+
HScrollBar *h_scroll;
VScrollBar *v_scroll;
@@ -167,9 +167,8 @@ private:
float lines_thickness = 2.0f;
bool lines_antialiased = true;
- void _bake_segment2d(Vector<Vector2> &points, Vector<Color> &colors, float p_begin, float p_end, const Vector2 &p_a, const Vector2 &p_out, const Vector2 &p_b, const Vector2 &p_in, int p_depth, int p_min_depth, int p_max_depth, float p_tol, const Color &p_color, const Color &p_to_color, int &lines) const;
-
- void _draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width, float p_bezier_ratio = 1.0);
+ PackedVector2Array get_connection_line(const Vector2 &p_from, const Vector2 &p_to);
+ void _draw_connection_line(CanvasItem *p_where, const Vector2 &p_from, const Vector2 &p_to, const Color &p_color, const Color &p_to_color, float p_width, float p_zoom);
void _graph_node_raised(Node *p_gn);
void _graph_node_moved(Node *p_gn);
@@ -177,14 +176,14 @@ private:
void _update_scroll();
void _scroll_moved(double);
- void _gui_input(const Ref<InputEvent> &p_ev);
+ virtual void gui_input(const Ref<InputEvent> &p_ev) override;
Control *connections_layer;
GraphEditFilter *top_layer;
GraphEditMinimap *minimap;
void _top_layer_input(const Ref<InputEvent> &p_ev);
- bool is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos);
+ bool is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos, const Vector2i &p_port_size, bool p_left);
void _top_layer_draw();
void _connections_layer_draw();
@@ -230,12 +229,32 @@ private:
bool _check_clickable_control(Control *p_control, const Vector2 &pos);
+ bool arranging_graph = false;
+
+ enum SET_OPERATIONS {
+ IS_EQUAL,
+ IS_SUBSET,
+ DIFFERENCE,
+ UNION,
+ };
+
+ int _set_operations(SET_OPERATIONS p_operation, Set<StringName> &r_u, const Set<StringName> &r_v);
+ HashMap<int, Vector<StringName>> _layering(const Set<StringName> &r_selected_nodes, const HashMap<StringName, Set<StringName>> &r_upper_neighbours);
+ Vector<StringName> _split(const Vector<StringName> &r_layer, const HashMap<StringName, Dictionary> &r_crossings);
+ void _horizontal_alignment(Dictionary &r_root, Dictionary &r_align, const HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, Set<StringName>> &r_upper_neighbours, const Set<StringName> &r_selected_nodes);
+ void _crossing_minimisation(HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, Set<StringName>> &r_upper_neighbours);
+ void _calculate_inner_shifts(Dictionary &r_inner_shifts, const Dictionary &r_root, const Dictionary &r_node_names, const Dictionary &r_align, const Set<StringName> &r_block_heads, const HashMap<StringName, Pair<int, int>> &r_port_info);
+ float _calculate_threshold(StringName p_v, StringName p_w, const Dictionary &r_node_names, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_inner_shift, real_t p_current_threshold, const HashMap<StringName, Vector2> &r_node_positions);
+ void _place_block(StringName p_v, float p_delta, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_node_name, const Dictionary &r_inner_shift, Dictionary &r_sink, Dictionary &r_shift, HashMap<StringName, Vector2> &r_node_positions);
+
protected:
static void _bind_methods();
virtual void add_child_notify(Node *p_child) override;
virtual void remove_child_notify(Node *p_child) override;
void _notification(int p_what);
+ GDVIRTUAL2RC(Vector<Vector2>, _get_connection_line, Vector2, Vector2)
+
public:
Error connect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port);
bool is_node_connected(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port);
@@ -304,6 +323,8 @@ public:
HBoxContainer *get_zoom_hbox();
+ void arrange_nodes();
+
GraphEdit();
};
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index e85cefcb7b..08c8c60d7a 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -863,7 +863,7 @@ Color GraphNode::get_connection_output_color(int p_idx) {
return conn_output_cache[p_idx].color;
}
-void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
+void GraphNode::gui_input(const Ref<InputEvent> &p_ev) {
ERR_FAIL_COND(p_ev.is_null());
Ref<InputEventMouseButton> mb = p_ev;
@@ -946,8 +946,6 @@ void GraphNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_language", "language"), &GraphNode::set_language);
ClassDB::bind_method(D_METHOD("get_language"), &GraphNode::get_language);
- ClassDB::bind_method(D_METHOD("_gui_input"), &GraphNode::_gui_input);
-
ClassDB::bind_method(D_METHOD("set_slot", "idx", "enable_left", "type_left", "color_left", "enable_right", "type_right", "color_right", "custom_left", "custom_right"), &GraphNode::set_slot, DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>()));
ClassDB::bind_method(D_METHOD("clear_slot", "idx"), &GraphNode::clear_slot);
ClassDB::bind_method(D_METHOD("clear_all_slots"), &GraphNode::clear_all_slots);
diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h
index c70f616b47..c7c7006bfc 100644
--- a/scene/gui/graph_node.h
+++ b/scene/gui/graph_node.h
@@ -99,7 +99,7 @@ private:
Overlay overlay = OVERLAY_DISABLED;
protected:
- void _gui_input(const Ref<InputEvent> &p_ev);
+ virtual void gui_input(const Ref<InputEvent> &p_ev) override;
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 258d65112a..d10ad90c1f 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -48,6 +48,8 @@ void ItemList::_shape(int p_idx) {
} else {
item.text_buf->set_flags(TextServer::BREAK_NONE);
}
+ item.text_buf->set_text_overrun_behavior(text_overrun_behavior);
+ item.text_buf->set_max_lines_visible(max_text_lines);
}
int ItemList::add_item(const String &p_item, const Ref<Texture2D> &p_texture, bool p_selectable) {
@@ -453,6 +455,7 @@ void ItemList::set_max_text_lines(int p_lines) {
for (int i = 0; i < items.size(); i++) {
if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
items.write[i].text_buf->set_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND);
+ items.write[i].text_buf->set_max_lines_visible(p_lines);
} else {
items.write[i].text_buf->set_flags(TextServer::BREAK_NONE);
}
@@ -534,7 +537,7 @@ Size2 ItemList::Item::get_icon_size() const {
return size_result;
}
-void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
+void ItemList::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
double prev_scroll = scroll_bar->get_value();
@@ -930,8 +933,14 @@ void ItemList::_notification(int p_what) {
}
if (items[i].text != "") {
+ int max_width = -1;
+ if (fixed_column_width) {
+ max_width = fixed_column_width;
+ } else if (same_column_width) {
+ max_width = items[i].rect_cache.size.x;
+ }
+ items.write[i].text_buf->set_width(max_width);
Size2 s = items[i].text_buf->get_size();
- //s.width=MIN(s.width,fixed_column_width);
if (icon_mode == ICON_MODE_TOP) {
minsize.x = MAX(minsize.x, s.width);
@@ -1139,11 +1148,8 @@ void ItemList::_notification(int p_what) {
if (icon_mode == ICON_MODE_TOP) {
pos.x += Math::floor((items[i].rect_cache.size.width - icon_size.width) / 2);
- pos.y += MIN(
- Math::floor((items[i].rect_cache.size.height - icon_size.height) / 2),
- items[i].rect_cache.size.height - items[i].min_rect_cache.size.height);
- text_ofs.y = icon_size.height + icon_margin;
- text_ofs.y += items[i].rect_cache.size.height - items[i].min_rect_cache.size.height;
+ pos.y += icon_margin;
+ text_ofs.y = icon_size.height + icon_margin * 2;
} else {
pos.y += Math::floor((items[i].rect_cache.size.height - icon_size.height) / 2);
text_ofs.x = icon_size.width + icon_margin;
@@ -1210,7 +1216,6 @@ void ItemList::_notification(int p_what) {
text_ofs.x = size.width - text_ofs.x - max_len;
}
- items.write[i].text_buf->set_width(max_len);
items.write[i].text_buf->set_align(HALIGN_CENTER);
if (outline_size > 0 && font_outline_color.a > 0) {
@@ -1488,6 +1493,21 @@ bool ItemList::has_auto_height() const {
return auto_height;
}
+void ItemList::set_text_overrun_behavior(TextParagraph::OverrunBehavior p_behavior) {
+ if (text_overrun_behavior != p_behavior) {
+ text_overrun_behavior = p_behavior;
+ for (int i = 0; i < items.size(); i++) {
+ items.write[i].text_buf->set_text_overrun_behavior(p_behavior);
+ }
+ shape_changed = true;
+ update();
+ }
+}
+
+TextParagraph::OverrunBehavior ItemList::get_text_overrun_behavior() const {
+ return text_overrun_behavior;
+}
+
void ItemList::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_item", "text", "icon", "selectable"), &ItemList::add_item, DEFVAL(Variant()), DEFVAL(true));
ClassDB::bind_method(D_METHOD("add_icon_item", "icon", "selectable"), &ItemList::add_icon_item, DEFVAL(true));
@@ -1594,11 +1614,12 @@ void ItemList::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_v_scroll"), &ItemList::get_v_scroll);
- ClassDB::bind_method(D_METHOD("_gui_input"), &ItemList::_gui_input);
-
ClassDB::bind_method(D_METHOD("_set_items"), &ItemList::_set_items);
ClassDB::bind_method(D_METHOD("_get_items"), &ItemList::_get_items);
+ ClassDB::bind_method(D_METHOD("set_text_overrun_behavior", "overrun_behavior"), &ItemList::set_text_overrun_behavior);
+ ClassDB::bind_method(D_METHOD("get_text_overrun_behavior"), &ItemList::get_text_overrun_behavior);
+
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items");
ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Multi"), "set_select_mode", "get_select_mode");
@@ -1606,6 +1627,7 @@ void ItemList::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_text_lines", PROPERTY_HINT_RANGE, "1,10,1,or_greater"), "set_max_text_lines", "get_max_text_lines");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_height"), "set_auto_height", "has_auto_height");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis,Word Ellipsis"), "set_text_overrun_behavior", "get_text_overrun_behavior");
ADD_GROUP("Columns", "");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_columns", PROPERTY_HINT_RANGE, "0,10,1,or_greater"), "set_max_columns", "get_max_columns");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "same_column_width"), "set_same_column_width", "is_same_column_width");
@@ -1634,7 +1656,7 @@ void ItemList::_bind_methods() {
ItemList::ItemList() {
scroll_bar = memnew(VScrollBar);
- add_child(scroll_bar);
+ add_child(scroll_bar, false, INTERNAL_MODE_FRONT);
scroll_bar->connect("value_changed", callable_mp(this, &ItemList::_scroll_changed));
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index 86a0174a20..148fa7ba9f 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -95,6 +95,7 @@ private:
SelectMode select_mode = SELECT_SINGLE;
IconMode icon_mode = ICON_MODE_LEFT;
VScrollBar *scroll_bar;
+ TextParagraph::OverrunBehavior text_overrun_behavior = TextParagraph::OVERRUN_NO_TRIMMING;
uint64_t search_time_msec = 0;
String search_string;
@@ -122,7 +123,6 @@ private:
void _set_items(const Array &p_items);
void _scroll_changed(double);
- void _gui_input(const Ref<InputEvent> &p_event);
void _shape(int p_idx);
protected:
@@ -130,6 +130,8 @@ protected:
static void _bind_methods();
public:
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
+
int add_item(const String &p_item, const Ref<Texture2D> &p_texture = Ref<Texture2D>(), bool p_selectable = true);
int add_icon_item(const Ref<Texture2D> &p_item, bool p_selectable = true);
@@ -182,6 +184,9 @@ public:
void set_item_custom_fg_color(int p_idx, const Color &p_custom_fg_color);
Color get_item_custom_fg_color(int p_idx) const;
+ void set_text_overrun_behavior(TextParagraph::OverrunBehavior p_behavior);
+ TextParagraph::OverrunBehavior get_text_overrun_behavior() const;
+
void select(int p_idx, bool p_single = true);
void deselect(int p_idx);
void deselect_all();
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index 1603989243..3f87003423 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -66,11 +66,11 @@ bool Label::is_uppercase() const {
int Label::get_line_height(int p_line) const {
Ref<Font> font = get_theme_font(SNAME("font"));
if (p_line >= 0 && p_line < lines_rid.size()) {
- return TS->shaped_text_get_size(lines_rid[p_line]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM);
+ return TS->shaped_text_get_size(lines_rid[p_line]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM);
} else if (lines_rid.size() > 0) {
int h = 0;
for (int i = 0; i < lines_rid.size(); i++) {
- h = MAX(h, TS->shaped_text_get_size(lines_rid[i]).y) + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM);
+ h = MAX(h, TS->shaped_text_get_size(lines_rid[i]).y) + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM);
}
return h;
} else {
@@ -89,13 +89,15 @@ void Label::_shape() {
} else {
TS->shaped_text_set_direction(text_rid, (TextServer::Direction)text_direction);
}
- TS->shaped_text_add_string(text_rid, (uppercase) ? xl_text.to_upper() : xl_text, get_theme_font(SNAME("font"))->get_rids(), get_theme_font_size(SNAME("font_size")), opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
+ const Ref<Font> &font = get_theme_font(SNAME("font"));
+ int font_size = get_theme_font_size(SNAME("font_size"));
+ ERR_FAIL_COND(font.is_null());
+ TS->shaped_text_add_string(text_rid, (uppercase) ? xl_text.to_upper() : xl_text, font->get_rids(), font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
TS->shaped_text_set_bidi_override(text_rid, structured_text_parser(st_parser, st_args, xl_text));
dirty = false;
lines_dirty = true;
}
- uint8_t overrun_flags = TextServer::OVERRUN_NO_TRIMMING;
if (lines_dirty) {
for (int i = 0; i < lines_rid.size(); i++) {
TS->free(lines_rid[i]);
@@ -116,53 +118,19 @@ void Label::_shape() {
case AUTOWRAP_OFF:
break;
}
- Vector<Vector2i> lines = TS->shaped_text_get_line_breaks(text_rid, width, 0, autowrap_flags);
-
- for (int i = 0; i < lines.size(); i++) {
- RID line = TS->shaped_text_substr(text_rid, lines[i].x, lines[i].y - lines[i].x);
-
- switch (overrun_behavior) {
- case OVERRUN_TRIM_WORD_ELLIPSIS:
- overrun_flags |= TextServer::OVERRUN_TRIM;
- overrun_flags |= TextServer::OVERRUN_TRIM_WORD_ONLY;
- overrun_flags |= TextServer::OVERRUN_ADD_ELLIPSIS;
- break;
- case OVERRUN_TRIM_ELLIPSIS:
- overrun_flags |= TextServer::OVERRUN_TRIM;
- overrun_flags |= TextServer::OVERRUN_ADD_ELLIPSIS;
- break;
- case OVERRUN_TRIM_WORD:
- overrun_flags |= TextServer::OVERRUN_TRIM;
- overrun_flags |= TextServer::OVERRUN_TRIM_WORD_ONLY;
- break;
- case OVERRUN_TRIM_CHAR:
- overrun_flags |= TextServer::OVERRUN_TRIM;
- break;
- case OVERRUN_NO_TRIMMING:
- break;
- }
-
- if (autowrap_mode == AUTOWRAP_OFF && align != ALIGN_FILL && overrun_behavior != OVERRUN_NO_TRIMMING) {
- TS->shaped_text_overrun_trim_to_width(line, width, overrun_flags);
- }
+ Vector<Vector2i> line_breaks = TS->shaped_text_get_line_breaks(text_rid, width, 0, autowrap_flags);
+ for (int i = 0; i < line_breaks.size(); i++) {
+ RID line = TS->shaped_text_substr(text_rid, line_breaks[i].x, line_breaks[i].y - line_breaks[i].x);
lines_rid.push_back(line);
}
-
- if (autowrap_mode != AUTOWRAP_OFF && overrun_behavior != OVERRUN_NO_TRIMMING) {
- int visible_lines = get_visible_line_count();
-
- if (visible_lines < lines_rid.size() && visible_lines > 0) {
- overrun_flags |= TextServer::OVERRUN_ENFORCE_ELLIPSIS;
- TS->shaped_text_overrun_trim_to_width(lines_rid[visible_lines - 1], width, overrun_flags);
- }
- }
}
if (xl_text.length() == 0) {
minsize = Size2(1, get_line_height());
return;
}
+
if (autowrap_mode == AUTOWRAP_OFF) {
minsize.width = 0.0f;
for (int i = 0; i < lines_rid.size(); i++) {
@@ -173,19 +141,59 @@ void Label::_shape() {
}
if (lines_dirty) {
+ uint8_t overrun_flags = TextServer::OVERRUN_NO_TRIMMING;
+ switch (overrun_behavior) {
+ case OVERRUN_TRIM_WORD_ELLIPSIS:
+ overrun_flags |= TextServer::OVERRUN_TRIM;
+ overrun_flags |= TextServer::OVERRUN_TRIM_WORD_ONLY;
+ overrun_flags |= TextServer::OVERRUN_ADD_ELLIPSIS;
+ break;
+ case OVERRUN_TRIM_ELLIPSIS:
+ overrun_flags |= TextServer::OVERRUN_TRIM;
+ overrun_flags |= TextServer::OVERRUN_ADD_ELLIPSIS;
+ break;
+ case OVERRUN_TRIM_WORD:
+ overrun_flags |= TextServer::OVERRUN_TRIM;
+ overrun_flags |= TextServer::OVERRUN_TRIM_WORD_ONLY;
+ break;
+ case OVERRUN_TRIM_CHAR:
+ overrun_flags |= TextServer::OVERRUN_TRIM;
+ break;
+ case OVERRUN_NO_TRIMMING:
+ break;
+ }
+
// Fill after min_size calculation.
- if (align == ALIGN_FILL) {
+
+ if (autowrap_mode != AUTOWRAP_OFF) {
+ int visible_lines = get_visible_line_count();
+ bool lines_hidden = visible_lines > 0 && visible_lines < lines_rid.size();
+ if (lines_hidden) {
+ overrun_flags |= TextServer::OVERRUN_ENFORCE_ELLIPSIS;
+ }
+ if (align == ALIGN_FILL) {
+ for (int i = 0; i < lines_rid.size(); i++) {
+ if (i < visible_lines - 1 || lines_rid.size() == 1) {
+ TS->shaped_text_fit_to_width(lines_rid[i], width);
+ } else if (i == (visible_lines - 1)) {
+ TS->shaped_text_overrun_trim_to_width(lines_rid[visible_lines - 1], width, overrun_flags);
+ }
+ }
+
+ } else if (lines_hidden) {
+ TS->shaped_text_overrun_trim_to_width(lines_rid[visible_lines - 1], width, overrun_flags);
+ }
+
+ } else {
+ // Autowrap disabled.
for (int i = 0; i < lines_rid.size(); i++) {
- if (overrun_behavior != OVERRUN_NO_TRIMMING && autowrap_mode == AUTOWRAP_OFF) {
- float line_unaltered_width = TS->shaped_text_get_width(lines_rid[i]);
+ if (align == ALIGN_FILL) {
TS->shaped_text_fit_to_width(lines_rid[i], width);
- float new_line_width = TS->shaped_text_get_width(lines_rid[i]);
- // Begin trimming when there is no space between words available anymore.
- if (new_line_width < line_unaltered_width) {
- TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags);
- }
+ overrun_flags |= TextServer::OVERRUN_JUSTIFICATION_AWARE;
+ TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags);
+ TS->shaped_text_fit_to_width(lines_rid[i], width, TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_CONSTRAIN_ELLIPSIS);
} else {
- TS->shaped_text_fit_to_width(lines_rid[i], width);
+ TS->shaped_text_overrun_trim_to_width(lines_rid[i], width, overrun_flags);
}
}
}
@@ -212,18 +220,37 @@ void Label::_update_visible() {
minsize.height = 0;
int last_line = MIN(lines_rid.size(), lines_visible + lines_skipped);
for (int64_t i = lines_skipped; i < last_line; i++) {
- minsize.height += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM) + line_spacing;
+ minsize.height += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM) + line_spacing;
if (minsize.height > (get_size().height - style->get_minimum_size().height + line_spacing)) {
break;
}
}
}
+inline void draw_glyph(const TextServer::Glyph &p_gl, const RID &p_canvas, const Color &p_font_color, const Color &p_font_shadow_color, const Color &p_font_outline_color, const int &p_shadow_outline_size, const int &p_outline_size, const Vector2 &p_ofs, const Vector2 &shadow_ofs) {
+ if (p_gl.font_rid != RID()) {
+ if (p_font_shadow_color.a > 0) {
+ TS->font_draw_glyph(p_gl.font_rid, p_canvas, p_gl.font_size, p_ofs + Vector2(p_gl.x_off, p_gl.y_off) + shadow_ofs, p_gl.index, p_font_shadow_color);
+ if (p_shadow_outline_size > 0) {
+ TS->font_draw_glyph_outline(p_gl.font_rid, p_canvas, p_gl.font_size, p_shadow_outline_size, p_ofs + Vector2(p_gl.x_off, p_gl.y_off) + Vector2(-shadow_ofs.x, shadow_ofs.y), p_gl.index, p_font_shadow_color);
+ TS->font_draw_glyph_outline(p_gl.font_rid, p_canvas, p_gl.font_size, p_shadow_outline_size, p_ofs + Vector2(p_gl.x_off, p_gl.y_off) + Vector2(shadow_ofs.x, -shadow_ofs.y), p_gl.index, p_font_shadow_color);
+ TS->font_draw_glyph_outline(p_gl.font_rid, p_canvas, p_gl.font_size, p_shadow_outline_size, p_ofs + Vector2(p_gl.x_off, p_gl.y_off) + Vector2(-shadow_ofs.x, -shadow_ofs.y), p_gl.index, p_font_shadow_color);
+ }
+ }
+ if (p_font_outline_color.a != 0.0 && p_outline_size > 0) {
+ TS->font_draw_glyph_outline(p_gl.font_rid, p_canvas, p_gl.font_size, p_outline_size, p_ofs + Vector2(p_gl.x_off, p_gl.y_off), p_gl.index, p_font_outline_color);
+ }
+ TS->font_draw_glyph(p_gl.font_rid, p_canvas, p_gl.font_size, p_ofs + Vector2(p_gl.x_off, p_gl.y_off), p_gl.index, p_font_color);
+ } else {
+ TS->draw_hex_code_box(p_canvas, p_gl.font_size, p_ofs + Vector2(p_gl.x_off, p_gl.y_off), p_gl.index, p_font_color);
+ }
+}
+
void Label::_notification(int p_what) {
if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
String new_text = atr(text);
if (new_text == xl_text) {
- return; //nothing new
+ return; // Nothing new.
}
xl_text = new_text;
dirty = true;
@@ -253,7 +280,7 @@ void Label::_notification(int p_what) {
Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
int outline_size = get_theme_constant(SNAME("outline_size"));
int shadow_outline_size = get_theme_constant(SNAME("shadow_outline_size"));
- bool rtl = is_layout_rtl();
+ bool rtl = TS->shaped_text_get_direction(text_rid);
style->draw(ci, Rect2(Point2(0, 0), get_size()));
@@ -262,7 +289,7 @@ void Label::_notification(int p_what) {
// Get number of lines to fit to the height.
for (int64_t i = lines_skipped; i < lines_rid.size(); i++) {
- total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM) + line_spacing;
+ total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM) + line_spacing;
if (total_h > (get_size().height - style->get_minimum_size().height + line_spacing)) {
break;
}
@@ -278,7 +305,7 @@ void Label::_notification(int p_what) {
// Get real total height.
total_h = 0;
for (int64_t i = lines_skipped; i < last_line; i++) {
- total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM) + line_spacing;
+ total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM) + line_spacing;
}
total_h += style->get_margin(SIDE_TOP) + style->get_margin(SIDE_BOTTOM);
@@ -286,7 +313,7 @@ void Label::_notification(int p_what) {
if (lines_visible > 0) {
switch (valign) {
case VALIGN_TOP: {
- //nothing
+ // Nothing.
} break;
case VALIGN_CENTER: {
vbegin = (size.y - (total_h - line_spacing)) / 2;
@@ -331,84 +358,85 @@ void Label::_notification(int p_what) {
Vector2 ofs;
ofs.y = style->get_offset().y + vbegin;
for (int i = lines_skipped; i < last_line; i++) {
+ Size2 line_size = TS->shaped_text_get_size(lines_rid[i]);
ofs.x = 0;
- ofs.y += TS->shaped_text_get_ascent(lines_rid[i]) + font->get_spacing(Font::SPACING_TOP);
+ ofs.y += TS->shaped_text_get_ascent(lines_rid[i]) + font->get_spacing(TextServer::SPACING_TOP);
switch (align) {
case ALIGN_FILL:
- case ALIGN_LEFT: {
- if (rtl) {
- ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - TS->shaped_text_get_size(lines_rid[i]).x);
+ if (rtl && autowrap_mode != AUTOWRAP_OFF) {
+ ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
} else {
ofs.x = style->get_offset().x;
}
+ break;
+ case ALIGN_LEFT: {
+ ofs.x = style->get_offset().x;
} break;
case ALIGN_CENTER: {
- ofs.x = int(size.width - TS->shaped_text_get_size(lines_rid[i]).x) / 2;
+ ofs.x = int(size.width - line_size.width) / 2;
} break;
case ALIGN_RIGHT: {
- if (rtl) {
- ofs.x = style->get_offset().x;
- } else {
- ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - TS->shaped_text_get_size(lines_rid[i]).x);
- }
+ ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
} break;
}
const Vector<TextServer::Glyph> visual = TS->shaped_text_get_glyphs(lines_rid[i]);
const TextServer::Glyph *glyphs = visual.ptr();
int gl_size = visual.size();
+ TextServer::TrimData trim_data = TS->shaped_text_get_trim_data(lines_rid[i]);
+
+ // Draw RTL ellipsis string when necessary.
+ if (rtl && trim_data.ellipsis_pos >= 0) {
+ for (int gl_idx = trim_data.ellipsis_glyph_buf.size() - 1; gl_idx >= 0; gl_idx--) {
+ for (int j = 0; j < trim_data.ellipsis_glyph_buf[gl_idx].repeat; j++) {
+ //Draw glyph outlines and shadow.
+ draw_glyph(trim_data.ellipsis_glyph_buf[gl_idx], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, ofs, shadow_ofs);
+ ofs.x += trim_data.ellipsis_glyph_buf[gl_idx].advance;
+ }
+ }
+ }
- float x = ofs.x;
- int outlines_drawn = glyhps_drawn;
+ // Draw main text.
for (int j = 0; j < gl_size; j++) {
for (int k = 0; k < glyphs[j].repeat; k++) {
- if (glyphs[j].font_rid != RID()) {
- if (font_shadow_color.a > 0) {
- TS->font_draw_glyph(glyphs[j].font_rid, ci, glyphs[j].font_size, ofs + Vector2(glyphs[j].x_off, glyphs[j].y_off) + shadow_ofs, glyphs[j].index, font_shadow_color);
- if (shadow_outline_size > 0) {
- //draw shadow
- TS->font_draw_glyph_outline(glyphs[j].font_rid, ci, glyphs[j].font_size, shadow_outline_size, ofs + Vector2(glyphs[j].x_off, glyphs[j].y_off) + Vector2(-shadow_ofs.x, shadow_ofs.y), glyphs[j].index, font_shadow_color);
- TS->font_draw_glyph_outline(glyphs[j].font_rid, ci, glyphs[j].font_size, shadow_outline_size, ofs + Vector2(glyphs[j].x_off, glyphs[j].y_off) + Vector2(shadow_ofs.x, -shadow_ofs.y), glyphs[j].index, font_shadow_color);
- TS->font_draw_glyph_outline(glyphs[j].font_rid, ci, glyphs[j].font_size, shadow_outline_size, ofs + Vector2(glyphs[j].x_off, glyphs[j].y_off) + Vector2(-shadow_ofs.x, -shadow_ofs.y), glyphs[j].index, font_shadow_color);
+ if (visible_glyphs != -1) {
+ if ((glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) {
+ if (glyhps_drawn >= visible_glyphs) {
+ return;
}
}
- if (font_outline_color.a != 0.0 && outline_size > 0) {
- TS->font_draw_glyph_outline(glyphs[j].font_rid, ci, glyphs[j].font_size, outline_size, ofs + Vector2(glyphs[j].x_off, glyphs[j].y_off), glyphs[j].index, font_outline_color);
- }
}
- ofs.x += glyphs[j].advance;
- }
- if (visible_glyphs != -1) {
- if ((glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) {
- outlines_drawn++;
- if (outlines_drawn >= visible_glyphs) {
- break;
+
+ // Trim when necessary.
+ if (trim_data.trim_pos >= 0) {
+ if (rtl) {
+ if (j < trim_data.trim_pos && (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) {
+ continue;
+ }
+ } else {
+ if (j >= trim_data.trim_pos && (glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) {
+ break;
+ }
}
}
- }
- }
- ofs.x = x;
- for (int j = 0; j < gl_size; j++) {
- for (int k = 0; k < glyphs[j].repeat; k++) {
- if (glyphs[j].font_rid != RID()) {
- TS->font_draw_glyph(glyphs[j].font_rid, ci, glyphs[j].font_size, ofs + Vector2(glyphs[j].x_off, glyphs[j].y_off), glyphs[j].index, font_color);
- } else if ((glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) {
- TS->draw_hex_code_box(ci, glyphs[j].font_size, ofs + Vector2(glyphs[j].x_off, glyphs[j].y_off), glyphs[j].index, font_color);
- }
+ // Draw glyph outlines and shadow.
+ draw_glyph(glyphs[j], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, ofs, shadow_ofs);
ofs.x += glyphs[j].advance;
+ glyhps_drawn++;
}
- if (visible_glyphs != -1) {
- if ((glyphs[j].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) {
- glyhps_drawn++;
- if (glyhps_drawn >= visible_glyphs) {
- return;
- }
+ }
+ // Draw LTR ellipsis string when necessary.
+ if (!rtl && trim_data.ellipsis_pos >= 0) {
+ for (int gl_idx = 0; gl_idx < trim_data.ellipsis_glyph_buf.size(); gl_idx++) {
+ for (int j = 0; j < trim_data.ellipsis_glyph_buf[gl_idx].repeat; j++) {
+ //Draw glyph outlines and shadow.
+ draw_glyph(trim_data.ellipsis_glyph_buf[gl_idx], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, ofs, shadow_ofs);
+ ofs.x += trim_data.ellipsis_glyph_buf[gl_idx].advance;
}
}
}
-
- ofs.y += TS->shaped_text_get_descent(lines_rid[i]) + vsep + line_spacing + font->get_spacing(Font::SPACING_BOTTOM);
+ ofs.y += TS->shaped_text_get_descent(lines_rid[i]) + vsep + line_spacing + font->get_spacing(TextServer::SPACING_BOTTOM);
}
}
@@ -430,7 +458,7 @@ Size2 Label::get_minimum_size() const {
Size2 min_size = minsize;
Ref<Font> font = get_theme_font(SNAME("font"));
- min_size.height = MAX(min_size.height, font->get_height(get_theme_font_size(SNAME("font_size"))) + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM));
+ min_size.height = MAX(min_size.height, font->get_height(get_theme_font_size(SNAME("font_size"))) + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM));
Size2 min_style = get_theme_stylebox(SNAME("normal"))->get_minimum_size();
if (autowrap_mode != AUTOWRAP_OFF) {
@@ -461,7 +489,7 @@ int Label::get_visible_line_count() const {
int lines_visible = 0;
float total_h = 0.0;
for (int64_t i = lines_skipped; i < lines_rid.size(); i++) {
- total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM) + line_spacing;
+ total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM) + line_spacing;
if (total_h > (get_size().height - style->get_minimum_size().height + line_spacing)) {
break;
}
@@ -624,6 +652,9 @@ void Label::set_visible_characters(int p_amount) {
} else {
percent_visible = 1.0;
}
+ if (p_amount == -1) {
+ lines_dirty = true;
+ }
update();
}
@@ -635,7 +666,7 @@ void Label::set_percent_visible(float p_percent) {
if (p_percent < 0 || p_percent >= 1) {
visible_chars = -1;
percent_visible = 1;
-
+ lines_dirty = true;
} else {
visible_chars = get_total_character_count() * p_percent;
percent_visible = p_percent;
@@ -793,7 +824,7 @@ void Label::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "valign", PROPERTY_HINT_ENUM, "Top,Center,Bottom,Fill"), "set_valign", "get_valign");
ADD_PROPERTY(PropertyInfo(Variant::INT, "autowrap_mode", PROPERTY_HINT_ENUM, "Off,Arbitrary,Word,Word (Smart)"), "set_autowrap_mode", "get_autowrap_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "is_clipping_text");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim nothing,Trim characters,Trim words,Ellipsis,Word ellipsis"), "set_text_overrun_behavior", "get_text_overrun_behavior");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis,Word Ellipsis"), "set_text_overrun_behavior", "get_text_overrun_behavior");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "uppercase"), "set_uppercase", "is_uppercase");
ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1", PROPERTY_USAGE_EDITOR), "set_visible_characters", "get_visible_characters");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible");
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 68e9171c15..d9acbeb828 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -216,7 +216,7 @@ void LineEdit::_delete(bool p_word, bool p_all_to_right) {
}
}
-void LineEdit::_gui_input(Ref<InputEvent> p_event) {
+void LineEdit::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
Ref<InputEventMouseButton> b = p_event;
@@ -577,8 +577,8 @@ void LineEdit::_notification(int p_what) {
#ifdef TOOLS_ENABLED
case NOTIFICATION_ENTER_TREE: {
if (Engine::get_singleton()->is_editor_hint() && !get_tree()->is_node_being_edited(this)) {
- set_caret_blink_enabled(EDITOR_DEF("text_editor/cursor/caret_blink", false));
- set_caret_blink_speed(EDITOR_DEF("text_editor/cursor/caret_blink_speed", 0.65));
+ set_caret_blink_enabled(EDITOR_DEF("text_editor/appearance/caret/caret_blink", false));
+ set_caret_blink_speed(EDITOR_DEF("text_editor/appearance/caret/caret_blink_speed", 0.65));
if (!EditorSettings::get_singleton()->is_connected("settings_changed", callable_mp(this, &LineEdit::_editor_settings_changed))) {
EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &LineEdit::_editor_settings_changed));
@@ -641,7 +641,7 @@ void LineEdit::_notification(int p_what) {
int x_ofs = 0;
bool using_placeholder = text.is_empty() && ime_text.is_empty();
float text_width = TS->shaped_text_get_size(text_rid).x;
- float text_height = TS->shaped_text_get_size(text_rid).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM);
+ float text_height = TS->shaped_text_get_size(text_rid).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM);
switch (align) {
case ALIGN_FILL:
@@ -674,7 +674,7 @@ void LineEdit::_notification(int p_what) {
int y_ofs = style->get_offset().y + (y_area - text_height) / 2;
Color selection_color = get_theme_color(SNAME("selection_color"));
- Color font_color = is_editable() ? get_theme_color(SNAME("font_color")) : get_theme_color(SNAME("font_uneditable_color"));
+ Color font_color = get_theme_color(is_editable() ? SNAME("font_color") : SNAME("font_uneditable_color"));
Color font_selected_color = get_theme_color(SNAME("font_selected_color"));
Color caret_color = get_theme_color(SNAME("caret_color"));
@@ -946,6 +946,17 @@ void LineEdit::paste_text() {
}
}
+bool LineEdit::has_undo() const {
+ if (undo_stack_pos == nullptr) {
+ return undo_stack.size() > 1;
+ }
+ return undo_stack_pos != undo_stack.front();
+}
+
+bool LineEdit::has_redo() const {
+ return undo_stack_pos != nullptr && undo_stack_pos != undo_stack.back();
+}
+
void LineEdit::undo() {
if (!editable) {
return;
@@ -1520,7 +1531,7 @@ Size2 LineEdit::get_minimum_size() const {
min_size.width = MAX(min_size.width, full_width + em_space_size);
}
- min_size.height = MAX(TS->shaped_text_get_size(text_rid).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM), font->get_height(font_size));
+ min_size.height = MAX(TS->shaped_text_get_size(text_rid).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM), font->get_height(font_size));
// Take icons into account.
bool using_placeholder = text.is_empty() && ime_text.is_empty();
@@ -1824,8 +1835,8 @@ PopupMenu *LineEdit::get_menu() const {
void LineEdit::_editor_settings_changed() {
#ifdef TOOLS_ENABLED
- set_caret_blink_enabled(EDITOR_DEF("text_editor/cursor/caret_blink", false));
- set_caret_blink_speed(EDITOR_DEF("text_editor/cursor/caret_blink_speed", 0.65));
+ set_caret_blink_enabled(EDITOR_DEF("text_editor/appearance/caret/caret_blink", false));
+ set_caret_blink_speed(EDITOR_DEF("text_editor/appearance/caret/caret_blink_speed", 0.65));
#endif
}
@@ -1930,6 +1941,7 @@ void LineEdit::_shape() {
const Ref<Font> &font = get_theme_font(SNAME("font"));
int font_size = get_theme_font_size(SNAME("font_size"));
+ ERR_FAIL_COND(font.is_null());
TS->shaped_text_add_string(text_rid, t, font->get_rids(), font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
TS->shaped_text_set_bidi_override(text_rid, structured_text_parser(st_parser, st_args, t));
@@ -2073,7 +2085,6 @@ void LineEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_align", "align"), &LineEdit::set_align);
ClassDB::bind_method(D_METHOD("get_align"), &LineEdit::get_align);
- ClassDB::bind_method(D_METHOD("_gui_input"), &LineEdit::_gui_input);
ClassDB::bind_method(D_METHOD("clear"), &LineEdit::clear);
ClassDB::bind_method(D_METHOD("select", "from", "to"), &LineEdit::select, DEFVAL(0), DEFVAL(-1));
ClassDB::bind_method(D_METHOD("select_all"), &LineEdit::select_all);
@@ -2209,7 +2220,7 @@ void LineEdit::_bind_methods() {
void LineEdit::_ensure_menu() {
if (!menu) {
menu = memnew(PopupMenu);
- add_child(menu);
+ add_child(menu, false, INTERNAL_MODE_FRONT);
menu_dir = memnew(PopupMenu);
menu_dir->set_name("DirMenu");
@@ -2277,6 +2288,11 @@ void LineEdit::_ensure_menu() {
menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_AUTO), text_direction == TEXT_DIRECTION_AUTO);
menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR);
menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_RTL), text_direction == TEXT_DIRECTION_RTL);
+
+ if (editable) {
+ menu->set_item_disabled(menu->get_item_index(MENU_UNDO), !has_undo());
+ menu->set_item_disabled(menu->get_item_index(MENU_REDO), !has_redo());
+ }
}
LineEdit::LineEdit() {
@@ -2289,7 +2305,7 @@ LineEdit::LineEdit() {
set_mouse_filter(MOUSE_FILTER_STOP);
caret_blink_timer = memnew(Timer);
- add_child(caret_blink_timer);
+ add_child(caret_blink_timer, false, INTERNAL_MODE_FRONT);
caret_blink_timer->set_wait_time(0.65);
caret_blink_timer->connect("timeout", callable_mp(this, &LineEdit::_toggle_draw_caret));
set_caret_blink_enabled(false);
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index c5c92d60aa..e364a79c83 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -202,7 +202,7 @@ private:
protected:
void _notification(int p_what);
static void _bind_methods();
- void _gui_input(Ref<InputEvent> p_event);
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
@@ -285,6 +285,8 @@ public:
void copy_text();
void cut_text();
void paste_text();
+ bool has_undo() const;
+ bool has_redo() const;
void undo();
void redo();
diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp
index 419d49bccf..925e6f5b97 100644
--- a/scene/gui/link_button.cpp
+++ b/scene/gui/link_button.cpp
@@ -41,12 +41,16 @@ void LinkButton::_shape() {
} else {
text_buf->set_direction((TextServer::Direction)text_direction);
}
- TS->shaped_text_set_bidi_override(text_buf->get_rid(), structured_text_parser(st_parser, st_args, text));
- text_buf->add_string(text, font, font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
+ TS->shaped_text_set_bidi_override(text_buf->get_rid(), structured_text_parser(st_parser, st_args, xl_text));
+ text_buf->add_string(xl_text, font, font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
}
void LinkButton::set_text(const String &p_text) {
+ if (text == p_text) {
+ return;
+ }
text = p_text;
+ xl_text = atr(text);
_shape();
minimum_size_changed();
update();
@@ -141,7 +145,13 @@ Size2 LinkButton::get_minimum_size() const {
void LinkButton::_notification(int p_what) {
switch (p_what) {
- case NOTIFICATION_TRANSLATION_CHANGED:
+ case NOTIFICATION_TRANSLATION_CHANGED: {
+ xl_text = atr(text);
+ _shape();
+
+ minimum_size_changed();
+ update();
+ } break;
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
update();
} break;
diff --git a/scene/gui/link_button.h b/scene/gui/link_button.h
index 7eaa9f88b6..231543c63c 100644
--- a/scene/gui/link_button.h
+++ b/scene/gui/link_button.h
@@ -47,6 +47,7 @@ public:
private:
String text;
+ String xl_text;
Ref<TextLine> text_buf;
UnderlineMode underline_mode = UNDERLINE_MODE_ALWAYS;
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index cf1f41d0fc..737ba84617 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -33,7 +33,7 @@
#include "core/os/keyboard.h"
#include "scene/main/window.h"
-void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) {
+void MenuButton::unhandled_key_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
if (!_is_focus_owner_in_shorcut_context()) {
@@ -44,7 +44,7 @@ void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) {
return;
}
- if (p_event->is_pressed() && !p_event->is_echo() && (Object::cast_to<InputEventKey>(p_event.ptr()) || Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventAction>(*p_event))) {
+ if (p_event->is_pressed() && !p_event->is_echo() && (Object::cast_to<InputEventKey>(p_event.ptr()) || Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventAction>(*p_event) || Object::cast_to<InputEventShortcut>(*p_event))) {
if (!get_parent() || !is_visible_in_tree() || is_disabled()) {
return;
}
@@ -86,6 +86,7 @@ void MenuButton::_popup_visibility_changed(bool p_visible) {
}
void MenuButton::pressed() {
+ emit_signal(SNAME("about_to_popup"));
Size2 size = get_size();
Point2 gp = get_screen_position();
@@ -99,8 +100,8 @@ void MenuButton::pressed() {
popup->popup();
}
-void MenuButton::_gui_input(Ref<InputEvent> p_event) {
- BaseButton::_gui_input(p_event);
+void MenuButton::gui_input(const Ref<InputEvent> &p_event) {
+ BaseButton::gui_input(p_event);
}
PopupMenu *MenuButton::get_popup() const {
@@ -171,7 +172,7 @@ MenuButton::MenuButton() {
popup = memnew(PopupMenu);
popup->hide();
- add_child(popup);
+ add_child(popup, false, INTERNAL_MODE_FRONT);
popup->connect("about_to_popup", callable_mp(this, &MenuButton::_popup_visibility_changed), varray(true));
popup->connect("popup_hide", callable_mp(this, &MenuButton::_popup_visibility_changed), varray(false));
}
diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h
index cc2ca117c4..730495b65d 100644
--- a/scene/gui/menu_button.h
+++ b/scene/gui/menu_button.h
@@ -47,14 +47,14 @@ class MenuButton : public Button {
Array _get_items() const;
void _set_items(const Array &p_items);
- void _gui_input(Ref<InputEvent> p_event) override;
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
void _popup_visibility_changed(bool p_visible);
protected:
void _notification(int p_what);
static void _bind_methods();
- virtual void _unhandled_key_input(Ref<InputEvent> p_event) override;
+ virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override;
public:
virtual void pressed() override;
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index cd55f258b3..d16e96dbec 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -351,7 +351,7 @@ OptionButton::OptionButton() {
popup = memnew(PopupMenu);
popup->hide();
- add_child(popup);
+ add_child(popup, false, INTERNAL_MODE_FRONT);
popup->connect("index_pressed", callable_mp(this, &OptionButton::_selected));
popup->connect("id_focused", callable_mp(this, &OptionButton::_focused));
popup->connect("popup_hide", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(false));
diff --git a/scene/gui/option_button.h b/scene/gui/option_button.h
index d846e395ad..953337ecce 100644
--- a/scene/gui/option_button.h
+++ b/scene/gui/option_button.h
@@ -56,6 +56,10 @@ protected:
static void _bind_methods();
public:
+ // ATTENTION: This is used by the POT generator's scene parser. If the number of properties returned by `_get_items()` ever changes,
+ // this value should be updated to reflect the new size.
+ static const int ITEM_PROPERTY_SIZE = 5;
+
void add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id = -1);
void add_item(const String &p_label, int p_id = -1);
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index f7e7e1cd60..e9414598a2 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -255,5 +255,5 @@ void PopupPanel::_notification(int p_what) {
PopupPanel::PopupPanel() {
panel = memnew(Panel);
- add_child(panel);
+ add_child(panel, false, INTERNAL_MODE_FRONT);
}
diff --git a/scene/gui/popup.h b/scene/gui/popup.h
index 0355405d7c..c7090e7231 100644
--- a/scene/gui/popup.h
+++ b/scene/gui/popup.h
@@ -35,6 +35,8 @@
#include "core/templates/local_vector.h"
+class Panel;
+
class Popup : public Window {
GDCLASS(Popup, Window);
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 44f7200cd7..c0a559e624 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -228,6 +228,7 @@ void PopupMenu::_activate_submenu(int p_over) {
// Set autohide areas
PopupMenu *submenu_pum = Object::cast_to<PopupMenu>(submenu_popup);
if (submenu_pum) {
+ submenu_pum->take_mouse_focus();
// Make the position of the parent popup relative to submenu popup
this_rect.position = this_rect.position - submenu_pum->get_position();
@@ -251,7 +252,7 @@ void PopupMenu::_submenu_timeout() {
submenu_over = -1;
}
-void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
+void PopupMenu::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
if (p_event->is_action("ui_down") && p_event->is_pressed()) {
@@ -358,9 +359,10 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
}
int button_idx = b->get_button_index();
- if (b->is_pressed() || (!b->is_pressed() && during_grabbed_click)) {
- // Allow activating item by releasing the LMB or any that was down when the popup appeared.
- // However, if button was not held when opening menu, do not allow release to activate item.
+ if (!b->is_pressed()) {
+ // Activate the item on release of either the left mouse button or
+ // any mouse button held down when the popup was opened.
+ // This allows for opening the popup and triggering an action in a single mouse click.
if (button_idx == MOUSE_BUTTON_LEFT || (initial_button_mask & (1 << (button_idx - 1)))) {
bool was_during_grabbed_click = during_grabbed_click;
during_grabbed_click = false;
@@ -1274,13 +1276,13 @@ int PopupMenu::get_item_count() const {
}
bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_for_global_only) {
- uint32_t code = 0;
+ Key code = KEY_NONE;
Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
code = k->get_keycode();
- if (code == 0) {
- code = k->get_unicode();
+ if (code == KEY_NONE) {
+ code = (Key)k->get_unicode();
}
if (k->is_ctrl_pressed()) {
code |= KEY_MASK_CTRL;
@@ -1580,8 +1582,6 @@ void PopupMenu::take_mouse_focus() {
}
void PopupMenu::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &PopupMenu::_gui_input);
-
ClassDB::bind_method(D_METHOD("add_item", "label", "id", "accel"), &PopupMenu::add_item, DEFVAL(-1), DEFVAL(0));
ClassDB::bind_method(D_METHOD("add_icon_item", "texture", "label", "id", "accel"), &PopupMenu::add_icon_item, DEFVAL(-1), DEFVAL(0));
ClassDB::bind_method(D_METHOD("add_check_item", "label", "id", "accel"), &PopupMenu::add_check_item, DEFVAL(-1), DEFVAL(0));
@@ -1690,7 +1690,7 @@ PopupMenu::PopupMenu() {
// Margin Container
margin_container = memnew(MarginContainer);
margin_container->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
- add_child(margin_container);
+ add_child(margin_container, false, INTERNAL_MODE_FRONT);
margin_container->connect("draw", callable_mp(this, &PopupMenu::_draw_background));
// Scroll Container
@@ -1704,22 +1704,22 @@ PopupMenu::PopupMenu() {
control->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
control->set_h_size_flags(Control::SIZE_EXPAND_FILL);
control->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- scroll_container->add_child(control);
+ scroll_container->add_child(control, false, INTERNAL_MODE_FRONT);
control->connect("draw", callable_mp(this, &PopupMenu::_draw_items));
- connect("window_input", callable_mp(this, &PopupMenu::_gui_input));
+ connect("window_input", callable_mp(this, &PopupMenu::gui_input));
submenu_timer = memnew(Timer);
submenu_timer->set_wait_time(0.3);
submenu_timer->set_one_shot(true);
submenu_timer->connect("timeout", callable_mp(this, &PopupMenu::_submenu_timeout));
- add_child(submenu_timer);
+ add_child(submenu_timer, false, INTERNAL_MODE_FRONT);
minimum_lifetime_timer = memnew(Timer);
minimum_lifetime_timer->set_wait_time(0.3);
minimum_lifetime_timer->set_one_shot(true);
minimum_lifetime_timer->connect("timeout", callable_mp(this, &PopupMenu::_minimum_lifetime_timeout));
- add_child(minimum_lifetime_timer);
+ add_child(minimum_lifetime_timer, false, INTERNAL_MODE_FRONT);
}
PopupMenu::~PopupMenu() {
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index aedc5d0155..428076c6da 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -31,10 +31,10 @@
#ifndef POPUP_MENU_H
#define POPUP_MENU_H
+#include "core/input/shortcut.h"
#include "scene/gui/margin_container.h"
#include "scene/gui/popup.h"
#include "scene/gui/scroll_container.h"
-#include "scene/gui/shortcut.h"
#include "scene/resources/text_line.h"
class PopupMenu : public Popup {
@@ -107,7 +107,7 @@ class PopupMenu : public Popup {
void _shape_item(int p_item);
- void _gui_input(const Ref<InputEvent> &p_event);
+ virtual void gui_input(const Ref<InputEvent> &p_event);
void _activate_submenu(int p_over);
void _submenu_timeout();
@@ -144,6 +144,10 @@ protected:
static void _bind_methods();
public:
+ // ATTENTION: This is used by the POT generator's scene parser. If the number of properties returned by `_get_items()` ever changes,
+ // this value should be updated to reflect the new size.
+ static const int ITEM_PROPERTY_SIZE = 10;
+
void add_item(const String &p_label, int p_id = -1, uint32_t p_accel = 0);
void add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id = -1, uint32_t p_accel = 0);
void add_check_item(const String &p_label, int p_id = -1, uint32_t p_accel = 0);
diff --git a/scene/gui/rich_text_effect.cpp b/scene/gui/rich_text_effect.cpp
index 39718a269a..236d106af8 100644
--- a/scene/gui/rich_text_effect.cpp
+++ b/scene/gui/rich_text_effect.cpp
@@ -32,8 +32,15 @@
#include "core/object/script_language.h"
-void RichTextEffect::_bind_methods() {
- BIND_VMETHOD(MethodInfo(Variant::BOOL, "_process_custom_fx", PropertyInfo(Variant::OBJECT, "char_fx", PROPERTY_HINT_RESOURCE_TYPE, "CharFXTransform")));
+CharFXTransform::CharFXTransform() {
+}
+
+CharFXTransform::~CharFXTransform() {
+ environment.clear();
+}
+
+void RichTextEffect::_bind_methods(){
+ GDVIRTUAL_BIND(_process_custom_fx, "char_fx")
}
Variant RichTextEffect::get_bbcode() const {
@@ -49,15 +56,10 @@ Variant RichTextEffect::get_bbcode() const {
bool RichTextEffect::_process_effect_impl(Ref<CharFXTransform> p_cfx) {
bool return_value = false;
- if (get_script_instance()) {
- Variant v = get_script_instance()->call("_process_custom_fx", p_cfx);
- if (v.get_type() != Variant::BOOL) {
- return_value = false;
- } else {
- return_value = (bool)v;
- }
+ if (GDVIRTUAL_CALL(_process_custom_fx, p_cfx, return_value)) {
+ return return_value;
}
- return return_value;
+ return false;
}
RichTextEffect::RichTextEffect() {
@@ -101,10 +103,3 @@ void CharFXTransform::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "glyph_index"), "set_glyph_index", "get_glyph_index");
ADD_PROPERTY(PropertyInfo(Variant::RID, "font"), "set_font", "get_font");
}
-
-CharFXTransform::CharFXTransform() {
-}
-
-CharFXTransform::~CharFXTransform() {
- environment.clear();
-}
diff --git a/scene/gui/rich_text_effect.h b/scene/gui/rich_text_effect.h
index 67323e7f93..f5506542bb 100644
--- a/scene/gui/rich_text_effect.h
+++ b/scene/gui/rich_text_effect.h
@@ -32,20 +32,8 @@
#define RICH_TEXT_EFFECT_H
#include "core/io/resource.h"
-
-class RichTextEffect : public Resource {
- GDCLASS(RichTextEffect, Resource);
- OBJ_SAVE_TYPE(RichTextEffect);
-
-protected:
- static void _bind_methods();
-
-public:
- Variant get_bbcode() const;
- bool _process_effect_impl(Ref<class CharFXTransform> p_cfx);
-
- RichTextEffect();
-};
+#include "core/object/gdvirtual.gen.inc"
+#include "core/object/script_language.h"
class CharFXTransform : public RefCounted {
GDCLASS(CharFXTransform, RefCounted);
@@ -61,7 +49,7 @@ public:
Color color;
double elapsed_time = 0.0f;
Dictionary environment;
- uint32_t glpyh_index = 0;
+ uint32_t glyph_index = 0;
RID font;
CharFXTransform();
@@ -80,8 +68,8 @@ public:
Color get_color() { return color; }
void set_color(Color p_color) { color = p_color; }
- uint32_t get_glyph_index() const { return glpyh_index; };
- void set_glyph_index(uint32_t p_glpyh_index) { glpyh_index = p_glpyh_index; };
+ uint32_t get_glyph_index() const { return glyph_index; };
+ void set_glyph_index(uint32_t p_glyph_index) { glyph_index = p_glyph_index; };
RID get_font() const { return font; };
void set_font(RID p_font) { font = p_font; };
@@ -89,4 +77,20 @@ public:
void set_environment(Dictionary p_environment) { environment = p_environment; }
};
+class RichTextEffect : public Resource {
+ GDCLASS(RichTextEffect, Resource);
+ OBJ_SAVE_TYPE(RichTextEffect);
+
+protected:
+ static void _bind_methods();
+
+ GDVIRTUAL1RC(bool, _process_custom_fx, Ref<CharFXTransform>)
+
+public:
+ Variant get_bbcode() const;
+ bool _process_effect_impl(Ref<class CharFXTransform> p_cfx);
+
+ RichTextEffect();
+};
+
#endif // RICH_TEXT_EFFECT_H
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index cf2a1481a1..aeadfd78ee 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -874,7 +874,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
charfx->visibility = visible;
charfx->outline = true;
charfx->font = frid;
- charfx->glpyh_index = gl;
+ charfx->glyph_index = gl;
charfx->offset = fx_offset;
charfx->color = font_color;
@@ -884,7 +884,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
fx_offset += charfx->offset;
font_color = charfx->color;
frid = charfx->font;
- gl = charfx->glpyh_index;
+ gl = charfx->glyph_index;
visible &= charfx->visibility;
}
} else if (item_fx->type == ITEM_SHAKE) {
@@ -1026,7 +1026,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
charfx->visibility = visible;
charfx->outline = false;
charfx->font = frid;
- charfx->glpyh_index = gl;
+ charfx->glyph_index = gl;
charfx->offset = fx_offset;
charfx->color = font_color;
@@ -1036,7 +1036,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
fx_offset += charfx->offset;
font_color = charfx->color;
frid = charfx->font;
- gl = charfx->glpyh_index;
+ gl = charfx->glyph_index;
visible &= charfx->visibility;
}
} else if (item_fx->type == ITEM_SHAKE) {
@@ -1127,7 +1127,7 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
Point2 ofs = text_rect.get_position() + Vector2(0, main->lines[from_line].offset.y - vofs);
while (ofs.y < size.height && from_line < main->lines.size()) {
_find_click_in_line(p_frame, from_line, ofs, text_rect.size.x, p_click, r_click_frame, r_click_line, r_click_item, r_click_char);
- ofs.y += main->lines[from_line].text_buf->get_size().y;
+ ofs.y += main->lines[from_line].text_buf->get_size().y + get_theme_constant(SNAME("line_separation"));
if (((r_click_item != nullptr) && ((*r_click_item) != nullptr)) || ((r_click_frame != nullptr) && ((*r_click_frame) != nullptr))) {
if (r_outside != nullptr) {
*r_outside = false;
@@ -1435,7 +1435,7 @@ void RichTextLabel::_notification(int p_what) {
while (ofs.y < size.height && from_line < main->lines.size()) {
visible_paragraph_count++;
visible_line_count += _draw_line(main, from_line, ofs, text_rect.size.x, base_color, outline_size, outline_color, font_shadow_color, use_outline, shadow_ofs);
- ofs.y += main->lines[from_line].text_buf->get_size().y;
+ ofs.y += main->lines[from_line].text_buf->get_size().y + get_theme_constant(SNAME("line_separation"));
from_line++;
}
} break;
@@ -1451,7 +1451,7 @@ void RichTextLabel::_notification(int p_what) {
Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const {
if (!underline_meta) {
- return CURSOR_ARROW;
+ return get_default_cursor_shape();
}
if (selection.click_item) {
@@ -1459,11 +1459,11 @@ Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const
}
if (main->first_invalid_line < main->lines.size()) {
- return CURSOR_ARROW; //invalid
+ return get_default_cursor_shape(); //invalid
}
if (main->first_resized_line < main->lines.size()) {
- return CURSOR_ARROW; //invalid
+ return get_default_cursor_shape(); //invalid
}
Item *item = nullptr;
@@ -1474,10 +1474,10 @@ Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const
return CURSOR_POINTING_HAND;
}
- return CURSOR_ARROW;
+ return get_default_cursor_shape();
}
-void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
+void RichTextLabel::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
Ref<InputEventMouseButton> b = p_event;
@@ -3946,24 +3946,15 @@ float RichTextLabel::get_percent_visible() const {
return percent_visible;
}
-void RichTextLabel::set_effects(const Vector<Variant> &effects) {
- custom_effects.clear();
- for (int i = 0; i < effects.size(); i++) {
- Ref<RichTextEffect> effect = Ref<RichTextEffect>(effects[i]);
- custom_effects.push_back(effect);
- }
-
+void RichTextLabel::set_effects(Array p_effects) {
+ custom_effects = p_effects;
if ((bbcode != "") && use_bbcode) {
parse_bbcode(bbcode);
}
}
-Vector<Variant> RichTextLabel::get_effects() {
- Vector<Variant> r;
- for (int i = 0; i < custom_effects.size(); i++) {
- r.push_back(custom_effects[i]);
- }
- return r;
+Array RichTextLabel::get_effects() {
+ return custom_effects;
}
void RichTextLabel::install_effect(const Variant effect) {
@@ -3993,7 +3984,6 @@ void RichTextLabel::_validate_property(PropertyInfo &property) const {
}
void RichTextLabel::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &RichTextLabel::_gui_input);
ClassDB::bind_method(D_METHOD("get_text"), &RichTextLabel::get_text);
ClassDB::bind_method(D_METHOD("add_text", "text"), &RichTextLabel::add_text);
ClassDB::bind_method(D_METHOD("set_text", "text"), &RichTextLabel::set_text);
@@ -4280,12 +4270,13 @@ void RichTextLabel::_draw_fbg_boxes(RID p_ci, RID p_rid, Vector2 line_off, Item
Ref<RichTextEffect> RichTextLabel::_get_custom_effect_by_code(String p_bbcode_identifier) {
for (int i = 0; i < custom_effects.size(); i++) {
- if (!custom_effects[i].is_valid()) {
+ Ref<RichTextEffect> effect = custom_effects[i];
+ if (!effect.is_valid()) {
continue;
}
- if (custom_effects[i]->get_bbcode() == p_bbcode_identifier) {
- return custom_effects[i];
+ if (effect->get_bbcode() == p_bbcode_identifier) {
+ return effect;
}
}
@@ -4362,7 +4353,7 @@ RichTextLabel::RichTextLabel() {
current_frame = main;
vscroll = memnew(VScrollBar);
- add_child(vscroll);
+ add_child(vscroll, false, INTERNAL_MODE_FRONT);
vscroll->set_drag_node(String(".."));
vscroll->set_step(1);
vscroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index 28dfe74b08..f25a8bf193 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -363,7 +363,7 @@ private:
ItemMeta *meta_hovering = nullptr;
Variant current_meta;
- Vector<Ref<RichTextEffect>> custom_effects;
+ Array custom_effects;
void _invalidate_current_line(ItemFrame *p_frame);
void _validate_line_caches(ItemFrame *p_frame);
@@ -443,7 +443,7 @@ private:
void _update_fx(ItemFrame *p_frame, double p_delta_time);
void _scroll_changed(double);
- void _gui_input(Ref<InputEvent> p_event);
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
Item *_get_next_item(Item *p_item, bool p_free = false) const;
Item *_get_prev_item(Item *p_item, bool p_free = false) const;
@@ -577,8 +577,8 @@ public:
void set_percent_visible(float p_percent);
float get_percent_visible() const;
- void set_effects(const Vector<Variant> &effects);
- Vector<Variant> get_effects();
+ void set_effects(Array p_effects);
+ Array get_effects();
void install_effect(const Variant effect);
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp
index ce04a0204b..08bcb0bdda 100644
--- a/scene/gui/scroll_bar.cpp
+++ b/scene/gui/scroll_bar.cpp
@@ -41,7 +41,7 @@ void ScrollBar::set_can_focus_by_default(bool p_can_focus) {
focus_by_default = p_can_focus;
}
-void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
+void ScrollBar::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
Ref<InputEventMouseMotion> m = p_event;
@@ -597,7 +597,6 @@ bool ScrollBar::is_smooth_scroll_enabled() const {
}
void ScrollBar::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &ScrollBar::_gui_input);
ClassDB::bind_method(D_METHOD("set_custom_step", "step"), &ScrollBar::set_custom_step);
ClassDB::bind_method(D_METHOD("get_custom_step"), &ScrollBar::get_custom_step);
diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h
index 24b3b33e82..fbc035397f 100644
--- a/scene/gui/scroll_bar.h
+++ b/scene/gui/scroll_bar.h
@@ -86,7 +86,7 @@ class ScrollBar : public Range {
void _drag_node_exit();
void _drag_node_input(const Ref<InputEvent> &p_input);
- void _gui_input(Ref<InputEvent> p_event);
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
protected:
void _notification(int p_what);
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index eb5fc924da..0c051f61e2 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -83,7 +83,7 @@ void ScrollContainer::_cancel_drag() {
}
}
-void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
+void ScrollContainer::gui_input(const Ref<InputEvent> &p_gui_input) {
ERR_FAIL_COND(p_gui_input.is_null());
double prev_v_scroll = v_scroll->get_value();
@@ -228,9 +228,6 @@ void ScrollContainer::_update_scrollbar_position() {
v_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);
v_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
- h_scroll->raise();
- v_scroll->raise();
-
_updating_scrollbars = false;
}
@@ -568,7 +565,6 @@ VScrollBar *ScrollContainer::get_v_scrollbar() {
}
void ScrollContainer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &ScrollContainer::_gui_input);
ClassDB::bind_method(D_METHOD("_update_scrollbar_position"), &ScrollContainer::_update_scrollbar_position);
ClassDB::bind_method(D_METHOD("set_h_scroll", "value"), &ScrollContainer::set_h_scroll);
@@ -619,12 +615,12 @@ void ScrollContainer::_bind_methods() {
ScrollContainer::ScrollContainer() {
h_scroll = memnew(HScrollBar);
h_scroll->set_name("_h_scroll");
- add_child(h_scroll);
+ add_child(h_scroll, false, INTERNAL_MODE_BACK);
h_scroll->connect("value_changed", callable_mp(this, &ScrollContainer::_scroll_moved));
v_scroll = memnew(VScrollBar);
v_scroll->set_name("_v_scroll");
- add_child(v_scroll);
+ add_child(v_scroll, false, INTERNAL_MODE_BACK);
v_scroll->connect("value_changed", callable_mp(this, &ScrollContainer::_scroll_moved));
deadzone = GLOBAL_GET("gui/common/default_scroll_deadzone");
diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.h
index 4733fdabca..9f4ec558dc 100644
--- a/scene/gui/scroll_container.h
+++ b/scene/gui/scroll_container.h
@@ -68,7 +68,7 @@ class ScrollContainer : public Container {
protected:
Size2 get_minimum_size() const override;
- void _gui_input(const Ref<InputEvent> &p_gui_input);
+ virtual void gui_input(const Ref<InputEvent> &p_gui_input) override;
void _gui_focus_changed(Control *p_control);
void _update_dimensions();
void _notification(int p_what);
diff --git a/scene/gui/shortcut.cpp b/scene/gui/shortcut.cpp
deleted file mode 100644
index 885a51e058..0000000000
--- a/scene/gui/shortcut.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/*************************************************************************/
-/* shortcut.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#include "shortcut.h"
-
-#include "core/os/keyboard.h"
-
-void Shortcut::set_event(const Ref<InputEvent> &p_event) {
- event = p_event;
- emit_changed();
-}
-
-Ref<InputEvent> Shortcut::get_event() const {
- return event;
-}
-
-bool Shortcut::matches_event(const Ref<InputEvent> &p_event) const {
- return event.is_valid() && event->is_match(p_event, true);
-}
-
-String Shortcut::get_as_text() const {
- if (event.is_valid()) {
- return event->as_text();
- } else {
- return "None";
- }
-}
-
-bool Shortcut::has_valid_event() const {
- return event.is_valid();
-}
-
-void Shortcut::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_event", "event"), &Shortcut::set_event);
- ClassDB::bind_method(D_METHOD("get_event"), &Shortcut::get_event);
-
- ClassDB::bind_method(D_METHOD("has_valid_event"), &Shortcut::has_valid_event);
-
- ClassDB::bind_method(D_METHOD("matches_event", "event"), &Shortcut::matches_event);
- ClassDB::bind_method(D_METHOD("get_as_text"), &Shortcut::get_as_text);
-
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), "set_event", "get_event");
-}
diff --git a/scene/gui/shortcut.h b/scene/gui/shortcut.h
deleted file mode 100644
index 249dd1971f..0000000000
--- a/scene/gui/shortcut.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*************************************************************************/
-/* shortcut.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#ifndef SHORTCUT_H
-#define SHORTCUT_H
-
-#include "core/input/input_event.h"
-#include "core/io/resource.h"
-
-class Shortcut : public Resource {
- GDCLASS(Shortcut, Resource);
-
- Ref<InputEvent> event;
-
-protected:
- static void _bind_methods();
-
-public:
- void set_event(const Ref<InputEvent> &p_shortcut);
- Ref<InputEvent> get_event() const;
- bool matches_event(const Ref<InputEvent> &p_event) const;
- bool has_valid_event() const;
-
- String get_as_text() const;
-};
-
-#endif // SHORTCUT_H
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index 61b5325175..352f87954e 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -45,7 +45,7 @@ Size2 Slider::get_minimum_size() const {
}
}
-void Slider::_gui_input(Ref<InputEvent> p_event) {
+void Slider::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
if (!editable) {
@@ -253,7 +253,6 @@ bool Slider::is_scrollable() const {
}
void Slider::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &Slider::_gui_input);
ClassDB::bind_method(D_METHOD("set_ticks", "count"), &Slider::set_ticks);
ClassDB::bind_method(D_METHOD("get_ticks"), &Slider::get_ticks);
diff --git a/scene/gui/slider.h b/scene/gui/slider.h
index 65a4036cd1..46fa08bbf0 100644
--- a/scene/gui/slider.h
+++ b/scene/gui/slider.h
@@ -50,7 +50,7 @@ class Slider : public Range {
bool scrollable = true;
protected:
- void _gui_input(Ref<InputEvent> p_event);
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
void _notification(int p_what);
static void _bind_methods();
bool ticks_on_borders = false;
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index 3f0368a4e2..1074d0d8a0 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -99,7 +99,7 @@ void SpinBox::_release_mouse() {
}
}
-void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
+void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
if (!is_editable()) {
@@ -258,7 +258,7 @@ void SpinBox::apply() {
void SpinBox::_bind_methods() {
//ClassDB::bind_method(D_METHOD("_value_changed"),&SpinBox::_value_changed);
- ClassDB::bind_method(D_METHOD("_gui_input"), &SpinBox::_gui_input);
+
ClassDB::bind_method(D_METHOD("set_align", "align"), &SpinBox::set_align);
ClassDB::bind_method(D_METHOD("get_align"), &SpinBox::get_align);
ClassDB::bind_method(D_METHOD("set_suffix", "suffix"), &SpinBox::set_suffix);
@@ -278,7 +278,7 @@ void SpinBox::_bind_methods() {
SpinBox::SpinBox() {
line_edit = memnew(LineEdit);
- add_child(line_edit);
+ add_child(line_edit, false, INTERNAL_MODE_FRONT);
line_edit->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
line_edit->set_mouse_filter(MOUSE_FILTER_PASS);
@@ -291,5 +291,5 @@ SpinBox::SpinBox() {
range_click_timer = memnew(Timer);
range_click_timer->connect("timeout", callable_mp(this, &SpinBox::_range_click_timeout));
- add_child(range_click_timer);
+ add_child(range_click_timer, false, INTERNAL_MODE_FRONT);
}
diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h
index fb10379296..9ec3885f1f 100644
--- a/scene/gui/spin_box.h
+++ b/scene/gui/spin_box.h
@@ -65,7 +65,7 @@ class SpinBox : public Range {
inline void _adjust_width_for_icon(const Ref<Texture2D> &icon);
protected:
- void _gui_input(const Ref<InputEvent> &p_event);
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
void _notification(int p_what);
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index 3114e5b7c0..4736a1ad37 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -206,7 +206,7 @@ void SplitContainer::_notification(int p_what) {
}
}
-void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
+void SplitContainer::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility != DRAGGER_VISIBLE) {
@@ -337,8 +337,6 @@ bool SplitContainer::is_collapsed() const {
}
void SplitContainer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &SplitContainer::_gui_input);
-
ClassDB::bind_method(D_METHOD("set_split_offset", "offset"), &SplitContainer::set_split_offset);
ClassDB::bind_method(D_METHOD("get_split_offset"), &SplitContainer::get_split_offset);
ClassDB::bind_method(D_METHOD("clamp_split_offset"), &SplitContainer::clamp_split_offset);
diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h
index 6cb94d6ecf..47fd30a122 100644
--- a/scene/gui/split_container.h
+++ b/scene/gui/split_container.h
@@ -60,7 +60,7 @@ private:
void _resort();
protected:
- void _gui_input(const Ref<InputEvent> &p_event);
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/gui/subviewport_container.cpp b/scene/gui/subviewport_container.cpp
index bfc7e29f9c..53ea32e1b7 100644
--- a/scene/gui/subviewport_container.cpp
+++ b/scene/gui/subviewport_container.cpp
@@ -139,7 +139,7 @@ void SubViewportContainer::_notification(int p_what) {
}
}
-void SubViewportContainer::_input(const Ref<InputEvent> &p_event) {
+void SubViewportContainer::input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
if (Engine::get_singleton()->is_editor_hint()) {
@@ -162,11 +162,11 @@ void SubViewportContainer::_input(const Ref<InputEvent> &p_event) {
continue;
}
- c->input(ev);
+ c->push_input(ev);
}
}
-void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
+void SubViewportContainer::unhandled_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
if (Engine::get_singleton()->is_editor_hint()) {
@@ -189,13 +189,11 @@ void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) {
continue;
}
- c->unhandled_input(ev);
+ c->push_unhandled_input(ev);
}
}
void SubViewportContainer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &SubViewportContainer::_unhandled_input);
- ClassDB::bind_method(D_METHOD("_input", "event"), &SubViewportContainer::_input);
ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &SubViewportContainer::set_stretch);
ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &SubViewportContainer::is_stretch_enabled);
diff --git a/scene/gui/subviewport_container.h b/scene/gui/subviewport_container.h
index 77cf4c16b3..7853f1590e 100644
--- a/scene/gui/subviewport_container.h
+++ b/scene/gui/subviewport_container.h
@@ -47,8 +47,8 @@ public:
void set_stretch(bool p_enable);
bool is_stretch_enabled() const;
- void _input(const Ref<InputEvent> &p_event);
- void _unhandled_input(const Ref<InputEvent> &p_event);
+ virtual void input(const Ref<InputEvent> &p_event) override;
+ virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
void set_stretch_shrink(int p_shrink);
int get_stretch_shrink() const;
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index cc41d961f6..137ce7e96f 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -71,7 +71,7 @@ int TabContainer::_get_top_margin() const {
return tab_height + content_height;
}
-void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
+void TabContainer::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
Ref<InputEventMouseButton> mb = p_event;
@@ -434,14 +434,14 @@ void TabContainer::_notification(int p_what) {
}
int tab_width = tab_widths[i];
- if (get_tab_disabled(index)) {
+ if (index == current) {
+ x_current = x;
+ } else if (get_tab_disabled(index)) {
if (rtl) {
_draw_tab(tab_disabled, font_disabled_color, index, size.width - (tabs_ofs_cache + x) - tab_width);
} else {
_draw_tab(tab_disabled, font_disabled_color, index, tabs_ofs_cache + x);
}
- } else if (index == current) {
- x_current = x;
} else {
if (rtl) {
_draw_tab(tab_unselected, font_unselected_color, index, size.width - (tabs_ofs_cache + x) - tab_width);
@@ -459,12 +459,13 @@ void TabContainer::_notification(int p_what) {
panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height));
}
- // Draw selected tab in front. only draw selected tab when it's in visible range.
+ // Draw selected tab in front. Only draw selected tab when it's in visible range.
if (tabs.size() > 0 && current - first_tab_cache < tab_widths.size() && current >= first_tab_cache) {
+ Ref<StyleBox> current_style_box = get_tab_disabled(current) ? tab_disabled : tab_selected;
if (rtl) {
- _draw_tab(tab_selected, font_selected_color, current, size.width - (tabs_ofs_cache + x_current) - tab_widths[current]);
+ _draw_tab(current_style_box, font_selected_color, current, size.width - (tabs_ofs_cache + x_current) - tab_widths[current]);
} else {
- _draw_tab(tab_selected, font_selected_color, current, tabs_ofs_cache + x_current);
+ _draw_tab(current_style_box, font_selected_color, current, tabs_ofs_cache + x_current);
}
}
@@ -535,7 +536,7 @@ void TabContainer::_notification(int p_what) {
}
void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, int p_index, float p_x) {
- Vector<Control *> tabs = _get_tabs();
+ Control *control = get_tab_control(p_index);
RID canvas = get_canvas_item();
Ref<Font> font = get_theme_font(SNAME("font"));
Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
@@ -549,7 +550,6 @@ void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, in
p_tab_style->draw(canvas, tab_rect);
// Draw the tab contents.
- Control *control = Object::cast_to<Control>(tabs[p_index]);
String text = control->has_meta("_tab_name") ? String(atr(String(control->get_meta("_tab_name")))) : String(atr(control->get_name()));
int x_content = tab_rect.position.x + p_tab_style->get_margin(SIDE_LEFT);
@@ -620,10 +620,10 @@ void TabContainer::_repaint() {
if (tabs_visible) {
c->set_offset(SIDE_TOP, _get_top_margin());
}
- c->set_offset(Side(SIDE_TOP), c->get_offset(Side(SIDE_TOP)) + sb->get_margin(Side(SIDE_TOP)));
- c->set_offset(Side(SIDE_LEFT), c->get_offset(Side(SIDE_LEFT)) + sb->get_margin(Side(SIDE_LEFT)));
- c->set_offset(Side(SIDE_RIGHT), c->get_offset(Side(SIDE_RIGHT)) - sb->get_margin(Side(SIDE_RIGHT)));
- c->set_offset(Side(SIDE_BOTTOM), c->get_offset(Side(SIDE_BOTTOM)) - sb->get_margin(Side(SIDE_BOTTOM)));
+ c->set_offset(SIDE_TOP, c->get_offset(SIDE_TOP) + sb->get_margin(SIDE_TOP));
+ c->set_offset(SIDE_LEFT, c->get_offset(SIDE_LEFT) + sb->get_margin(SIDE_LEFT));
+ c->set_offset(SIDE_RIGHT, c->get_offset(SIDE_RIGHT) - sb->get_margin(SIDE_RIGHT));
+ c->set_offset(SIDE_BOTTOM, c->get_offset(SIDE_BOTTOM) - sb->get_margin(SIDE_BOTTOM));
} else {
c->hide();
@@ -641,8 +641,8 @@ void TabContainer::_on_mouse_exited() {
int TabContainer::_get_tab_width(int p_index) const {
ERR_FAIL_INDEX_V(p_index, get_tab_count(), 0);
- Control *control = Object::cast_to<Control>(_get_tabs()[p_index]);
- if (!control || control->is_set_as_top_level() || get_tab_hidden(p_index)) {
+ Control *control = get_tab_control(p_index);
+ if (!control || get_tab_hidden(p_index)) {
return 0;
}
@@ -682,7 +682,7 @@ Vector<Control *> TabContainer::_get_tabs() const {
Vector<Control *> controls;
for (int i = 0; i < get_child_count(); i++) {
Control *control = Object::cast_to<Control>(get_child(i));
- if (!control || control->is_top_level_control()) {
+ if (!control || control->is_set_as_top_level()) {
continue;
}
@@ -700,10 +700,7 @@ void TabContainer::add_child_notify(Node *p_child) {
Container::add_child_notify(p_child);
Control *c = Object::cast_to<Control>(p_child);
- if (!c) {
- return;
- }
- if (c->is_set_as_top_level()) {
+ if (!c || c->is_set_as_top_level()) {
return;
}
@@ -726,10 +723,10 @@ void TabContainer::add_child_notify(Node *p_child) {
c->set_offset(SIDE_TOP, _get_top_margin());
}
Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel"));
- c->set_offset(Side(SIDE_TOP), c->get_offset(Side(SIDE_TOP)) + sb->get_margin(Side(SIDE_TOP)));
- c->set_offset(Side(SIDE_LEFT), c->get_offset(Side(SIDE_LEFT)) + sb->get_margin(Side(SIDE_LEFT)));
- c->set_offset(Side(SIDE_RIGHT), c->get_offset(Side(SIDE_RIGHT)) - sb->get_margin(Side(SIDE_RIGHT)));
- c->set_offset(Side(SIDE_BOTTOM), c->get_offset(Side(SIDE_BOTTOM)) - sb->get_margin(Side(SIDE_BOTTOM)));
+ c->set_offset(SIDE_TOP, c->get_offset(SIDE_TOP) + sb->get_margin(SIDE_TOP));
+ c->set_offset(SIDE_LEFT, c->get_offset(SIDE_LEFT) + sb->get_margin(SIDE_LEFT));
+ c->set_offset(SIDE_RIGHT, c->get_offset(SIDE_RIGHT) - sb->get_margin(SIDE_RIGHT));
+ c->set_offset(SIDE_BOTTOM, c->get_offset(SIDE_BOTTOM) - sb->get_margin(SIDE_BOTTOM));
update();
p_child->connect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback));
if (first && is_inside_tree()) {
@@ -739,8 +736,13 @@ void TabContainer::add_child_notify(Node *p_child) {
void TabContainer::move_child_notify(Node *p_child) {
Container::move_child_notify(p_child);
- call_deferred(SNAME("_update_current_tab"));
- _refresh_texts();
+
+ Control *c = Object::cast_to<Control>(p_child);
+ if (!c || c->is_set_as_top_level()) {
+ return;
+ }
+
+ _update_current_tab();
update();
}
@@ -785,21 +787,18 @@ Control *TabContainer::get_tab_control(int p_idx) const {
}
Control *TabContainer::get_current_tab_control() const {
- Vector<Control *> tabs = _get_tabs();
- if (current >= 0 && current < tabs.size()) {
- return tabs[current];
- } else {
- return nullptr;
- }
+ return get_tab_control(current);
}
void TabContainer::remove_child_notify(Node *p_child) {
Container::remove_child_notify(p_child);
- if (!Object::cast_to<Control>(p_child)) {
+ Control *c = Object::cast_to<Control>(p_child);
+ if (!c || c->is_set_as_top_level()) {
return;
}
+ // Defer the call because tab is not yet removed (remove_child_notify is called right before p_child is actually removed).
call_deferred(SNAME("_update_current_tab"));
p_child->disconnect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback));
@@ -808,10 +807,9 @@ void TabContainer::remove_child_notify(Node *p_child) {
}
void TabContainer::_update_current_tab() {
- Vector<Control *> tabs = _get_tabs();
_refresh_texts();
- int tc = tabs.size();
+ int tc = get_tab_count();
if (current >= tc) {
current = tc - 1;
}
@@ -908,7 +906,7 @@ void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
if (from_tabc && from_tabc->get_tabs_rearrange_group() == get_tabs_rearrange_group()) {
Control *moving_tabc = from_tabc->get_tab_control(tab_from_id);
from_tabc->remove_child(moving_tabc);
- add_child(moving_tabc);
+ add_child(moving_tabc, false, INTERNAL_MODE_FRONT);
if (hover_now < 0) {
hover_now = get_tab_count() - 1;
}
@@ -1019,12 +1017,8 @@ bool TabContainer::is_all_tabs_in_front() const {
return all_tabs_in_front;
}
-Control *TabContainer::_get_tab(int p_idx) const {
- return get_tab_control(p_idx);
-}
-
void TabContainer::set_tab_title(int p_tab, const String &p_title) {
- Control *child = _get_tab(p_tab);
+ Control *child = get_tab_control(p_tab);
ERR_FAIL_COND(!child);
child->set_meta("_tab_name", p_title);
_refresh_texts();
@@ -1032,7 +1026,7 @@ void TabContainer::set_tab_title(int p_tab, const String &p_title) {
}
String TabContainer::get_tab_title(int p_tab) const {
- Control *child = _get_tab(p_tab);
+ Control *child = get_tab_control(p_tab);
ERR_FAIL_COND_V(!child, "");
if (child->has_meta("_tab_name")) {
return child->get_meta("_tab_name");
@@ -1042,14 +1036,14 @@ String TabContainer::get_tab_title(int p_tab) const {
}
void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) {
- Control *child = _get_tab(p_tab);
+ Control *child = get_tab_control(p_tab);
ERR_FAIL_COND(!child);
child->set_meta("_tab_icon", p_icon);
update();
}
Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const {
- Control *child = _get_tab(p_tab);
+ Control *child = get_tab_control(p_tab);
ERR_FAIL_COND_V(!child, Ref<Texture2D>());
if (child->has_meta("_tab_icon")) {
return child->get_meta("_tab_icon");
@@ -1059,14 +1053,14 @@ Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const {
}
void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
- Control *child = _get_tab(p_tab);
+ Control *child = get_tab_control(p_tab);
ERR_FAIL_COND(!child);
child->set_meta("_tab_disabled", p_disabled);
update();
}
bool TabContainer::get_tab_disabled(int p_tab) const {
- Control *child = _get_tab(p_tab);
+ Control *child = get_tab_control(p_tab);
ERR_FAIL_COND_V(!child, false);
if (child->has_meta("_tab_disabled")) {
return child->get_meta("_tab_disabled");
@@ -1076,7 +1070,7 @@ bool TabContainer::get_tab_disabled(int p_tab) const {
}
void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
- Control *child = _get_tab(p_tab);
+ Control *child = get_tab_control(p_tab);
ERR_FAIL_COND(!child);
child->set_meta("_tab_hidden", p_hidden);
update();
@@ -1095,7 +1089,7 @@ void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
}
bool TabContainer::get_tab_hidden(int p_tab) const {
- Control *child = _get_tab(p_tab);
+ Control *child = get_tab_control(p_tab);
ERR_FAIL_COND_V(!child, false);
if (child->has_meta("_tab_hidden")) {
return child->get_meta("_tab_hidden");
@@ -1200,7 +1194,6 @@ bool TabContainer::get_use_hidden_tabs_for_min_size() const {
}
void TabContainer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &TabContainer::_gui_input);
ClassDB::bind_method(D_METHOD("get_tab_count"), &TabContainer::get_tab_count);
ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &TabContainer::set_current_tab);
ClassDB::bind_method(D_METHOD("get_current_tab"), &TabContainer::get_current_tab);
@@ -1219,6 +1212,7 @@ void TabContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tab_icon", "tab_idx"), &TabContainer::get_tab_icon);
ClassDB::bind_method(D_METHOD("set_tab_disabled", "tab_idx", "disabled"), &TabContainer::set_tab_disabled);
ClassDB::bind_method(D_METHOD("get_tab_disabled", "tab_idx"), &TabContainer::get_tab_disabled);
+ ClassDB::bind_method(D_METHOD("get_tab_idx_at_point", "point"), &TabContainer::get_tab_idx_at_point);
ClassDB::bind_method(D_METHOD("set_popup", "popup"), &TabContainer::set_popup);
ClassDB::bind_method(D_METHOD("get_popup"), &TabContainer::get_popup);
ClassDB::bind_method(D_METHOD("set_drag_to_rearrange_enabled", "enabled"), &TabContainer::set_drag_to_rearrange_enabled);
diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h
index 4ed5255729..fe96df25e8 100644
--- a/scene/gui/tab_container.h
+++ b/scene/gui/tab_container.h
@@ -57,7 +57,6 @@ private:
bool menu_hovered = false;
int highlight_arrow = -1;
TabAlign align = ALIGN_CENTER;
- Control *_get_tab(int p_idx) const;
int _get_top_margin() const;
mutable ObjectID popup_obj_id;
bool drag_to_rearrange_enabled = false;
@@ -77,7 +76,7 @@ private:
protected:
void _child_renamed_callback();
- void _gui_input(const Ref<InputEvent> &p_event);
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
void _notification(int p_what);
virtual void add_child_notify(Node *p_child) override;
virtual void move_child_notify(Node *p_child) override;
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 103860ad78..3ca2d1c1e9 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -90,7 +90,7 @@ Size2 Tabs::get_minimum_size() const {
return ms;
}
-void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
+void Tabs::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
Ref<InputEventMouseMotion> mm = p_event;
@@ -1107,7 +1107,6 @@ bool Tabs::get_select_with_rmb() const {
}
void Tabs::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &Tabs::_gui_input);
ClassDB::bind_method(D_METHOD("_update_hover"), &Tabs::_update_hover);
ClassDB::bind_method(D_METHOD("get_tab_count"), &Tabs::get_tab_count);
ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &Tabs::set_current_tab);
diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h
index 61c9a5d96a..b044453803 100644
--- a/scene/gui/tabs.h
+++ b/scene/gui/tabs.h
@@ -112,7 +112,7 @@ private:
void _shape(int p_tab);
protected:
- void _gui_input(const Ref<InputEvent> &p_event);
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 1b3935dd25..f64c07df76 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -37,6 +37,7 @@
#include "core/object/script_language.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
+#include "core/string/string_builder.h"
#include "core/string/translation.h"
#include "scene/main/window.h"
@@ -45,12 +46,6 @@
#include "editor/editor_scale.h"
#endif
-#define TAB_PIXELS
-
-inline bool _is_symbol(char32_t c) {
- return is_symbol(c);
-}
-
static bool _is_text_char(char32_t c) {
return !is_symbol(c);
}
@@ -64,17 +59,31 @@ static bool _is_char(char32_t c) {
}
///////////////////////////////////////////////////////////////////////////////
+/// TEXT ///
+///////////////////////////////////////////////////////////////////////////////
void TextEdit::Text::set_font(const Ref<Font> &p_font) {
+ if (font == p_font) {
+ return;
+ }
font = p_font;
+ is_dirty = true;
}
void TextEdit::Text::set_font_size(int p_font_size) {
+ if (font_size == p_font_size) {
+ return;
+ }
font_size = p_font_size;
+ is_dirty = true;
}
void TextEdit::Text::set_tab_size(int p_tab_size) {
+ if (tab_size == p_tab_size) {
+ return;
+ }
tab_size = p_tab_size;
+ tab_size_dirty = true;
}
int TextEdit::Text::get_tab_size() const {
@@ -82,16 +91,28 @@ int TextEdit::Text::get_tab_size() const {
}
void TextEdit::Text::set_font_features(const Dictionary &p_features) {
+ if (opentype_features.hash() == p_features.hash()) {
+ return;
+ }
opentype_features = p_features;
+ is_dirty = true;
}
-void TextEdit::Text::set_direction_and_language(TextServer::Direction p_direction, String p_language) {
+void TextEdit::Text::set_direction_and_language(TextServer::Direction p_direction, const String &p_language) {
+ if (direction == p_direction && language == p_language) {
+ return;
+ }
direction = p_direction;
language = p_language;
+ is_dirty = true;
}
void TextEdit::Text::set_draw_control_chars(bool p_draw_control_chars) {
+ if (draw_control_chars == p_draw_control_chars) {
+ return;
+ }
draw_control_chars = p_draw_control_chars;
+ is_dirty = true;
}
int TextEdit::Text::get_line_width(int p_line, int p_wrap_index) const {
@@ -102,10 +123,8 @@ int TextEdit::Text::get_line_width(int p_line, int p_wrap_index) const {
return text[p_line].data_buf->get_size().x;
}
-int TextEdit::Text::get_line_height(int p_line, int p_wrap_index) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), 0);
-
- return text[p_line].data_buf->get_line_size(p_wrap_index).y;
+int TextEdit::Text::get_line_height() const {
+ return line_height;
}
void TextEdit::Text::set_width(float p_width) {
@@ -137,6 +156,36 @@ _FORCE_INLINE_ const String &TextEdit::Text::operator[](int p_line) const {
return text[p_line].data;
}
+void TextEdit::Text::_calculate_line_height() {
+ int height = 0;
+ for (int i = 0; i < text.size(); i++) {
+ // Found another line with the same height...nothing to update.
+ if (text[i].height == line_height) {
+ height = line_height;
+ break;
+ }
+ height = MAX(height, text[i].height);
+ }
+ line_height = height;
+}
+
+void TextEdit::Text::_calculate_max_line_width() {
+ int width = 0;
+ for (int i = 0; i < text.size(); i++) {
+ if (is_hidden(i)) {
+ continue;
+ }
+
+ // Found another line with the same width...nothing to update.
+ if (text[i].width == max_width) {
+ width = max_width;
+ break;
+ }
+ width = MAX(width, text[i].width);
+ }
+ max_width = width;
+}
+
void TextEdit::Text::invalidate_cache(int p_line, int p_column, const String &p_ime_text, const Vector<Vector2i> &p_bidi_override) {
ERR_FAIL_INDEX(p_line, text.size());
@@ -166,23 +215,65 @@ void TextEdit::Text::invalidate_cache(int p_line, int p_column, const String &p_
tabs.push_back(font->get_char_size(' ', 0, font_size).width * tab_size);
text.write[p_line].data_buf->tab_align(tabs);
}
+
+ // Update height.
+ const int old_height = text.write[p_line].height;
+ const int wrap_amount = get_line_wrap_amount(p_line);
+ int height = font->get_height(font_size);
+ for (int i = 0; i <= wrap_amount; i++) {
+ height = MAX(height, text[p_line].data_buf->get_line_size(i).y);
+ }
+ text.write[p_line].height = height;
+
+ // If this line has shrunk, this may no longer the the tallest line.
+ if (old_height == line_height && height < line_height) {
+ _calculate_line_height();
+ } else {
+ line_height = MAX(height, line_height);
+ }
+
+ // Update width.
+ const int old_width = text.write[p_line].width;
+ int width = get_line_width(p_line);
+ text.write[p_line].width = width;
+
+ // If this line has shrunk, this may no longer the the longest line.
+ if (old_width == max_width && width < max_width) {
+ _calculate_max_line_width();
+ } else if (!is_hidden(p_line)) {
+ max_width = MAX(width, max_width);
+ }
}
void TextEdit::Text::invalidate_all_lines() {
for (int i = 0; i < text.size(); i++) {
text.write[i].data_buf->set_width(width);
- if (tab_size > 0) {
- Vector<float> tabs;
- tabs.push_back(font->get_char_size(' ', 0, font_size).width * tab_size);
- text.write[i].data_buf->tab_align(tabs);
+ if (tab_size_dirty) {
+ if (tab_size > 0) {
+ Vector<float> tabs;
+ tabs.push_back(font->get_char_size(' ', 0, font_size).width * tab_size);
+ text.write[i].data_buf->tab_align(tabs);
+ }
+ // Tabs have changes, force width update.
+ text.write[i].width = get_line_width(i);
}
}
+
+ if (tab_size_dirty) {
+ _calculate_max_line_width();
+ tab_size_dirty = false;
+ }
}
void TextEdit::Text::invalidate_all() {
+ if (!is_dirty) {
+ return;
+ }
+
for (int i = 0; i < text.size(); i++) {
invalidate_cache(i);
}
+ is_dirty = false;
}
void TextEdit::Text::clear() {
@@ -190,16 +281,8 @@ void TextEdit::Text::clear() {
insert(0, "", Vector<Vector2i>());
}
-int TextEdit::Text::get_max_width(bool p_exclude_hidden) const {
- // Quite some work, but should be fast enough.
-
- int max = 0;
- for (int i = 0; i < text.size(); i++) {
- if (!p_exclude_hidden || !is_hidden(i)) {
- max = MAX(max, get_line_width(i));
- }
- }
- return max;
+int TextEdit::Text::get_max_width() const {
+ return max_width;
}
void TextEdit::Text::set(int p_line, const String &p_text, const Vector<Vector2i> &p_bidi_override) {
@@ -222,7 +305,20 @@ void TextEdit::Text::insert(int p_at, const String &p_text, const Vector<Vector2
}
void TextEdit::Text::remove(int p_at) {
+ int height = text[p_at].height;
+ int width = text[p_at].width;
+
text.remove(p_at);
+
+ // If this is the tallest line, we need to get the next tallest.
+ if (height == line_height) {
+ _calculate_line_height();
+ }
+
+ // If this is the longest line, we need to get the next longest.
+ if (width == max_width) {
+ _calculate_max_line_width();
+ }
}
void TextEdit::Text::add_gutter(int p_at) {
@@ -249,269 +345,37 @@ void TextEdit::Text::move_gutters(int p_from_line, int p_to_line) {
text.write[p_from_line].gutters.resize(gutter_count);
}
-////////////////////////////////////////////////////////////////////////////////
-
-void TextEdit::_update_scrollbars() {
- Size2 size = get_size();
- Size2 hmin = h_scroll->get_combined_minimum_size();
- Size2 vmin = v_scroll->get_combined_minimum_size();
-
- v_scroll->set_begin(Point2(size.width - vmin.width, cache.style_normal->get_margin(SIDE_TOP)));
- v_scroll->set_end(Point2(size.width, size.height - cache.style_normal->get_margin(SIDE_TOP) - cache.style_normal->get_margin(SIDE_BOTTOM)));
-
- h_scroll->set_begin(Point2(0, size.height - hmin.height));
- h_scroll->set_end(Point2(size.width - vmin.width, size.height));
-
- int visible_rows = get_visible_rows();
- int total_rows = get_total_visible_rows();
- if (scroll_past_end_of_file_enabled) {
- total_rows += visible_rows - 1;
- }
-
- int visible_width = size.width - cache.style_normal->get_minimum_size().width;
- int total_width = text.get_max_width(true) + vmin.x + gutters_width + gutter_padding;
-
- if (draw_minimap) {
- total_width += cache.minimap_width;
- }
-
- updating_scrolls = true;
-
- if (total_rows > visible_rows) {
- v_scroll->show();
- v_scroll->set_max(total_rows + get_visible_rows_offset());
- v_scroll->set_page(visible_rows + get_visible_rows_offset());
- if (smooth_scroll_enabled) {
- v_scroll->set_step(0.25);
- } else {
- v_scroll->set_step(1);
- }
- set_v_scroll(get_v_scroll());
-
- } else {
- cursor.line_ofs = 0;
- cursor.wrap_ofs = 0;
- v_scroll->set_value(0);
- v_scroll->hide();
- }
-
- if (total_width > visible_width && !is_wrap_enabled()) {
- h_scroll->show();
- h_scroll->set_max(total_width);
- h_scroll->set_page(visible_width);
- if (cursor.x_ofs > (total_width - visible_width)) {
- cursor.x_ofs = (total_width - visible_width);
- }
- if (fabs(h_scroll->get_value() - (double)cursor.x_ofs) >= 1) {
- h_scroll->set_value(cursor.x_ofs);
- }
-
- } else {
- cursor.x_ofs = 0;
- h_scroll->set_value(0);
- h_scroll->hide();
- }
-
- updating_scrolls = false;
-}
-
-void TextEdit::_click_selection_held() {
- // Warning: is_mouse_button_pressed(MOUSE_BUTTON_LEFT) returns false for double+ clicks, so this doesn't work for MODE_WORD
- // and MODE_LINE. However, moving the mouse triggers _gui_input, which calls these functions too, so that's not a huge problem.
- // I'm unsure if there's an actual fix that doesn't have a ton of side effects.
- if (Input::get_singleton()->is_mouse_button_pressed(MOUSE_BUTTON_LEFT) && selection.selecting_mode != SelectionMode::SELECTION_MODE_NONE) {
- switch (selection.selecting_mode) {
- case SelectionMode::SELECTION_MODE_POINTER: {
- _update_selection_mode_pointer();
- } break;
- case SelectionMode::SELECTION_MODE_WORD: {
- _update_selection_mode_word();
- } break;
- case SelectionMode::SELECTION_MODE_LINE: {
- _update_selection_mode_line();
- } break;
- default: {
- break;
- }
- }
- } else {
- click_select_held->stop();
- }
-}
-
-Point2 TextEdit::_get_local_mouse_pos() const {
- Point2 mp = get_local_mouse_position();
- if (is_layout_rtl()) {
- mp.x = get_size().width - mp.x;
- }
- return mp;
-}
-
-void TextEdit::_update_selection_mode_pointer() {
- dragging_selection = true;
- Point2 mp = _get_local_mouse_pos();
-
- int row, col;
- _get_mouse_pos(Point2i(mp.x, mp.y), row, col);
-
- select(selection.selecting_line, selection.selecting_column, row, col);
-
- cursor_set_line(row, false);
- cursor_set_column(col);
- update();
-
- click_select_held->start();
-}
-
-void TextEdit::_update_selection_mode_word() {
- dragging_selection = true;
- Point2 mp = _get_local_mouse_pos();
-
- int row, col;
- _get_mouse_pos(Point2i(mp.x, mp.y), row, col);
-
- String line = text[row];
- int cursor_pos = CLAMP(col, 0, line.length());
- int beg = cursor_pos;
- int end = beg;
- Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(row)->get_rid());
- for (int i = 0; i < words.size(); i++) {
- if (words[i].x < cursor_pos && words[i].y > cursor_pos) {
- beg = words[i].x;
- end = words[i].y;
- break;
- }
- }
-
- // Initial selection.
- if (!selection.active) {
- select(row, beg, row, end);
- selection.selecting_column = beg;
- selection.selected_word_beg = beg;
- selection.selected_word_end = end;
- selection.selected_word_origin = beg;
- cursor_set_line(selection.to_line, false);
- cursor_set_column(selection.to_column);
- } else {
- if ((col <= selection.selected_word_origin && row == selection.selecting_line) || row < selection.selecting_line) {
- selection.selecting_column = selection.selected_word_end;
- select(row, beg, selection.selecting_line, selection.selected_word_end);
- cursor_set_line(selection.from_line, false);
- cursor_set_column(selection.from_column);
- } else {
- selection.selecting_column = selection.selected_word_beg;
- select(selection.selecting_line, selection.selected_word_beg, row, end);
- cursor_set_line(selection.to_line, false);
- cursor_set_column(selection.to_column);
- }
- }
-
- update();
-
- click_select_held->start();
-}
-
-void TextEdit::_update_selection_mode_line() {
- dragging_selection = true;
- Point2 mp = _get_local_mouse_pos();
-
- int row, col;
- _get_mouse_pos(Point2i(mp.x, mp.y), row, col);
-
- col = 0;
- if (row < selection.selecting_line) {
- // Cursor is above us.
- cursor_set_line(row - 1, false);
- selection.selecting_column = text[selection.selecting_line].length();
- } else {
- // Cursor is below us.
- cursor_set_line(row + 1, false);
- selection.selecting_column = 0;
- col = text[row].length();
- }
- cursor_set_column(0);
-
- select(selection.selecting_line, selection.selecting_column, row, col);
- update();
-
- click_select_held->start();
-}
-
-void TextEdit::_update_minimap_click() {
- Point2 mp = _get_local_mouse_pos();
-
- int xmargin_end = get_size().width - cache.style_normal->get_margin(SIDE_RIGHT);
- if (!dragging_minimap && (mp.x < xmargin_end - minimap_width || mp.y > xmargin_end)) {
- minimap_clicked = false;
- return;
- }
- minimap_clicked = true;
- dragging_minimap = true;
-
- int row;
- _get_minimap_mouse_row(Point2i(mp.x, mp.y), row);
-
- if (row >= get_first_visible_line() && (row < get_last_full_visible_line() || row >= (text.size() - 1))) {
- minimap_scroll_ratio = v_scroll->get_as_ratio();
- minimap_scroll_click_pos = mp.y;
- can_drag_minimap = true;
- return;
- }
-
- int wi;
- int first_line = row - num_lines_from_rows(row, 0, -get_visible_rows() / 2, wi) + 1;
- double delta = get_scroll_pos_for_line(first_line, wi) - get_v_scroll();
- if (delta < 0) {
- _scroll_up(-delta);
- } else {
- _scroll_down(delta);
- }
-}
-
-void TextEdit::_update_minimap_drag() {
- if (!can_drag_minimap) {
- return;
- }
-
- int control_height = _get_control_height();
- int scroll_height = v_scroll->get_max() * (minimap_char_size.y + minimap_line_spacing);
- if (control_height > scroll_height) {
- control_height = scroll_height;
- }
-
- Point2 mp = _get_local_mouse_pos();
-
- double diff = (mp.y - minimap_scroll_click_pos) / control_height;
- v_scroll->set_as_ratio(minimap_scroll_ratio + diff);
-}
+///////////////////////////////////////////////////////////////////////////////
+/// TEXT EDIT ///
+///////////////////////////////////////////////////////////////////////////////
void TextEdit::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_caches();
- if (cursor_changed_dirty) {
- MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
+ if (caret_pos_dirty) {
+ MessageQueue::get_singleton()->push_call(this, "_emit_caret_changed");
}
if (text_changed_dirty) {
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
}
- _update_wrap_at(true);
+ _update_wrap_at_column(true);
} break;
case NOTIFICATION_RESIZED: {
_update_scrollbars();
- _update_wrap_at();
+ _update_wrap_at_column();
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible()) {
call_deferred(SNAME("_update_scrollbars"));
- call_deferred(SNAME("_update_wrap_at"));
+ call_deferred(SNAME("_update_wrap_at_column"));
}
} break;
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_THEME_CHANGED: {
_update_caches();
- _update_wrap_at(true);
+ _update_wrap_at_column(true);
} break;
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
window_has_focus = true;
@@ -546,8 +410,8 @@ void TextEdit::_notification(int p_what) {
} break;
case NOTIFICATION_DRAW: {
if (first_draw) {
- // Size may not be the final one, so attempts to ensure cursor was visible may have failed.
- adjust_viewport_to_cursor();
+ // Size may not be the final one, so attempts to ensure caret was visible may have failed.
+ adjust_viewport_to_caret();
first_draw = false;
}
@@ -564,34 +428,32 @@ void TextEdit::_notification(int p_what) {
draw_caret = false;
}
- cache.minimap_width = 0;
- if (draw_minimap) {
- cache.minimap_width = minimap_width;
- }
-
_update_scrollbars();
RID ci = get_canvas_item();
RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
- int xmargin_beg = cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding;
+ int xmargin_beg = style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding;
- int xmargin_end = size.width - cache.style_normal->get_margin(SIDE_RIGHT) - cache.minimap_width;
+ int xmargin_end = size.width - style_normal->get_margin(SIDE_RIGHT);
+ if (draw_minimap) {
+ xmargin_end -= minimap_width;
+ }
// Let's do it easy for now.
- cache.style_normal->draw(ci, Rect2(Point2(), size));
- if (readonly) {
- cache.style_readonly->draw(ci, Rect2(Point2(), size));
+ style_normal->draw(ci, Rect2(Point2(), size));
+ if (!editable) {
+ style_readonly->draw(ci, Rect2(Point2(), size));
draw_caret = false;
}
if (has_focus()) {
- cache.style_focus->draw(ci, Rect2(Point2(), size));
+ style_focus->draw(ci, Rect2(Point2(), size));
}
- int visible_rows = get_visible_rows() + 1;
+ int visible_rows = get_visible_line_count() + 1;
- Color color = readonly ? cache.font_readonly_color : cache.font_color;
+ Color color = !editable ? font_readonly_color : font_color;
- if (cache.background_color.a > 0.01) {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(), get_size()), cache.background_color);
+ if (background_color.a > 0.01) {
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(), get_size()), background_color);
}
int brace_open_match_line = -1;
@@ -603,10 +465,10 @@ void TextEdit::_notification(int p_what) {
bool brace_close_matching = false;
bool brace_close_mismatch = false;
- if (highlight_matching_braces_enabled && cursor.line >= 0 && cursor.line < text.size() && cursor.column >= 0) {
- if (cursor.column < text[cursor.line].length()) {
+ if (highlight_matching_braces_enabled && caret.line >= 0 && caret.line < text.size() && caret.column >= 0) {
+ if (caret.column < text[caret.line].length()) {
// Check for open.
- char32_t c = text[cursor.line][cursor.column];
+ char32_t c = text[caret.line][caret.column];
char32_t closec = 0;
if (c == '[') {
@@ -620,8 +482,8 @@ void TextEdit::_notification(int p_what) {
if (closec != 0) {
int stack = 1;
- for (int i = cursor.line; i < text.size(); i++) {
- int from = i == cursor.line ? cursor.column + 1 : 0;
+ for (int i = caret.line; i < text.size(); i++) {
+ int from = i == caret.line ? caret.column + 1 : 0;
for (int j = from; j < text[i].length(); j++) {
char32_t cc = text[i][j];
// Ignore any brackets inside a string.
@@ -671,8 +533,8 @@ void TextEdit::_notification(int p_what) {
}
}
- if (cursor.column > 0) {
- char32_t c = text[cursor.line][cursor.column - 1];
+ if (caret.column > 0) {
+ char32_t c = text[caret.line][caret.column - 1];
char32_t closec = 0;
if (c == ']') {
@@ -686,8 +548,8 @@ void TextEdit::_notification(int p_what) {
if (closec != 0) {
int stack = 1;
- for (int i = cursor.line; i >= 0; i--) {
- int from = i == cursor.line ? cursor.column - 2 : text[i].length() - 1;
+ for (int i = caret.line; i >= 0; i--) {
+ int from = i == caret.line ? caret.column - 2 : text[i].length() - 1;
for (int j = from; j >= 0; j--) {
char32_t cc = text[i][j];
// Ignore any brackets inside a string.
@@ -739,22 +601,20 @@ void TextEdit::_notification(int p_what) {
}
// Get the highlighted words.
- String highlighted_text = get_selection_text();
+ String highlighted_text = get_selected_text();
// Check if highlighted words contain only whitespaces (tabs or spaces).
bool only_whitespaces_highlighted = highlighted_text.strip_edges() == String();
- int cursor_wrap_index = get_cursor_wrap_index();
-
- //FontDrawer drawer(cache.font, Color(1, 1, 1));
+ const int caret_wrap_index = get_caret_wrap_index();
int first_visible_line = get_first_visible_line() - 1;
int draw_amount = visible_rows + (smooth_scroll_enabled ? 1 : 0);
- draw_amount += times_line_wraps(first_visible_line + 1);
+ draw_amount += get_line_wrap_count(first_visible_line + 1);
// minimap
if (draw_minimap) {
- int minimap_visible_lines = _get_minimap_visible_rows();
+ int minimap_visible_lines = get_minimap_visible_lines();
int minimap_line_height = (minimap_char_size.y + minimap_line_spacing);
int minimap_tab_size = minimap_char_size.x * text.get_tab_size();
@@ -765,21 +625,32 @@ void TextEdit::_notification(int p_what) {
// calculate the first line.
int num_lines_before = round((viewport_offset_y) / minimap_line_height);
- int wi;
int minimap_line = (v_scroll->get_max() <= minimap_visible_lines) ? -1 : first_visible_line;
if (minimap_line >= 0) {
- minimap_line -= num_lines_from_rows(first_visible_line, 0, -num_lines_before, wi);
+ minimap_line -= get_next_visible_line_index_offset_from(first_visible_line, 0, -num_lines_before).x;
minimap_line -= (minimap_line > 0 && smooth_scroll_enabled ? 1 : 0);
}
- int minimap_draw_amount = minimap_visible_lines + times_line_wraps(minimap_line + 1);
+ int minimap_draw_amount = minimap_visible_lines + get_line_wrap_count(minimap_line + 1);
+
+ // Draw the minimap.
- // draw the minimap
- Color viewport_color = (cache.background_color.get_v() < 0.5) ? Color(1, 1, 1, 0.1) : Color(0, 0, 0, 0.1);
+ // Add visual feedback when dragging or hovering the the visible area rectangle.
+ float viewport_alpha;
+ if (dragging_minimap) {
+ viewport_alpha = 0.25;
+ } else if (hovering_minimap) {
+ viewport_alpha = 0.175;
+ } else {
+ viewport_alpha = 0.1;
+ }
+
+ const Color viewport_color = (background_color.get_v() < 0.5) ? Color(1, 1, 1, viewport_alpha) : Color(0, 0, 0, viewport_alpha);
if (rtl) {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - (xmargin_end + 2) - cache.minimap_width, viewport_offset_y, cache.minimap_width, viewport_height), viewport_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - (xmargin_end + 2) - minimap_width, viewport_offset_y, minimap_width, viewport_height), viewport_color);
} else {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), viewport_offset_y, cache.minimap_width, viewport_height), viewport_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), viewport_offset_y, minimap_width, viewport_height), viewport_color);
}
+
for (int i = 0; i < minimap_draw_amount; i++) {
minimap_line++;
@@ -787,7 +658,7 @@ void TextEdit::_notification(int p_what) {
break;
}
- while (is_line_hidden(minimap_line)) {
+ while (_is_line_hidden(minimap_line)) {
minimap_line++;
if (minimap_line < 0 || minimap_line >= (int)text.size()) {
break;
@@ -802,13 +673,13 @@ void TextEdit::_notification(int p_what) {
Color line_background_color = text.get_line_background_color(minimap_line);
line_background_color.a *= 0.6;
- Color current_color = cache.font_color;
- if (readonly) {
- current_color = cache.font_readonly_color;
+ Color current_color = font_color;
+ if (!editable) {
+ current_color = font_readonly_color;
}
- Vector<String> wrap_rows = get_wrap_rows_text(minimap_line);
- int line_wrap_amount = times_line_wraps(minimap_line);
+ Vector<String> wrap_rows = get_line_wrapped_text(minimap_line);
+ int line_wrap_amount = get_line_wrap_count(minimap_line);
int last_wrap_column = 0;
for (int line_wrap_index = 0; line_wrap_index < line_wrap_amount + 1; line_wrap_index++) {
@@ -821,7 +692,7 @@ void TextEdit::_notification(int p_what) {
const String &str = wrap_rows[line_wrap_index];
int indent_px = line_wrap_index != 0 ? get_indent_level(minimap_line) : 0;
- if (indent_px >= wrap_at) {
+ if (indent_px >= wrap_at_column) {
indent_px = 0;
}
indent_px = minimap_char_size.x * indent_px;
@@ -830,17 +701,17 @@ void TextEdit::_notification(int p_what) {
last_wrap_column += wrap_rows[line_wrap_index - 1].length();
}
- if (minimap_line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) {
+ if (minimap_line == caret.line && caret_wrap_index == line_wrap_index && highlight_current_line) {
if (rtl) {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - (xmargin_end + 2) - cache.minimap_width, i * 3, cache.minimap_width, 2), cache.current_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - (xmargin_end + 2) - minimap_width, i * 3, minimap_width, 2), current_line_color);
} else {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, cache.minimap_width, 2), cache.current_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, minimap_width, 2), current_line_color);
}
} else if (line_background_color != Color(0, 0, 0, 0)) {
if (rtl) {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - (xmargin_end + 2) - cache.minimap_width, i * 3, cache.minimap_width, 2), line_background_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - (xmargin_end + 2) - minimap_width, i * 3, minimap_width, 2), line_background_color);
} else {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, cache.minimap_width, 2), line_background_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, minimap_width, 2), line_background_color);
}
}
@@ -848,10 +719,11 @@ void TextEdit::_notification(int p_what) {
int characters = 0;
int tabs = 0;
for (int j = 0; j < str.length(); j++) {
- if (color_map.has(last_wrap_column + j)) {
- current_color = color_map[last_wrap_column + j].get("color");
- if (readonly) {
- current_color.a = cache.font_readonly_color.a;
+ const Variant *color_data = color_map.getptr(last_wrap_column + j);
+ if (color_data != nullptr) {
+ current_color = (color_data->operator Dictionary()).get("color", font_color);
+ if (!editable) {
+ current_color.a = font_readonly_color.a;
}
}
color = current_color;
@@ -861,7 +733,7 @@ void TextEdit::_notification(int p_what) {
}
int xpos = indent_px + ((xmargin_end + minimap_char_size.x) + (minimap_char_size.x * j)) + tabs;
- bool out_of_bounds = (xpos >= xmargin_end + cache.minimap_width);
+ bool out_of_bounds = (xpos >= xmargin_end + minimap_width);
bool is_whitespace = _is_whitespace(str[j]);
if (!is_whitespace) {
@@ -912,18 +784,17 @@ void TextEdit::_notification(int p_what) {
int top_limit_y = 0;
int bottom_limit_y = get_size().height;
- if (readonly) {
- top_limit_y += cache.style_readonly->get_margin(SIDE_TOP);
- bottom_limit_y -= cache.style_readonly->get_margin(SIDE_BOTTOM);
+ if (!editable) {
+ top_limit_y += style_readonly->get_margin(SIDE_TOP);
+ bottom_limit_y -= style_readonly->get_margin(SIDE_BOTTOM);
} else {
- top_limit_y += cache.style_normal->get_margin(SIDE_TOP);
- bottom_limit_y -= cache.style_normal->get_margin(SIDE_BOTTOM);
+ top_limit_y += style_normal->get_margin(SIDE_TOP);
+ bottom_limit_y -= style_normal->get_margin(SIDE_BOTTOM);
}
// draw main text
- cursor.visible = false;
- const int caret_wrap_index = get_cursor_wrap_index();
- int row_height = get_row_height();
+ caret.visible = false;
+ int row_height = get_line_height();
int line = first_visible_line;
for (int i = 0; i < draw_amount; i++) {
line++;
@@ -932,7 +803,7 @@ void TextEdit::_notification(int p_what) {
continue;
}
- while (is_line_hidden(line)) {
+ while (_is_line_hidden(line)) {
line++;
if (line < 0 || line >= (int)text.size()) {
break;
@@ -946,12 +817,12 @@ void TextEdit::_notification(int p_what) {
Dictionary color_map = _get_line_syntax_highlighting(line);
// Ensure we at least use the font color.
- Color current_color = readonly ? cache.font_readonly_color : cache.font_color;
+ Color current_color = !editable ? font_readonly_color : font_color;
const Ref<TextParagraph> ldata = text.get_line_data(line);
- Vector<String> wrap_rows = get_wrap_rows_text(line);
- int line_wrap_amount = times_line_wraps(line);
+ Vector<String> wrap_rows = get_line_wrapped_text(line);
+ int line_wrap_amount = get_line_wrap_count(line);
for (int line_wrap_index = 0; line_wrap_index <= line_wrap_amount; line_wrap_index++) {
if (line_wrap_index != 0) {
@@ -962,21 +833,21 @@ void TextEdit::_notification(int p_what) {
}
const String &str = wrap_rows[line_wrap_index];
- int char_margin = xmargin_beg - cursor.x_ofs;
+ int char_margin = xmargin_beg - caret.x_ofs;
int ofs_x = 0;
int ofs_y = 0;
- if (readonly) {
- ofs_x = cache.style_readonly->get_offset().x / 2;
- ofs_x -= cache.style_normal->get_offset().x / 2;
- ofs_y = cache.style_readonly->get_offset().y / 2;
+ if (!editable) {
+ ofs_x = style_readonly->get_offset().x / 2;
+ ofs_x -= style_normal->get_offset().x / 2;
+ ofs_y = style_readonly->get_offset().y / 2;
} else {
- ofs_y = cache.style_normal->get_offset().y / 2;
+ ofs_y = style_normal->get_offset().y / 2;
}
- ofs_y += i * row_height + cache.line_spacing / 2;
- ofs_y -= cursor.wrap_ofs * row_height;
- ofs_y -= get_v_scroll_offset() * row_height;
+ ofs_y += i * row_height + line_spacing / 2;
+ ofs_y -= caret.wrap_ofs * row_height;
+ ofs_y -= _get_v_scroll_offset() * row_height;
bool clipped = false;
if (ofs_y + row_height < top_limit_y) {
@@ -1001,30 +872,30 @@ void TextEdit::_notification(int p_what) {
if (str.length() == 0) {
// Draw line background if empty as we won't loop at all.
- if (line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) {
+ if (line == caret.line && caret_wrap_index == line_wrap_index && highlight_current_line) {
if (rtl) {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - ofs_x - xmargin_end, ofs_y, xmargin_end, row_height), cache.current_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - ofs_x - xmargin_end, ofs_y, xmargin_end, row_height), current_line_color);
} else {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(ofs_x, ofs_y, xmargin_end, row_height), cache.current_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(ofs_x, ofs_y, xmargin_end, row_height), current_line_color);
}
}
// Give visual indication of empty selected line.
if (selection.active && line >= selection.from_line && line <= selection.to_line && char_margin >= xmargin_beg) {
- int char_w = cache.font->get_char_size(' ', 0, cache.font_size).width;
+ int char_w = font->get_char_size(' ', 0, font_size).width;
if (rtl) {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - xmargin_beg - ofs_x - char_w, ofs_y, char_w, row_height), cache.selection_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - xmargin_beg - ofs_x - char_w, ofs_y, char_w, row_height), selection_color);
} else {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, char_w, row_height), cache.selection_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, char_w, row_height), selection_color);
}
}
} else {
// If it has text, then draw current line marker in the margin, as line number etc will draw over it, draw the rest of line marker later.
- if (line == cursor.line && cursor_wrap_index == line_wrap_index && highlight_current_line) {
+ if (line == caret.line && caret_wrap_index == line_wrap_index && highlight_current_line) {
if (rtl) {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - ofs_x - xmargin_end, ofs_y, xmargin_end, row_height), cache.current_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - ofs_x - xmargin_end, ofs_y, xmargin_end, row_height), current_line_color);
} else {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(ofs_x, ofs_y, xmargin_end, row_height), cache.current_line_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(ofs_x, ofs_y, xmargin_end, row_height), current_line_color);
}
}
}
@@ -1032,7 +903,7 @@ void TextEdit::_notification(int p_what) {
if (line_wrap_index == 0) {
// Only do these if we are on the first wrapped part of a line.
- int gutter_offset = cache.style_normal->get_margin(SIDE_LEFT);
+ int gutter_offset = style_normal->get_margin(SIDE_LEFT);
for (int g = 0; g < gutters.size(); g++) {
const GutterInfo gutter = gutters[g];
@@ -1049,11 +920,11 @@ void TextEdit::_notification(int p_what) {
Ref<TextLine> tl;
tl.instantiate();
- tl->add_string(text, cache.font, cache.font_size);
+ tl->add_string(text, font, font_size);
int yofs = ofs_y + (row_height - tl->get_size().y) / 2;
- if (cache.outline_size > 0 && cache.outline_color.a > 0) {
- tl->draw_outline(ci, Point2(gutter_offset + ofs_x, yofs), cache.outline_size, cache.outline_color);
+ if (outline_size > 0 && outline_color.a > 0) {
+ tl->draw_outline(ci, Point2(gutter_offset + ofs_x, yofs), outline_size, outline_color);
}
tl->draw(ci, Point2(gutter_offset + ofs_x, yofs), get_line_gutter_item_color(line, g));
} break;
@@ -1105,7 +976,7 @@ void TextEdit::_notification(int p_what) {
// Draw line.
RID rid = ldata->get_line_rid(line_wrap_index);
- float text_height = TS->shaped_text_get_size(rid).y + cache.font->get_spacing(Font::SPACING_TOP) + cache.font->get_spacing(Font::SPACING_BOTTOM);
+ float text_height = TS->shaped_text_get_size(rid).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM);
if (rtl) {
char_margin = size.width - char_margin - TS->shaped_text_get_size(rid).x;
@@ -1127,7 +998,7 @@ void TextEdit::_notification(int p_what) {
if (rect.position.x + rect.size.x > xmargin_end) {
rect.size.x = xmargin_end - rect.position.x;
}
- draw_rect(rect, cache.selection_color, true);
+ draw_rect(rect, selection_color, true);
}
}
@@ -1147,8 +1018,8 @@ void TextEdit::_notification(int p_what) {
} else if (rect.position.x + rect.size.x > xmargin_end) {
rect.size.x = xmargin_end - rect.position.x;
}
- draw_rect(rect, cache.search_result_color, true);
- draw_rect(rect, cache.search_result_border_color, false);
+ draw_rect(rect, search_result_color, true);
+ draw_rect(rect, search_result_border_color, false);
}
search_text_col = _get_column_pos_of_word(search_text, str, search_flags, search_text_col + 1);
@@ -1170,7 +1041,7 @@ void TextEdit::_notification(int p_what) {
} else if (rect.position.x + rect.size.x > xmargin_end) {
rect.size.x = xmargin_end - rect.position.x;
}
- draw_rect(rect, cache.word_highlighted_color);
+ draw_rect(rect, word_highlighted_color);
}
highlighted_text_col = _get_column_pos_of_word(highlighted_text, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, highlighted_text_col + 1);
@@ -1193,9 +1064,9 @@ void TextEdit::_notification(int p_what) {
} else if (rect.position.x + rect.size.x > xmargin_end) {
rect.size.x = xmargin_end - rect.position.x;
}
- rect.position.y = TS->shaped_text_get_ascent(rid) + cache.font->get_underline_position(cache.font_size);
- rect.size.y = cache.font->get_underline_thickness(cache.font_size);
- draw_rect(rect, cache.font_selected_color);
+ rect.position.y = TS->shaped_text_get_ascent(rid) + font->get_underline_position(font_size);
+ rect.size.y = font->get_underline_thickness(font_size);
+ draw_rect(rect, font_selected_color);
}
highlighted_word_col = _get_column_pos_of_word(lookup_symbol_word, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, highlighted_word_col + 1);
@@ -1211,12 +1082,12 @@ void TextEdit::_notification(int p_what) {
ofs_y += ldata->get_line_ascent(line_wrap_index);
int char_ofs = 0;
- if (cache.outline_size > 0 && cache.outline_color.a > 0) {
+ if (outline_size > 0 && outline_color.a > 0) {
for (int j = 0; j < gl_size; j++) {
for (int k = 0; k < glyphs[j].repeat; k++) {
if ((char_ofs + char_margin) >= xmargin_beg && (char_ofs + glyphs[j].advance + char_margin) <= xmargin_end) {
if (glyphs[j].font_rid != RID()) {
- TS->font_draw_glyph_outline(glyphs[j].font_rid, ci, glyphs[j].font_size, cache.outline_size, Vector2(char_margin + char_ofs + ofs_x + glyphs[j].x_off, ofs_y + glyphs[j].y_off), glyphs[j].index, cache.outline_color);
+ TS->font_draw_glyph_outline(glyphs[j].font_rid, ci, glyphs[j].font_size, outline_size, Vector2(char_margin + char_ofs + ofs_x + glyphs[j].x_off, ofs_y + glyphs[j].y_off), glyphs[j].index, outline_color);
}
}
char_ofs += glyphs[j].advance;
@@ -1228,10 +1099,11 @@ void TextEdit::_notification(int p_what) {
char_ofs = 0;
}
for (int j = 0; j < gl_size; j++) {
- if (color_map.has(glyphs[j].start)) {
- current_color = color_map[glyphs[j].start].get("color");
- if (readonly && current_color.a > cache.font_readonly_color.a) {
- current_color.a = cache.font_readonly_color.a;
+ const Variant *color_data = color_map.getptr(glyphs[j].start);
+ if (color_data != nullptr) {
+ current_color = (color_data->operator Dictionary()).get("color", font_color);
+ if (!editable && current_color.a > font_readonly_color.a) {
+ current_color.a = font_readonly_color.a;
}
}
@@ -1240,7 +1112,7 @@ void TextEdit::_notification(int p_what) {
int sel_to = (line < selection.to_line) ? TS->shaped_text_get_range(rid).y : selection.to_column;
if (glyphs[j].start >= sel_from && glyphs[j].end <= sel_to && override_selected_font_color) {
- current_color = cache.font_selected_color;
+ current_color = font_selected_color;
}
}
@@ -1248,31 +1120,31 @@ void TextEdit::_notification(int p_what) {
if (char_pos >= xmargin_beg) {
if (highlight_matching_braces_enabled) {
if ((brace_open_match_line == line && brace_open_match_column == glyphs[j].start) ||
- (cursor.column == glyphs[j].start && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_open_matching || brace_open_mismatch))) {
+ (caret.column == glyphs[j].start && caret.line == line && caret_wrap_index == line_wrap_index && (brace_open_matching || brace_open_mismatch))) {
if (brace_open_mismatch) {
- current_color = cache.brace_mismatch_color;
+ current_color = brace_mismatch_color;
}
- Rect2 rect = Rect2(char_pos, ofs_y + cache.font->get_underline_position(cache.font_size), glyphs[j].advance * glyphs[j].repeat, cache.font->get_underline_thickness(cache.font_size));
+ Rect2 rect = Rect2(char_pos, ofs_y + font->get_underline_position(font_size), glyphs[j].advance * glyphs[j].repeat, font->get_underline_thickness(font_size));
draw_rect(rect, current_color);
}
if ((brace_close_match_line == line && brace_close_match_column == glyphs[j].start) ||
- (cursor.column == glyphs[j].start + 1 && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_close_matching || brace_close_mismatch))) {
+ (caret.column == glyphs[j].start + 1 && caret.line == line && caret_wrap_index == line_wrap_index && (brace_close_matching || brace_close_mismatch))) {
if (brace_close_mismatch) {
- current_color = cache.brace_mismatch_color;
+ current_color = brace_mismatch_color;
}
- Rect2 rect = Rect2(char_pos, ofs_y + cache.font->get_underline_position(cache.font_size), glyphs[j].advance * glyphs[j].repeat, cache.font->get_underline_thickness(cache.font_size));
+ Rect2 rect = Rect2(char_pos, ofs_y + font->get_underline_position(font_size), glyphs[j].advance * glyphs[j].repeat, font->get_underline_thickness(font_size));
draw_rect(rect, current_color);
}
}
if (draw_tabs && ((glyphs[j].flags & TextServer::GRAPHEME_IS_TAB) == TextServer::GRAPHEME_IS_TAB)) {
- int yofs = (text_height - cache.tab_icon->get_height()) / 2 - ldata->get_line_ascent(line_wrap_index);
- cache.tab_icon->draw(ci, Point2(char_pos, ofs_y + yofs), current_color);
+ int yofs = (text_height - tab_icon->get_height()) / 2 - ldata->get_line_ascent(line_wrap_index);
+ tab_icon->draw(ci, Point2(char_pos, ofs_y + yofs), current_color);
} else if (draw_spaces && ((glyphs[j].flags & TextServer::GRAPHEME_IS_SPACE) == TextServer::GRAPHEME_IS_SPACE)) {
- int yofs = (text_height - cache.space_icon->get_height()) / 2 - ldata->get_line_ascent(line_wrap_index);
- int xofs = (glyphs[j].advance * glyphs[j].repeat - cache.space_icon->get_width()) / 2;
- cache.space_icon->draw(ci, Point2(char_pos + xofs, ofs_y + yofs), current_color);
+ int yofs = (text_height - space_icon->get_height()) / 2 - ldata->get_line_ascent(line_wrap_index);
+ int xofs = (glyphs[j].advance * glyphs[j].repeat - space_icon->get_width()) / 2;
+ space_icon->draw(ci, Point2(char_pos + xofs, ofs_y + yofs), current_color);
}
}
@@ -1292,13 +1164,13 @@ void TextEdit::_notification(int p_what) {
}
// is_line_folded
- if (line_wrap_index == line_wrap_amount && line < text.size() - 1 && is_line_hidden(line + 1)) {
- int xofs = char_ofs + char_margin + ofs_x + (cache.folded_eol_icon->get_width() / 2);
+ if (line_wrap_index == line_wrap_amount && line < text.size() - 1 && _is_line_hidden(line + 1)) {
+ int xofs = char_ofs + char_margin + ofs_x + (folded_eol_icon->get_width() / 2);
if (xofs >= xmargin_beg && xofs < xmargin_end) {
- int yofs = (text_height - cache.folded_eol_icon->get_height()) / 2 - ldata->get_line_ascent(line_wrap_index);
- Color eol_color = cache.code_folding_color;
+ int yofs = (text_height - folded_eol_icon->get_height()) / 2 - ldata->get_line_ascent(line_wrap_index);
+ Color eol_color = code_folding_color;
eol_color.a = 1;
- cache.folded_eol_icon->draw(ci, Point2(xofs, ofs_y + yofs), eol_color);
+ folded_eol_icon->draw(ci, Point2(xofs, ofs_y + yofs), eol_color);
}
}
@@ -1309,18 +1181,18 @@ void TextEdit::_notification(int p_what) {
int caret_width = 1;
#endif
- if (!clipped && cursor.line == line && line_wrap_index == caret_wrap_index) {
- cursor.draw_pos.y = ofs_y + ldata->get_line_descent(line_wrap_index);
+ if (!clipped && caret.line == line && line_wrap_index == caret_wrap_index) {
+ caret.draw_pos.y = ofs_y + ldata->get_line_descent(line_wrap_index);
if (ime_text.length() == 0) {
Rect2 l_caret, t_caret;
TextServer::Direction l_dir, t_dir;
if (str.length() != 0) {
// Get carets.
- TS->shaped_text_get_carets(rid, cursor.column, l_caret, l_dir, t_caret, t_dir);
+ TS->shaped_text_get_carets(rid, caret.column, l_caret, l_dir, t_caret, t_dir);
} else {
// No carets, add one at the start.
- int h = cache.font->get_height(cache.font_size);
+ int h = font->get_height(font_size);
if (rtl) {
l_dir = TextServer::DIRECTION_RTL;
l_caret = Rect2(Vector2(xmargin_end - char_margin + ofs_x, -h / 2), Size2(caret_width * 4, h));
@@ -1331,20 +1203,20 @@ void TextEdit::_notification(int p_what) {
}
if ((l_caret != Rect2() && (l_dir == TextServer::DIRECTION_AUTO || l_dir == (TextServer::Direction)input_direction)) || (t_caret == Rect2())) {
- cursor.draw_pos.x = char_margin + ofs_x + l_caret.position.x;
+ caret.draw_pos.x = char_margin + ofs_x + l_caret.position.x;
} else {
- cursor.draw_pos.x = char_margin + ofs_x + t_caret.position.x;
+ caret.draw_pos.x = char_margin + ofs_x + t_caret.position.x;
}
- if (cursor.draw_pos.x >= xmargin_beg && cursor.draw_pos.x < xmargin_end) {
- cursor.visible = true;
+ if (caret.draw_pos.x >= xmargin_beg && caret.draw_pos.x < xmargin_end) {
+ caret.visible = true;
if (draw_caret) {
- if (block_caret || insert_mode) {
+ if (caret_type == CaretType::CARET_TYPE_BLOCK || overtype_mode) {
//Block or underline caret, draw trailing carets at full height.
- int h = cache.font->get_height(cache.font_size);
+ int h = font->get_height(font_size);
if (t_caret != Rect2()) {
- if (insert_mode) {
+ if (overtype_mode) {
t_caret.position.y = TS->shaped_text_get_descent(rid);
t_caret.size.y = caret_width;
} else {
@@ -1352,20 +1224,37 @@ void TextEdit::_notification(int p_what) {
t_caret.size.y = h;
}
t_caret.position += Vector2(char_margin + ofs_x, ofs_y);
+ draw_rect(t_caret, caret_color, overtype_mode);
- draw_rect(t_caret, cache.caret_color, false);
+ if (l_caret != Rect2() && l_dir != t_dir) {
+ l_caret.position += Vector2(char_margin + ofs_x, ofs_y);
+ l_caret.size.x = caret_width;
+ draw_rect(l_caret, caret_color * Color(1, 1, 1, 0.5));
+ }
} else { // End of the line.
- if (insert_mode) {
- l_caret.position.y = TS->shaped_text_get_descent(rid);
+ if (gl_size > 0) {
+ // Adjust for actual line dimensions.
+ if (overtype_mode) {
+ l_caret.position.y = TS->shaped_text_get_descent(rid);
+ l_caret.size.y = caret_width;
+ } else {
+ l_caret.position.y = -TS->shaped_text_get_ascent(rid);
+ l_caret.size.y = h;
+ }
+ } else if (overtype_mode) {
+ l_caret.position.y += l_caret.size.y;
l_caret.size.y = caret_width;
+ }
+ if (l_caret.position.x >= TS->shaped_text_get_size(rid).x) {
+ l_caret.size.x = font->get_char_size('m', 0, font_size).x;
} else {
- l_caret.position.y = -TS->shaped_text_get_ascent(rid);
- l_caret.size.y = h;
+ l_caret.size.x = 3 * caret_width;
}
l_caret.position += Vector2(char_margin + ofs_x, ofs_y);
- l_caret.size.x = cache.font->get_char_size('M', 0, cache.font_size).x;
-
- draw_rect(l_caret, cache.caret_color, false);
+ if (l_dir == TextServer::DIRECTION_RTL) {
+ l_caret.position.x -= l_caret.size.x;
+ }
+ draw_rect(l_caret, caret_color, overtype_mode);
}
} else {
// Normal caret.
@@ -1373,24 +1262,24 @@ void TextEdit::_notification(int p_what) {
// Draw extra marker on top of mid caret.
Rect2 trect = Rect2(l_caret.position.x - 3 * caret_width, l_caret.position.y, 6 * caret_width, caret_width);
trect.position += Vector2(char_margin + ofs_x, ofs_y);
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, trect, cache.caret_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, trect, caret_color);
}
l_caret.position += Vector2(char_margin + ofs_x, ofs_y);
l_caret.size.x = caret_width;
- draw_rect(l_caret, cache.caret_color);
+ draw_rect(l_caret, caret_color);
t_caret.position += Vector2(char_margin + ofs_x, ofs_y);
t_caret.size.x = caret_width;
- draw_rect(t_caret, cache.caret_color);
+ draw_rect(t_caret, caret_color);
}
}
}
} else {
{
// IME Intermediate text range.
- Vector<Vector2> sel = TS->shaped_text_get_selection(rid, cursor.column, cursor.column + ime_text.length());
+ Vector<Vector2> sel = TS->shaped_text_get_selection(rid, caret.column, caret.column + ime_text.length());
for (int j = 0; j < sel.size(); j++) {
Rect2 rect = Rect2(sel[j].x + char_margin + ofs_x, ofs_y, sel[j].y - sel[j].x, text_height);
if (rect.position.x + rect.size.x <= xmargin_beg || rect.position.x > xmargin_end) {
@@ -1403,13 +1292,13 @@ void TextEdit::_notification(int p_what) {
rect.size.x = xmargin_end - rect.position.x;
}
rect.size.y = caret_width;
- draw_rect(rect, cache.caret_color);
- cursor.draw_pos.x = rect.position.x;
+ draw_rect(rect, caret_color);
+ caret.draw_pos.x = rect.position.x;
}
}
{
// IME caret.
- Vector<Vector2> sel = TS->shaped_text_get_selection(rid, cursor.column + ime_selection.x, cursor.column + ime_selection.x + ime_selection.y);
+ Vector<Vector2> sel = TS->shaped_text_get_selection(rid, caret.column + ime_selection.x, caret.column + ime_selection.x + ime_selection.y);
for (int j = 0; j < sel.size(); j++) {
Rect2 rect = Rect2(sel[j].x + char_margin + ofs_x, ofs_y, sel[j].y - sel[j].x, text_height);
if (rect.position.x + rect.size.x <= xmargin_beg || rect.position.x > xmargin_end) {
@@ -1422,8 +1311,8 @@ void TextEdit::_notification(int p_what) {
rect.size.x = xmargin_end - rect.position.x;
}
rect.size.y = caret_width * 3;
- draw_rect(rect, cache.caret_color);
- cursor.draw_pos.x = rect.position.x;
+ draw_rect(rect, caret_color);
+ caret.draw_pos.x = rect.position.x;
}
}
}
@@ -1434,7 +1323,7 @@ void TextEdit::_notification(int p_what) {
if (has_focus()) {
if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) {
DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id());
- DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + cursor.draw_pos, get_viewport()->get_window_id());
+ DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + caret.draw_pos, get_viewport()->get_window_id());
}
}
} break;
@@ -1447,26 +1336,26 @@ void TextEdit::_notification(int p_what) {
if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_IME)) {
DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id());
- DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + _get_cursor_pixel_pos(false), get_viewport()->get_window_id());
+ DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + get_caret_draw_pos(), get_viewport()->get_window_id());
}
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
- int cursor_start = -1;
- int cursor_end = -1;
+ int caret_start = -1;
+ int caret_end = -1;
if (!selection.active) {
- String full_text = _base_get_text(0, 0, cursor.line, cursor.column);
+ String full_text = _base_get_text(0, 0, caret.line, caret.column);
- cursor_start = full_text.length();
+ caret_start = full_text.length();
} else {
String pre_text = _base_get_text(0, 0, selection.from_line, selection.from_column);
- String post_text = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
+ String post_text = get_selected_text();
- cursor_start = pre_text.length();
- cursor_end = cursor_start + post_text.length();
+ caret_start = pre_text.length();
+ caret_end = caret_start + post_text.length();
}
- DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect(), true, -1, cursor_start, cursor_end);
+ DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect(), true, -1, caret_start, caret_end);
}
} break;
case NOTIFICATION_FOCUS_EXIT: {
@@ -1480,7 +1369,7 @@ void TextEdit::_notification(int p_what) {
}
ime_text = "";
ime_selection = Point2();
- text.invalidate_cache(cursor.line, cursor.column, ime_text);
+ text.invalidate_cache(caret.line, caret.column, ime_text);
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
DisplayServer::get_singleton()->virtual_keyboard_hide();
@@ -1492,631 +1381,20 @@ void TextEdit::_notification(int p_what) {
ime_selection = DisplayServer::get_singleton()->ime_get_selection();
String t;
- if (cursor.column >= 0) {
- t = text[cursor.line].substr(0, cursor.column) + ime_text + text[cursor.line].substr(cursor.column, text[cursor.line].length());
+ if (caret.column >= 0) {
+ t = text[caret.line].substr(0, caret.column) + ime_text + text[caret.line].substr(caret.column, text[caret.line].length());
} else {
t = ime_text;
}
- text.invalidate_cache(cursor.line, cursor.column, t, structured_text_parser(st_parser, st_args, t));
+ text.invalidate_cache(caret.line, caret.column, t, structured_text_parser(st_parser, st_args, t));
update();
}
} break;
}
}
-void TextEdit::backspace() {
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_backspace")) {
- si->call("_backspace");
- return;
- }
-
- if (readonly) {
- return;
- }
-
- if (cursor.column == 0 && cursor.line == 0) {
- return;
- }
-
- if (is_selection_active()) {
- delete_selection();
- return;
- }
-
- int prev_line = cursor.column ? cursor.line : cursor.line - 1;
- int prev_column = cursor.column ? (cursor.column - 1) : (text[cursor.line - 1].length());
-
- merge_gutters(cursor.line, prev_line);
-
- if (is_line_hidden(cursor.line)) {
- set_line_as_hidden(prev_line, true);
- }
- _remove_text(prev_line, prev_column, cursor.line, cursor.column);
-
- cursor_set_line(prev_line, false, true);
- cursor_set_column(prev_column);
-}
-
-void TextEdit::_swap_current_input_direction() {
- if (input_direction == TEXT_DIRECTION_LTR) {
- input_direction = TEXT_DIRECTION_RTL;
- } else {
- input_direction = TEXT_DIRECTION_LTR;
- }
- cursor_set_column(cursor.column);
- update();
-}
-
-void TextEdit::_new_line(bool p_split_current_line, bool p_above) {
- if (readonly) {
- return;
- }
-
- begin_complex_operation();
-
- bool first_line = false;
- if (!p_split_current_line) {
- if (p_above) {
- if (cursor.line > 0) {
- cursor_set_line(cursor.line - 1, false);
- cursor_set_column(text[cursor.line].length());
- } else {
- cursor_set_column(0);
- first_line = true;
- }
- } else {
- cursor_set_column(text[cursor.line].length());
- }
- }
-
- insert_text_at_cursor("\n");
-
- if (first_line) {
- cursor_set_line(0);
- }
-
- end_complex_operation();
-}
-
-void TextEdit::_move_cursor_left(bool p_select, bool p_move_by_word) {
- // Handle selection
- if (p_select) {
- _pre_shift_selection();
- } else {
- deselect();
- }
-
- if (p_move_by_word) {
- int cc = cursor.column;
-
- if (cc == 0 && cursor.line > 0) {
- cursor_set_line(cursor.line - 1);
- cursor_set_column(text[cursor.line].length());
- } else {
- Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(cursor.line)->get_rid());
- for (int i = words.size() - 1; i >= 0; i--) {
- if (words[i].x < cc) {
- cc = words[i].x;
- break;
- }
- }
- cursor_set_column(cc);
- }
- } else {
- // If the cursor is at the start of the line, and not on the first line, move it up to the end of the previous line.
- if (cursor.column == 0) {
- if (cursor.line > 0) {
- 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 {
- if (mid_grapheme_caret_enabled) {
- cursor_set_column(cursor_get_column() - 1);
- } else {
- cursor_set_column(TS->shaped_text_prev_grapheme_pos(text.get_line_data(cursor.line)->get_rid(), cursor_get_column()));
- }
- }
- }
-
- if (p_select) {
- _post_shift_selection();
- }
-}
-
-void TextEdit::_move_cursor_right(bool p_select, bool p_move_by_word) {
- // Handle selection
- if (p_select) {
- _pre_shift_selection();
- } else {
- deselect();
- }
-
- if (p_move_by_word) {
- int cc = cursor.column;
-
- if (cc == text[cursor.line].length() && cursor.line < text.size() - 1) {
- cursor_set_line(cursor.line + 1);
- cursor_set_column(0);
- } else {
- Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(cursor.line)->get_rid());
- for (int i = 0; i < words.size(); i++) {
- if (words[i].y > cc) {
- cc = words[i].y;
- break;
- }
- }
- cursor_set_column(cc);
- }
- } else {
- // If we are at the end of the line, move the caret to the next line down.
- if (cursor.column == text[cursor.line].length()) {
- if (cursor.line < text.size() - 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 {
- if (mid_grapheme_caret_enabled) {
- cursor_set_column(cursor_get_column() + 1);
- } else {
- cursor_set_column(TS->shaped_text_next_grapheme_pos(text.get_line_data(cursor.line)->get_rid(), cursor_get_column()));
- }
- }
- }
-
- if (p_select) {
- _post_shift_selection();
- }
-}
-
-void TextEdit::_move_cursor_up(bool p_select) {
- if (p_select) {
- _pre_shift_selection();
- } else {
- deselect();
- }
-
- int cur_wrap_index = get_cursor_wrap_index();
- if (cur_wrap_index > 0) {
- cursor_set_line(cursor.line, true, false, cur_wrap_index - 1);
- } else if (cursor.line == 0) {
- cursor_set_column(0);
- } else {
- int new_line = cursor.line - num_lines_from(cursor.line - 1, -1);
- if (line_wraps(new_line)) {
- cursor_set_line(new_line, true, false, times_line_wraps(new_line));
- } else {
- cursor_set_line(new_line, true, false);
- }
- }
-
- if (p_select) {
- _post_shift_selection();
- }
-}
-
-void TextEdit::_move_cursor_down(bool p_select) {
- if (p_select) {
- _pre_shift_selection();
- } else {
- deselect();
- }
-
- int cur_wrap_index = get_cursor_wrap_index();
- if (cur_wrap_index < times_line_wraps(cursor.line)) {
- cursor_set_line(cursor.line, true, false, cur_wrap_index + 1);
- } else if (cursor.line == get_last_unhidden_line()) {
- cursor_set_column(text[cursor.line].length());
- } else {
- int new_line = cursor.line + num_lines_from(CLAMP(cursor.line + 1, 0, text.size() - 1), 1);
- cursor_set_line(new_line, true, false, 0);
- }
-
- if (p_select) {
- _post_shift_selection();
- }
-}
-
-void TextEdit::_move_cursor_to_line_start(bool p_select) {
- if (p_select) {
- _pre_shift_selection();
- } else {
- deselect();
- }
-
- // Move cursor column to start of wrapped row and then to start of text.
- Vector<String> rows = get_wrap_rows_text(cursor.line);
- int wi = get_cursor_wrap_index();
- int row_start_col = 0;
- for (int i = 0; i < wi; i++) {
- row_start_col += rows[i].length();
- }
- if (cursor.column == row_start_col || wi == 0) {
- // Compute whitespace symbols sequence length.
- int current_line_whitespace_len = 0;
- while (current_line_whitespace_len < text[cursor.line].length()) {
- char32_t c = text[cursor.line][current_line_whitespace_len];
- if (c != '\t' && c != ' ') {
- break;
- }
- current_line_whitespace_len++;
- }
-
- if (cursor_get_column() == current_line_whitespace_len) {
- cursor_set_column(0);
- } else {
- cursor_set_column(current_line_whitespace_len);
- }
- } else {
- cursor_set_column(row_start_col);
- }
-
- if (p_select) {
- _post_shift_selection();
- }
-}
-
-void TextEdit::_move_cursor_to_line_end(bool p_select) {
- if (p_select) {
- _pre_shift_selection();
- } else {
- deselect();
- }
-
- // Move cursor column to end of wrapped row and then to end of text.
- Vector<String> rows = get_wrap_rows_text(cursor.line);
- int wi = get_cursor_wrap_index();
- int row_end_col = -1;
- for (int i = 0; i < wi + 1; i++) {
- row_end_col += rows[i].length();
- }
- if (wi == rows.size() - 1 || cursor.column == row_end_col) {
- cursor_set_column(text[cursor.line].length());
- } else {
- cursor_set_column(row_end_col);
- }
-
- if (p_select) {
- _post_shift_selection();
- }
-}
-
-void TextEdit::_move_cursor_page_up(bool p_select) {
- if (p_select) {
- _pre_shift_selection();
- } else {
- deselect();
- }
-
- int wi;
- int n_line = cursor.line - num_lines_from_rows(cursor.line, get_cursor_wrap_index(), -get_visible_rows(), wi) + 1;
- cursor_set_line(n_line, true, false, wi);
-
- if (p_select) {
- _post_shift_selection();
- }
-}
-
-void TextEdit::_move_cursor_page_down(bool p_select) {
- if (p_select) {
- _pre_shift_selection();
- } else {
- deselect();
- }
-
- int wi;
- int n_line = cursor.line + num_lines_from_rows(cursor.line, get_cursor_wrap_index(), get_visible_rows(), wi) - 1;
- cursor_set_line(n_line, true, false, wi);
-
- if (p_select) {
- _post_shift_selection();
- }
-}
-
-void TextEdit::_do_backspace(bool p_word, bool p_all_to_left) {
- if (readonly) {
- return;
- }
-
- if (is_selection_active() || (!p_all_to_left && !p_word)) {
- backspace();
- return;
- }
-
- if (p_all_to_left) {
- int cursor_current_column = cursor.column;
- cursor.column = 0;
- _remove_text(cursor.line, 0, cursor.line, cursor_current_column);
- return;
- }
-
- if (p_word) {
- int line = cursor.line;
- int column = cursor.column;
-
- Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(line)->get_rid());
- for (int i = words.size() - 1; i >= 0; i--) {
- if (words[i].x < column) {
- column = words[i].x;
- break;
- }
- }
-
- _remove_text(line, column, cursor.line, cursor.column);
-
- cursor_set_line(line, false);
- cursor_set_column(column);
- return;
- }
-}
-
-void TextEdit::_delete(bool p_word, bool p_all_to_right) {
- if (readonly) {
- return;
- }
-
- if (is_selection_active()) {
- delete_selection();
- return;
- }
- int curline_len = text[cursor.line].length();
-
- if (cursor.line == text.size() - 1 && cursor.column == curline_len) {
- return; // Last line, last column: Nothing to do.
- }
-
- int next_line = cursor.column < curline_len ? cursor.line : cursor.line + 1;
- int next_column;
-
- if (p_all_to_right) {
- // Delete everything to right of cursor
- next_column = curline_len;
- next_line = cursor.line;
- } else if (p_word && cursor.column < curline_len - 1) {
- // Delete next word to right of cursor
- int line = cursor.line;
- int column = cursor.column;
-
- Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(line)->get_rid());
- for (int i = 0; i < words.size(); i++) {
- if (words[i].y > column) {
- column = words[i].y;
- break;
- }
- }
-
- next_line = line;
- next_column = column;
- } else {
- // Delete one character
- next_column = cursor.column < curline_len ? (cursor.column + 1) : 0;
- if (mid_grapheme_caret_enabled) {
- next_column = cursor.column < curline_len ? (cursor.column + 1) : 0;
- } else {
- next_column = cursor.column < curline_len ? TS->shaped_text_next_grapheme_pos(text.get_line_data(cursor.line)->get_rid(), (cursor.column)) : 0;
- }
- }
-
- _remove_text(cursor.line, cursor.column, next_line, next_column);
- update();
-}
-
-void TextEdit::delete_selection() {
- if (!is_selection_active()) {
- return;
- }
-
- selection.active = false;
- selection.selecting_mode = SelectionMode::SELECTION_MODE_NONE;
- _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
- cursor_set_line(selection.from_line, false, false);
- cursor_set_column(selection.from_column);
- update();
-}
-
-void TextEdit::_move_cursor_document_start(bool p_select) {
- if (p_select) {
- _pre_shift_selection();
- } else {
- deselect();
- }
-
- cursor_set_line(0);
- cursor_set_column(0);
-
- if (p_select) {
- _post_shift_selection();
- }
-}
-
-void TextEdit::_move_cursor_document_end(bool p_select) {
- if (p_select) {
- _pre_shift_selection();
- } else {
- deselect();
- }
-
- cursor_set_line(get_last_unhidden_line(), true, false, 9999);
- cursor_set_column(text[cursor.line].length());
-
- if (p_select) {
- _post_shift_selection();
- }
-}
-
-void TextEdit::handle_unicode_input(uint32_t p_unicode) {
- ScriptInstance *si = get_script_instance();
- if (si && si->has_method("_handle_unicode_input")) {
- si->call("_handle_unicode_input", p_unicode);
- return;
- }
-
- bool had_selection = selection.active;
- if (had_selection) {
- begin_complex_operation();
- delete_selection();
- }
-
- // Remove the old character if in insert mode and no selection.
- if (insert_mode && !had_selection) {
- begin_complex_operation();
-
- // Make sure we don't try and remove empty space.
- if (cursor.column < get_line(cursor.line).length()) {
- _remove_text(cursor.line, cursor.column, cursor.line, cursor.column + 1);
- }
- }
-
- const char32_t chr[2] = { (char32_t)p_unicode, 0 };
- insert_text_at_cursor(chr);
-
- if ((insert_mode && !had_selection) || (had_selection)) {
- end_complex_operation();
- }
-}
-
-void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const {
- float rows = p_mouse.y;
- rows -= cache.style_normal->get_margin(SIDE_TOP);
- rows /= get_row_height();
- rows += get_v_scroll_offset();
- int first_vis_line = get_first_visible_line();
- int row = first_vis_line + Math::floor(rows);
- int wrap_index = 0;
-
- if (is_wrap_enabled() || is_hiding_enabled()) {
- int f_ofs = num_lines_from_rows(first_vis_line, cursor.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
- if (rows < 0) {
- row = first_vis_line - f_ofs;
- } else {
- row = first_vis_line + f_ofs;
- }
- }
-
- if (row < 0) {
- row = 0;
- }
-
- int col = 0;
-
- if (row >= text.size()) {
- row = text.size() - 1;
- col = text[row].size();
- } else {
- int colx = p_mouse.x - (cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding);
- colx += cursor.x_ofs;
- col = get_char_pos_for_line(colx, row, wrap_index);
- if (is_wrap_enabled() && wrap_index < times_line_wraps(row)) {
- // Move back one if we are at the end of the row.
- Vector<String> rows2 = get_wrap_rows_text(row);
- int row_end_col = 0;
- for (int i = 0; i < wrap_index + 1; i++) {
- row_end_col += rows2[i].length();
- }
- if (col >= row_end_col) {
- col -= 1;
- }
- }
-
- RID text_rid = text.get_line_data(row)->get_line_rid(wrap_index);
- if (is_layout_rtl()) {
- colx = TS->shaped_text_get_size(text_rid).x - colx;
- }
- col = TS->shaped_text_hit_test_position(text_rid, colx);
- }
-
- r_row = row;
- r_col = col;
-}
-
-Vector2i TextEdit::_get_cursor_pixel_pos(bool p_adjust_viewport) {
- if (p_adjust_viewport) {
- adjust_viewport_to_cursor();
- }
- int row = 1;
- for (int i = get_first_visible_line(); i < cursor.line; i++) {
- if (!is_line_hidden(i)) {
- row += times_line_wraps(i) + 1;
- }
- }
- row += cursor.wrap_ofs;
-
- // Calculate final pixel position
- int y = (row - get_v_scroll_offset()) * get_row_height();
- int x = cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding - cursor.x_ofs;
-
- Rect2 l_caret, t_caret;
- TextServer::Direction l_dir, t_dir;
- RID text_rid = text.get_line_data(cursor.line)->get_line_rid(cursor.wrap_ofs);
- TS->shaped_text_get_carets(text_rid, cursor.column, l_caret, l_dir, t_caret, t_dir);
- if ((l_caret != Rect2() && (l_dir == TextServer::DIRECTION_AUTO || l_dir == (TextServer::Direction)input_direction)) || (t_caret == Rect2())) {
- x += l_caret.position.x;
- } else {
- x += t_caret.position.x;
- }
-
- return Vector2i(x, y);
-}
-
-void TextEdit::_get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const {
- float rows = p_mouse.y;
- rows -= cache.style_normal->get_margin(SIDE_TOP);
- rows /= (minimap_char_size.y + minimap_line_spacing);
- rows += get_v_scroll_offset();
-
- // calculate visible lines
- int minimap_visible_lines = _get_minimap_visible_rows();
- int visible_rows = get_visible_rows() + 1;
- int first_visible_line = get_first_visible_line() - 1;
- int draw_amount = visible_rows + (smooth_scroll_enabled ? 1 : 0);
- draw_amount += times_line_wraps(first_visible_line + 1);
- int minimap_line_height = (minimap_char_size.y + minimap_line_spacing);
-
- // calculate viewport size and y offset
- int viewport_height = (draw_amount - 1) * minimap_line_height;
- int control_height = _get_control_height() - viewport_height;
- int viewport_offset_y = round(get_scroll_pos_for_line(first_visible_line) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount));
-
- // calculate the first line.
- int num_lines_before = round((viewport_offset_y) / minimap_line_height);
- int wi;
- int minimap_line = (v_scroll->get_max() <= minimap_visible_lines) ? -1 : first_visible_line;
- if (first_visible_line > 0 && minimap_line >= 0) {
- minimap_line -= num_lines_from_rows(first_visible_line, 0, -num_lines_before, wi);
- minimap_line -= (minimap_line > 0 && smooth_scroll_enabled ? 1 : 0);
- } else {
- minimap_line = 0;
- }
-
- int row = minimap_line + Math::floor(rows);
- int wrap_index = 0;
-
- if (is_wrap_enabled() || is_hiding_enabled()) {
- int f_ofs = num_lines_from_rows(minimap_line, cursor.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
- if (rows < 0) {
- row = minimap_line - f_ofs;
- } else {
- row = minimap_line + f_ofs;
- }
- }
-
- if (row < 0) {
- row = 0;
- }
-
- if (row >= text.size()) {
- row = text.size() - 1;
- }
-
- r_row = row;
-}
-
-bool TextEdit::is_dragging_cursor() const {
- return dragging_selection || dragging_minimap;
-}
-
-void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
+void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
ERR_FAIL_COND(p_gui_input.is_null());
double prev_v_scroll = v_scroll->get_value();
@@ -2166,10 +1444,11 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (mb->get_button_index() == MOUSE_BUTTON_LEFT) {
_reset_caret_blink_timer();
- int row, col;
- _get_mouse_pos(Point2i(mpos.x, mpos.y), row, col);
+ Point2i pos = get_line_column_at_pos(Point2i(mpos.x, mpos.y));
+ int row = pos.y;
+ int col = pos.x;
- int left_margin = cache.style_normal->get_margin(SIDE_LEFT);
+ int left_margin = style_normal->get_margin(SIDE_LEFT);
for (int i = 0; i < gutters.size(); i++) {
if (!gutters[i].draw || gutters[i].width <= 0) {
continue;
@@ -2191,20 +1470,20 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
- int prev_col = cursor.column;
- int prev_line = cursor.line;
+ int prev_col = caret.column;
+ int prev_line = caret.line;
- cursor_set_line(row, false, false);
- cursor_set_column(col);
+ set_caret_line(row, false, false);
+ set_caret_column(col);
- if (mb->is_shift_pressed() && (cursor.column != prev_col || cursor.line != prev_line)) {
+ if (mb->is_shift_pressed() && (caret.column != prev_col || caret.line != prev_line)) {
if (!selection.active) {
selection.active = true;
selection.selecting_mode = SelectionMode::SELECTION_MODE_POINTER;
selection.from_column = prev_col;
selection.from_line = prev_line;
- selection.to_column = cursor.column;
- selection.to_line = cursor.line;
+ selection.to_column = caret.column;
+ selection.to_line = caret.line;
if (selection.from_line > selection.to_line || (selection.from_line == selection.to_line && selection.from_column > selection.to_column)) {
SWAP(selection.from_column, selection.to_column);
@@ -2217,21 +1496,21 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
selection.selecting_column = prev_col;
update();
} else {
- if (cursor.line < selection.selecting_line || (cursor.line == selection.selecting_line && cursor.column < selection.selecting_column)) {
+ if (caret.line < selection.selecting_line || (caret.line == selection.selecting_line && caret.column < selection.selecting_column)) {
if (selection.shiftclick_left) {
selection.shiftclick_left = !selection.shiftclick_left;
}
- selection.from_column = cursor.column;
- selection.from_line = cursor.line;
+ selection.from_column = caret.column;
+ selection.from_line = caret.line;
- } else if (cursor.line > selection.selecting_line || (cursor.line == selection.selecting_line && cursor.column > selection.selecting_column)) {
+ } else if (caret.line > selection.selecting_line || (caret.line == selection.selecting_line && caret.column > selection.selecting_column)) {
if (!selection.shiftclick_left) {
SWAP(selection.from_column, selection.to_column);
SWAP(selection.from_line, selection.to_line);
selection.shiftclick_left = !selection.shiftclick_left;
}
- selection.to_column = cursor.column;
- selection.to_line = cursor.line;
+ selection.to_column = caret.column;
+ selection.to_line = caret.line;
} else {
selection.active = false;
@@ -2246,16 +1525,20 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
selection.selecting_column = col;
}
- if (!mb->is_double_click() && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < 600 && cursor.line == prev_line) {
+ const int triple_click_timeout = 600;
+ const int triple_click_tolerance = 5;
+
+ if (!mb->is_double_click() && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < triple_click_timeout && mb->get_position().distance_to(last_dblclk_pos) < triple_click_tolerance) {
// Triple-click select line.
selection.selecting_mode = SelectionMode::SELECTION_MODE_LINE;
_update_selection_mode_line();
last_dblclk = 0;
- } else if (mb->is_double_click() && text[cursor.line].length()) {
+ } else if (mb->is_double_click() && text[caret.line].length()) {
// Double-click select word.
selection.selecting_mode = SelectionMode::SELECTION_MODE_WORD;
_update_selection_mode_word();
last_dblclk = OS::get_singleton()->get_ticks_msec();
+ last_dblclk_pos = mb->get_position();
}
update();
@@ -2264,11 +1547,12 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (mb->get_button_index() == MOUSE_BUTTON_RIGHT && context_menu_enabled) {
_reset_caret_blink_timer();
- int row, col;
- _get_mouse_pos(Point2i(mpos.x, mpos.y), row, col);
+ Point2i pos = get_line_column_at_pos(Point2i(mpos.x, mpos.y));
+ int row = pos.y;
+ int col = pos.x;
- if (is_right_click_moving_caret()) {
- if (is_selection_active()) {
+ if (is_move_caret_on_right_click_enabled()) {
+ if (has_selection()) {
int from_line = get_selection_from_line();
int to_line = get_selection_to_line();
int from_column = get_selection_from_column();
@@ -2279,13 +1563,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
deselect();
}
}
- if (!is_selection_active()) {
- cursor_set_line(row, true, false);
- cursor_set_column(col);
+ if (!has_selection()) {
+ set_caret_line(row, true, false);
+ set_caret_column(col);
}
}
- _ensure_menu();
+ _generate_context_menu();
menu->set_position(get_screen_transform().xform(mpos));
menu->set_size(Vector2(1, 1));
menu->popup();
@@ -2354,6 +1638,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
+ if (draw_minimap && !dragging_selection) {
+ _update_minimap_hover();
+ }
+
if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
accept_event(); // Accept event if scroll changed.
}
@@ -2484,8 +1772,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// MISC.
if (k->is_action("ui_menu", true)) {
if (context_menu_enabled) {
- _ensure_menu();
- menu->set_position(get_screen_transform().xform(_get_cursor_pixel_pos()));
+ _generate_context_menu();
+ adjust_viewport_to_caret();
+ menu->set_position(get_screen_transform().xform(get_caret_draw_pos()));
menu->set_size(Vector2(1, 1));
menu->popup();
menu->grab_focus();
@@ -2494,7 +1783,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
return;
}
if (k->is_action("ui_text_toggle_insert_mode", true)) {
- set_insert_mode(!insert_mode);
+ set_overtype_mode_enabled(!overtype_mode);
accept_event();
return;
}
@@ -2504,85 +1793,85 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
return;
}
- // CURSOR MOVEMENT
+ // CARET MOVEMENT
k = k->duplicate();
bool shift_pressed = k->is_shift_pressed();
// Remove shift or else actions will not match. Use above variable for selection.
k->set_shift_pressed(false);
- // CURSOR MOVEMENT - LEFT, RIGHT.
+ // CARET MOVEMENT - LEFT, RIGHT.
if (k->is_action("ui_text_caret_word_left", true)) {
- _move_cursor_left(shift_pressed, true);
+ _move_caret_left(shift_pressed, true);
accept_event();
return;
}
if (k->is_action("ui_text_caret_left", true)) {
- _move_cursor_left(shift_pressed, false);
+ _move_caret_left(shift_pressed, false);
accept_event();
return;
}
if (k->is_action("ui_text_caret_word_right", true)) {
- _move_cursor_right(shift_pressed, true);
+ _move_caret_right(shift_pressed, true);
accept_event();
return;
}
if (k->is_action("ui_text_caret_right", true)) {
- _move_cursor_right(shift_pressed, false);
+ _move_caret_right(shift_pressed, false);
accept_event();
return;
}
- // CURSOR MOVEMENT - UP, DOWN.
+ // CARET MOVEMENT - UP, DOWN.
if (k->is_action("ui_text_caret_up", true)) {
- _move_cursor_up(shift_pressed);
+ _move_caret_up(shift_pressed);
accept_event();
return;
}
if (k->is_action("ui_text_caret_down", true)) {
- _move_cursor_down(shift_pressed);
+ _move_caret_down(shift_pressed);
accept_event();
return;
}
- // CURSOR MOVEMENT - DOCUMENT START/END.
+ // CARET MOVEMENT - DOCUMENT START/END.
if (k->is_action("ui_text_caret_document_start", true)) { // && shift_pressed) {
- _move_cursor_document_start(shift_pressed);
+ _move_caret_document_start(shift_pressed);
accept_event();
return;
}
if (k->is_action("ui_text_caret_document_end", true)) { // && shift_pressed) {
- _move_cursor_document_end(shift_pressed);
+ _move_caret_document_end(shift_pressed);
accept_event();
return;
}
- // CURSOR MOVEMENT - LINE START/END.
+ // CARET MOVEMENT - LINE START/END.
if (k->is_action("ui_text_caret_line_start", true)) {
- _move_cursor_to_line_start(shift_pressed);
+ _move_caret_to_line_start(shift_pressed);
accept_event();
return;
}
if (k->is_action("ui_text_caret_line_end", true)) {
- _move_cursor_to_line_end(shift_pressed);
+ _move_caret_to_line_end(shift_pressed);
accept_event();
return;
}
- // CURSOR MOVEMENT - PAGE UP/DOWN.
+ // CARET MOVEMENT - PAGE UP/DOWN.
if (k->is_action("ui_text_caret_page_up", true)) {
- _move_cursor_page_up(shift_pressed);
+ _move_caret_page_up(shift_pressed);
accept_event();
return;
}
if (k->is_action("ui_text_caret_page_down", true)) {
- _move_cursor_page_down(shift_pressed);
+ _move_caret_page_down(shift_pressed);
accept_event();
return;
}
- // Handle Unicode (if no modifiers active).
- if (allow_unicode_handling && !readonly && k->get_unicode() >= 32) {
+ // Handle Unicode (if no modifiers active). Tab has a value of 0x09.
+ if (allow_unicode_handling && editable && (k->get_unicode() >= 32 || k->get_keycode() == KEY_TAB)) {
handle_unicode_input(k->get_unicode());
accept_event();
return;
@@ -2590,902 +1879,485 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
-void TextEdit::_scroll_up(real_t p_delta) {
- if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(-p_delta)) {
- scrolling = false;
- minimap_clicked = false;
- }
-
- if (scrolling) {
- target_v_scroll = (target_v_scroll - p_delta);
- } else {
- target_v_scroll = (get_v_scroll() - p_delta);
- }
-
- if (smooth_scroll_enabled) {
- if (target_v_scroll <= 0) {
- target_v_scroll = 0;
- }
- if (Math::abs(target_v_scroll - v_scroll->get_value()) < 1.0) {
- v_scroll->set_value(target_v_scroll);
- } else {
- scrolling = true;
- set_physics_process_internal(true);
- }
+/* Input actions. */
+void TextEdit::_swap_current_input_direction() {
+ if (input_direction == TEXT_DIRECTION_LTR) {
+ input_direction = TEXT_DIRECTION_RTL;
} else {
- set_v_scroll(target_v_scroll);
+ input_direction = TEXT_DIRECTION_LTR;
}
+ set_caret_column(caret.column);
+ update();
}
-void TextEdit::_scroll_down(real_t p_delta) {
- if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(p_delta)) {
- scrolling = false;
- minimap_clicked = false;
+void TextEdit::_new_line(bool p_split_current_line, bool p_above) {
+ if (!editable) {
+ return;
}
- if (scrolling) {
- target_v_scroll = (target_v_scroll + p_delta);
- } else {
- target_v_scroll = (get_v_scroll() + p_delta);
- }
+ begin_complex_operation();
- if (smooth_scroll_enabled) {
- int max_v_scroll = round(v_scroll->get_max() - v_scroll->get_page());
- if (target_v_scroll > max_v_scroll) {
- target_v_scroll = max_v_scroll;
- }
- if (Math::abs(target_v_scroll - v_scroll->get_value()) < 1.0) {
- v_scroll->set_value(target_v_scroll);
+ bool first_line = false;
+ if (!p_split_current_line) {
+ if (p_above) {
+ if (caret.line > 0) {
+ set_caret_line(caret.line - 1, false);
+ set_caret_column(text[caret.line].length());
+ } else {
+ set_caret_column(0);
+ first_line = true;
+ }
} else {
- scrolling = true;
- set_physics_process_internal(true);
+ set_caret_column(text[caret.line].length());
}
- } else {
- set_v_scroll(target_v_scroll);
- }
-}
-
-void TextEdit::_pre_shift_selection() {
- if (!selection.active || selection.selecting_mode == SelectionMode::SELECTION_MODE_NONE) {
- selection.selecting_line = cursor.line;
- selection.selecting_column = cursor.column;
- selection.active = true;
- }
-
- selection.selecting_mode = SelectionMode::SELECTION_MODE_SHIFT;
-}
-
-void TextEdit::_post_shift_selection() {
- if (selection.active && selection.selecting_mode == SelectionMode::SELECTION_MODE_SHIFT) {
- select(selection.selecting_line, selection.selecting_column, cursor.line, cursor.column);
- update();
}
- selection.selecting_text = true;
-}
-
-void TextEdit::_scroll_lines_up() {
- scrolling = false;
- minimap_clicked = false;
-
- // Adjust the vertical scroll.
- set_v_scroll(get_v_scroll() - 1);
-
- // Adjust the cursor to viewport.
- if (!selection.active) {
- int cur_line = cursor.line;
- int cur_wrap = get_cursor_wrap_index();
- int last_vis_line = get_last_full_visible_line();
- int last_vis_wrap = get_last_full_visible_line_wrap_index();
+ insert_text_at_caret("\n");
- if (cur_line > last_vis_line || (cur_line == last_vis_line && cur_wrap > last_vis_wrap)) {
- cursor_set_line(last_vis_line, false, false, last_vis_wrap);
- }
+ if (first_line) {
+ set_caret_line(0);
}
-}
-
-void TextEdit::_scroll_lines_down() {
- scrolling = false;
- minimap_clicked = false;
- // Adjust the vertical scroll.
- set_v_scroll(get_v_scroll() + 1);
-
- // Adjust the cursor to viewport.
- if (!selection.active) {
- int cur_line = cursor.line;
- int cur_wrap = get_cursor_wrap_index();
- int first_vis_line = get_first_visible_line();
- int first_vis_wrap = cursor.wrap_ofs;
-
- if (cur_line < first_vis_line || (cur_line == first_vis_line && cur_wrap < first_vis_wrap)) {
- cursor_set_line(first_vis_line, false, false, first_vis_wrap);
- }
- }
+ end_complex_operation();
}
-/**** TEXT EDIT CORE API ****/
-
-void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, int &r_end_line, int &r_end_column) {
- // Save for undo.
- ERR_FAIL_INDEX(p_line, text.size());
- ERR_FAIL_COND(p_char < 0);
-
- /* STEP 1: Remove \r from source text and separate in substrings. */
-
- Vector<String> substrings = p_text.replace("\r", "").split("\n");
-
- // Is this just a new empty line?
- bool shift_first_line = p_char == 0 && p_text.replace("\r", "") == "\n";
-
- /* STEP 2: Add spaces if the char is greater than the end of the line. */
- while (p_char > text[p_line].length()) {
- text.set(p_line, text[p_line] + String::chr(' '), structured_text_parser(st_parser, st_args, text[p_line] + String::chr(' ')));
+void TextEdit::_move_caret_left(bool p_select, bool p_move_by_word) {
+ // Handle selection
+ if (p_select) {
+ _pre_shift_selection();
+ } else if (selection.active && !p_move_by_word) {
+ // If a selection is active, move caret to start of selection
+ set_caret_line(selection.from_line);
+ set_caret_column(selection.from_column);
+ deselect();
+ return;
+ } else {
+ deselect();
}
- /* STEP 3: Separate dest string in pre and post text. */
-
- String preinsert_text = text[p_line].substr(0, p_char);
- String postinsert_text = text[p_line].substr(p_char, text[p_line].size());
-
- for (int j = 0; j < substrings.size(); j++) {
- // Insert the substrings.
+ if (p_move_by_word) {
+ int cc = caret.column;
- if (j == 0) {
- text.set(p_line, preinsert_text + substrings[j], structured_text_parser(st_parser, st_args, preinsert_text + substrings[j]));
+ if (cc == 0 && caret.line > 0) {
+ set_caret_line(caret.line - 1);
+ set_caret_column(text[caret.line].length());
} else {
- text.insert(p_line + j, substrings[j], structured_text_parser(st_parser, st_args, substrings[j]));
- }
-
- if (j == substrings.size() - 1) {
- text.set(p_line + j, text[p_line + j] + postinsert_text, structured_text_parser(st_parser, st_args, text[p_line + j] + postinsert_text));
+ Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(caret.line)->get_rid());
+ for (int i = words.size() - 1; i >= 0; i--) {
+ if (words[i].x < cc) {
+ cc = words[i].x;
+ break;
+ }
+ }
+ set_caret_column(cc);
}
- }
-
- if (shift_first_line) {
- text.move_gutters(p_line, p_line + 1);
- text.set_hidden(p_line + 1, text.is_hidden(p_line));
-
- text.set_hidden(p_line, false);
- }
-
- text.invalidate_cache(p_line);
-
- r_end_line = p_line + substrings.size() - 1;
- r_end_column = text[r_end_line].length() - postinsert_text.length();
-
- TextServer::Direction dir = TS->shaped_text_get_dominant_direciton_in_range(text.get_line_data(r_end_line)->get_rid(), (r_end_line == p_line) ? cursor.column : 0, r_end_column);
- if (dir != TextServer::DIRECTION_AUTO) {
- input_direction = (TextDirection)dir;
- }
-
- if (!text_changed_dirty && !setting_text) {
- if (is_inside_tree()) {
- MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ } else {
+ // If the caret is at the start of the line, and not on the first line, move it up to the end of the previous line.
+ if (caret.column == 0) {
+ if (caret.line > 0) {
+ set_caret_line(caret.line - get_next_visible_line_offset_from(CLAMP(caret.line - 1, 0, text.size() - 1), -1));
+ set_caret_column(text[caret.line].length());
+ }
+ } else {
+ if (caret_mid_grapheme_enabled) {
+ set_caret_column(get_caret_column() - 1);
+ } else {
+ set_caret_column(TS->shaped_text_prev_grapheme_pos(text.get_line_data(caret.line)->get_rid(), get_caret_column()));
+ }
}
- text_changed_dirty = true;
}
- emit_signal(SNAME("lines_edited_from"), p_line, r_end_line);
-}
-
-String TextEdit::_base_get_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) const {
- ERR_FAIL_INDEX_V(p_from_line, text.size(), String());
- ERR_FAIL_INDEX_V(p_from_column, text[p_from_line].length() + 1, String());
- ERR_FAIL_INDEX_V(p_to_line, text.size(), String());
- ERR_FAIL_INDEX_V(p_to_column, text[p_to_line].length() + 1, String());
- ERR_FAIL_COND_V(p_to_line < p_from_line, String()); // 'from > to'.
- ERR_FAIL_COND_V(p_to_line == p_from_line && p_to_column < p_from_column, String()); // 'from > to'.
- String ret;
-
- for (int i = p_from_line; i <= p_to_line; i++) {
- int begin = (i == p_from_line) ? p_from_column : 0;
- int end = (i == p_to_line) ? p_to_column : text[i].length();
-
- if (i > p_from_line) {
- ret += "\n";
- }
- ret += text[i].substr(begin, end - begin);
+ if (p_select) {
+ _post_shift_selection();
}
-
- return ret;
}
-void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
- ERR_FAIL_INDEX(p_from_line, text.size());
- ERR_FAIL_INDEX(p_from_column, text[p_from_line].length() + 1);
- ERR_FAIL_INDEX(p_to_line, text.size());
- ERR_FAIL_INDEX(p_to_column, text[p_to_line].length() + 1);
- ERR_FAIL_COND(p_to_line < p_from_line); // 'from > to'.
- ERR_FAIL_COND(p_to_line == p_from_line && p_to_column < p_from_column); // 'from > to'.
-
- String pre_text = text[p_from_line].substr(0, p_from_column);
- String post_text = text[p_to_line].substr(p_to_column, text[p_to_line].length());
-
- for (int i = p_from_line; i < p_to_line; i++) {
- text.remove(p_from_line + 1);
+void TextEdit::_move_caret_right(bool p_select, bool p_move_by_word) {
+ // Handle selection
+ if (p_select) {
+ _pre_shift_selection();
+ } else if (selection.active && !p_move_by_word) {
+ // If a selection is active, move caret to end of selection
+ set_caret_line(selection.to_line);
+ set_caret_column(selection.to_column);
+ deselect();
+ return;
+ } else {
+ deselect();
}
- text.set(p_from_line, pre_text + post_text, structured_text_parser(st_parser, st_args, pre_text + post_text));
- //text.set_line_wrap_amount(p_from_line, -1);
- text.invalidate_cache(p_from_line);
+ if (p_move_by_word) {
+ int cc = caret.column;
- if (!text_changed_dirty && !setting_text) {
- if (is_inside_tree()) {
- MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ if (cc == text[caret.line].length() && caret.line < text.size() - 1) {
+ set_caret_line(caret.line + 1);
+ set_caret_column(0);
+ } else {
+ Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(caret.line)->get_rid());
+ for (int i = 0; i < words.size(); i++) {
+ if (words[i].y > cc) {
+ cc = words[i].y;
+ break;
+ }
+ }
+ set_caret_column(cc);
+ }
+ } else {
+ // If we are at the end of the line, move the caret to the next line down.
+ if (caret.column == text[caret.line].length()) {
+ if (caret.line < text.size() - 1) {
+ set_caret_line(get_caret_line() + get_next_visible_line_offset_from(CLAMP(caret.line + 1, 0, text.size() - 1), 1), true, false);
+ set_caret_column(0);
+ }
+ } else {
+ if (caret_mid_grapheme_enabled) {
+ set_caret_column(get_caret_column() + 1);
+ } else {
+ set_caret_column(TS->shaped_text_next_grapheme_pos(text.get_line_data(caret.line)->get_rid(), get_caret_column()));
+ }
}
- text_changed_dirty = true;
- }
- emit_signal(SNAME("lines_edited_from"), p_to_line, p_from_line);
-}
-
-void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r_end_line, int *r_end_char) {
- if (!setting_text && idle_detect->is_inside_tree()) {
- idle_detect->start();
- }
-
- if (undo_enabled) {
- _clear_redo();
- }
-
- int retline, retchar;
- _base_insert_text(p_line, p_char, p_text, retline, retchar);
- if (r_end_line) {
- *r_end_line = retline;
- }
- if (r_end_char) {
- *r_end_char = retchar;
- }
-
- if (!undo_enabled) {
- return;
}
- /* UNDO!! */
- TextOperation op;
- op.type = TextOperation::TYPE_INSERT;
- op.from_line = p_line;
- op.from_column = p_char;
- op.to_line = retline;
- op.to_column = retchar;
- op.text = p_text;
- op.version = ++version;
- op.chain_forward = false;
- op.chain_backward = false;
-
- // See if it should just be set as current op.
- if (current_op.type != op.type) {
- op.prev_version = get_version();
- _push_current_op();
- current_op = op;
-
- return; // Set as current op, return.
- }
- // See if it can be merged.
- if (current_op.to_line != p_line || current_op.to_column != p_char) {
- op.prev_version = get_version();
- _push_current_op();
- current_op = op;
- return; // Set as current op, return.
+ if (p_select) {
+ _post_shift_selection();
}
- // Merge current op.
-
- current_op.text += p_text;
- current_op.to_column = retchar;
- current_op.to_line = retline;
- current_op.version = op.version;
}
-void TextEdit::_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
- if (!setting_text && idle_detect->is_inside_tree()) {
- idle_detect->start();
- }
-
- String text;
- if (undo_enabled) {
- _clear_redo();
- text = _base_get_text(p_from_line, p_from_column, p_to_line, p_to_column);
- }
-
- _base_remove_text(p_from_line, p_from_column, p_to_line, p_to_column);
-
- if (!undo_enabled) {
- return;
- }
-
- /* UNDO! */
- TextOperation op;
- op.type = TextOperation::TYPE_REMOVE;
- op.from_line = p_from_line;
- op.from_column = p_from_column;
- op.to_line = p_to_line;
- op.to_column = p_to_column;
- op.text = text;
- op.version = ++version;
- op.chain_forward = false;
- op.chain_backward = false;
-
- // See if it should just be set as current op.
- if (current_op.type != op.type) {
- op.prev_version = get_version();
- _push_current_op();
- current_op = op;
- return; // Set as current op, return.
- }
- // See if it can be merged.
- if (current_op.from_line == p_to_line && current_op.from_column == p_to_column) {
- // Backspace or similar.
- current_op.text = text + current_op.text;
- current_op.from_line = p_from_line;
- current_op.from_column = p_from_column;
- return; // Update current op.
+void TextEdit::_move_caret_up(bool p_select) {
+ if (p_select) {
+ _pre_shift_selection();
+ } else {
+ deselect();
}
- op.prev_version = get_version();
- _push_current_op();
- current_op = op;
-}
-
-int TextEdit::get_char_count() {
- int totalsize = 0;
-
- for (int i = 0; i < text.size(); i++) {
- if (i > 0) {
- totalsize++; // Include \n.
+ int cur_wrap_index = get_caret_wrap_index();
+ if (cur_wrap_index > 0) {
+ set_caret_line(caret.line, true, false, cur_wrap_index - 1);
+ } else if (caret.line == 0) {
+ set_caret_column(0);
+ } else {
+ int new_line = caret.line - get_next_visible_line_offset_from(caret.line - 1, -1);
+ if (is_line_wrapped(new_line)) {
+ set_caret_line(new_line, true, false, get_line_wrap_count(new_line));
+ } else {
+ set_caret_line(new_line, true, false);
}
- totalsize += text[i].length();
}
- return totalsize; // Omit last \n.
-}
-
-Size2 TextEdit::get_minimum_size() const {
- return cache.style_normal->get_minimum_size();
-}
-
-int TextEdit::_get_control_height() const {
- int control_height = get_size().height;
- control_height -= cache.style_normal->get_minimum_size().height;
- if (h_scroll->is_visible_in_tree()) {
- control_height -= h_scroll->get_size().height;
+ if (p_select) {
+ _post_shift_selection();
}
- return control_height;
}
-int TextEdit::_get_menu_action_accelerator(const String &p_action) {
- const List<Ref<InputEvent>> *events = InputMap::get_singleton()->action_get_events(p_action);
- if (!events) {
- return 0;
- }
-
- // Use first event in the list for the accelerator.
- const List<Ref<InputEvent>>::Element *first_event = events->front();
- if (!first_event) {
- return 0;
- }
-
- const Ref<InputEventKey> event = first_event->get();
- if (event.is_null()) {
- return 0;
- }
-
- // Use physical keycode if non-zero
- if (event->get_physical_keycode() != 0) {
- return event->get_physical_keycode_with_modifiers();
+void TextEdit::_move_caret_down(bool p_select) {
+ if (p_select) {
+ _pre_shift_selection();
} else {
- return event->get_keycode_with_modifiers();
- }
-}
-
-int TextEdit::get_visible_rows() const {
- return _get_control_height() / get_row_height();
-}
-
-int TextEdit::_get_minimap_visible_rows() const {
- return _get_control_height() / (minimap_char_size.y + minimap_line_spacing);
-}
-
-int TextEdit::get_total_visible_rows() const {
- // Returns the total amount of rows we need in the editor.
- // This skips hidden lines and counts each wrapping of a line.
- if (!is_hiding_enabled() && !is_wrap_enabled()) {
- return text.size();
- }
-
- int total_rows = 0;
- for (int i = 0; i < text.size(); i++) {
- if (!text.is_hidden(i)) {
- total_rows++;
- total_rows += times_line_wraps(i);
- }
+ deselect();
}
- return total_rows;
-}
-void TextEdit::_update_wrap_at(bool p_force) {
- int new_wrap_at = get_size().width - cache.style_normal->get_minimum_size().width - gutters_width - gutter_padding;
- if (draw_minimap) {
- new_wrap_at -= minimap_width;
- }
- if (v_scroll->is_visible_in_tree()) {
- new_wrap_at -= v_scroll->get_combined_minimum_size().width;
+ int cur_wrap_index = get_caret_wrap_index();
+ if (cur_wrap_index < get_line_wrap_count(caret.line)) {
+ set_caret_line(caret.line, true, false, cur_wrap_index + 1);
+ } else if (caret.line == get_last_unhidden_line()) {
+ set_caret_column(text[caret.line].length());
+ } else {
+ int new_line = caret.line + get_next_visible_line_offset_from(CLAMP(caret.line + 1, 0, text.size() - 1), 1);
+ set_caret_line(new_line, true, false, 0);
}
- new_wrap_at -= wrap_right_offset; // Give it a little more space.
- if ((wrap_at != new_wrap_at) || p_force) {
- wrap_at = new_wrap_at;
- if (wrap_enabled) {
- text.set_width(wrap_at);
- } else {
- text.set_width(-1);
- }
- text.invalidate_all_lines();
+ if (p_select) {
+ _post_shift_selection();
}
-
- update_cursor_wrap_offset();
}
-void TextEdit::adjust_viewport_to_cursor() {
- // Make sure cursor is visible on the screen.
- scrolling = false;
- minimap_clicked = false;
-
- int cur_line = cursor.line;
- int cur_wrap = get_cursor_wrap_index();
-
- int first_vis_line = get_first_visible_line();
- int first_vis_wrap = cursor.wrap_ofs;
- int last_vis_line = get_last_full_visible_line();
- int last_vis_wrap = get_last_full_visible_line_wrap_index();
-
- if (cur_line < first_vis_line || (cur_line == first_vis_line && cur_wrap < first_vis_wrap)) {
- // Cursor is above screen.
- set_line_as_first_visible(cur_line, cur_wrap);
- } else if (cur_line > last_vis_line || (cur_line == last_vis_line && cur_wrap > last_vis_wrap)) {
- // Cursor is below screen.
- set_line_as_last_visible(cur_line, cur_wrap);
+void TextEdit::_move_caret_to_line_start(bool p_select) {
+ if (p_select) {
+ _pre_shift_selection();
+ } else {
+ deselect();
}
- int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - gutters_width - gutter_padding - cache.minimap_width;
- if (v_scroll->is_visible_in_tree()) {
- visible_width -= v_scroll->get_combined_minimum_size().width;
+ // Move caret column to start of wrapped row and then to start of text.
+ Vector<String> rows = get_line_wrapped_text(caret.line);
+ int wi = get_caret_wrap_index();
+ int row_start_col = 0;
+ for (int i = 0; i < wi; i++) {
+ row_start_col += rows[i].length();
}
- visible_width -= 20; // Give it a little more space.
-
- if (!is_wrap_enabled()) {
- // Adjust x offset.
- Vector2i cursor_pos;
-
- // Get position of the start of caret.
- if (ime_text.length() != 0 && ime_selection.x != 0) {
- cursor_pos.x = get_column_x_offset_for_line(cursor.column + ime_selection.x, cursor.line);
- } else {
- cursor_pos.x = get_column_x_offset_for_line(cursor.column, cursor.line);
- }
-
- // Get position of the end of caret.
- if (ime_text.length() != 0) {
- if (ime_selection.y != 0) {
- cursor_pos.y = get_column_x_offset_for_line(cursor.column + ime_selection.x + ime_selection.y, cursor.line);
- } else {
- cursor_pos.y = get_column_x_offset_for_line(cursor.column + ime_text.size(), cursor.line);
+ if (caret.column == row_start_col || wi == 0) {
+ // Compute whitespace symbols sequence length.
+ int current_line_whitespace_len = 0;
+ while (current_line_whitespace_len < text[caret.line].length()) {
+ char32_t c = text[caret.line][current_line_whitespace_len];
+ if (c != '\t' && c != ' ') {
+ break;
}
- } else {
- cursor_pos.y = cursor_pos.x;
- }
-
- if (MAX(cursor_pos.x, cursor_pos.y) > (cursor.x_ofs + visible_width)) {
- cursor.x_ofs = MAX(cursor_pos.x, cursor_pos.y) - visible_width + 1;
+ current_line_whitespace_len++;
}
- if (MIN(cursor_pos.x, cursor_pos.y) < cursor.x_ofs) {
- cursor.x_ofs = MIN(cursor_pos.x, cursor_pos.y);
+ if (get_caret_column() == current_line_whitespace_len) {
+ set_caret_column(0);
+ } else {
+ set_caret_column(current_line_whitespace_len);
}
} else {
- cursor.x_ofs = 0;
+ set_caret_column(row_start_col);
}
- h_scroll->set_value(cursor.x_ofs);
- update();
-}
-
-void TextEdit::center_viewport_to_cursor() {
- // Move viewport so the cursor is in the center of the screen.
- scrolling = false;
- minimap_clicked = false;
-
- set_line_as_center_visible(cursor.line, get_cursor_wrap_index());
- int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - gutters_width - gutter_padding - cache.minimap_width;
- if (v_scroll->is_visible_in_tree()) {
- visible_width -= v_scroll->get_combined_minimum_size().width;
+ if (p_select) {
+ _post_shift_selection();
}
- visible_width -= 20; // Give it a little more space.
-
- if (is_wrap_enabled()) {
- // Center x offset.
-
- Vector2i cursor_pos;
-
- // Get position of the start of caret.
- if (ime_text.length() != 0 && ime_selection.x != 0) {
- cursor_pos.x = get_column_x_offset_for_line(cursor.column + ime_selection.x, cursor.line);
- } else {
- cursor_pos.x = get_column_x_offset_for_line(cursor.column, cursor.line);
- }
-
- // Get position of the end of caret.
- if (ime_text.length() != 0) {
- if (ime_selection.y != 0) {
- cursor_pos.y = get_column_x_offset_for_line(cursor.column + ime_selection.x + ime_selection.y, cursor.line);
- } else {
- cursor_pos.y = get_column_x_offset_for_line(cursor.column + ime_text.size(), cursor.line);
- }
- } else {
- cursor_pos.y = cursor_pos.x;
- }
-
- if (MAX(cursor_pos.x, cursor_pos.y) > (cursor.x_ofs + visible_width)) {
- cursor.x_ofs = MAX(cursor_pos.x, cursor_pos.y) - visible_width + 1;
- }
+}
- if (MIN(cursor_pos.x, cursor_pos.y) < cursor.x_ofs) {
- cursor.x_ofs = MIN(cursor_pos.x, cursor_pos.y);
- }
+void TextEdit::_move_caret_to_line_end(bool p_select) {
+ if (p_select) {
+ _pre_shift_selection();
} else {
- cursor.x_ofs = 0;
+ deselect();
}
- h_scroll->set_value(cursor.x_ofs);
-
- update();
-}
-void TextEdit::update_cursor_wrap_offset() {
- int first_vis_line = get_first_visible_line();
- if (line_wraps(first_vis_line)) {
- cursor.wrap_ofs = MIN(cursor.wrap_ofs, times_line_wraps(first_vis_line));
+ // Move caret column to end of wrapped row and then to end of text.
+ Vector<String> rows = get_line_wrapped_text(caret.line);
+ int wi = get_caret_wrap_index();
+ int row_end_col = -1;
+ for (int i = 0; i < wi + 1; i++) {
+ row_end_col += rows[i].length();
+ }
+ if (wi == rows.size() - 1 || caret.column == row_end_col) {
+ set_caret_column(text[caret.line].length());
} else {
- cursor.wrap_ofs = 0;
+ set_caret_column(row_end_col);
}
- set_line_as_first_visible(cursor.line_ofs, cursor.wrap_ofs);
-}
-bool TextEdit::line_wraps(int line) const {
- ERR_FAIL_INDEX_V(line, text.size(), 0);
- if (!is_wrap_enabled()) {
- return false;
+ if (p_select) {
+ _post_shift_selection();
}
- return text.get_line_wrap_amount(line) > 0;
}
-int TextEdit::times_line_wraps(int line) const {
- ERR_FAIL_INDEX_V(line, text.size(), 0);
-
- if (!line_wraps(line)) {
- return 0;
+void TextEdit::_move_caret_page_up(bool p_select) {
+ if (p_select) {
+ _pre_shift_selection();
+ } else {
+ deselect();
}
- return text.get_line_wrap_amount(line);
-}
-
-Vector<String> TextEdit::get_wrap_rows_text(int p_line) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), Vector<String>());
+ Point2i next_line = get_next_visible_line_index_offset_from(caret.line, get_caret_wrap_index(), -get_visible_line_count());
+ int n_line = caret.line - next_line.x + 1;
+ set_caret_line(n_line, true, false, next_line.y);
- Vector<String> lines;
- if (!line_wraps(p_line)) {
- lines.push_back(text[p_line]);
- return lines;
+ if (p_select) {
+ _post_shift_selection();
}
+}
- const String &line_text = text[p_line];
- Vector<Vector2i> line_ranges = text.get_line_wrap_ranges(p_line);
- for (int i = 0; i < line_ranges.size(); i++) {
- lines.push_back(line_text.substr(line_ranges[i].x, line_ranges[i].y - line_ranges[i].x));
+void TextEdit::_move_caret_page_down(bool p_select) {
+ if (p_select) {
+ _pre_shift_selection();
+ } else {
+ deselect();
}
- return lines;
-}
+ Point2i next_line = get_next_visible_line_index_offset_from(caret.line, get_caret_wrap_index(), get_visible_line_count());
+ int n_line = caret.line + next_line.x - 1;
+ set_caret_line(n_line, true, false, next_line.y);
-int TextEdit::get_cursor_wrap_index() const {
- return get_line_wrap_index_at_col(cursor.line, cursor.column);
+ if (p_select) {
+ _post_shift_selection();
+ }
}
-int TextEdit::get_line_wrap_index_at_col(int p_line, int p_column) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), 0);
-
- if (!line_wraps(p_line)) {
- return 0;
+void TextEdit::_do_backspace(bool p_word, bool p_all_to_left) {
+ if (!editable) {
+ return;
}
- // Loop through wraps in the line text until we get to the column.
- int wrap_index = 0;
- int col = 0;
- Vector<String> rows = get_wrap_rows_text(p_line);
- for (int i = 0; i < rows.size(); i++) {
- wrap_index = i;
- String s = rows[wrap_index];
- col += s.length();
- if (col > p_column) {
- break;
- }
+ if (has_selection() || (!p_all_to_left && !p_word)) {
+ backspace();
+ return;
}
- return wrap_index;
-}
-void TextEdit::set_mid_grapheme_caret_enabled(const bool p_enabled) {
- mid_grapheme_caret_enabled = p_enabled;
-}
-
-bool TextEdit::get_mid_grapheme_caret_enabled() const {
- return mid_grapheme_caret_enabled;
-}
-
-void TextEdit::cursor_set_column(int p_col, bool p_adjust_viewport) {
- if (p_col < 0) {
- p_col = 0;
+ if (p_all_to_left) {
+ int caret_current_column = caret.column;
+ caret.column = 0;
+ _remove_text(caret.line, 0, caret.line, caret_current_column);
+ return;
}
- cursor.column = p_col;
- if (cursor.column > get_line(cursor.line).length()) {
- cursor.column = get_line(cursor.line).length();
- }
+ if (p_word) {
+ int line = caret.line;
+ int column = caret.column;
- cursor.last_fit_x = get_column_x_offset_for_line(cursor.column, cursor.line);
+ Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(line)->get_rid());
+ for (int i = words.size() - 1; i >= 0; i--) {
+ if (words[i].x < column) {
+ column = words[i].x;
+ break;
+ }
+ }
- if (p_adjust_viewport) {
- adjust_viewport_to_cursor();
- }
+ _remove_text(line, column, caret.line, caret.column);
- if (!cursor_changed_dirty) {
- if (is_inside_tree()) {
- MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
- }
- cursor_changed_dirty = true;
+ set_caret_line(line, false);
+ set_caret_column(column);
+ return;
}
}
-void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport, bool p_can_be_hidden, int p_wrap_index) {
- if (setting_row) {
+void TextEdit::_delete(bool p_word, bool p_all_to_right) {
+ if (!editable) {
return;
}
- setting_row = true;
- if (p_row < 0) {
- p_row = 0;
- }
-
- if (p_row >= text.size()) {
- p_row = 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_PRINT(("Cursor set to hidden line " + itos(p_row) + " and there are no nonhidden lines."));
- }
- }
- }
+ if (has_selection()) {
+ delete_selection();
+ return;
}
- cursor.line = p_row;
+ int curline_len = text[caret.line].length();
- int n_col = get_char_pos_for_line(cursor.last_fit_x, p_row, p_wrap_index);
- if (n_col != 0 && is_wrap_enabled() && p_wrap_index < times_line_wraps(p_row)) {
- Vector<String> rows = get_wrap_rows_text(p_row);
- int row_end_col = 0;
- for (int i = 0; i < p_wrap_index + 1; i++) {
- row_end_col += rows[i].length();
- }
- if (n_col >= row_end_col) {
- n_col -= 1;
- }
+ if (caret.line == text.size() - 1 && caret.column == curline_len) {
+ return; // Last line, last column: Nothing to do.
}
- cursor.column = n_col;
- if (p_adjust_viewport) {
- adjust_viewport_to_cursor();
- }
+ int next_line = caret.column < curline_len ? caret.line : caret.line + 1;
+ int next_column;
- setting_row = false;
+ if (p_all_to_right) {
+ // Delete everything to right of caret
+ next_column = curline_len;
+ next_line = caret.line;
+ } else if (p_word && caret.column < curline_len - 1) {
+ // Delete next word to right of caret
+ int line = caret.line;
+ int column = caret.column;
- if (!cursor_changed_dirty) {
- if (is_inside_tree()) {
- MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
+ Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(line)->get_rid());
+ for (int i = 0; i < words.size(); i++) {
+ if (words[i].y > column) {
+ column = words[i].y;
+ break;
+ }
}
- cursor_changed_dirty = true;
- }
-}
-
-Point2 TextEdit::get_caret_draw_pos() const {
- return cursor.draw_pos;
-}
-
-bool TextEdit::is_caret_visible() const {
- return cursor.visible;
-}
-
-int TextEdit::cursor_get_column() const {
- return cursor.column;
-}
-
-int TextEdit::cursor_get_line() const {
- return cursor.line;
-}
-
-bool TextEdit::cursor_get_blink_enabled() const {
- return caret_blink_enabled;
-}
-
-void TextEdit::cursor_set_blink_enabled(const bool p_enabled) {
- caret_blink_enabled = p_enabled;
- if (has_focus()) {
- if (p_enabled) {
- caret_blink_timer->start();
+ next_line = line;
+ next_column = column;
+ } else {
+ // Delete one character
+ if (caret_mid_grapheme_enabled) {
+ next_column = caret.column < curline_len ? (caret.column + 1) : 0;
} else {
- caret_blink_timer->stop();
+ next_column = caret.column < curline_len ? TS->shaped_text_next_grapheme_pos(text.get_line_data(caret.line)->get_rid(), (caret.column)) : 0;
}
}
- draw_caret = true;
-}
-
-float TextEdit::cursor_get_blink_speed() const {
- return caret_blink_timer->get_wait_time();
-}
-
-void TextEdit::cursor_set_blink_speed(const float p_speed) {
- ERR_FAIL_COND(p_speed <= 0);
- caret_blink_timer->set_wait_time(p_speed);
-}
-
-void TextEdit::cursor_set_block_mode(const bool p_enable) {
- block_caret = p_enable;
+ _remove_text(caret.line, caret.column, next_line, next_column);
update();
}
-bool TextEdit::cursor_is_block_mode() const {
- return block_caret;
-}
-
-void TextEdit::set_right_click_moves_caret(bool p_enable) {
- right_click_moves_caret = p_enable;
-}
+void TextEdit::_move_caret_document_start(bool p_select) {
+ if (p_select) {
+ _pre_shift_selection();
+ } else {
+ deselect();
+ }
-bool TextEdit::is_right_click_moving_caret() const {
- return right_click_moves_caret;
-}
+ set_caret_line(0);
+ set_caret_column(0);
-TextEdit::SelectionMode TextEdit::get_selection_mode() const {
- return selection.selecting_mode;
+ if (p_select) {
+ _post_shift_selection();
+ }
}
-void TextEdit::set_selection_mode(SelectionMode p_mode, int p_line, int p_column) {
- selection.selecting_mode = p_mode;
- if (p_line >= 0) {
- ERR_FAIL_INDEX(p_line, text.size());
- selection.selecting_line = p_line;
+void TextEdit::_move_caret_document_end(bool p_select) {
+ if (p_select) {
+ _pre_shift_selection();
+ } else {
+ deselect();
}
- if (p_column >= 0) {
- ERR_FAIL_INDEX(p_column, text[selection.selecting_line].length());
- selection.selecting_column = p_column;
+
+ set_caret_line(get_last_unhidden_line(), true, false, 9999);
+ set_caret_column(text[caret.line].length());
+
+ if (p_select) {
+ _post_shift_selection();
}
}
-int TextEdit::get_selection_line() const {
- return selection.selecting_line;
-};
-
-int TextEdit::get_selection_column() const {
- return selection.selecting_column;
-};
+void TextEdit::_update_caches() {
+ /* Internal API for CodeEdit. */
+ brace_mismatch_color = get_theme_color(SNAME("brace_mismatch_color"), SNAME("CodeEdit"));
+ code_folding_color = get_theme_color(SNAME("code_folding_color"), SNAME("CodeEdit"));
+ folded_eol_icon = get_theme_icon(SNAME("folded_eol_icon"), SNAME("CodeEdit"));
-void TextEdit::_v_scroll_input() {
- scrolling = false;
- minimap_clicked = false;
-}
+ /* Search */
+ search_result_color = get_theme_color(SNAME("search_result_color"));
+ search_result_border_color = get_theme_color(SNAME("search_result_border_color"));
-void TextEdit::_scroll_moved(double p_to_val) {
- if (updating_scrolls) {
- return;
- }
+ /* Caret */
+ caret_color = get_theme_color(SNAME("caret_color"));
+ caret_background_color = get_theme_color(SNAME("caret_background_color"));
- if (h_scroll->is_visible_in_tree()) {
- cursor.x_ofs = h_scroll->get_value();
- }
- if (v_scroll->is_visible_in_tree()) {
- // Set line ofs and wrap ofs.
- int v_scroll_i = floor(get_v_scroll());
- int sc = 0;
- int n_line;
- for (n_line = 0; n_line < text.size(); n_line++) {
- if (!is_line_hidden(n_line)) {
- sc++;
- sc += times_line_wraps(n_line);
- if (sc > v_scroll_i) {
- break;
- }
- }
- }
- n_line = MIN(n_line, text.size() - 1);
- int line_wrap_amount = times_line_wraps(n_line);
- int wi = line_wrap_amount - (sc - v_scroll_i - 1);
- wi = CLAMP(wi, 0, line_wrap_amount);
+ /* Selection */
+ font_selected_color = get_theme_color(SNAME("font_selected_color"));
+ selection_color = get_theme_color(SNAME("selection_color"));
- cursor.line_ofs = n_line;
- cursor.wrap_ofs = wi;
- }
- update();
-}
+ /* Visual. */
+ style_normal = get_theme_stylebox(SNAME("normal"));
+ style_focus = get_theme_stylebox(SNAME("focus"));
+ style_readonly = get_theme_stylebox(SNAME("read_only"));
-int TextEdit::get_row_height() const {
- int height = cache.font->get_height(cache.font_size);
- for (int i = 0; i < text.size(); i++) {
- for (int j = 0; j <= text.get_line_wrap_amount(i); j++) {
- height = MAX(height, text.get_line_height(i, j));
- }
- }
- return height + cache.line_spacing;
-}
+ tab_icon = get_theme_icon(SNAME("tab"));
+ space_icon = get_theme_icon(SNAME("space"));
-int TextEdit::get_char_pos_for_line(int p_px, int p_line, int p_wrap_index) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), 0);
- p_wrap_index = MIN(p_wrap_index, text.get_line_data(p_line)->get_line_count() - 1);
+ font = get_theme_font(SNAME("font"));
+ font_size = get_theme_font_size(SNAME("font_size"));
+ font_color = get_theme_color(SNAME("font_color"));
+ font_readonly_color = get_theme_color(SNAME("font_readonly_color"));
- RID text_rid = text.get_line_data(p_line)->get_line_rid(p_wrap_index);
- if (is_layout_rtl()) {
- p_px = TS->shaped_text_get_size(text_rid).x - p_px;
- }
- return TS->shaped_text_hit_test_position(text_rid, p_px);
-}
+ outline_size = get_theme_constant(SNAME("outline_size"));
+ outline_color = get_theme_color(SNAME("font_outline_color"));
-int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), 0);
+ line_spacing = get_theme_constant(SNAME("line_spacing"));
- int row = 0;
- Vector<Vector2i> rows2 = text.get_line_wrap_ranges(p_line);
- for (int i = 0; i < rows2.size(); i++) {
- if ((p_char >= rows2[i].x) && (p_char < rows2[i].y)) {
- row = i;
- break;
- }
- }
+ background_color = get_theme_color(SNAME("background_color"));
+ current_line_color = get_theme_color(SNAME("current_line_color"));
+ word_highlighted_color = get_theme_color(SNAME("word_highlighted_color"));
- Rect2 l_caret, t_caret;
- TextServer::Direction l_dir, t_dir;
- RID text_rid = text.get_line_data(p_line)->get_line_rid(row);
- TS->shaped_text_get_carets(text_rid, cursor.column, l_caret, l_dir, t_caret, t_dir);
- if ((l_caret != Rect2() && (l_dir == TextServer::DIRECTION_AUTO || l_dir == (TextServer::Direction)input_direction)) || (t_caret == Rect2())) {
- return l_caret.position.x;
+ /* Text properties. */
+ TextServer::Direction dir;
+ if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
+ dir = is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR;
} else {
- return t_caret.position.x;
+ dir = (TextServer::Direction)text_direction;
}
-}
+ text.set_direction_and_language(dir, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
+ text.set_font_features(opentype_features);
+ text.set_draw_control_chars(draw_control_chars);
+ text.set_font(font);
+ text.set_font_size(font_size);
+ text.invalidate_all();
-void TextEdit::insert_text_at_cursor(const String &p_text) {
- if (selection.active) {
- delete_selection();
+ /* Syntax highlighting. */
+ if (syntax_highlighter.is_valid()) {
+ syntax_highlighter->set_text_edit(this);
}
+}
- int new_column, new_line;
- _insert_text(cursor.line, cursor.column, p_text, &new_line, &new_column);
- _update_scrollbars();
+/* General overrides. */
+Size2 TextEdit::get_minimum_size() const {
+ return style_normal->get_minimum_size();
+}
- cursor_set_line(new_line, false);
- cursor_set_column(new_column);
- update();
+bool TextEdit::is_text_field() const {
+ return true;
}
Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
- int row, col;
- _get_mouse_pos(p_pos, row, col);
+ Point2i pos = get_line_column_at_pos(p_pos);
+ int row = pos.y;
- int left_margin = cache.style_normal->get_margin(SIDE_LEFT);
+ int left_margin = style_normal->get_margin(SIDE_LEFT);
int gutter = left_margin + gutters_width;
if (p_pos.x < gutter) {
for (int i = 0; i < gutters.size(); i++) {
@@ -3503,75 +2375,59 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
return CURSOR_ARROW;
}
- int xmargin_end = get_size().width - cache.style_normal->get_margin(SIDE_RIGHT);
+ int xmargin_end = get_size().width - style_normal->get_margin(SIDE_RIGHT);
if (draw_minimap && p_pos.x > xmargin_end - minimap_width && p_pos.x <= xmargin_end) {
return CURSOR_ARROW;
}
return get_default_cursor_shape();
}
-void TextEdit::set_text(String p_text) {
- setting_text = true;
- if (!undo_enabled) {
- _clear();
- insert_text_at_cursor(p_text);
+String TextEdit::get_tooltip(const Point2 &p_pos) const {
+ if (!tooltip_obj) {
+ return Control::get_tooltip(p_pos);
}
+ Point2i pos = get_line_column_at_pos(p_pos);
+ int row = pos.y;
+ int col = pos.x;
- if (undo_enabled) {
- cursor_set_line(0);
- cursor_set_column(0);
-
- begin_complex_operation();
- _remove_text(0, 0, MAX(0, get_line_count() - 1), MAX(get_line(MAX(get_line_count() - 1, 0)).size() - 1, 0));
- insert_text_at_cursor(p_text);
- end_complex_operation();
- selection.active = false;
+ String s = text[row];
+ if (s.length() == 0) {
+ return Control::get_tooltip(p_pos);
}
+ int beg, end;
+ if (select_word(s, col, beg, end)) {
+ String tt = tooltip_obj->call(tooltip_func, s.substr(beg, end - beg), tooltip_ud);
- cursor_set_line(0);
- cursor_set_column(0);
-
- update();
- setting_text = false;
-}
-
-String TextEdit::get_text() {
- String longthing;
- int len = text.size();
- for (int i = 0; i < len; i++) {
- longthing += text[i];
- if (i != len - 1) {
- longthing += "\n";
- }
+ return tt;
}
- return longthing;
+ return Control::get_tooltip(p_pos);
}
-void TextEdit::set_structured_text_bidi_override(Control::StructuredTextParser p_parser) {
- if (st_parser != p_parser) {
- st_parser = p_parser;
- for (int i = 0; i < text.size(); i++) {
- text.set(i, text[i], structured_text_parser(st_parser, st_args, text[i]));
- }
- update();
- }
+void TextEdit::set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata) {
+ tooltip_obj = p_obj;
+ tooltip_func = p_function;
+ tooltip_ud = p_udata;
}
-Control::StructuredTextParser TextEdit::get_structured_text_bidi_override() const {
- return st_parser;
+/* Text */
+// Text properties.
+bool TextEdit::has_ime_text() const {
+ return !ime_text.is_empty();
}
-void TextEdit::set_structured_text_bidi_override_options(Array p_args) {
- st_args = p_args;
- for (int i = 0; i < text.size(); i++) {
- text.set(i, text[i], structured_text_parser(st_parser, st_args, text[i]));
+void TextEdit::set_editable(const bool p_editable) {
+ if (editable == p_editable) {
+ return;
}
+
+ editable = p_editable;
+
update();
}
-Array TextEdit::get_structured_text_bidi_override_options() const {
- return st_args;
+bool TextEdit::is_editable() const {
+ return editable;
}
void TextEdit::set_text_direction(Control::TextDirection p_text_direction) {
@@ -3604,13 +2460,6 @@ Control::TextDirection TextEdit::get_text_direction() const {
return text_direction;
}
-void TextEdit::clear_opentype_features() {
- opentype_features.clear();
- text.set_font_features(opentype_features);
- text.invalidate_all();
- update();
-}
-
void TextEdit::set_opentype_feature(const String &p_name, int p_value) {
int32_t tag = TS->name_to_tag(p_name);
if (!opentype_features.has(tag) || (int)opentype_features[tag] != p_value) {
@@ -3629,6 +2478,13 @@ int TextEdit::get_opentype_feature(const String &p_name) const {
return opentype_features[tag];
}
+void TextEdit::clear_opentype_features() {
+ opentype_features.clear();
+ text.set_font_features(opentype_features);
+ text.invalidate_all();
+ update();
+}
+
void TextEdit::set_language(const String &p_language) {
if (language != p_language) {
language = p_language;
@@ -3648,630 +2504,665 @@ String TextEdit::get_language() const {
return language;
}
-void TextEdit::set_draw_control_chars(bool p_draw_control_chars) {
- if (draw_control_chars != p_draw_control_chars) {
- draw_control_chars = p_draw_control_chars;
- if (menu && menu->get_item_index(MENU_DISPLAY_UCC) >= 0) {
- menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars);
+void TextEdit::set_structured_text_bidi_override(Control::StructuredTextParser p_parser) {
+ if (st_parser != p_parser) {
+ st_parser = p_parser;
+ for (int i = 0; i < text.size(); i++) {
+ text.set(i, text[i], structured_text_parser(st_parser, st_args, text[i]));
}
- text.set_draw_control_chars(draw_control_chars);
- text.invalidate_all();
update();
}
}
-bool TextEdit::get_draw_control_chars() const {
- return draw_control_chars;
+Control::StructuredTextParser TextEdit::get_structured_text_bidi_override() const {
+ return st_parser;
}
-String TextEdit::get_line(int line) const {
- if (line < 0 || line >= text.size()) {
- return "";
+void TextEdit::set_structured_text_bidi_override_options(Array p_args) {
+ st_args = p_args;
+ for (int i = 0; i < text.size(); i++) {
+ text.set(i, text[i], structured_text_parser(st_parser, st_args, text[i]));
}
-
- return text[line];
-};
-
-bool TextEdit::has_ime_text() const {
- return !ime_text.is_empty();
+ update();
}
-void TextEdit::_clear() {
- clear_undo_history();
- text.clear();
- cursor.column = 0;
- cursor.line = 0;
- cursor.x_ofs = 0;
- cursor.line_ofs = 0;
- cursor.wrap_ofs = 0;
- cursor.last_fit_x = 0;
- selection.active = false;
+Array TextEdit::get_structured_text_bidi_override_options() const {
+ return st_args;
}
-void TextEdit::clear() {
- setting_text = true;
- _clear();
- setting_text = false;
-};
-
-void TextEdit::set_readonly(bool p_readonly) {
- if (readonly == p_readonly) {
+void TextEdit::set_tab_size(const int p_size) {
+ ERR_FAIL_COND_MSG(p_size <= 0, "Tab size must be greater than 0.");
+ if (p_size == text.get_tab_size()) {
return;
}
-
- readonly = p_readonly;
-
+ text.set_tab_size(p_size);
+ text.invalidate_all_lines();
update();
}
-bool TextEdit::is_readonly() const {
- return readonly;
+int TextEdit::get_tab_size() const {
+ return text.get_tab_size();
}
-void TextEdit::set_wrap_enabled(bool p_wrap_enabled) {
- if (wrap_enabled != p_wrap_enabled) {
- wrap_enabled = p_wrap_enabled;
- _update_wrap_at(true);
- }
+// User controls
+void TextEdit::set_overtype_mode_enabled(const bool p_enabled) {
+ overtype_mode = p_enabled;
+ update();
}
-bool TextEdit::is_wrap_enabled() const {
- return wrap_enabled;
+bool TextEdit::is_overtype_mode_enabled() const {
+ return overtype_mode;
}
-void TextEdit::_reset_caret_blink_timer() {
- if (caret_blink_enabled) {
- draw_caret = true;
- if (has_focus()) {
- caret_blink_timer->stop();
- caret_blink_timer->start();
- update();
- }
- }
+void TextEdit::set_context_menu_enabled(bool p_enable) {
+ context_menu_enabled = p_enable;
}
-void TextEdit::_toggle_draw_caret() {
- draw_caret = !draw_caret;
- if (is_visible_in_tree() && has_focus() && window_has_focus) {
- update();
- }
+bool TextEdit::is_context_menu_enabled() const {
+ return context_menu_enabled;
}
-void TextEdit::_update_caches() {
- cache.style_normal = get_theme_stylebox(SNAME("normal"));
- cache.style_focus = get_theme_stylebox(SNAME("focus"));
- cache.style_readonly = get_theme_stylebox(SNAME("read_only"));
- cache.font = get_theme_font(SNAME("font"));
- cache.font_size = get_theme_font_size(SNAME("font_size"));
- cache.outline_color = get_theme_color(SNAME("font_outline_color"));
- cache.outline_size = get_theme_constant(SNAME("outline_size"));
- cache.caret_color = get_theme_color(SNAME("caret_color"));
- cache.caret_background_color = get_theme_color(SNAME("caret_background_color"));
- cache.font_color = get_theme_color(SNAME("font_color"));
- cache.font_selected_color = get_theme_color(SNAME("font_selected_color"));
- cache.font_readonly_color = get_theme_color(SNAME("font_readonly_color"));
- cache.selection_color = get_theme_color(SNAME("selection_color"));
- cache.current_line_color = get_theme_color(SNAME("current_line_color"));
- cache.code_folding_color = get_theme_color(SNAME("code_folding_color"), SNAME("CodeEdit"));
- cache.brace_mismatch_color = get_theme_color(SNAME("brace_mismatch_color"), SNAME("CodeEdit"));
- cache.word_highlighted_color = get_theme_color(SNAME("word_highlighted_color"));
- cache.search_result_color = get_theme_color(SNAME("search_result_color"));
- cache.search_result_border_color = get_theme_color(SNAME("search_result_border_color"));
- cache.background_color = get_theme_color(SNAME("background_color"));
-#ifdef TOOLS_ENABLED
- cache.line_spacing = get_theme_constant(SNAME("line_spacing")) * EDSCALE;
-#else
- cache.line_spacing = get_theme_constant(SNAME("line_spacing"));
-#endif
- cache.tab_icon = get_theme_icon(SNAME("tab"));
- cache.space_icon = get_theme_icon(SNAME("space"));
- cache.folded_eol_icon = get_theme_icon(SNAME("folded_eol_icon"), SNAME("CodeEdit"));
-
- TextServer::Direction dir;
- if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
- dir = is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR;
- } else {
- dir = (TextServer::Direction)text_direction;
- }
- text.set_direction_and_language(dir, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
- text.set_font_features(opentype_features);
- text.set_draw_control_chars(draw_control_chars);
- text.set_font(cache.font);
- text.set_font_size(cache.font_size);
- text.invalidate_all();
-
- if (syntax_highlighter.is_valid()) {
- syntax_highlighter->set_text_edit(this);
- }
+void TextEdit::set_shortcut_keys_enabled(bool p_enabled) {
+ shortcut_keys_enabled = p_enabled;
}
-/* Syntax Highlighting. */
-Ref<SyntaxHighlighter> TextEdit::get_syntax_highlighter() {
- return syntax_highlighter;
+bool TextEdit::is_shortcut_keys_enabled() const {
+ return shortcut_keys_enabled;
}
-void TextEdit::set_syntax_highlighter(Ref<SyntaxHighlighter> p_syntax_highlighter) {
- syntax_highlighter = p_syntax_highlighter;
- if (syntax_highlighter.is_valid()) {
- syntax_highlighter->set_text_edit(this);
- }
- update();
+void TextEdit::set_virtual_keyboard_enabled(bool p_enable) {
+ virtual_keyboard_enabled = p_enable;
}
-/* Gutters. */
-void TextEdit::_update_gutter_width() {
- gutters_width = 0;
- for (int i = 0; i < gutters.size(); i++) {
- if (gutters[i].draw) {
- gutters_width += gutters[i].width;
- }
- }
- if (gutters_width > 0) {
- gutter_padding = 2;
- }
- update();
+bool TextEdit::is_virtual_keyboard_enabled() const {
+ return virtual_keyboard_enabled;
}
-void TextEdit::add_gutter(int p_at) {
- if (p_at < 0 || p_at > gutters.size()) {
- gutters.push_back(GutterInfo());
- } else {
- gutters.insert(p_at, GutterInfo());
- }
-
- for (int i = 0; i < text.size() + 1; i++) {
- text.add_gutter(p_at);
- }
- emit_signal(SNAME("gutter_added"));
- update();
+// Text manipulation
+void TextEdit::clear() {
+ setting_text = true;
+ _clear();
+ setting_text = false;
+ emit_signal(SNAME("text_set"));
}
-void TextEdit::remove_gutter(int p_gutter) {
- ERR_FAIL_INDEX(p_gutter, gutters.size());
-
- gutters.remove(p_gutter);
+void TextEdit::_clear() {
+ clear_undo_history();
+ text.clear();
+ caret.column = 0;
+ caret.line = 0;
+ caret.x_ofs = 0;
+ caret.line_ofs = 0;
+ caret.wrap_ofs = 0;
+ caret.last_fit_x = 0;
+ selection.active = false;
+}
- for (int i = 0; i < text.size() + 1; i++) {
- text.remove_gutter(p_gutter);
+void TextEdit::set_text(const String &p_text) {
+ setting_text = true;
+ if (!undo_enabled) {
+ _clear();
+ insert_text_at_caret(p_text);
}
- emit_signal(SNAME("gutter_removed"));
- update();
-}
-int TextEdit::get_gutter_count() const {
- return gutters.size();
-}
+ if (undo_enabled) {
+ set_caret_line(0);
+ set_caret_column(0);
-void TextEdit::set_gutter_name(int p_gutter, const String &p_name) {
- ERR_FAIL_INDEX(p_gutter, gutters.size());
- gutters.write[p_gutter].name = p_name;
-}
+ begin_complex_operation();
+ _remove_text(0, 0, MAX(0, get_line_count() - 1), MAX(get_line(MAX(get_line_count() - 1, 0)).size() - 1, 0));
+ insert_text_at_caret(p_text);
+ end_complex_operation();
+ selection.active = false;
+ }
-String TextEdit::get_gutter_name(int p_gutter) const {
- ERR_FAIL_INDEX_V(p_gutter, gutters.size(), "");
- return gutters[p_gutter].name;
-}
+ set_caret_line(0);
+ set_caret_column(0);
-void TextEdit::set_gutter_type(int p_gutter, GutterType p_type) {
- ERR_FAIL_INDEX(p_gutter, gutters.size());
- gutters.write[p_gutter].type = p_type;
update();
+ setting_text = false;
+ emit_signal(SNAME("text_set"));
}
-TextEdit::GutterType TextEdit::get_gutter_type(int p_gutter) const {
- ERR_FAIL_INDEX_V(p_gutter, gutters.size(), GUTTER_TYPE_STRING);
- return gutters[p_gutter].type;
+String TextEdit::get_text() const {
+ StringBuilder ret_text;
+ const int text_size = text.size();
+ for (int i = 0; i < text_size; i++) {
+ ret_text += text[i];
+ if (i != text_size - 1) {
+ ret_text += "\n";
+ }
+ }
+ return ret_text.as_string();
}
-void TextEdit::set_gutter_width(int p_gutter, int p_width) {
- ERR_FAIL_INDEX(p_gutter, gutters.size());
- gutters.write[p_gutter].width = p_width;
- _update_gutter_width();
+int TextEdit::get_line_count() const {
+ return text.size();
}
-int TextEdit::get_gutter_width(int p_gutter) const {
- ERR_FAIL_INDEX_V(p_gutter, gutters.size(), -1);
- return gutters[p_gutter].width;
+void TextEdit::set_line(int p_line, const String &p_new_text) {
+ if (p_line < 0 || p_line >= text.size()) {
+ return;
+ }
+ _remove_text(p_line, 0, p_line, text[p_line].length());
+ _insert_text(p_line, 0, p_new_text);
+ if (caret.line == p_line) {
+ caret.column = MIN(caret.column, p_new_text.length());
+ }
+ if (has_selection() && p_line == selection.to_line && selection.to_column > text[p_line].length()) {
+ selection.to_column = text[p_line].length();
+ }
}
-int TextEdit::get_total_gutter_width() const {
- return gutters_width + gutter_padding;
+String TextEdit::get_line(int p_line) const {
+ if (p_line < 0 || p_line >= text.size()) {
+ return "";
+ }
+ return text[p_line];
}
-void TextEdit::set_gutter_draw(int p_gutter, bool p_draw) {
- ERR_FAIL_INDEX(p_gutter, gutters.size());
- gutters.write[p_gutter].draw = p_draw;
- _update_gutter_width();
-}
+int TextEdit::get_line_width(int p_line, int p_wrap_index) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), 0);
+ ERR_FAIL_COND_V(p_wrap_index > get_line_wrap_count(p_line), 0);
-bool TextEdit::is_gutter_drawn(int p_gutter) const {
- ERR_FAIL_INDEX_V(p_gutter, gutters.size(), false);
- return gutters[p_gutter].draw;
+ return text.get_line_width(p_line, p_wrap_index);
}
-void TextEdit::set_gutter_clickable(int p_gutter, bool p_clickable) {
- ERR_FAIL_INDEX(p_gutter, gutters.size());
- gutters.write[p_gutter].clickable = p_clickable;
- update();
+int TextEdit::get_line_height() const {
+ return text.get_line_height() + line_spacing;
}
-bool TextEdit::is_gutter_clickable(int p_gutter) const {
- ERR_FAIL_INDEX_V(p_gutter, gutters.size(), false);
- return gutters[p_gutter].clickable;
-}
+int TextEdit::get_indent_level(int p_line) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), 0);
-void TextEdit::set_gutter_overwritable(int p_gutter, bool p_overwritable) {
- ERR_FAIL_INDEX(p_gutter, gutters.size());
- gutters.write[p_gutter].overwritable = p_overwritable;
+ int tab_count = 0;
+ 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') {
+ tab_count++;
+ } else if (text[p_line][i] == ' ') {
+ whitespace_count++;
+ } else {
+ break;
+ }
+ }
+ return tab_count * text.get_tab_size() + whitespace_count;
}
-bool TextEdit::is_gutter_overwritable(int p_gutter) const {
- ERR_FAIL_INDEX_V(p_gutter, gutters.size(), false);
- return gutters[p_gutter].overwritable;
+int TextEdit::get_first_non_whitespace_column(int p_line) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), 0);
+
+ int col = 0;
+ while (col < text[p_line].length() && _is_whitespace(text[p_line][col])) {
+ col++;
+ }
+ return col;
}
-void TextEdit::merge_gutters(int p_from_line, int p_to_line) {
+void TextEdit::swap_lines(int p_from_line, int p_to_line) {
ERR_FAIL_INDEX(p_from_line, text.size());
ERR_FAIL_INDEX(p_to_line, text.size());
- if (p_from_line == p_to_line) {
- return;
- }
-
- for (int i = 0; i < gutters.size(); i++) {
- if (!gutters[i].overwritable) {
- continue;
- }
- if (text.get_line_gutter_text(p_from_line, i) != "") {
- text.set_line_gutter_text(p_to_line, i, text.get_line_gutter_text(p_from_line, i));
- text.set_line_gutter_item_color(p_to_line, i, text.get_line_gutter_item_color(p_from_line, i));
- }
-
- if (text.get_line_gutter_icon(p_from_line, i).is_valid()) {
- text.set_line_gutter_icon(p_to_line, i, text.get_line_gutter_icon(p_from_line, i));
- text.set_line_gutter_item_color(p_to_line, i, text.get_line_gutter_item_color(p_from_line, i));
- }
+ String tmp = get_line(p_from_line);
+ String tmp2 = get_line(p_to_line);
+ set_line(p_to_line, tmp);
+ set_line(p_from_line, tmp2);
+}
- if (text.get_line_gutter_metadata(p_from_line, i) != "") {
- text.set_line_gutter_metadata(p_to_line, i, text.get_line_gutter_metadata(p_from_line, i));
- }
+void TextEdit::insert_line_at(int p_at, const String &p_text) {
+ ERR_FAIL_INDEX(p_at, text.size());
- if (text.is_line_gutter_clickable(p_from_line, i)) {
- text.set_line_gutter_clickable(p_to_line, i, true);
+ _insert_text(p_at, 0, p_text + "\n");
+ if (caret.line >= p_at) {
+ // offset caret when located after inserted line
+ ++caret.line;
+ }
+ if (has_selection()) {
+ if (selection.from_line >= p_at) {
+ // offset selection when located after inserted line
+ ++selection.from_line;
+ ++selection.to_line;
+ } else if (selection.to_line >= p_at) {
+ // extend selection that includes inserted line
+ ++selection.to_line;
}
}
- update();
}
-void TextEdit::set_gutter_custom_draw(int p_gutter, Object *p_object, const StringName &p_callback) {
- ERR_FAIL_INDEX(p_gutter, gutters.size());
- ERR_FAIL_NULL(p_object);
+void TextEdit::insert_text_at_caret(const String &p_text) {
+ delete_selection();
- gutters.write[p_gutter].custom_draw_obj = p_object->get_instance_id();
- gutters.write[p_gutter].custom_draw_callback = p_callback;
+ int new_column, new_line;
+ _insert_text(caret.line, caret.column, p_text, &new_line, &new_column);
+ _update_scrollbars();
+
+ set_caret_line(new_line, false);
+ set_caret_column(new_column);
update();
}
-// Line gutters.
-void TextEdit::set_line_gutter_metadata(int p_line, int p_gutter, const Variant &p_metadata) {
- ERR_FAIL_INDEX(p_line, text.size());
- ERR_FAIL_INDEX(p_gutter, gutters.size());
- text.set_line_gutter_metadata(p_line, p_gutter, p_metadata);
-}
+void TextEdit::remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
+ ERR_FAIL_INDEX(p_from_line, text.size());
+ ERR_FAIL_INDEX(p_from_column, text[p_from_line].length() + 1);
+ ERR_FAIL_INDEX(p_to_line, text.size());
+ ERR_FAIL_INDEX(p_to_column, text[p_to_line].length() + 1);
+ ERR_FAIL_COND(p_to_line < p_from_line);
+ ERR_FAIL_COND(p_to_line == p_from_line && p_to_column < p_from_column);
-Variant TextEdit::get_line_gutter_metadata(int p_line, int p_gutter) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), "");
- ERR_FAIL_INDEX_V(p_gutter, gutters.size(), "");
- return text.get_line_gutter_metadata(p_line, p_gutter);
+ _remove_text(p_from_line, p_from_column, p_to_line, p_to_column);
}
-void TextEdit::set_line_gutter_text(int p_line, int p_gutter, const String &p_text) {
- ERR_FAIL_INDEX(p_line, text.size());
- ERR_FAIL_INDEX(p_gutter, gutters.size());
- text.set_line_gutter_text(p_line, p_gutter, p_text);
- update();
-}
+int TextEdit::get_last_unhidden_line() const {
+ // Returns the last line in the text that is not hidden.
+ if (!_is_hiding_enabled()) {
+ return text.size() - 1;
+ }
-String TextEdit::get_line_gutter_text(int p_line, int p_gutter) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), "");
- ERR_FAIL_INDEX_V(p_gutter, gutters.size(), "");
- return text.get_line_gutter_text(p_line, p_gutter);
+ int last_line;
+ for (last_line = text.size() - 1; last_line > 0; last_line--) {
+ if (!_is_line_hidden(last_line)) {
+ break;
+ }
+ }
+ return last_line;
}
-void TextEdit::set_line_gutter_icon(int p_line, int p_gutter, Ref<Texture2D> p_icon) {
- ERR_FAIL_INDEX(p_line, text.size());
- ERR_FAIL_INDEX(p_gutter, gutters.size());
- text.set_line_gutter_icon(p_line, p_gutter, p_icon);
- update();
-}
+int TextEdit::get_next_visible_line_offset_from(int p_line_from, int p_visible_amount) const {
+ // Returns the number of lines (hidden and unhidden) from p_line_from to (p_line_from + visible_amount of unhidden lines).
+ ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(p_visible_amount));
-Ref<Texture2D> TextEdit::get_line_gutter_icon(int p_line, int p_gutter) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), Ref<Texture2D>());
- ERR_FAIL_INDEX_V(p_gutter, gutters.size(), Ref<Texture2D>());
- return text.get_line_gutter_icon(p_line, p_gutter);
-}
+ if (!_is_hiding_enabled()) {
+ return ABS(p_visible_amount);
+ }
-void TextEdit::set_line_gutter_item_color(int p_line, int p_gutter, const Color &p_color) {
- ERR_FAIL_INDEX(p_line, text.size());
- ERR_FAIL_INDEX(p_gutter, gutters.size());
- text.set_line_gutter_item_color(p_line, p_gutter, p_color);
- update();
+ int num_visible = 0;
+ int num_total = 0;
+ if (p_visible_amount >= 0) {
+ for (int i = p_line_from; i < text.size(); i++) {
+ num_total++;
+ if (!_is_line_hidden(i)) {
+ num_visible++;
+ }
+ if (num_visible >= p_visible_amount) {
+ break;
+ }
+ }
+ } else {
+ p_visible_amount = ABS(p_visible_amount);
+ for (int i = p_line_from; i >= 0; i--) {
+ num_total++;
+ if (!_is_line_hidden(i)) {
+ num_visible++;
+ }
+ if (num_visible >= p_visible_amount) {
+ break;
+ }
+ }
+ }
+ return num_total;
}
-Color TextEdit::get_line_gutter_item_color(int p_line, int p_gutter) {
- ERR_FAIL_INDEX_V(p_line, text.size(), Color());
- ERR_FAIL_INDEX_V(p_gutter, gutters.size(), Color());
- return text.get_line_gutter_item_color(p_line, p_gutter);
-}
+Point2i TextEdit::get_next_visible_line_index_offset_from(int p_line_from, int p_wrap_index_from, int p_visible_amount) const {
+ // Returns the number of lines (hidden and unhidden) from (p_line_from + p_wrap_index_from) row to (p_line_from + visible_amount of unhidden and wrapped rows).
+ // Wrap index is set to the wrap index of the last line.
+ int wrap_index = 0;
+ ERR_FAIL_INDEX_V(p_line_from, text.size(), Point2i(ABS(p_visible_amount), 0));
-void TextEdit::set_line_gutter_clickable(int p_line, int p_gutter, bool p_clickable) {
- ERR_FAIL_INDEX(p_line, text.size());
- ERR_FAIL_INDEX(p_gutter, gutters.size());
- text.set_line_gutter_clickable(p_line, p_gutter, p_clickable);
-}
+ if (!_is_hiding_enabled() && get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE) {
+ return Point2i(ABS(p_visible_amount), 0);
+ }
-bool TextEdit::is_line_gutter_clickable(int p_line, int p_gutter) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), false);
- ERR_FAIL_INDEX_V(p_gutter, gutters.size(), false);
- return text.is_line_gutter_clickable(p_line, p_gutter);
+ int num_visible = 0;
+ int num_total = 0;
+ if (p_visible_amount == 0) {
+ num_total = 0;
+ wrap_index = 0;
+ } else if (p_visible_amount > 0) {
+ int i;
+ num_visible -= p_wrap_index_from;
+ for (i = p_line_from; i < text.size(); i++) {
+ num_total++;
+ if (!_is_line_hidden(i)) {
+ num_visible++;
+ num_visible += get_line_wrap_count(i);
+ }
+ if (num_visible >= p_visible_amount) {
+ break;
+ }
+ }
+ wrap_index = get_line_wrap_count(MIN(i, text.size() - 1)) - MAX(0, num_visible - p_visible_amount);
+ } else {
+ p_visible_amount = ABS(p_visible_amount);
+ int i;
+ num_visible -= get_line_wrap_count(p_line_from) - p_wrap_index_from;
+ for (i = p_line_from; i >= 0; i--) {
+ num_total++;
+ if (!_is_line_hidden(i)) {
+ num_visible++;
+ num_visible += get_line_wrap_count(i);
+ }
+ if (num_visible >= p_visible_amount) {
+ break;
+ }
+ }
+ wrap_index = MAX(0, num_visible - p_visible_amount);
+ }
+ wrap_index = MAX(wrap_index, 0);
+ return Point2i(num_total, wrap_index);
}
-// Line style
-void TextEdit::set_line_background_color(int p_line, const Color &p_color) {
- ERR_FAIL_INDEX(p_line, text.size());
- text.set_line_background_color(p_line, p_color);
- update();
+// Overridable actions
+void TextEdit::handle_unicode_input(const uint32_t p_unicode) {
+ if (GDVIRTUAL_CALL(_handle_unicode_input, p_unicode)) {
+ return;
+ }
+ _handle_unicode_input_internal(p_unicode);
}
-Color TextEdit::get_line_background_color(int p_line) {
- ERR_FAIL_INDEX_V(p_line, text.size(), Color());
- return text.get_line_background_color(p_line);
+void TextEdit::backspace() {
+ if (GDVIRTUAL_CALL(_backspace)) {
+ return;
+ }
+ _backspace_internal();
}
void TextEdit::cut() {
- if (readonly) {
+ if (GDVIRTUAL_CALL(_cut)) {
return;
}
-
- if (!selection.active) {
- String clipboard = text[cursor.line];
- DisplayServer::get_singleton()->clipboard_set(clipboard);
- cursor_set_line(cursor.line);
- cursor_set_column(0);
-
- if (cursor.line == 0 && get_line_count() > 1) {
- _remove_text(cursor.line, 0, cursor.line + 1, 0);
- } else {
- _remove_text(cursor.line, 0, cursor.line, text[cursor.line].length());
- backspace();
- cursor_set_line(cursor.line + 1);
- }
-
- update();
- cut_copy_line = clipboard;
-
- } else {
- String clipboard = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
- DisplayServer::get_singleton()->clipboard_set(clipboard);
-
- _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
- cursor_set_line(selection.from_line, false); // Set afterwards else it causes the view to be offset.
- cursor_set_column(selection.from_column);
-
- selection.active = false;
- selection.selecting_mode = SelectionMode::SELECTION_MODE_NONE;
- update();
- cut_copy_line = "";
- }
+ _cut_internal();
}
void TextEdit::copy() {
- if (!selection.active) {
- if (text[cursor.line].length() != 0) {
- String clipboard = _base_get_text(cursor.line, 0, cursor.line, text[cursor.line].length());
- DisplayServer::get_singleton()->clipboard_set(clipboard);
- cut_copy_line = clipboard;
- }
- } else {
- String clipboard = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
- DisplayServer::get_singleton()->clipboard_set(clipboard);
- cut_copy_line = "";
+ if (GDVIRTUAL_CALL(_copy)) {
+ return;
}
+ _copy_internal();
}
void TextEdit::paste() {
- if (readonly) {
+ if (GDVIRTUAL_CALL(_paste)) {
return;
}
+ _paste_internal();
+}
- String clipboard = DisplayServer::get_singleton()->clipboard_get();
+// Context menu.
+PopupMenu *TextEdit::get_menu() const {
+ const_cast<TextEdit *>(this)->_generate_context_menu();
+ return menu;
+}
- begin_complex_operation();
- if (selection.active) {
- selection.active = false;
- selection.selecting_mode = SelectionMode::SELECTION_MODE_NONE;
- _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
- cursor_set_line(selection.from_line, false);
- cursor_set_column(selection.from_column);
+bool TextEdit::is_menu_visible() const {
+ return menu && menu->is_visible();
+}
- } else if (!cut_copy_line.is_empty() && cut_copy_line == clipboard) {
- cursor_set_column(0);
- String ins = "\n";
- clipboard += ins;
+void TextEdit::menu_option(int p_option) {
+ switch (p_option) {
+ case MENU_CUT: {
+ cut();
+ } break;
+ case MENU_COPY: {
+ copy();
+ } break;
+ case MENU_PASTE: {
+ paste();
+ } break;
+ case MENU_CLEAR: {
+ if (editable) {
+ clear();
+ }
+ } break;
+ case MENU_SELECT_ALL: {
+ select_all();
+ } break;
+ case MENU_UNDO: {
+ undo();
+ } break;
+ case MENU_REDO: {
+ redo();
+ } break;
+ case MENU_DIR_INHERITED: {
+ set_text_direction(TEXT_DIRECTION_INHERITED);
+ } break;
+ case MENU_DIR_AUTO: {
+ set_text_direction(TEXT_DIRECTION_AUTO);
+ } break;
+ case MENU_DIR_LTR: {
+ set_text_direction(TEXT_DIRECTION_LTR);
+ } break;
+ case MENU_DIR_RTL: {
+ set_text_direction(TEXT_DIRECTION_RTL);
+ } break;
+ case MENU_DISPLAY_UCC: {
+ set_draw_control_chars(!get_draw_control_chars());
+ } break;
+ case MENU_INSERT_LRM: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x200E));
+ }
+ } break;
+ case MENU_INSERT_RLM: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x200F));
+ }
+ } break;
+ case MENU_INSERT_LRE: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x202A));
+ }
+ } break;
+ case MENU_INSERT_RLE: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x202B));
+ }
+ } break;
+ case MENU_INSERT_LRO: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x202D));
+ }
+ } break;
+ case MENU_INSERT_RLO: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x202E));
+ }
+ } break;
+ case MENU_INSERT_PDF: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x202C));
+ }
+ } break;
+ case MENU_INSERT_ALM: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x061C));
+ }
+ } break;
+ case MENU_INSERT_LRI: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x2066));
+ }
+ } break;
+ case MENU_INSERT_RLI: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x2067));
+ }
+ } break;
+ case MENU_INSERT_FSI: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x2068));
+ }
+ } break;
+ case MENU_INSERT_PDI: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x2069));
+ }
+ } break;
+ case MENU_INSERT_ZWJ: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x200D));
+ }
+ } break;
+ case MENU_INSERT_ZWNJ: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x200C));
+ }
+ } break;
+ case MENU_INSERT_WJ: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x2060));
+ }
+ } break;
+ case MENU_INSERT_SHY: {
+ if (editable) {
+ insert_text_at_caret(String::chr(0x00AD));
+ }
+ }
}
+}
- insert_text_at_cursor(clipboard);
- end_complex_operation();
-
- update();
+/* Versioning */
+void TextEdit::begin_complex_operation() {
+ _push_current_op();
+ next_operation_is_complex = true;
}
-void TextEdit::select_all() {
- if (!selecting_enabled) {
+void TextEdit::end_complex_operation() {
+ _push_current_op();
+ ERR_FAIL_COND(undo_stack.size() == 0);
+
+ if (undo_stack.back()->get().chain_forward) {
+ undo_stack.back()->get().chain_forward = false;
return;
}
- if (text.size() == 1 && text[0].length() == 0) {
- return;
+ undo_stack.back()->get().chain_backward = true;
+}
+
+bool TextEdit::has_undo() const {
+ if (undo_stack_pos == nullptr) {
+ int pending = current_op.type == TextOperation::TYPE_NONE ? 0 : 1;
+ return undo_stack.size() + pending > 0;
}
- selection.active = true;
- selection.from_line = 0;
- selection.from_column = 0;
- selection.selecting_line = 0;
- selection.selecting_column = 0;
- selection.to_line = text.size() - 1;
- selection.to_column = text[selection.to_line].length();
- selection.selecting_mode = SelectionMode::SELECTION_MODE_SHIFT;
- selection.shiftclick_left = true;
- cursor_set_line(selection.to_line, false);
- cursor_set_column(selection.to_column, false);
- update();
+ return undo_stack_pos != undo_stack.front();
}
-void TextEdit::select_word_under_caret() {
- if (!selecting_enabled) {
+bool TextEdit::has_redo() const {
+ return undo_stack_pos != nullptr;
+}
+
+void TextEdit::undo() {
+ if (!editable) {
return;
}
- if (text.size() == 1 && text[0].length() == 0) {
- return;
+ _push_current_op();
+
+ if (undo_stack_pos == nullptr) {
+ if (!undo_stack.size()) {
+ return; // Nothing to undo.
+ }
+
+ undo_stack_pos = undo_stack.back();
+
+ } else if (undo_stack_pos == undo_stack.front()) {
+ return; // At the bottom of the undo stack.
+ } else {
+ undo_stack_pos = undo_stack_pos->prev();
}
- if (selection.active) {
- // Allow toggling selection by pressing the shortcut a second time.
- // This is also usable as a general-purpose "deselect" shortcut after
- // selecting anything.
- deselect();
- return;
+ deselect();
+
+ TextOperation op = undo_stack_pos->get();
+ _do_text_op(op, true);
+ if (op.type != TextOperation::TYPE_INSERT && (op.from_line != op.to_line || op.to_column != op.from_column + 1)) {
+ select(op.from_line, op.from_column, op.to_line, op.to_column);
}
- int begin = 0;
- int end = 0;
- const Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(cursor.line)->get_rid());
- for (int i = 0; i < words.size(); i++) {
- if (words[i].x <= cursor.column && words[i].y >= cursor.column) {
- begin = words[i].x;
- end = words[i].y;
- break;
+ current_op.version = op.prev_version;
+ if (undo_stack_pos->get().chain_backward) {
+ while (true) {
+ ERR_BREAK(!undo_stack_pos->prev());
+ undo_stack_pos = undo_stack_pos->prev();
+ op = undo_stack_pos->get();
+ _do_text_op(op, true);
+ current_op.version = op.prev_version;
+ if (undo_stack_pos->get().chain_forward) {
+ break;
+ }
}
}
- select(cursor.line, begin, cursor.line, end);
- // Move the cursor to the end of the word for easier editing.
- cursor_set_column(end, false);
-}
-
-void TextEdit::deselect() {
- selection.active = false;
+ _update_scrollbars();
+ if (undo_stack_pos->get().type == TextOperation::TYPE_REMOVE) {
+ set_caret_line(undo_stack_pos->get().to_line, false);
+ set_caret_column(undo_stack_pos->get().to_column);
+ } else {
+ set_caret_line(undo_stack_pos->get().from_line, false);
+ set_caret_column(undo_stack_pos->get().from_column);
+ }
update();
}
-void TextEdit::select(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
- if (!selecting_enabled) {
+void TextEdit::redo() {
+ if (!editable) {
return;
}
+ _push_current_op();
- if (p_from_line < 0) {
- p_from_line = 0;
- } else if (p_from_line >= text.size()) {
- p_from_line = text.size() - 1;
- }
- if (p_from_column >= text[p_from_line].length()) {
- p_from_column = text[p_from_line].length();
- }
- if (p_from_column < 0) {
- p_from_column = 0;
- }
-
- if (p_to_line < 0) {
- p_to_line = 0;
- } else if (p_to_line >= text.size()) {
- p_to_line = text.size() - 1;
- }
- if (p_to_column >= text[p_to_line].length()) {
- p_to_column = text[p_to_line].length();
- }
- if (p_to_column < 0) {
- p_to_column = 0;
+ if (undo_stack_pos == nullptr) {
+ return; // Nothing to do.
}
- selection.from_line = p_from_line;
- selection.from_column = p_from_column;
- selection.to_line = p_to_line;
- selection.to_column = p_to_column;
-
- selection.active = true;
-
- if (selection.from_line == selection.to_line) {
- if (selection.from_column == selection.to_column) {
- selection.active = false;
+ deselect();
- } else if (selection.from_column > selection.to_column) {
- selection.shiftclick_left = false;
- SWAP(selection.from_column, selection.to_column);
- } else {
- selection.shiftclick_left = true;
+ TextOperation op = undo_stack_pos->get();
+ _do_text_op(op, false);
+ current_op.version = op.version;
+ if (undo_stack_pos->get().chain_forward) {
+ while (true) {
+ ERR_BREAK(!undo_stack_pos->next());
+ undo_stack_pos = undo_stack_pos->next();
+ op = undo_stack_pos->get();
+ _do_text_op(op, false);
+ current_op.version = op.version;
+ if (undo_stack_pos->get().chain_backward) {
+ break;
+ }
}
- } else if (selection.from_line > selection.to_line) {
- selection.shiftclick_left = false;
- SWAP(selection.from_line, selection.to_line);
- SWAP(selection.from_column, selection.to_column);
- } else {
- selection.shiftclick_left = true;
}
+ _update_scrollbars();
+ set_caret_line(undo_stack_pos->get().to_line, false);
+ set_caret_column(undo_stack_pos->get().to_column);
+ undo_stack_pos = undo_stack_pos->next();
update();
}
-void TextEdit::swap_lines(int line1, int line2) {
- String tmp = get_line(line1);
- String tmp2 = get_line(line2);
- set_line(line2, tmp);
- set_line(line1, tmp2);
-}
-
-bool TextEdit::is_selection_active() const {
- return selection.active;
-}
-
-int TextEdit::get_selection_from_line() const {
- ERR_FAIL_COND_V(!selection.active, -1);
- return selection.from_line;
-}
-
-int TextEdit::get_selection_from_column() const {
- ERR_FAIL_COND_V(!selection.active, -1);
- return selection.from_column;
+void TextEdit::clear_undo_history() {
+ saved_version = 0;
+ current_op.type = TextOperation::TYPE_NONE;
+ undo_stack_pos = nullptr;
+ undo_stack.clear();
}
-int TextEdit::get_selection_to_line() const {
- ERR_FAIL_COND_V(!selection.active, -1);
- return selection.to_line;
+bool TextEdit::is_insert_text_operation() const {
+ return (current_op.type == TextOperation::TYPE_INSERT);
}
-int TextEdit::get_selection_to_column() const {
- ERR_FAIL_COND_V(!selection.active, -1);
- return selection.to_column;
+void TextEdit::tag_saved_version() {
+ saved_version = get_version();
}
-String TextEdit::get_selection_text() const {
- if (!selection.active) {
- return "";
- }
-
- return _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
+uint32_t TextEdit::get_version() const {
+ return current_op.version;
}
-String TextEdit::get_word_under_cursor() const {
- Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(cursor.line)->get_rid());
- for (int i = 0; i < words.size(); i++) {
- if (words[i].x <= cursor.column && words[i].y > cursor.column) {
- return text[cursor.line].substr(words[i].x, words[i].y - words[i].x);
- }
- }
- return "";
+uint32_t TextEdit::get_saved_version() const {
+ return saved_version;
}
+/* Search */
void TextEdit::set_search_text(const String &p_search_text) {
search_text = p_search_text;
}
@@ -4280,72 +3171,12 @@ void TextEdit::set_search_flags(uint32_t p_flags) {
search_flags = p_flags;
}
-void TextEdit::set_current_search_result(int line, int col) {
- search_result_line = line;
- search_result_col = col;
- update();
-}
-
-void TextEdit::set_highlight_all_occurrences(const bool p_enabled) {
- highlight_all_occurrences = p_enabled;
- update();
-}
-
-bool TextEdit::is_highlight_all_occurrences_enabled() const {
- return highlight_all_occurrences;
-}
-
-int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column) {
- int col = -1;
-
- if (p_key.length() > 0 && p_search.length() > 0) {
- if (p_from_column < 0 || p_from_column > p_search.length()) {
- p_from_column = 0;
- }
-
- while (col == -1 && p_from_column <= p_search.length()) {
- if (p_search_flags & SEARCH_MATCH_CASE) {
- col = p_search.find(p_key, p_from_column);
- } else {
- col = p_search.findn(p_key, p_from_column);
- }
-
- // Whole words only.
- if (col != -1 && p_search_flags & SEARCH_WHOLE_WORDS) {
- p_from_column = col;
-
- if (col > 0 && _is_text_char(p_search[col - 1])) {
- col = -1;
- } else if ((col + p_key.length()) < p_search.length() && _is_text_char(p_search[col + p_key.length()])) {
- col = -1;
- }
- }
-
- p_from_column += 1;
- }
- }
- return col;
-}
-
-Dictionary TextEdit::_search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const {
- int col, line;
- if (search(p_key, p_search_flags, p_from_line, p_from_column, line, col)) {
- Dictionary result;
- result["line"] = line;
- result["column"] = col;
- return result;
-
- } else {
- return Dictionary();
- }
-}
-
-bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column, int &r_line, int &r_column) const {
+Point2i TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const {
if (p_key.length() == 0) {
- return false;
+ return Point2(-1, -1);
}
- ERR_FAIL_INDEX_V(p_from_line, text.size(), false);
- ERR_FAIL_INDEX_V(p_from_column, text[p_from_line].length() + 1, false);
+ ERR_FAIL_INDEX_V(p_from_line, text.size(), Point2i(-1, -1));
+ ERR_FAIL_INDEX_V(p_from_column, text[p_from_line].length() + 1, Point2i(-1, -1));
// Search through the whole document, but start by current line.
@@ -4444,417 +3275,665 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l
line++;
}
}
+ return (pos == -1) ? Point2i(-1, -1) : Point2i(pos, line);
+}
- if (pos == -1) {
- r_line = -1;
- r_column = -1;
- return false;
+/* Mouse */
+Point2 TextEdit::get_local_mouse_pos() const {
+ Point2 mp = get_local_mouse_position();
+ if (is_layout_rtl()) {
+ mp.x = get_size().width - mp.x;
}
+ return mp;
+}
- r_line = line;
- r_column = pos;
+String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
+ Point2i pos = get_line_column_at_pos(p_pos);
+ int row = pos.y;
+ int col = pos.x;
- return true;
-}
+ String s = text[row];
+ if (s.length() == 0) {
+ return "";
+ }
+ int beg, end;
+ if (select_word(s, col, beg, end)) {
+ bool inside_quotes = false;
+ char32_t selected_quote = '\0';
+ int qbegin = 0, qend = 0;
+ for (int i = 0; i < s.length(); i++) {
+ if (s[i] == '"' || s[i] == '\'') {
+ if (i == 0 || s[i - 1] != '\\') {
+ if (inside_quotes && selected_quote == s[i]) {
+ qend = i;
+ inside_quotes = false;
+ selected_quote = '\0';
+ if (col >= qbegin && col <= qend) {
+ return s.substr(qbegin, qend - qbegin);
+ }
+ } else if (!inside_quotes) {
+ qbegin = i + 1;
+ inside_quotes = true;
+ selected_quote = s[i];
+ }
+ }
+ }
+ }
+
+ return s.substr(beg, end - beg);
+ }
-void TextEdit::_cursor_changed_emit() {
- emit_signal(SNAME("cursor_changed"));
- cursor_changed_dirty = false;
+ return String();
}
-void TextEdit::_text_changed_emit() {
- emit_signal(SNAME("text_changed"));
- text_changed_dirty = false;
+Point2i TextEdit::get_line_column_at_pos(const Point2i &p_pos) const {
+ float rows = p_pos.y;
+ rows -= style_normal->get_margin(SIDE_TOP);
+ rows /= get_line_height();
+ rows += _get_v_scroll_offset();
+ int first_vis_line = get_first_visible_line();
+ int row = first_vis_line + Math::floor(rows);
+ int wrap_index = 0;
+
+ if (get_line_wrapping_mode() != LineWrappingMode::LINE_WRAPPING_NONE || _is_hiding_enabled()) {
+ Point2i f_ofs = get_next_visible_line_index_offset_from(first_vis_line, caret.wrap_ofs, rows + (1 * SGN(rows)));
+ wrap_index = f_ofs.y;
+ if (rows < 0) {
+ row = first_vis_line - (f_ofs.x - 1);
+ } else {
+ row = first_vis_line + (f_ofs.x - 1);
+ }
+ }
+
+ if (row < 0) {
+ row = 0;
+ }
+
+ int col = 0;
+
+ if (row >= text.size()) {
+ row = text.size() - 1;
+ col = text[row].size();
+ } else {
+ int colx = p_pos.x - (style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding);
+ colx += caret.x_ofs;
+ col = _get_char_pos_for_line(colx, row, wrap_index);
+ if (get_line_wrapping_mode() != LineWrappingMode::LINE_WRAPPING_NONE && wrap_index < get_line_wrap_count(row)) {
+ // Move back one if we are at the end of the row.
+ Vector<String> rows2 = get_line_wrapped_text(row);
+ int row_end_col = 0;
+ for (int i = 0; i < wrap_index + 1; i++) {
+ row_end_col += rows2[i].length();
+ }
+ if (col >= row_end_col) {
+ col -= 1;
+ }
+ }
+
+ RID text_rid = text.get_line_data(row)->get_line_rid(wrap_index);
+ if (is_layout_rtl()) {
+ colx = TS->shaped_text_get_size(text_rid).x - colx;
+ }
+ col = TS->shaped_text_hit_test_position(text_rid, colx);
+ }
+
+ return Point2i(col, row);
}
-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);
+int TextEdit::get_minimap_line_at_pos(const Point2i &p_pos) const {
+ float rows = p_pos.y;
+ rows -= style_normal->get_margin(SIDE_TOP);
+ rows /= (minimap_char_size.y + minimap_line_spacing);
+ rows += _get_v_scroll_offset();
+
+ // calculate visible lines
+ int minimap_visible_lines = get_minimap_visible_lines();
+ int visible_rows = get_visible_line_count() + 1;
+ int first_visible_line = get_first_visible_line() - 1;
+ int draw_amount = visible_rows + (smooth_scroll_enabled ? 1 : 0);
+ draw_amount += get_line_wrap_count(first_visible_line + 1);
+ int minimap_line_height = (minimap_char_size.y + minimap_line_spacing);
+
+ // calculate viewport size and y offset
+ int viewport_height = (draw_amount - 1) * minimap_line_height;
+ int control_height = _get_control_height() - viewport_height;
+ int viewport_offset_y = round(get_scroll_pos_for_line(first_visible_line + 1) * control_height) / ((v_scroll->get_max() <= minimap_visible_lines) ? (minimap_visible_lines - draw_amount) : (v_scroll->get_max() - draw_amount));
+
+ // calculate the first line.
+ int num_lines_before = round((viewport_offset_y) / minimap_line_height);
+ int minimap_line = (v_scroll->get_max() <= minimap_visible_lines) ? -1 : first_visible_line;
+ if (first_visible_line > 0 && minimap_line >= 0) {
+ minimap_line -= get_next_visible_line_index_offset_from(first_visible_line, 0, -num_lines_before).x;
+ minimap_line -= (minimap_line > 0 && smooth_scroll_enabled ? 1 : 0);
+ } else {
+ minimap_line = 0;
}
- update();
+
+ int row = minimap_line + Math::floor(rows);
+ if (get_line_wrapping_mode() != LineWrappingMode::LINE_WRAPPING_NONE || _is_hiding_enabled()) {
+ int f_ofs = get_next_visible_line_index_offset_from(minimap_line, caret.wrap_ofs, rows + (1 * SGN(rows))).x - 1;
+ if (rows < 0) {
+ row = minimap_line - f_ofs;
+ } else {
+ row = minimap_line + f_ofs;
+ }
+ }
+
+ if (row < 0) {
+ row = 0;
+ }
+
+ if (row >= text.size()) {
+ row = text.size() - 1;
+ }
+
+ return row;
}
-bool TextEdit::is_line_hidden(int p_line) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), false);
- return text.is_hidden(p_line);
+bool TextEdit::is_dragging_cursor() const {
+ return dragging_selection || dragging_minimap;
}
-void TextEdit::unhide_all_lines() {
- for (int i = 0; i < text.size(); i++) {
- text.set_hidden(i, false);
- }
- _update_scrollbars();
+/* Caret */
+void TextEdit::set_caret_type(CaretType p_type) {
+ caret_type = p_type;
update();
}
-int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
- // Returns the number of lines (hidden and unhidden) from p_line_from to (p_line_from + visible_amount of unhidden lines).
- ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(visible_amount));
+TextEdit::CaretType TextEdit::get_caret_type() const {
+ return caret_type;
+}
- if (!is_hiding_enabled()) {
- return ABS(visible_amount);
- }
+void TextEdit::set_caret_blink_enabled(const bool p_enabled) {
+ caret_blink_enabled = p_enabled;
- int num_visible = 0;
- int num_total = 0;
- if (visible_amount >= 0) {
- for (int i = p_line_from; i < text.size(); i++) {
- num_total++;
- if (!is_line_hidden(i)) {
- num_visible++;
- }
- if (num_visible >= visible_amount) {
- break;
- }
- }
- } else {
- visible_amount = ABS(visible_amount);
- for (int i = p_line_from; i >= 0; i--) {
- num_total++;
- if (!is_line_hidden(i)) {
- num_visible++;
- }
- if (num_visible >= visible_amount) {
- break;
- }
+ if (has_focus()) {
+ if (p_enabled) {
+ caret_blink_timer->start();
+ } else {
+ caret_blink_timer->stop();
}
}
- return num_total;
+ draw_caret = true;
}
-int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int visible_amount, int &wrap_index) const {
- // Returns the number of lines (hidden and unhidden) from (p_line_from + p_wrap_index_from) row to (p_line_from + visible_amount of unhidden and wrapped rows).
- // Wrap index is set to the wrap index of the last line.
- wrap_index = 0;
- ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(visible_amount));
+bool TextEdit::is_caret_blink_enabled() const {
+ return caret_blink_enabled;
+}
+
+float TextEdit::get_caret_blink_speed() const {
+ return caret_blink_timer->get_wait_time();
+}
+
+void TextEdit::set_caret_blink_speed(const float p_speed) {
+ ERR_FAIL_COND(p_speed <= 0);
+ caret_blink_timer->set_wait_time(p_speed);
+}
+
+void TextEdit::set_move_caret_on_right_click_enabled(const bool p_enable) {
+ move_caret_on_right_click = p_enable;
+}
+
+bool TextEdit::is_move_caret_on_right_click_enabled() const {
+ return move_caret_on_right_click;
+}
+
+void TextEdit::set_caret_mid_grapheme_enabled(const bool p_enabled) {
+ caret_mid_grapheme_enabled = p_enabled;
+}
+
+bool TextEdit::is_caret_mid_grapheme_enabled() const {
+ return caret_mid_grapheme_enabled;
+}
+
+bool TextEdit::is_caret_visible() const {
+ return caret.visible;
+}
- if (!is_hiding_enabled() && !is_wrap_enabled()) {
- return ABS(visible_amount);
+Point2 TextEdit::get_caret_draw_pos() const {
+ return caret.draw_pos;
+}
+
+void TextEdit::set_caret_line(int p_line, bool p_adjust_viewport, bool p_can_be_hidden, int p_wrap_index) {
+ if (setting_caret_line) {
+ return;
}
- int num_visible = 0;
- int num_total = 0;
- if (visible_amount == 0) {
- num_total = 0;
- wrap_index = 0;
- } else if (visible_amount > 0) {
- int i;
- num_visible -= p_wrap_index_from;
- for (i = p_line_from; i < text.size(); i++) {
- num_total++;
- if (!is_line_hidden(i)) {
- num_visible++;
- num_visible += times_line_wraps(i);
- }
- if (num_visible >= visible_amount) {
- break;
+ setting_caret_line = true;
+ if (p_line < 0) {
+ p_line = 0;
+ }
+
+ if (p_line >= text.size()) {
+ p_line = text.size() - 1;
+ }
+
+ if (!p_can_be_hidden) {
+ if (_is_line_hidden(CLAMP(p_line, 0, text.size() - 1))) {
+ int move_down = get_next_visible_line_offset_from(p_line, 1) - 1;
+ if (p_line + move_down <= text.size() - 1 && !_is_line_hidden(p_line + move_down)) {
+ p_line += move_down;
+ } else {
+ int move_up = get_next_visible_line_offset_from(p_line, -1) - 1;
+ if (p_line - move_up > 0 && !_is_line_hidden(p_line - move_up)) {
+ p_line -= move_up;
+ } else {
+ WARN_PRINT(("Caret set to hidden line " + itos(p_line) + " and there are no nonhidden lines."));
+ }
}
}
- wrap_index = times_line_wraps(MIN(i, text.size() - 1)) - MAX(0, num_visible - visible_amount);
- } else {
- visible_amount = ABS(visible_amount);
- int i;
- num_visible -= times_line_wraps(p_line_from) - p_wrap_index_from;
- for (i = p_line_from; i >= 0; i--) {
- num_total++;
- if (!is_line_hidden(i)) {
- num_visible++;
- num_visible += times_line_wraps(i);
- }
- if (num_visible >= visible_amount) {
- break;
- }
+ }
+ caret.line = p_line;
+
+ int n_col = _get_char_pos_for_line(caret.last_fit_x, p_line, p_wrap_index);
+ if (n_col != 0 && get_line_wrapping_mode() != LineWrappingMode::LINE_WRAPPING_NONE && p_wrap_index < get_line_wrap_count(p_line)) {
+ Vector<String> rows = get_line_wrapped_text(p_line);
+ int row_end_col = 0;
+ for (int i = 0; i < p_wrap_index + 1; i++) {
+ row_end_col += rows[i].length();
+ }
+ if (n_col >= row_end_col) {
+ n_col -= 1;
}
- wrap_index = MAX(0, num_visible - visible_amount);
}
- wrap_index = MAX(wrap_index, 0);
- return num_total;
+ caret.column = n_col;
+
+ if (p_adjust_viewport) {
+ adjust_viewport_to_caret();
+ }
+
+ setting_caret_line = false;
+
+ if (!caret_pos_dirty) {
+ if (is_inside_tree()) {
+ MessageQueue::get_singleton()->push_call(this, "_emit_caret_changed");
+ }
+ caret_pos_dirty = true;
+ }
}
-int TextEdit::get_last_unhidden_line() const {
- // Returns the last line in the text that is not hidden.
- if (!is_hiding_enabled()) {
- return text.size() - 1;
+int TextEdit::get_caret_line() const {
+ return caret.line;
+}
+
+void TextEdit::set_caret_column(int p_col, bool p_adjust_viewport) {
+ if (p_col < 0) {
+ p_col = 0;
}
- int last_line;
- for (last_line = text.size() - 1; last_line > 0; last_line--) {
- if (!is_line_hidden(last_line)) {
- break;
+ caret.column = p_col;
+ if (caret.column > get_line(caret.line).length()) {
+ caret.column = get_line(caret.line).length();
+ }
+
+ caret.last_fit_x = _get_column_x_offset_for_line(caret.column, caret.line);
+
+ if (p_adjust_viewport) {
+ adjust_viewport_to_caret();
+ }
+
+ if (!caret_pos_dirty) {
+ if (is_inside_tree()) {
+ MessageQueue::get_singleton()->push_call(this, "_emit_caret_changed");
}
+ caret_pos_dirty = true;
}
- return last_line;
}
-int TextEdit::get_indent_level(int p_line) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), 0);
+int TextEdit::get_caret_column() const {
+ return caret.column;
+}
- int tab_count = 0;
- 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') {
- tab_count++;
- } else if (text[p_line][i] == ' ') {
- whitespace_count++;
- } else {
- break;
+int TextEdit::get_caret_wrap_index() const {
+ return get_line_wrap_index_at_column(caret.line, caret.column);
+}
+
+String TextEdit::get_word_under_caret() const {
+ Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(caret.line)->get_rid());
+ for (int i = 0; i < words.size(); i++) {
+ if (words[i].x <= caret.column && words[i].y > caret.column) {
+ return text[caret.line].substr(words[i].x, words[i].y - words[i].x);
}
}
- return tab_count * text.get_tab_size() + whitespace_count;
+ return "";
}
-int TextEdit::get_first_non_whitespace_column(int p_line) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), 0);
+/* Selection. */
+void TextEdit::set_selecting_enabled(const bool p_enabled) {
+ selecting_enabled = p_enabled;
- int col = 0;
- while (col < text[p_line].length() && _is_whitespace(text[p_line][col])) {
- col++;
+ if (!selecting_enabled) {
+ deselect();
}
- return col;
}
-int TextEdit::get_line_count() const {
- return text.size();
+bool TextEdit::is_selecting_enabled() const {
+ return selecting_enabled;
}
-int TextEdit::get_line_width(int p_line, int p_wrap_offset) const {
- return text.get_line_width(p_line, p_wrap_offset);
+void TextEdit::set_override_selected_font_color(bool p_override_selected_font_color) {
+ override_selected_font_color = p_override_selected_font_color;
}
-void TextEdit::_do_text_op(const TextOperation &p_op, bool p_reverse) {
- ERR_FAIL_COND(p_op.type == TextOperation::TYPE_NONE);
+bool TextEdit::is_overriding_selected_font_color() const {
+ return override_selected_font_color;
+}
- bool insert = p_op.type == TextOperation::TYPE_INSERT;
- if (p_reverse) {
- insert = !insert;
+void TextEdit::set_selection_mode(SelectionMode p_mode, int p_line, int p_column) {
+ selection.selecting_mode = p_mode;
+ if (p_line >= 0) {
+ ERR_FAIL_INDEX(p_line, text.size());
+ selection.selecting_line = p_line;
}
-
- if (insert) {
- int check_line;
- int check_column;
- _base_insert_text(p_op.from_line, p_op.from_column, p_op.text, check_line, check_column);
- ERR_FAIL_COND(check_line != p_op.to_line); // BUG.
- ERR_FAIL_COND(check_column != p_op.to_column); // BUG.
- } else {
- _base_remove_text(p_op.from_line, p_op.from_column, p_op.to_line, p_op.to_column);
+ if (p_column >= 0) {
+ ERR_FAIL_INDEX(p_column, text[selection.selecting_line].length());
+ selection.selecting_column = p_column;
}
}
-void TextEdit::_clear_redo() {
- if (undo_stack_pos == nullptr) {
- return; // Nothing to clear.
- }
+TextEdit::SelectionMode TextEdit::get_selection_mode() const {
+ return selection.selecting_mode;
+}
- _push_current_op();
+void TextEdit::select_all() {
+ if (!selecting_enabled) {
+ return;
+ }
- while (undo_stack_pos) {
- List<TextOperation>::Element *elem = undo_stack_pos;
- undo_stack_pos = undo_stack_pos->next();
- undo_stack.erase(elem);
+ if (text.size() == 1 && text[0].length() == 0) {
+ return;
}
+ selection.active = true;
+ selection.from_line = 0;
+ selection.from_column = 0;
+ selection.selecting_line = 0;
+ selection.selecting_column = 0;
+ selection.to_line = text.size() - 1;
+ selection.to_column = text[selection.to_line].length();
+ selection.selecting_mode = SelectionMode::SELECTION_MODE_SHIFT;
+ selection.shiftclick_left = true;
+ set_caret_line(selection.to_line, false);
+ set_caret_column(selection.to_column, false);
+ update();
}
-void TextEdit::undo() {
- if (readonly) {
+void TextEdit::select_word_under_caret() {
+ if (!selecting_enabled) {
return;
}
- _push_current_op();
+ if (text.size() == 1 && text[0].length() == 0) {
+ return;
+ }
- if (undo_stack_pos == nullptr) {
- if (!undo_stack.size()) {
- return; // Nothing to undo.
+ if (selection.active) {
+ /* Allow toggling selection by pressing the shortcut a second time. */
+ /* This is also usable as a general-purpose "deselect" shortcut after */
+ /* selecting anything. */
+ deselect();
+ return;
+ }
+
+ int begin = 0;
+ int end = 0;
+ const Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(caret.line)->get_rid());
+ for (int i = 0; i < words.size(); i++) {
+ if (words[i].x <= caret.column && words[i].y >= caret.column) {
+ begin = words[i].x;
+ end = words[i].y;
+ break;
}
+ }
- undo_stack_pos = undo_stack.back();
+ select(caret.line, begin, caret.line, end);
+ /* Move the caret to the end of the word for easier editing. */
+ set_caret_column(end, false);
+}
- } else if (undo_stack_pos == undo_stack.front()) {
- return; // At the bottom of the undo stack.
- } else {
- undo_stack_pos = undo_stack_pos->prev();
+void TextEdit::select(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
+ if (!selecting_enabled) {
+ return;
}
- deselect();
-
- TextOperation op = undo_stack_pos->get();
- _do_text_op(op, true);
- if (op.type != TextOperation::TYPE_INSERT && (op.from_line != op.to_line || op.to_column != op.from_column + 1)) {
- select(op.from_line, op.from_column, op.to_line, op.to_column);
+ if (p_from_line < 0) {
+ p_from_line = 0;
+ } else if (p_from_line >= text.size()) {
+ p_from_line = text.size() - 1;
+ }
+ if (p_from_column >= text[p_from_line].length()) {
+ p_from_column = text[p_from_line].length();
+ }
+ if (p_from_column < 0) {
+ p_from_column = 0;
}
- current_op.version = op.prev_version;
- if (undo_stack_pos->get().chain_backward) {
- while (true) {
- ERR_BREAK(!undo_stack_pos->prev());
- undo_stack_pos = undo_stack_pos->prev();
- op = undo_stack_pos->get();
- _do_text_op(op, true);
- current_op.version = op.prev_version;
- if (undo_stack_pos->get().chain_forward) {
- break;
- }
- }
+ if (p_to_line < 0) {
+ p_to_line = 0;
+ } else if (p_to_line >= text.size()) {
+ p_to_line = text.size() - 1;
+ }
+ if (p_to_column >= text[p_to_line].length()) {
+ p_to_column = text[p_to_line].length();
+ }
+ if (p_to_column < 0) {
+ p_to_column = 0;
}
- _update_scrollbars();
- if (undo_stack_pos->get().type == TextOperation::TYPE_REMOVE) {
- cursor_set_line(undo_stack_pos->get().to_line, false);
- cursor_set_column(undo_stack_pos->get().to_column);
+ selection.from_line = p_from_line;
+ selection.from_column = p_from_column;
+ selection.to_line = p_to_line;
+ selection.to_column = p_to_column;
+
+ selection.active = true;
+
+ if (selection.from_line == selection.to_line) {
+ if (selection.from_column == selection.to_column) {
+ selection.active = false;
+
+ } else if (selection.from_column > selection.to_column) {
+ selection.shiftclick_left = false;
+ SWAP(selection.from_column, selection.to_column);
+ } else {
+ selection.shiftclick_left = true;
+ }
+ } else if (selection.from_line > selection.to_line) {
+ selection.shiftclick_left = false;
+ SWAP(selection.from_line, selection.to_line);
+ SWAP(selection.from_column, selection.to_column);
} else {
- cursor_set_line(undo_stack_pos->get().from_line, false);
- cursor_set_column(undo_stack_pos->get().from_column);
+ selection.shiftclick_left = true;
}
+
update();
}
-void TextEdit::redo() {
- if (readonly) {
- return;
- }
- _push_current_op();
+bool TextEdit::has_selection() const {
+ return selection.active;
+}
- if (undo_stack_pos == nullptr) {
- return; // Nothing to do.
+String TextEdit::get_selected_text() const {
+ if (!selection.active) {
+ return "";
}
- deselect();
+ return _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
+}
- TextOperation op = undo_stack_pos->get();
- _do_text_op(op, false);
- current_op.version = op.version;
- if (undo_stack_pos->get().chain_forward) {
- while (true) {
- ERR_BREAK(!undo_stack_pos->next());
- undo_stack_pos = undo_stack_pos->next();
- op = undo_stack_pos->get();
- _do_text_op(op, false);
- current_op.version = op.version;
- if (undo_stack_pos->get().chain_backward) {
- break;
- }
- }
- }
+int TextEdit::get_selection_line() const {
+ return selection.selecting_line;
+}
- _update_scrollbars();
- cursor_set_line(undo_stack_pos->get().to_line, false);
- cursor_set_column(undo_stack_pos->get().to_column);
- undo_stack_pos = undo_stack_pos->next();
- update();
+int TextEdit::get_selection_column() const {
+ return selection.selecting_column;
}
-void TextEdit::clear_undo_history() {
- saved_version = 0;
- current_op.type = TextOperation::TYPE_NONE;
- undo_stack_pos = nullptr;
- undo_stack.clear();
+int TextEdit::get_selection_from_line() const {
+ ERR_FAIL_COND_V(!selection.active, -1);
+ return selection.from_line;
}
-void TextEdit::begin_complex_operation() {
- _push_current_op();
- next_operation_is_complex = true;
+int TextEdit::get_selection_from_column() const {
+ ERR_FAIL_COND_V(!selection.active, -1);
+ return selection.from_column;
}
-void TextEdit::end_complex_operation() {
- _push_current_op();
- ERR_FAIL_COND(undo_stack.size() == 0);
+int TextEdit::get_selection_to_line() const {
+ ERR_FAIL_COND_V(!selection.active, -1);
+ return selection.to_line;
+}
- if (undo_stack.back()->get().chain_forward) {
- undo_stack.back()->get().chain_forward = false;
+int TextEdit::get_selection_to_column() const {
+ ERR_FAIL_COND_V(!selection.active, -1);
+ return selection.to_column;
+}
+
+void TextEdit::deselect() {
+ selection.active = false;
+ update();
+}
+
+void TextEdit::delete_selection() {
+ if (!has_selection()) {
return;
}
- undo_stack.back()->get().chain_backward = true;
+ selection.active = false;
+ selection.selecting_mode = SelectionMode::SELECTION_MODE_NONE;
+ _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
+ set_caret_line(selection.from_line, false, false);
+ set_caret_column(selection.from_column);
+ update();
}
-void TextEdit::_push_current_op() {
- if (current_op.type == TextOperation::TYPE_NONE) {
- return; // Nothing to do.
+/* line wrapping. */
+void TextEdit::set_line_wrapping_mode(LineWrappingMode p_wrapping_mode) {
+ if (line_wrapping_mode != p_wrapping_mode) {
+ line_wrapping_mode = p_wrapping_mode;
+ _update_wrap_at_column(true);
}
+}
- if (next_operation_is_complex) {
- current_op.chain_forward = true;
- next_operation_is_complex = false;
+TextEdit::LineWrappingMode TextEdit::get_line_wrapping_mode() const {
+ return line_wrapping_mode;
+}
+
+bool TextEdit::is_line_wrapped(int p_line) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), 0);
+ if (get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE) {
+ return false;
}
+ return text.get_line_wrap_amount(p_line) > 0;
+}
- undo_stack.push_back(current_op);
- current_op.type = TextOperation::TYPE_NONE;
- current_op.text = "";
- current_op.chain_forward = false;
+int TextEdit::get_line_wrap_count(int p_line) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), 0);
- if (undo_stack.size() > undo_stack_max_size) {
- undo_stack.pop_front();
+ if (!is_line_wrapped(p_line)) {
+ return 0;
}
+
+ return text.get_line_wrap_amount(p_line);
}
-void TextEdit::set_tab_size(const int p_size) {
- ERR_FAIL_COND_MSG(p_size <= 0, "Tab size must be greater than 0.");
- if (p_size == text.get_tab_size()) {
- return;
+int TextEdit::get_line_wrap_index_at_column(int p_line, int p_column) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), 0);
+ ERR_FAIL_COND_V(p_column < 0, 0);
+ ERR_FAIL_COND_V(p_column > text[p_line].length(), 0);
+
+ if (!is_line_wrapped(p_line)) {
+ return 0;
}
- text.set_tab_size(p_size);
- text.invalidate_all_lines();
- update();
-}
-int TextEdit::get_tab_size() const {
- return text.get_tab_size();
+ /* Loop through wraps in the line text until we get to the column. */
+ int wrap_index = 0;
+ int col = 0;
+ Vector<String> lines = get_line_wrapped_text(p_line);
+ for (int i = 0; i < lines.size(); i++) {
+ wrap_index = i;
+ String s = lines[wrap_index];
+ col += s.length();
+ if (col > p_column) {
+ break;
+ }
+ }
+ return wrap_index;
}
-void TextEdit::set_draw_tabs(bool p_draw) {
- draw_tabs = p_draw;
- update();
-}
+Vector<String> TextEdit::get_line_wrapped_text(int p_line) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), Vector<String>());
-bool TextEdit::is_drawing_tabs() const {
- return draw_tabs;
+ Vector<String> lines;
+ if (!is_line_wrapped(p_line)) {
+ lines.push_back(text[p_line]);
+ return lines;
+ }
+
+ const String &line_text = text[p_line];
+ Vector<Vector2i> line_ranges = text.get_line_wrap_ranges(p_line);
+ for (int i = 0; i < line_ranges.size(); i++) {
+ lines.push_back(line_text.substr(line_ranges[i].x, line_ranges[i].y - line_ranges[i].x));
+ }
+
+ return lines;
}
-void TextEdit::set_draw_spaces(bool p_draw) {
- draw_spaces = p_draw;
- update();
+/* Viewport */
+// Scrolling.
+void TextEdit::set_smooth_scroll_enabled(const bool p_enable) {
+ v_scroll->set_smooth_scroll_enabled(p_enable);
+ smooth_scroll_enabled = p_enable;
}
-bool TextEdit::is_drawing_spaces() const {
- return draw_spaces;
+bool TextEdit::is_smooth_scroll_enabled() const {
+ return smooth_scroll_enabled;
}
-void TextEdit::set_override_selected_font_color(bool p_override_selected_font_color) {
- override_selected_font_color = p_override_selected_font_color;
+void TextEdit::set_scroll_past_end_of_file_enabled(const bool p_enabled) {
+ scroll_past_end_of_file_enabled = p_enabled;
+ update();
}
-bool TextEdit::is_overriding_selected_font_color() const {
- return override_selected_font_color;
+bool TextEdit::is_scroll_past_end_of_file_enabled() const {
+ return scroll_past_end_of_file_enabled;
}
-void TextEdit::set_insert_mode(bool p_enabled) {
- insert_mode = p_enabled;
- update();
+void TextEdit::set_v_scroll(double p_scroll) {
+ v_scroll->set_value(p_scroll);
+ int max_v_scroll = v_scroll->get_max() - v_scroll->get_page();
+ if (p_scroll >= max_v_scroll - 1.0) {
+ _scroll_moved(v_scroll->get_value());
+ }
}
-bool TextEdit::is_insert_mode() const {
- return insert_mode;
+double TextEdit::get_v_scroll() const {
+ return v_scroll->get_value();
}
-bool TextEdit::is_insert_text_operation() {
- return (current_op.type == TextOperation::TYPE_INSERT);
+void TextEdit::set_h_scroll(int p_scroll) {
+ if (p_scroll < 0) {
+ p_scroll = 0;
+ }
+ h_scroll->set_value(p_scroll);
}
-uint32_t TextEdit::get_version() const {
- return current_op.version;
+int TextEdit::get_h_scroll() const {
+ return h_scroll->get_value();
}
-uint32_t TextEdit::get_saved_version() const {
- return saved_version;
+void TextEdit::set_v_scroll_speed(float p_speed) {
+ v_scroll_speed = p_speed;
}
-void TextEdit::tag_saved_version() {
- saved_version = get_version();
+float TextEdit::get_v_scroll_speed() const {
+ return v_scroll_speed;
}
double TextEdit::get_scroll_pos_for_line(int p_line, int p_wrap_index) const {
- if (!is_wrap_enabled() && !is_hiding_enabled()) {
+ ERR_FAIL_INDEX_V(p_line, text.size(), 0);
+ ERR_FAIL_COND_V(p_wrap_index < 0, 0);
+ ERR_FAIL_COND_V(p_wrap_index > get_line_wrap_count(p_line), 0);
+
+ if (get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE && !_is_hiding_enabled()) {
return p_line;
}
@@ -4864,206 +3943,207 @@ double TextEdit::get_scroll_pos_for_line(int p_line, int p_wrap_index) const {
for (int i = 0; i < to; i++) {
if (!text.is_hidden(i)) {
new_line_scroll_pos++;
- new_line_scroll_pos += times_line_wraps(i);
+ new_line_scroll_pos += get_line_wrap_count(i);
}
}
new_line_scroll_pos += p_wrap_index;
return new_line_scroll_pos;
}
+// Visible lines.
void TextEdit::set_line_as_first_visible(int p_line, int p_wrap_index) {
+ ERR_FAIL_INDEX(p_line, text.size());
+ ERR_FAIL_COND(p_wrap_index < 0);
+ ERR_FAIL_COND(p_wrap_index > get_line_wrap_count(p_line));
set_v_scroll(get_scroll_pos_for_line(p_line, p_wrap_index));
}
+int TextEdit::get_first_visible_line() const {
+ return CLAMP(caret.line_ofs, 0, text.size() - 1);
+}
+
void TextEdit::set_line_as_center_visible(int p_line, int p_wrap_index) {
- int visible_rows = get_visible_rows();
- int wi;
- int first_line = p_line - num_lines_from_rows(p_line, p_wrap_index, -visible_rows / 2, wi) + 1;
+ ERR_FAIL_INDEX(p_line, text.size());
+ ERR_FAIL_COND(p_wrap_index < 0);
+ ERR_FAIL_COND(p_wrap_index > get_line_wrap_count(p_line));
+
+ int visible_rows = get_visible_line_count();
+ Point2i next_line = get_next_visible_line_index_offset_from(p_line, p_wrap_index, -visible_rows / 2);
+ int first_line = p_line - next_line.x + 1;
- set_v_scroll(get_scroll_pos_for_line(first_line, wi));
+ set_v_scroll(get_scroll_pos_for_line(first_line, next_line.y));
}
void TextEdit::set_line_as_last_visible(int p_line, int p_wrap_index) {
- int wi;
- int first_line = p_line - num_lines_from_rows(p_line, p_wrap_index, -get_visible_rows() - 1, wi) + 1;
+ ERR_FAIL_INDEX(p_line, text.size());
+ ERR_FAIL_COND(p_wrap_index < 0);
+ ERR_FAIL_COND(p_wrap_index > get_line_wrap_count(p_line));
- set_v_scroll(get_scroll_pos_for_line(first_line, wi) + get_visible_rows_offset());
-}
+ Point2i next_line = get_next_visible_line_index_offset_from(p_line, p_wrap_index, -get_visible_line_count() - 1);
+ int first_line = p_line - next_line.x + 1;
-int TextEdit::get_first_visible_line() const {
- return CLAMP(cursor.line_ofs, 0, text.size() - 1);
+ set_v_scroll(get_scroll_pos_for_line(first_line, next_line.y) + _get_visible_lines_offset());
}
int TextEdit::get_last_full_visible_line() const {
int first_vis_line = get_first_visible_line();
int last_vis_line = 0;
- int wi;
- last_vis_line = first_vis_line + num_lines_from_rows(first_vis_line, cursor.wrap_ofs, get_visible_rows(), wi) - 1;
+ last_vis_line = first_vis_line + get_next_visible_line_index_offset_from(first_vis_line, caret.wrap_ofs, get_visible_line_count()).x - 1;
last_vis_line = CLAMP(last_vis_line, 0, text.size() - 1);
return last_vis_line;
}
int TextEdit::get_last_full_visible_line_wrap_index() const {
int first_vis_line = get_first_visible_line();
- int wi;
- num_lines_from_rows(first_vis_line, cursor.wrap_ofs, get_visible_rows(), wi);
- return wi;
-}
-
-double TextEdit::get_visible_rows_offset() const {
- double total = _get_control_height();
- total /= (double)get_row_height();
- total = total - floor(total);
- total = -CLAMP(total, 0.001, 1) + 1;
- return total;
+ return get_next_visible_line_index_offset_from(first_vis_line, caret.wrap_ofs, get_visible_line_count()).y;
}
-double TextEdit::get_v_scroll_offset() const {
- double val = get_v_scroll() - floor(get_v_scroll());
- return CLAMP(val, 0, 1);
+int TextEdit::get_visible_line_count() const {
+ return _get_control_height() / get_line_height();
}
-double TextEdit::get_v_scroll() const {
- return v_scroll->get_value();
-}
+int TextEdit::get_total_visible_line_count() const {
+ /* Returns the total number of (lines + wraped - hidden). */
+ if (!_is_hiding_enabled() && get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE) {
+ return text.size();
+ }
-void TextEdit::set_v_scroll(double p_scroll) {
- v_scroll->set_value(p_scroll);
- int max_v_scroll = v_scroll->get_max() - v_scroll->get_page();
- if (p_scroll >= max_v_scroll - 1.0) {
- _scroll_moved(v_scroll->get_value());
+ int total_rows = 0;
+ for (int i = 0; i < text.size(); i++) {
+ if (!text.is_hidden(i)) {
+ total_rows++;
+ total_rows += get_line_wrap_count(i);
+ }
}
+ return total_rows;
}
-int TextEdit::get_h_scroll() const {
- return h_scroll->get_value();
-}
+// Auto adjust
+void TextEdit::adjust_viewport_to_caret() {
+ // Make sure Caret is visible on the screen.
+ scrolling = false;
+ minimap_clicked = false;
-void TextEdit::set_h_scroll(int p_scroll) {
- if (p_scroll < 0) {
- p_scroll = 0;
- }
- h_scroll->set_value(p_scroll);
-}
+ int cur_line = caret.line;
+ int cur_wrap = get_caret_wrap_index();
-void TextEdit::set_smooth_scroll_enabled(bool p_enable) {
- v_scroll->set_smooth_scroll_enabled(p_enable);
- smooth_scroll_enabled = p_enable;
-}
+ int first_vis_line = get_first_visible_line();
+ int first_vis_wrap = caret.wrap_ofs;
+ int last_vis_line = get_last_full_visible_line();
+ int last_vis_wrap = get_last_full_visible_line_wrap_index();
-bool TextEdit::is_smooth_scroll_enabled() const {
- return smooth_scroll_enabled;
-}
+ if (cur_line < first_vis_line || (cur_line == first_vis_line && cur_wrap < first_vis_wrap)) {
+ // Caret is above screen.
+ set_line_as_first_visible(cur_line, cur_wrap);
+ } else if (cur_line > last_vis_line || (cur_line == last_vis_line && cur_wrap > last_vis_wrap)) {
+ // Caret is below screen.
+ set_line_as_last_visible(cur_line, cur_wrap);
+ }
-void TextEdit::set_v_scroll_speed(float p_speed) {
- v_scroll_speed = p_speed;
-}
+ int visible_width = get_size().width - style_normal->get_minimum_size().width - gutters_width - gutter_padding;
+ if (draw_minimap) {
+ visible_width -= minimap_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.
-float TextEdit::get_v_scroll_speed() const {
- return v_scroll_speed;
-}
+ if (get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE) {
+ // Adjust x offset.
+ Vector2i caret_pos;
-String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
- int row, col;
- _get_mouse_pos(p_pos, row, col);
+ // Get position of the start of caret.
+ if (ime_text.length() != 0 && ime_selection.x != 0) {
+ caret_pos.x = _get_column_x_offset_for_line(caret.column + ime_selection.x, caret.line);
+ } else {
+ caret_pos.x = _get_column_x_offset_for_line(caret.column, caret.line);
+ }
- String s = text[row];
- if (s.length() == 0) {
- return "";
- }
- int beg, end;
- if (select_word(s, col, beg, end)) {
- bool inside_quotes = false;
- char32_t selected_quote = '\0';
- int qbegin = 0, qend = 0;
- for (int i = 0; i < s.length(); i++) {
- if (s[i] == '"' || s[i] == '\'') {
- if (i == 0 || s[i - 1] != '\\') {
- if (inside_quotes && selected_quote == s[i]) {
- qend = i;
- inside_quotes = false;
- selected_quote = '\0';
- if (col >= qbegin && col <= qend) {
- return s.substr(qbegin, qend - qbegin);
- }
- } else if (!inside_quotes) {
- qbegin = i + 1;
- inside_quotes = true;
- selected_quote = s[i];
- }
- }
+ // Get position of the end of caret.
+ if (ime_text.length() != 0) {
+ if (ime_selection.y != 0) {
+ caret_pos.y = _get_column_x_offset_for_line(caret.column + ime_selection.x + ime_selection.y, caret.line);
+ } else {
+ caret_pos.y = _get_column_x_offset_for_line(caret.column + ime_text.size(), caret.line);
}
+ } else {
+ caret_pos.y = caret_pos.x;
}
- return s.substr(beg, end - beg);
+ if (MAX(caret_pos.x, caret_pos.y) > (caret.x_ofs + visible_width)) {
+ caret.x_ofs = MAX(caret_pos.x, caret_pos.y) - visible_width + 1;
+ }
+
+ if (MIN(caret_pos.x, caret_pos.y) < caret.x_ofs) {
+ caret.x_ofs = MIN(caret_pos.x, caret_pos.y);
+ }
+ } else {
+ caret.x_ofs = 0;
}
+ h_scroll->set_value(caret.x_ofs);
- return String();
+ update();
}
-String TextEdit::get_tooltip(const Point2 &p_pos) const {
- if (!tooltip_obj) {
- return Control::get_tooltip(p_pos);
- }
- int row, col;
- _get_mouse_pos(p_pos, row, col);
+void TextEdit::center_viewport_to_caret() {
+ // Move viewport so the caret is in the center of the screen.
+ scrolling = false;
+ minimap_clicked = false;
- String s = text[row];
- if (s.length() == 0) {
- return Control::get_tooltip(p_pos);
+ set_line_as_center_visible(caret.line, get_caret_wrap_index());
+ int visible_width = get_size().width - style_normal->get_minimum_size().width - gutters_width - gutter_padding;
+ if (draw_minimap) {
+ visible_width -= minimap_width;
}
- int beg, end;
- if (select_word(s, col, beg, end)) {
- String tt = tooltip_obj->call(tooltip_func, s.substr(beg, end - beg), tooltip_ud);
-
- return tt;
+ 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.
- return Control::get_tooltip(p_pos);
-}
+ if (get_line_wrapping_mode() != LineWrappingMode::LINE_WRAPPING_NONE) {
+ // Center x offset.
-void TextEdit::set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata) {
- tooltip_obj = p_obj;
- tooltip_func = p_function;
- tooltip_ud = p_udata;
-}
+ Vector2i caret_pos;
-void TextEdit::set_line(int line, String new_text) {
- if (line < 0 || line >= text.size()) {
- return;
- }
- _remove_text(line, 0, line, text[line].length());
- _insert_text(line, 0, new_text);
- if (cursor.line == line) {
- cursor.column = MIN(cursor.column, new_text.length());
- }
- if (is_selection_active() && line == selection.to_line && selection.to_column > text[line].length()) {
- selection.to_column = text[line].length();
- }
-}
+ // Get position of the start of caret.
+ if (ime_text.length() != 0 && ime_selection.x != 0) {
+ caret_pos.x = _get_column_x_offset_for_line(caret.column + ime_selection.x, caret.line);
+ } else {
+ caret_pos.x = _get_column_x_offset_for_line(caret.column, caret.line);
+ }
-void TextEdit::insert_at(const String &p_text, int at) {
- _insert_text(at, 0, p_text + "\n");
- if (cursor.line >= at) {
- // offset cursor when located after inserted line
- ++cursor.line;
- }
- if (is_selection_active()) {
- if (selection.from_line >= at) {
- // offset selection when located after inserted line
- ++selection.from_line;
- ++selection.to_line;
- } else if (selection.to_line >= at) {
- // extend selection that includes inserted line
- ++selection.to_line;
+ // Get position of the end of caret.
+ if (ime_text.length() != 0) {
+ if (ime_selection.y != 0) {
+ caret_pos.y = _get_column_x_offset_for_line(caret.column + ime_selection.x + ime_selection.y, caret.line);
+ } else {
+ caret_pos.y = _get_column_x_offset_for_line(caret.column + ime_text.size(), caret.line);
+ }
+ } else {
+ caret_pos.y = caret_pos.x;
+ }
+
+ if (MAX(caret_pos.x, caret_pos.y) > (caret.x_ofs + visible_width)) {
+ caret.x_ofs = MAX(caret_pos.x, caret_pos.y) - visible_width + 1;
}
+
+ if (MIN(caret_pos.x, caret_pos.y) < caret.x_ofs) {
+ caret.x_ofs = MIN(caret_pos.x, caret_pos.y);
+ }
+ } else {
+ caret.x_ofs = 0;
}
+ h_scroll->set_value(caret.x_ofs);
+
+ update();
}
+/* Minimap */
void TextEdit::set_draw_minimap(bool p_draw) {
if (draw_minimap != p_draw) {
draw_minimap = p_draw;
- _update_wrap_at();
+ _update_wrap_at_column();
}
update();
}
@@ -5075,7 +4155,7 @@ bool TextEdit::is_drawing_minimap() const {
void TextEdit::set_minimap_width(int p_minimap_width) {
if (minimap_width != p_minimap_width) {
minimap_width = p_minimap_width;
- _update_wrap_at();
+ _update_wrap_at_column();
}
update();
}
@@ -5084,391 +4164,581 @@ int TextEdit::get_minimap_width() const {
return minimap_width;
}
-void TextEdit::set_hiding_enabled(bool p_enabled) {
- if (!p_enabled) {
- unhide_all_lines();
+int TextEdit::get_minimap_visible_lines() const {
+ return _get_control_height() / (minimap_char_size.y + minimap_line_spacing);
+}
+
+/* Gutters. */
+void TextEdit::add_gutter(int p_at) {
+ if (p_at < 0 || p_at > gutters.size()) {
+ gutters.push_back(GutterInfo());
+ } else {
+ gutters.insert(p_at, GutterInfo());
}
- hiding_enabled = p_enabled;
+
+ for (int i = 0; i < text.size() + 1; i++) {
+ text.add_gutter(p_at);
+ }
+ emit_signal(SNAME("gutter_added"));
update();
}
-bool TextEdit::is_hiding_enabled() const {
- return hiding_enabled;
+void TextEdit::remove_gutter(int p_gutter) {
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+
+ gutters.remove(p_gutter);
+
+ for (int i = 0; i < text.size() + 1; i++) {
+ text.remove_gutter(p_gutter);
+ }
+ emit_signal(SNAME("gutter_removed"));
+ update();
}
-void TextEdit::set_highlight_current_line(bool p_enabled) {
- highlight_current_line = p_enabled;
+int TextEdit::get_gutter_count() const {
+ return gutters.size();
+}
+
+void TextEdit::set_gutter_name(int p_gutter, const String &p_name) {
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+ gutters.write[p_gutter].name = p_name;
+}
+
+String TextEdit::get_gutter_name(int p_gutter) const {
+ ERR_FAIL_INDEX_V(p_gutter, gutters.size(), "");
+ return gutters[p_gutter].name;
+}
+
+void TextEdit::set_gutter_type(int p_gutter, GutterType p_type) {
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+ gutters.write[p_gutter].type = p_type;
update();
}
-bool TextEdit::is_highlight_current_line_enabled() const {
- return highlight_current_line;
+TextEdit::GutterType TextEdit::get_gutter_type(int p_gutter) const {
+ ERR_FAIL_INDEX_V(p_gutter, gutters.size(), GUTTER_TYPE_STRING);
+ return gutters[p_gutter].type;
}
-bool TextEdit::is_text_field() const {
- return true;
+void TextEdit::set_gutter_width(int p_gutter, int p_width) {
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+ if (gutters[p_gutter].width == p_width) {
+ return;
+ }
+ gutters.write[p_gutter].width = p_width;
+ _update_gutter_width();
}
-void TextEdit::menu_option(int p_option) {
- switch (p_option) {
- case MENU_CUT: {
- if (!readonly) {
- cut();
- }
- } break;
- case MENU_COPY: {
- copy();
- } break;
- case MENU_PASTE: {
- if (!readonly) {
- paste();
- }
- } break;
- case MENU_CLEAR: {
- if (!readonly) {
- clear();
- }
- } break;
- case MENU_SELECT_ALL: {
- select_all();
- } break;
- case MENU_UNDO: {
- undo();
- } break;
- case MENU_REDO: {
- redo();
- } break;
- case MENU_DIR_INHERITED: {
- set_text_direction(TEXT_DIRECTION_INHERITED);
- } break;
- case MENU_DIR_AUTO: {
- set_text_direction(TEXT_DIRECTION_AUTO);
- } break;
- case MENU_DIR_LTR: {
- set_text_direction(TEXT_DIRECTION_LTR);
- } break;
- case MENU_DIR_RTL: {
- set_text_direction(TEXT_DIRECTION_RTL);
- } break;
- case MENU_DISPLAY_UCC: {
- set_draw_control_chars(!get_draw_control_chars());
- } break;
- case MENU_INSERT_LRM: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x200E));
- }
- } break;
- case MENU_INSERT_RLM: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x200F));
- }
- } break;
- case MENU_INSERT_LRE: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x202A));
- }
- } break;
- case MENU_INSERT_RLE: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x202B));
- }
- } break;
- case MENU_INSERT_LRO: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x202D));
- }
- } break;
- case MENU_INSERT_RLO: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x202E));
- }
- } break;
- case MENU_INSERT_PDF: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x202C));
- }
- } break;
- case MENU_INSERT_ALM: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x061C));
- }
- } break;
- case MENU_INSERT_LRI: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x2066));
- }
- } break;
- case MENU_INSERT_RLI: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x2067));
- }
- } break;
- case MENU_INSERT_FSI: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x2068));
- }
- } break;
- case MENU_INSERT_PDI: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x2069));
- }
- } break;
- case MENU_INSERT_ZWJ: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x200D));
- }
- } break;
- case MENU_INSERT_ZWNJ: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x200C));
- }
- } break;
- case MENU_INSERT_WJ: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x2060));
- }
- } break;
- case MENU_INSERT_SHY: {
- if (!readonly) {
- insert_text_at_cursor(String::chr(0x00AD));
- }
+int TextEdit::get_gutter_width(int p_gutter) const {
+ ERR_FAIL_INDEX_V(p_gutter, gutters.size(), -1);
+ return gutters[p_gutter].width;
+}
+
+int TextEdit::get_total_gutter_width() const {
+ return gutters_width + gutter_padding;
+}
+
+void TextEdit::set_gutter_draw(int p_gutter, bool p_draw) {
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+ if (gutters[p_gutter].draw == p_draw) {
+ return;
+ }
+ gutters.write[p_gutter].draw = p_draw;
+ _update_gutter_width();
+}
+
+bool TextEdit::is_gutter_drawn(int p_gutter) const {
+ ERR_FAIL_INDEX_V(p_gutter, gutters.size(), false);
+ return gutters[p_gutter].draw;
+}
+
+void TextEdit::set_gutter_clickable(int p_gutter, bool p_clickable) {
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+ gutters.write[p_gutter].clickable = p_clickable;
+ update();
+}
+
+bool TextEdit::is_gutter_clickable(int p_gutter) const {
+ ERR_FAIL_INDEX_V(p_gutter, gutters.size(), false);
+ return gutters[p_gutter].clickable;
+}
+
+void TextEdit::set_gutter_overwritable(int p_gutter, bool p_overwritable) {
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+ gutters.write[p_gutter].overwritable = p_overwritable;
+}
+
+bool TextEdit::is_gutter_overwritable(int p_gutter) const {
+ ERR_FAIL_INDEX_V(p_gutter, gutters.size(), false);
+ return gutters[p_gutter].overwritable;
+}
+
+void TextEdit::merge_gutters(int p_from_line, int p_to_line) {
+ ERR_FAIL_INDEX(p_from_line, text.size());
+ ERR_FAIL_INDEX(p_to_line, text.size());
+ if (p_from_line == p_to_line) {
+ return;
+ }
+
+ for (int i = 0; i < gutters.size(); i++) {
+ if (!gutters[i].overwritable) {
+ continue;
+ }
+
+ if (text.get_line_gutter_text(p_from_line, i) != "") {
+ text.set_line_gutter_text(p_to_line, i, text.get_line_gutter_text(p_from_line, i));
+ text.set_line_gutter_item_color(p_to_line, i, text.get_line_gutter_item_color(p_from_line, i));
+ }
+
+ if (text.get_line_gutter_icon(p_from_line, i).is_valid()) {
+ text.set_line_gutter_icon(p_to_line, i, text.get_line_gutter_icon(p_from_line, i));
+ text.set_line_gutter_item_color(p_to_line, i, text.get_line_gutter_item_color(p_from_line, i));
+ }
+
+ if (text.get_line_gutter_metadata(p_from_line, i) != "") {
+ text.set_line_gutter_metadata(p_to_line, i, text.get_line_gutter_metadata(p_from_line, i));
+ }
+
+ if (text.is_line_gutter_clickable(p_from_line, i)) {
+ text.set_line_gutter_clickable(p_to_line, i, true);
}
}
+ update();
}
-void TextEdit::_set_symbol_lookup_word(const String &p_symbol) {
- lookup_symbol_word = p_symbol;
+void TextEdit::set_gutter_custom_draw(int p_gutter, Object *p_object, const StringName &p_callback) {
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+ ERR_FAIL_NULL(p_object);
+
+ gutters.write[p_gutter].custom_draw_obj = p_object->get_instance_id();
+ gutters.write[p_gutter].custom_draw_callback = p_callback;
update();
}
-void TextEdit::set_context_menu_enabled(bool p_enable) {
- context_menu_enabled = p_enable;
+// Line gutters.
+void TextEdit::set_line_gutter_metadata(int p_line, int p_gutter, const Variant &p_metadata) {
+ ERR_FAIL_INDEX(p_line, text.size());
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+ text.set_line_gutter_metadata(p_line, p_gutter, p_metadata);
}
-bool TextEdit::is_context_menu_enabled() {
- return context_menu_enabled;
+Variant TextEdit::get_line_gutter_metadata(int p_line, int p_gutter) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), "");
+ ERR_FAIL_INDEX_V(p_gutter, gutters.size(), "");
+ return text.get_line_gutter_metadata(p_line, p_gutter);
}
-void TextEdit::set_shortcut_keys_enabled(bool p_enabled) {
- shortcut_keys_enabled = p_enabled;
+void TextEdit::set_line_gutter_text(int p_line, int p_gutter, const String &p_text) {
+ ERR_FAIL_INDEX(p_line, text.size());
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+ text.set_line_gutter_text(p_line, p_gutter, p_text);
+ update();
}
-void TextEdit::set_virtual_keyboard_enabled(bool p_enable) {
- virtual_keyboard_enabled = p_enable;
+String TextEdit::get_line_gutter_text(int p_line, int p_gutter) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), "");
+ ERR_FAIL_INDEX_V(p_gutter, gutters.size(), "");
+ return text.get_line_gutter_text(p_line, p_gutter);
}
-void TextEdit::set_selecting_enabled(bool p_enabled) {
- selecting_enabled = p_enabled;
+void TextEdit::set_line_gutter_icon(int p_line, int p_gutter, const Ref<Texture2D> &p_icon) {
+ ERR_FAIL_INDEX(p_line, text.size());
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+ text.set_line_gutter_icon(p_line, p_gutter, p_icon);
+ update();
+}
- if (!selecting_enabled) {
- deselect();
- }
+Ref<Texture2D> TextEdit::get_line_gutter_icon(int p_line, int p_gutter) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), Ref<Texture2D>());
+ ERR_FAIL_INDEX_V(p_gutter, gutters.size(), Ref<Texture2D>());
+ return text.get_line_gutter_icon(p_line, p_gutter);
}
-bool TextEdit::is_selecting_enabled() const {
- return selecting_enabled;
+void TextEdit::set_line_gutter_item_color(int p_line, int p_gutter, const Color &p_color) {
+ ERR_FAIL_INDEX(p_line, text.size());
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+ text.set_line_gutter_item_color(p_line, p_gutter, p_color);
+ update();
}
-bool TextEdit::is_shortcut_keys_enabled() const {
- return shortcut_keys_enabled;
+Color TextEdit::get_line_gutter_item_color(int p_line, int p_gutter) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), Color());
+ ERR_FAIL_INDEX_V(p_gutter, gutters.size(), Color());
+ return text.get_line_gutter_item_color(p_line, p_gutter);
}
-bool TextEdit::is_virtual_keyboard_enabled() const {
- return virtual_keyboard_enabled;
+void TextEdit::set_line_gutter_clickable(int p_line, int p_gutter, bool p_clickable) {
+ ERR_FAIL_INDEX(p_line, text.size());
+ ERR_FAIL_INDEX(p_gutter, gutters.size());
+ text.set_line_gutter_clickable(p_line, p_gutter, p_clickable);
}
-bool TextEdit::is_menu_visible() const {
- return menu && menu->is_visible();
+bool TextEdit::is_line_gutter_clickable(int p_line, int p_gutter) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), false);
+ ERR_FAIL_INDEX_V(p_gutter, gutters.size(), false);
+ return text.is_line_gutter_clickable(p_line, p_gutter);
}
-PopupMenu *TextEdit::get_menu() const {
- const_cast<TextEdit *>(this)->_ensure_menu();
- return menu;
+// Line style
+void TextEdit::set_line_background_color(int p_line, const Color &p_color) {
+ ERR_FAIL_INDEX(p_line, text.size());
+ text.set_line_background_color(p_line, p_color);
+ update();
}
-bool TextEdit::_set(const StringName &p_name, const Variant &p_value) {
- String str = p_name;
- if (str.begins_with("opentype_features/")) {
- String name = str.get_slicec('/', 1);
- int32_t tag = TS->name_to_tag(name);
- double value = p_value;
- if (value == -1) {
- if (opentype_features.has(tag)) {
- opentype_features.erase(tag);
- text.set_font_features(opentype_features);
- text.invalidate_all();
- update();
- }
- } else {
- if ((double)opentype_features[tag] != value) {
- opentype_features[tag] = value;
- text.set_font_features(opentype_features);
- text.invalidate_all();
- ;
- update();
- }
- }
- notify_property_list_changed();
- return true;
+Color TextEdit::get_line_background_color(int p_line) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), Color());
+ return text.get_line_background_color(p_line);
+}
+
+/* Syntax Highlighting. */
+void TextEdit::set_syntax_highlighter(Ref<SyntaxHighlighter> p_syntax_highlighter) {
+ syntax_highlighter = p_syntax_highlighter;
+ if (syntax_highlighter.is_valid()) {
+ syntax_highlighter->set_text_edit(this);
}
+ update();
+}
- return false;
+Ref<SyntaxHighlighter> TextEdit::get_syntax_highlighter() const {
+ return syntax_highlighter;
}
-bool TextEdit::_get(const StringName &p_name, Variant &r_ret) const {
- String str = p_name;
- if (str.begins_with("opentype_features/")) {
- String name = str.get_slicec('/', 1);
- int32_t tag = TS->name_to_tag(name);
- if (opentype_features.has(tag)) {
- r_ret = opentype_features[tag];
- return true;
- } else {
- r_ret = -1;
- return true;
+/* Visual. */
+void TextEdit::set_highlight_current_line(bool p_enabled) {
+ highlight_current_line = p_enabled;
+ update();
+}
+
+bool TextEdit::is_highlight_current_line_enabled() const {
+ return highlight_current_line;
+}
+
+void TextEdit::set_highlight_all_occurrences(const bool p_enabled) {
+ highlight_all_occurrences = p_enabled;
+ update();
+}
+
+bool TextEdit::is_highlight_all_occurrences_enabled() const {
+ return highlight_all_occurrences;
+}
+
+void TextEdit::set_draw_control_chars(bool p_draw_control_chars) {
+ if (draw_control_chars != p_draw_control_chars) {
+ draw_control_chars = p_draw_control_chars;
+ if (menu) {
+ menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars);
}
+ text.set_draw_control_chars(draw_control_chars);
+ text.invalidate_all();
+ update();
}
- return false;
}
-void TextEdit::_get_property_list(List<PropertyInfo> *p_list) const {
- for (const Variant *ftr = opentype_features.next(nullptr); ftr != nullptr; ftr = opentype_features.next(ftr)) {
- String name = TS->tag_to_name(*ftr);
- p_list->push_back(PropertyInfo(Variant::FLOAT, "opentype_features/" + name));
- }
- p_list->push_back(PropertyInfo(Variant::NIL, "opentype_features/_new", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
+bool TextEdit::get_draw_control_chars() const {
+ return draw_control_chars;
+}
+
+void TextEdit::set_draw_tabs(bool p_draw) {
+ draw_tabs = p_draw;
+ update();
+}
+
+bool TextEdit::is_drawing_tabs() const {
+ return draw_tabs;
+}
+
+void TextEdit::set_draw_spaces(bool p_draw) {
+ draw_spaces = p_draw;
+ update();
+}
+
+bool TextEdit::is_drawing_spaces() const {
+ return draw_spaces;
}
void TextEdit::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &TextEdit::_gui_input);
- ClassDB::bind_method(D_METHOD("_cursor_changed_emit"), &TextEdit::_cursor_changed_emit);
- ClassDB::bind_method(D_METHOD("_text_changed_emit"), &TextEdit::_text_changed_emit);
- ClassDB::bind_method(D_METHOD("_update_wrap_at", "force"), &TextEdit::_update_wrap_at, DEFVAL(false));
+ /*Internal. */
- BIND_ENUM_CONSTANT(SEARCH_MATCH_CASE);
- BIND_ENUM_CONSTANT(SEARCH_WHOLE_WORDS);
- BIND_ENUM_CONSTANT(SEARCH_BACKWARDS);
+ ClassDB::bind_method(D_METHOD("_text_changed_emit"), &TextEdit::_text_changed_emit);
- BIND_ENUM_CONSTANT(SELECTION_MODE_NONE);
- BIND_ENUM_CONSTANT(SELECTION_MODE_SHIFT);
- BIND_ENUM_CONSTANT(SELECTION_MODE_POINTER);
- BIND_ENUM_CONSTANT(SELECTION_MODE_WORD);
- BIND_ENUM_CONSTANT(SELECTION_MODE_LINE);
+ /* Text */
+ // Text properties
+ ClassDB::bind_method(D_METHOD("has_ime_text"), &TextEdit::has_ime_text);
- /*
- ClassDB::bind_method(D_METHOD("delete_char"),&TextEdit::delete_char);
- ClassDB::bind_method(D_METHOD("delete_line"),&TextEdit::delete_line);
-*/
+ ClassDB::bind_method(D_METHOD("set_editable", "enable"), &TextEdit::set_editable);
+ ClassDB::bind_method(D_METHOD("is_editable"), &TextEdit::is_editable);
- ClassDB::bind_method(D_METHOD("get_draw_control_chars"), &TextEdit::get_draw_control_chars);
- ClassDB::bind_method(D_METHOD("set_draw_control_chars", "enable"), &TextEdit::set_draw_control_chars);
ClassDB::bind_method(D_METHOD("set_text_direction", "direction"), &TextEdit::set_text_direction);
ClassDB::bind_method(D_METHOD("get_text_direction"), &TextEdit::get_text_direction);
+
ClassDB::bind_method(D_METHOD("set_opentype_feature", "tag", "value"), &TextEdit::set_opentype_feature);
ClassDB::bind_method(D_METHOD("get_opentype_feature", "tag"), &TextEdit::get_opentype_feature);
ClassDB::bind_method(D_METHOD("clear_opentype_features"), &TextEdit::clear_opentype_features);
+
ClassDB::bind_method(D_METHOD("set_language", "language"), &TextEdit::set_language);
ClassDB::bind_method(D_METHOD("get_language"), &TextEdit::get_language);
- ClassDB::bind_method(D_METHOD("get_first_non_whitespace_column", "line"), &TextEdit::get_first_non_whitespace_column);
- ClassDB::bind_method(D_METHOD("get_indent_level", "line"), &TextEdit::get_indent_level);
- ClassDB::bind_method(D_METHOD("set_tab_size", "size"), &TextEdit::set_tab_size);
- ClassDB::bind_method(D_METHOD("get_tab_size"), &TextEdit::get_tab_size);
-
- ClassDB::bind_method(D_METHOD("set_text", "text"), &TextEdit::set_text);
- ClassDB::bind_method(D_METHOD("insert_text_at_cursor", "text"), &TextEdit::insert_text_at_cursor);
-
- ClassDB::bind_method(D_METHOD("get_line_count"), &TextEdit::get_line_count);
- ClassDB::bind_method(D_METHOD("get_text"), &TextEdit::get_text);
- ClassDB::bind_method(D_METHOD("get_line", "line"), &TextEdit::get_line);
- ClassDB::bind_method(D_METHOD("get_visible_line_count"), &TextEdit::get_total_visible_rows);
- ClassDB::bind_method(D_METHOD("set_line", "line", "new_text"), &TextEdit::set_line);
-
ClassDB::bind_method(D_METHOD("set_structured_text_bidi_override", "parser"), &TextEdit::set_structured_text_bidi_override);
ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override"), &TextEdit::get_structured_text_bidi_override);
ClassDB::bind_method(D_METHOD("set_structured_text_bidi_override_options", "args"), &TextEdit::set_structured_text_bidi_override_options);
ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override_options"), &TextEdit::get_structured_text_bidi_override_options);
- ClassDB::bind_method(D_METHOD("center_viewport_to_cursor"), &TextEdit::center_viewport_to_cursor);
- 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", "can_be_hidden", "wrap_index"), &TextEdit::cursor_set_line, DEFVAL(true), DEFVAL(true), DEFVAL(0));
-
- ClassDB::bind_method(D_METHOD("get_caret_draw_pos"), &TextEdit::get_caret_draw_pos);
- ClassDB::bind_method(D_METHOD("is_caret_visible"), &TextEdit::is_caret_visible);
- ClassDB::bind_method(D_METHOD("cursor_get_column"), &TextEdit::cursor_get_column);
- ClassDB::bind_method(D_METHOD("cursor_get_line"), &TextEdit::cursor_get_line);
- ClassDB::bind_method(D_METHOD("cursor_set_blink_enabled", "enable"), &TextEdit::cursor_set_blink_enabled);
- ClassDB::bind_method(D_METHOD("cursor_get_blink_enabled"), &TextEdit::cursor_get_blink_enabled);
- ClassDB::bind_method(D_METHOD("cursor_set_blink_speed", "blink_speed"), &TextEdit::cursor_set_blink_speed);
- ClassDB::bind_method(D_METHOD("cursor_get_blink_speed"), &TextEdit::cursor_get_blink_speed);
- ClassDB::bind_method(D_METHOD("cursor_set_block_mode", "enable"), &TextEdit::cursor_set_block_mode);
- ClassDB::bind_method(D_METHOD("cursor_is_block_mode"), &TextEdit::cursor_is_block_mode);
-
- ClassDB::bind_method(D_METHOD("set_mid_grapheme_caret_enabled", "enabled"), &TextEdit::set_mid_grapheme_caret_enabled);
- ClassDB::bind_method(D_METHOD("get_mid_grapheme_caret_enabled"), &TextEdit::get_mid_grapheme_caret_enabled);
-
- ClassDB::bind_method(D_METHOD("set_right_click_moves_caret", "enable"), &TextEdit::set_right_click_moves_caret);
- ClassDB::bind_method(D_METHOD("is_right_click_moving_caret"), &TextEdit::is_right_click_moving_caret);
-
- ClassDB::bind_method(D_METHOD("get_selection_mode"), &TextEdit::get_selection_mode);
- ClassDB::bind_method(D_METHOD("set_selection_mode", "mode", "line", "column"), &TextEdit::set_selection_mode, DEFVAL(-1), DEFVAL(-1));
- ClassDB::bind_method(D_METHOD("get_selection_line"), &TextEdit::get_selection_line);
- ClassDB::bind_method(D_METHOD("get_selection_column"), &TextEdit::get_selection_column);
+ ClassDB::bind_method(D_METHOD("set_tab_size", "size"), &TextEdit::set_tab_size);
+ ClassDB::bind_method(D_METHOD("get_tab_size"), &TextEdit::get_tab_size);
- ClassDB::bind_method(D_METHOD("set_readonly", "enable"), &TextEdit::set_readonly);
- ClassDB::bind_method(D_METHOD("is_readonly"), &TextEdit::is_readonly);
+ // User controls
+ ClassDB::bind_method(D_METHOD("set_overtype_mode_enabled", "enabled"), &TextEdit::set_overtype_mode_enabled);
+ ClassDB::bind_method(D_METHOD("is_overtype_mode_enabled"), &TextEdit::is_overtype_mode_enabled);
- ClassDB::bind_method(D_METHOD("set_wrap_enabled", "enable"), &TextEdit::set_wrap_enabled);
- ClassDB::bind_method(D_METHOD("is_wrap_enabled"), &TextEdit::is_wrap_enabled);
ClassDB::bind_method(D_METHOD("set_context_menu_enabled", "enable"), &TextEdit::set_context_menu_enabled);
ClassDB::bind_method(D_METHOD("is_context_menu_enabled"), &TextEdit::is_context_menu_enabled);
+
ClassDB::bind_method(D_METHOD("set_shortcut_keys_enabled", "enable"), &TextEdit::set_shortcut_keys_enabled);
ClassDB::bind_method(D_METHOD("is_shortcut_keys_enabled"), &TextEdit::is_shortcut_keys_enabled);
+
ClassDB::bind_method(D_METHOD("set_virtual_keyboard_enabled", "enable"), &TextEdit::set_virtual_keyboard_enabled);
ClassDB::bind_method(D_METHOD("is_virtual_keyboard_enabled"), &TextEdit::is_virtual_keyboard_enabled);
- ClassDB::bind_method(D_METHOD("set_selecting_enabled", "enable"), &TextEdit::set_selecting_enabled);
- ClassDB::bind_method(D_METHOD("is_selecting_enabled"), &TextEdit::is_selecting_enabled);
- ClassDB::bind_method(D_METHOD("delete_selection"), &TextEdit::delete_selection);
+ // Text manipulation
+ ClassDB::bind_method(D_METHOD("clear"), &TextEdit::clear);
+
+ ClassDB::bind_method(D_METHOD("set_text", "text"), &TextEdit::set_text);
+ ClassDB::bind_method(D_METHOD("get_text"), &TextEdit::get_text);
+ ClassDB::bind_method(D_METHOD("get_line_count"), &TextEdit::get_line_count);
+
+ ClassDB::bind_method(D_METHOD("set_line", "line", "new_text"), &TextEdit::set_line);
+ ClassDB::bind_method(D_METHOD("get_line", "line"), &TextEdit::get_line);
+
+ ClassDB::bind_method(D_METHOD("get_line_width", "line", "wrap_index"), &TextEdit::get_line_width, DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("get_line_height"), &TextEdit::get_line_height);
+
+ ClassDB::bind_method(D_METHOD("get_indent_level", "line"), &TextEdit::get_indent_level);
+ ClassDB::bind_method(D_METHOD("get_first_non_whitespace_column", "line"), &TextEdit::get_first_non_whitespace_column);
+
+ ClassDB::bind_method(D_METHOD("swap_lines", "from_line", "to_line"), &TextEdit::swap_lines);
+
+ ClassDB::bind_method(D_METHOD("insert_line_at", "line", "text"), &TextEdit::insert_line_at);
+ ClassDB::bind_method(D_METHOD("insert_text_at_caret", "text"), &TextEdit::insert_text_at_caret);
+
+ ClassDB::bind_method(D_METHOD("remove_text", "from_line", "from_column", "to_line", "to_column"), &TextEdit::remove_text);
+
+ ClassDB::bind_method(D_METHOD("get_last_unhidden_line"), &TextEdit::get_last_unhidden_line);
+ ClassDB::bind_method(D_METHOD("get_next_visible_line_offset_from", "line", "visible_amount"), &TextEdit::get_next_visible_line_offset_from);
+ ClassDB::bind_method(D_METHOD("get_next_visible_line_index_offset_from", "line", "wrap_index", "visible_amount"), &TextEdit::get_next_visible_line_index_offset_from);
+
+ // Overridable actions
ClassDB::bind_method(D_METHOD("backspace"), &TextEdit::backspace);
- BIND_VMETHOD(MethodInfo("_backspace"));
- BIND_VMETHOD(MethodInfo("_handle_unicode_input", PropertyInfo(Variant::INT, "unicode")))
ClassDB::bind_method(D_METHOD("cut"), &TextEdit::cut);
ClassDB::bind_method(D_METHOD("copy"), &TextEdit::copy);
ClassDB::bind_method(D_METHOD("paste"), &TextEdit::paste);
- ClassDB::bind_method(D_METHOD("select", "from_line", "from_column", "to_line", "to_column"), &TextEdit::select);
- ClassDB::bind_method(D_METHOD("select_all"), &TextEdit::select_all);
- ClassDB::bind_method(D_METHOD("deselect"), &TextEdit::deselect);
- ClassDB::bind_method(D_METHOD("is_dragging_cursor"), &TextEdit::is_dragging_cursor);
+ GDVIRTUAL_BIND(_handle_unicode_input, "unicode_char")
+ GDVIRTUAL_BIND(_backspace)
+ GDVIRTUAL_BIND(_cut)
+ GDVIRTUAL_BIND(_copy)
+ GDVIRTUAL_BIND(_paste)
- ClassDB::bind_method(D_METHOD("is_selection_active"), &TextEdit::is_selection_active);
- ClassDB::bind_method(D_METHOD("get_selection_from_line"), &TextEdit::get_selection_from_line);
- ClassDB::bind_method(D_METHOD("get_selection_from_column"), &TextEdit::get_selection_from_column);
- ClassDB::bind_method(D_METHOD("get_selection_to_line"), &TextEdit::get_selection_to_line);
- ClassDB::bind_method(D_METHOD("get_selection_to_column"), &TextEdit::get_selection_to_column);
- ClassDB::bind_method(D_METHOD("get_selection_text"), &TextEdit::get_selection_text);
- ClassDB::bind_method(D_METHOD("get_word_under_cursor"), &TextEdit::get_word_under_cursor);
- ClassDB::bind_method(D_METHOD("search", "key", "flags", "from_line", "from_column"), &TextEdit::_search_bind);
+ // Context Menu
+ BIND_ENUM_CONSTANT(MENU_CUT);
+ BIND_ENUM_CONSTANT(MENU_COPY);
+ BIND_ENUM_CONSTANT(MENU_PASTE);
+ BIND_ENUM_CONSTANT(MENU_CLEAR);
+ BIND_ENUM_CONSTANT(MENU_SELECT_ALL);
+ BIND_ENUM_CONSTANT(MENU_UNDO);
+ BIND_ENUM_CONSTANT(MENU_REDO);
+ BIND_ENUM_CONSTANT(MENU_DIR_INHERITED);
+ BIND_ENUM_CONSTANT(MENU_DIR_AUTO);
+ BIND_ENUM_CONSTANT(MENU_DIR_LTR);
+ BIND_ENUM_CONSTANT(MENU_DIR_RTL);
+ BIND_ENUM_CONSTANT(MENU_DISPLAY_UCC);
+ BIND_ENUM_CONSTANT(MENU_INSERT_LRM);
+ BIND_ENUM_CONSTANT(MENU_INSERT_RLM);
+ BIND_ENUM_CONSTANT(MENU_INSERT_LRE);
+ BIND_ENUM_CONSTANT(MENU_INSERT_RLE);
+ BIND_ENUM_CONSTANT(MENU_INSERT_LRO);
+ BIND_ENUM_CONSTANT(MENU_INSERT_RLO);
+ BIND_ENUM_CONSTANT(MENU_INSERT_PDF);
+ BIND_ENUM_CONSTANT(MENU_INSERT_ALM);
+ BIND_ENUM_CONSTANT(MENU_INSERT_LRI);
+ BIND_ENUM_CONSTANT(MENU_INSERT_RLI);
+ BIND_ENUM_CONSTANT(MENU_INSERT_FSI);
+ BIND_ENUM_CONSTANT(MENU_INSERT_PDI);
+ BIND_ENUM_CONSTANT(MENU_INSERT_ZWJ);
+ BIND_ENUM_CONSTANT(MENU_INSERT_ZWNJ);
+ BIND_ENUM_CONSTANT(MENU_INSERT_WJ);
+ BIND_ENUM_CONSTANT(MENU_INSERT_SHY);
+ BIND_ENUM_CONSTANT(MENU_MAX);
+
+ /* Versioning */
+ ClassDB::bind_method(D_METHOD("begin_complex_operation"), &TextEdit::begin_complex_operation);
+ ClassDB::bind_method(D_METHOD("end_complex_operation"), &TextEdit::end_complex_operation);
+ ClassDB::bind_method(D_METHOD("has_undo"), &TextEdit::has_undo);
+ ClassDB::bind_method(D_METHOD("has_redo"), &TextEdit::has_redo);
ClassDB::bind_method(D_METHOD("undo"), &TextEdit::undo);
ClassDB::bind_method(D_METHOD("redo"), &TextEdit::redo);
ClassDB::bind_method(D_METHOD("clear_undo_history"), &TextEdit::clear_undo_history);
- ClassDB::bind_method(D_METHOD("set_draw_tabs"), &TextEdit::set_draw_tabs);
- ClassDB::bind_method(D_METHOD("is_drawing_tabs"), &TextEdit::is_drawing_tabs);
- ClassDB::bind_method(D_METHOD("set_draw_spaces"), &TextEdit::set_draw_spaces);
- ClassDB::bind_method(D_METHOD("is_drawing_spaces"), &TextEdit::is_drawing_spaces);
+ ClassDB::bind_method(D_METHOD("tag_saved_version"), &TextEdit::tag_saved_version);
- 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);
+ ClassDB::bind_method(D_METHOD("get_version"), &TextEdit::get_version);
+ ClassDB::bind_method(D_METHOD("get_saved_version"), &TextEdit::get_saved_version);
+
+ /* Search */
+ BIND_ENUM_CONSTANT(SEARCH_MATCH_CASE);
+ BIND_ENUM_CONSTANT(SEARCH_WHOLE_WORDS);
+ BIND_ENUM_CONSTANT(SEARCH_BACKWARDS);
+
+ ClassDB::bind_method(D_METHOD("set_search_text", "search_text"), &TextEdit::set_search_text);
+ ClassDB::bind_method(D_METHOD("set_search_flags", "flags"), &TextEdit::set_search_flags);
+
+ ClassDB::bind_method(D_METHOD("search", "text", "flags", "from_line", "from_colum"), &TextEdit::search);
+
+ /* Tooltip */
+ ClassDB::bind_method(D_METHOD("set_tooltip_request_func", "object", "callback", "data"), &TextEdit::set_tooltip_request_func);
+
+ /* Mouse */
+ ClassDB::bind_method(D_METHOD("get_local_mouse_pos"), &TextEdit::get_local_mouse_pos);
+
+ ClassDB::bind_method(D_METHOD("get_word_at_pos", "position"), &TextEdit::get_word_at_pos);
+
+ ClassDB::bind_method(D_METHOD("get_line_column_at_pos", "position"), &TextEdit::get_line_column_at_pos);
+ ClassDB::bind_method(D_METHOD("get_minimap_line_at_pos", "position"), &TextEdit::get_minimap_line_at_pos);
+
+ ClassDB::bind_method(D_METHOD("is_dragging_cursor"), &TextEdit::is_dragging_cursor);
+
+ /* Caret. */
+ BIND_ENUM_CONSTANT(CARET_TYPE_LINE);
+ BIND_ENUM_CONSTANT(CARET_TYPE_BLOCK);
+
+ // internal.
+ ClassDB::bind_method(D_METHOD("_emit_caret_changed"), &TextEdit::_emit_caret_changed);
+
+ ClassDB::bind_method(D_METHOD("set_caret_type", "type"), &TextEdit::set_caret_type);
+ ClassDB::bind_method(D_METHOD("get_caret_type"), &TextEdit::get_caret_type);
+
+ ClassDB::bind_method(D_METHOD("set_caret_blink_enabled", "enable"), &TextEdit::set_caret_blink_enabled);
+ ClassDB::bind_method(D_METHOD("is_caret_blink_enabled"), &TextEdit::is_caret_blink_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_caret_blink_speed", "blink_speed"), &TextEdit::set_caret_blink_speed);
+ ClassDB::bind_method(D_METHOD("get_caret_blink_speed"), &TextEdit::get_caret_blink_speed);
+
+ ClassDB::bind_method(D_METHOD("set_move_caret_on_right_click_enabled", "enable"), &TextEdit::set_move_caret_on_right_click_enabled);
+ ClassDB::bind_method(D_METHOD("is_move_caret_on_right_click_enabled"), &TextEdit::is_move_caret_on_right_click_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_caret_mid_grapheme_enabled", "enabled"), &TextEdit::set_caret_mid_grapheme_enabled);
+ ClassDB::bind_method(D_METHOD("is_caret_mid_grapheme_enabled"), &TextEdit::is_caret_mid_grapheme_enabled);
+
+ ClassDB::bind_method(D_METHOD("is_caret_visible"), &TextEdit::is_caret_visible);
+ ClassDB::bind_method(D_METHOD("get_caret_draw_pos"), &TextEdit::get_caret_draw_pos);
+
+ ClassDB::bind_method(D_METHOD("set_caret_line", "line", "adjust_viewport", "can_be_hidden", "wrap_index"), &TextEdit::set_caret_line, DEFVAL(true), DEFVAL(true), DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_caret_line"), &TextEdit::get_caret_line);
+
+ ClassDB::bind_method(D_METHOD("set_caret_column", "column", "adjust_viewport"), &TextEdit::set_caret_column, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("get_caret_column"), &TextEdit::get_caret_column);
+
+ ClassDB::bind_method(D_METHOD("get_caret_wrap_index"), &TextEdit::get_caret_wrap_index);
+
+ ClassDB::bind_method(D_METHOD("get_word_under_caret"), &TextEdit::get_word_under_caret);
+
+ /* Selection. */
+ BIND_ENUM_CONSTANT(SELECTION_MODE_NONE);
+ BIND_ENUM_CONSTANT(SELECTION_MODE_SHIFT);
+ BIND_ENUM_CONSTANT(SELECTION_MODE_POINTER);
+ BIND_ENUM_CONSTANT(SELECTION_MODE_WORD);
+ BIND_ENUM_CONSTANT(SELECTION_MODE_LINE);
+
+ ClassDB::bind_method(D_METHOD("set_selecting_enabled", "enable"), &TextEdit::set_selecting_enabled);
+ ClassDB::bind_method(D_METHOD("is_selecting_enabled"), &TextEdit::is_selecting_enabled);
ClassDB::bind_method(D_METHOD("set_override_selected_font_color", "override"), &TextEdit::set_override_selected_font_color);
ClassDB::bind_method(D_METHOD("is_overriding_selected_font_color"), &TextEdit::is_overriding_selected_font_color);
- ClassDB::bind_method(D_METHOD("set_syntax_highlighter", "syntax_highlighter"), &TextEdit::set_syntax_highlighter);
- ClassDB::bind_method(D_METHOD("get_syntax_highlighter"), &TextEdit::get_syntax_highlighter);
+ ClassDB::bind_method(D_METHOD("set_selection_mode", "mode", "line", "column"), &TextEdit::set_selection_mode, DEFVAL(-1), DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("get_selection_mode"), &TextEdit::get_selection_mode);
+
+ ClassDB::bind_method(D_METHOD("select_all"), &TextEdit::select_all);
+ ClassDB::bind_method(D_METHOD("select_word_under_caret"), &TextEdit::select_word_under_caret);
+ ClassDB::bind_method(D_METHOD("select", "from_line", "from_column", "to_line", "to_column"), &TextEdit::select);
+
+ ClassDB::bind_method(D_METHOD("has_selection"), &TextEdit::has_selection);
+
+ ClassDB::bind_method(D_METHOD("get_selected_text"), &TextEdit::get_selected_text);
+
+ ClassDB::bind_method(D_METHOD("get_selection_line"), &TextEdit::get_selection_line);
+ ClassDB::bind_method(D_METHOD("get_selection_column"), &TextEdit::get_selection_column);
+
+ ClassDB::bind_method(D_METHOD("get_selection_from_line"), &TextEdit::get_selection_from_line);
+ ClassDB::bind_method(D_METHOD("get_selection_from_column"), &TextEdit::get_selection_from_column);
+ ClassDB::bind_method(D_METHOD("get_selection_to_line"), &TextEdit::get_selection_to_line);
+ ClassDB::bind_method(D_METHOD("get_selection_to_column"), &TextEdit::get_selection_to_column);
+
+ ClassDB::bind_method(D_METHOD("deselect"), &TextEdit::deselect);
+ ClassDB::bind_method(D_METHOD("delete_selection"), &TextEdit::delete_selection);
+
+ /* line wrapping. */
+ BIND_ENUM_CONSTANT(LINE_WRAPPING_NONE);
+ BIND_ENUM_CONSTANT(LINE_WRAPPING_BOUNDARY);
+
+ // internal.
+ ClassDB::bind_method(D_METHOD("_update_wrap_at_column", "force"), &TextEdit::_update_wrap_at_column, DEFVAL(false));
+
+ ClassDB::bind_method(D_METHOD("set_line_wrapping_mode", "mode"), &TextEdit::set_line_wrapping_mode);
+ ClassDB::bind_method(D_METHOD("get_line_wrapping_mode"), &TextEdit::get_line_wrapping_mode);
+
+ ClassDB::bind_method(D_METHOD("is_line_wrapped", "line"), &TextEdit::is_line_wrapped);
+ ClassDB::bind_method(D_METHOD("get_line_wrap_count", "line"), &TextEdit::get_line_wrap_count);
+ ClassDB::bind_method(D_METHOD("get_line_wrap_index_at_column", "line", "column"), &TextEdit::get_line_wrap_index_at_column);
+
+ ClassDB::bind_method(D_METHOD("get_line_wrapped_text", "line"), &TextEdit::get_line_wrapped_text);
+
+ /* Viewport. */
+ // Scolling.
+ ClassDB::bind_method(D_METHOD("set_smooth_scroll_enable", "enable"), &TextEdit::set_smooth_scroll_enabled);
+ ClassDB::bind_method(D_METHOD("is_smooth_scroll_enabled"), &TextEdit::is_smooth_scroll_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_v_scroll", "value"), &TextEdit::set_v_scroll);
+ ClassDB::bind_method(D_METHOD("get_v_scroll"), &TextEdit::get_v_scroll);
+
+ ClassDB::bind_method(D_METHOD("set_h_scroll", "value"), &TextEdit::set_h_scroll);
+ ClassDB::bind_method(D_METHOD("get_h_scroll"), &TextEdit::get_h_scroll);
+
+ ClassDB::bind_method(D_METHOD("set_scroll_past_end_of_file_enabled", "enable"), &TextEdit::set_scroll_past_end_of_file_enabled);
+ ClassDB::bind_method(D_METHOD("is_scroll_past_end_of_file_enabled"), &TextEdit::is_scroll_past_end_of_file_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_v_scroll_speed", "speed"), &TextEdit::set_v_scroll_speed);
+ ClassDB::bind_method(D_METHOD("get_v_scroll_speed"), &TextEdit::get_v_scroll_speed);
+
+ ClassDB::bind_method(D_METHOD("get_scroll_pos_for_line", "line", "wrap_index"), &TextEdit::get_scroll_pos_for_line, DEFVAL(0));
+
+ // Visible lines.
+ ClassDB::bind_method(D_METHOD("set_line_as_first_visible", "line", "wrap_index"), &TextEdit::set_line_as_first_visible, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_first_visible_line"), &TextEdit::get_first_visible_line);
+
+ ClassDB::bind_method(D_METHOD("set_line_as_center_visible", "line", "wrap_index"), &TextEdit::set_line_as_center_visible, DEFVAL(0));
+
+ ClassDB::bind_method(D_METHOD("set_line_as_last_visible", "line", "wrap_index"), &TextEdit::set_line_as_last_visible, DEFVAL(0));
+ ClassDB::bind_method(D_METHOD("get_last_full_visible_line"), &TextEdit::get_last_full_visible_line);
+ ClassDB::bind_method(D_METHOD("get_last_full_visible_line_wrap_index"), &TextEdit::get_last_full_visible_line_wrap_index);
+
+ ClassDB::bind_method(D_METHOD("get_visible_line_count"), &TextEdit::get_visible_line_count);
+ ClassDB::bind_method(D_METHOD("get_total_visible_line_count"), &TextEdit::get_total_visible_line_count);
+
+ // Auto adjust
+ ClassDB::bind_method(D_METHOD("adjust_viewport_to_caret"), &TextEdit::adjust_viewport_to_caret);
+ ClassDB::bind_method(D_METHOD("center_viewport_to_caret"), &TextEdit::center_viewport_to_caret);
+
+ // Minimap
+ ClassDB::bind_method(D_METHOD("draw_minimap", "draw"), &TextEdit::set_draw_minimap);
+ ClassDB::bind_method(D_METHOD("is_drawing_minimap"), &TextEdit::is_drawing_minimap);
+
+ ClassDB::bind_method(D_METHOD("set_minimap_width", "width"), &TextEdit::set_minimap_width);
+ ClassDB::bind_method(D_METHOD("get_minimap_width"), &TextEdit::get_minimap_width);
+
+ ClassDB::bind_method(D_METHOD("get_minimap_visible_lines"), &TextEdit::get_minimap_visible_lines);
/* Gutters. */
BIND_ENUM_CONSTANT(GUTTER_TYPE_STRING);
@@ -5510,111 +4780,324 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_line_background_color", "line", "color"), &TextEdit::set_line_background_color);
ClassDB::bind_method(D_METHOD("get_line_background_color", "line"), &TextEdit::get_line_background_color);
+ /* Syntax Highlighting. */
+ ClassDB::bind_method(D_METHOD("set_syntax_highlighter", "syntax_highlighter"), &TextEdit::set_syntax_highlighter);
+ ClassDB::bind_method(D_METHOD("get_syntax_highlighter"), &TextEdit::get_syntax_highlighter);
+
+ /* Visual. */
ClassDB::bind_method(D_METHOD("set_highlight_current_line", "enabled"), &TextEdit::set_highlight_current_line);
ClassDB::bind_method(D_METHOD("is_highlight_current_line_enabled"), &TextEdit::is_highlight_current_line_enabled);
- ClassDB::bind_method(D_METHOD("set_smooth_scroll_enable", "enable"), &TextEdit::set_smooth_scroll_enabled);
- ClassDB::bind_method(D_METHOD("is_smooth_scroll_enabled"), &TextEdit::is_smooth_scroll_enabled);
- ClassDB::bind_method(D_METHOD("set_v_scroll_speed", "speed"), &TextEdit::set_v_scroll_speed);
- ClassDB::bind_method(D_METHOD("get_v_scroll_speed"), &TextEdit::get_v_scroll_speed);
- ClassDB::bind_method(D_METHOD("set_v_scroll", "value"), &TextEdit::set_v_scroll);
- ClassDB::bind_method(D_METHOD("get_v_scroll"), &TextEdit::get_v_scroll);
- ClassDB::bind_method(D_METHOD("set_h_scroll", "value"), &TextEdit::set_h_scroll);
- ClassDB::bind_method(D_METHOD("get_h_scroll"), &TextEdit::get_h_scroll);
+ 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);
+
+ ClassDB::bind_method(D_METHOD("get_draw_control_chars"), &TextEdit::get_draw_control_chars);
+ ClassDB::bind_method(D_METHOD("set_draw_control_chars", "enable"), &TextEdit::set_draw_control_chars);
+
+ ClassDB::bind_method(D_METHOD("set_draw_tabs"), &TextEdit::set_draw_tabs);
+ ClassDB::bind_method(D_METHOD("is_drawing_tabs"), &TextEdit::is_drawing_tabs);
+
+ ClassDB::bind_method(D_METHOD("set_draw_spaces"), &TextEdit::set_draw_spaces);
+ ClassDB::bind_method(D_METHOD("is_drawing_spaces"), &TextEdit::is_drawing_spaces);
- ClassDB::bind_method(D_METHOD("menu_option", "option"), &TextEdit::menu_option);
ClassDB::bind_method(D_METHOD("get_menu"), &TextEdit::get_menu);
ClassDB::bind_method(D_METHOD("is_menu_visible"), &TextEdit::is_menu_visible);
+ ClassDB::bind_method(D_METHOD("menu_option", "option"), &TextEdit::menu_option);
- ClassDB::bind_method(D_METHOD("draw_minimap", "draw"), &TextEdit::set_draw_minimap);
- ClassDB::bind_method(D_METHOD("is_drawing_minimap"), &TextEdit::is_drawing_minimap);
- ClassDB::bind_method(D_METHOD("set_minimap_width", "width"), &TextEdit::set_minimap_width);
- ClassDB::bind_method(D_METHOD("get_minimap_width"), &TextEdit::get_minimap_width);
-
+ /* Inspector */
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text");
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "language"), "set_language", "get_language");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_control_chars"), "set_draw_control_chars", "get_draw_control_chars");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "readonly"), "set_readonly", "is_readonly");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_current_line"), "set_highlight_current_line", "is_highlight_current_line_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_tabs"), "set_draw_tabs", "is_drawing_tabs");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_spaces"), "set_draw_spaces", "is_drawing_spaces");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_all_occurrences"), "set_highlight_all_occurrences", "is_highlight_all_occurrences_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color");
+
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "context_menu_enabled"), "set_context_menu_enabled", "is_context_menu_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shortcut_keys_enabled"), "set_shortcut_keys_enabled", "is_shortcut_keys_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "virtual_keyboard_enabled"), "set_virtual_keyboard_enabled", "is_virtual_keyboard_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selecting_enabled"), "set_selecting_enabled", "is_selecting_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_scrolling"), "set_smooth_scroll_enable", "is_smooth_scroll_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "v_scroll_speed"), "set_v_scroll_speed", "get_v_scroll_speed");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "wrap_enabled"), "set_wrap_enabled", "is_wrap_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scroll_vertical"), "set_v_scroll", "get_v_scroll");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_horizontal"), "set_h_scroll", "get_h_scroll");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "virtual_keyboard_enabled"), "set_virtual_keyboard_enabled", "is_virtual_keyboard_enabled");
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "wrap_mode", PROPERTY_HINT_ENUM, "None,Boundary"), "set_line_wrapping_mode", "get_line_wrapping_mode");
+
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_all_occurrences"), "set_highlight_all_occurrences", "is_highlight_all_occurrences_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_current_line"), "set_highlight_current_line", "is_highlight_current_line_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_control_chars"), "set_draw_control_chars", "get_draw_control_chars");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_tabs"), "set_draw_tabs", "is_drawing_tabs");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_spaces"), "set_draw_spaces", "is_drawing_spaces");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "syntax_highlighter", PROPERTY_HINT_RESOURCE_TYPE, "SyntaxHighlighter", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE), "set_syntax_highlighter", "get_syntax_highlighter");
+ ADD_GROUP("Scroll", "scroll_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_smooth"), "set_smooth_scroll_enable", "is_smooth_scroll_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scroll_v_scroll_speed"), "set_v_scroll_speed", "get_v_scroll_speed");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_past_end_of_file"), "set_scroll_past_end_of_file_enabled", "is_scroll_past_end_of_file_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scroll_vertical"), "set_v_scroll", "get_v_scroll");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_horizontal"), "set_h_scroll", "get_h_scroll");
+
ADD_GROUP("Minimap", "minimap_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "minimap_draw"), "draw_minimap", "is_drawing_minimap");
ADD_PROPERTY(PropertyInfo(Variant::INT, "minimap_width"), "set_minimap_width", "get_minimap_width");
ADD_GROUP("Caret", "caret_");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_block_mode"), "cursor_set_block_mode", "cursor_is_block_mode");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "cursor_set_blink_enabled", "cursor_get_blink_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "cursor_set_blink_speed", "cursor_get_blink_speed");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_moving_by_right_click"), "set_right_click_moves_caret", "is_right_click_moving_caret");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_mid_grapheme"), "set_mid_grapheme_caret_enabled", "get_mid_grapheme_caret_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "caret_type", PROPERTY_HINT_ENUM, "Line,Block"), "set_caret_type", "get_caret_type");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "set_caret_blink_enabled", "is_caret_blink_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "set_caret_blink_speed", "get_caret_blink_speed");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_move_on_right_click"), "set_move_caret_on_right_click_enabled", "is_move_caret_on_right_click_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_mid_grapheme"), "set_caret_mid_grapheme_enabled", "is_caret_mid_grapheme_enabled");
ADD_GROUP("Structured Text", "structured_text_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "structured_text_bidi_override", PROPERTY_HINT_ENUM, "Default,URI,File,Email,List,None,Custom"), "set_structured_text_bidi_override", "get_structured_text_bidi_override");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "structured_text_bidi_override_options"), "set_structured_text_bidi_override_options", "get_structured_text_bidi_override_options");
- ADD_SIGNAL(MethodInfo("cursor_changed"));
+ /* Signals */
+ /* Core. */
+ ADD_SIGNAL(MethodInfo("text_set"));
ADD_SIGNAL(MethodInfo("text_changed"));
ADD_SIGNAL(MethodInfo("lines_edited_from", PropertyInfo(Variant::INT, "from_line"), PropertyInfo(Variant::INT, "to_line")));
+
+ /* Caret. */
+ ADD_SIGNAL(MethodInfo("caret_changed"));
+
+ /* Gutters. */
ADD_SIGNAL(MethodInfo("gutter_clicked", PropertyInfo(Variant::INT, "line"), PropertyInfo(Variant::INT, "gutter")));
ADD_SIGNAL(MethodInfo("gutter_added"));
ADD_SIGNAL(MethodInfo("gutter_removed"));
- BIND_ENUM_CONSTANT(MENU_CUT);
- BIND_ENUM_CONSTANT(MENU_COPY);
- BIND_ENUM_CONSTANT(MENU_PASTE);
- BIND_ENUM_CONSTANT(MENU_CLEAR);
- BIND_ENUM_CONSTANT(MENU_SELECT_ALL);
- BIND_ENUM_CONSTANT(MENU_UNDO);
- BIND_ENUM_CONSTANT(MENU_REDO);
- BIND_ENUM_CONSTANT(MENU_DIR_INHERITED);
- BIND_ENUM_CONSTANT(MENU_DIR_AUTO);
- BIND_ENUM_CONSTANT(MENU_DIR_LTR);
- BIND_ENUM_CONSTANT(MENU_DIR_RTL);
- BIND_ENUM_CONSTANT(MENU_DISPLAY_UCC);
- BIND_ENUM_CONSTANT(MENU_INSERT_LRM);
- BIND_ENUM_CONSTANT(MENU_INSERT_RLM);
- BIND_ENUM_CONSTANT(MENU_INSERT_LRE);
- BIND_ENUM_CONSTANT(MENU_INSERT_RLE);
- BIND_ENUM_CONSTANT(MENU_INSERT_LRO);
- BIND_ENUM_CONSTANT(MENU_INSERT_RLO);
- BIND_ENUM_CONSTANT(MENU_INSERT_PDF);
- BIND_ENUM_CONSTANT(MENU_INSERT_ALM);
- BIND_ENUM_CONSTANT(MENU_INSERT_LRI);
- BIND_ENUM_CONSTANT(MENU_INSERT_RLI);
- BIND_ENUM_CONSTANT(MENU_INSERT_FSI);
- BIND_ENUM_CONSTANT(MENU_INSERT_PDI);
- BIND_ENUM_CONSTANT(MENU_INSERT_ZWJ);
- BIND_ENUM_CONSTANT(MENU_INSERT_ZWNJ);
- BIND_ENUM_CONSTANT(MENU_INSERT_WJ);
- BIND_ENUM_CONSTANT(MENU_INSERT_SHY);
- BIND_ENUM_CONSTANT(MENU_MAX);
-
+ /* Settings. */
GLOBAL_DEF("gui/timers/text_edit_idle_detect_sec", 3);
ProjectSettings::get_singleton()->set_custom_property_info("gui/timers/text_edit_idle_detect_sec", PropertyInfo(Variant::FLOAT, "gui/timers/text_edit_idle_detect_sec", PROPERTY_HINT_RANGE, "0,10,0.01,or_greater")); // No negative numbers.
GLOBAL_DEF("gui/common/text_edit_undo_stack_max_size", 1024);
ProjectSettings::get_singleton()->set_custom_property_info("gui/common/text_edit_undo_stack_max_size", PropertyInfo(Variant::INT, "gui/common/text_edit_undo_stack_max_size", PROPERTY_HINT_RANGE, "0,10000,1,or_greater")); // No negative numbers.
}
-void TextEdit::_ensure_menu() {
+bool TextEdit::_set(const StringName &p_name, const Variant &p_value) {
+ String str = p_name;
+ if (str.begins_with("opentype_features/")) {
+ String name = str.get_slicec('/', 1);
+ int32_t tag = TS->name_to_tag(name);
+ double value = p_value;
+ if (value == -1) {
+ if (opentype_features.has(tag)) {
+ opentype_features.erase(tag);
+ text.set_font_features(opentype_features);
+ text.invalidate_all();
+ update();
+ }
+ } else {
+ if ((double)opentype_features[tag] != value) {
+ opentype_features[tag] = value;
+ text.set_font_features(opentype_features);
+ text.invalidate_all();
+ update();
+ }
+ }
+ notify_property_list_changed();
+ return true;
+ }
+
+ return false;
+}
+
+bool TextEdit::_get(const StringName &p_name, Variant &r_ret) const {
+ String str = p_name;
+ if (str.begins_with("opentype_features/")) {
+ String name = str.get_slicec('/', 1);
+ int32_t tag = TS->name_to_tag(name);
+ if (opentype_features.has(tag)) {
+ r_ret = opentype_features[tag];
+ return true;
+ } else {
+ r_ret = -1;
+ return true;
+ }
+ }
+ return false;
+}
+
+void TextEdit::_get_property_list(List<PropertyInfo> *p_list) const {
+ for (const Variant *ftr = opentype_features.next(nullptr); ftr != nullptr; ftr = opentype_features.next(ftr)) {
+ String name = TS->tag_to_name(*ftr);
+ p_list->push_back(PropertyInfo(Variant::FLOAT, "opentype_features/" + name));
+ }
+ p_list->push_back(PropertyInfo(Variant::NIL, "opentype_features/_new", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
+}
+
+/* Internal API for CodeEdit. */
+// Line hiding.
+void TextEdit::_set_hiding_enabled(bool p_enabled) {
+ if (!p_enabled) {
+ _unhide_all_lines();
+ }
+ hiding_enabled = p_enabled;
+ update();
+}
+
+bool TextEdit::_is_hiding_enabled() const {
+ return hiding_enabled;
+}
+
+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::_unhide_all_lines() {
+ for (int i = 0; i < text.size(); i++) {
+ text.set_hidden(i, false);
+ }
+ _update_scrollbars();
+ update();
+}
+
+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();
+}
+
+// Symbol lookup.
+void TextEdit::_set_symbol_lookup_word(const String &p_symbol) {
+ lookup_symbol_word = p_symbol;
+ update();
+}
+
+/* Text manipulation */
+
+// Overridable actions
+void TextEdit::_handle_unicode_input_internal(const uint32_t p_unicode) {
+ if (!editable) {
+ return;
+ }
+
+ bool had_selection = has_selection();
+ if (had_selection) {
+ begin_complex_operation();
+ delete_selection();
+ }
+
+ /* Remove the old character if in insert mode and no selection. */
+ if (overtype_mode && !had_selection) {
+ begin_complex_operation();
+
+ /* Make sure we don't try and remove empty space. */
+ int cl = get_caret_line();
+ int cc = get_caret_column();
+ if (cc < get_line(cl).length()) {
+ _remove_text(cl, cc, cl, cc + 1);
+ }
+ }
+
+ const char32_t chr[2] = { (char32_t)p_unicode, 0 };
+ insert_text_at_caret(chr);
+
+ if ((overtype_mode && !had_selection) || (had_selection)) {
+ end_complex_operation();
+ }
+}
+
+void TextEdit::_backspace_internal() {
+ if (!editable) {
+ return;
+ }
+
+ if (has_selection()) {
+ delete_selection();
+ return;
+ }
+
+ int cc = get_caret_column();
+ int cl = get_caret_line();
+
+ if (cc == 0 && cl == 0) {
+ return;
+ }
+
+ int prev_line = cc ? cl : cl - 1;
+ int prev_column = cc ? (cc - 1) : (text[cl - 1].length());
+
+ merge_gutters(prev_line, cl);
+
+ if (_is_line_hidden(cl)) {
+ _set_line_as_hidden(prev_line, true);
+ }
+ _remove_text(prev_line, prev_column, cl, cc);
+
+ set_caret_line(prev_line, false, true);
+ set_caret_column(prev_column);
+}
+
+void TextEdit::_cut_internal() {
+ if (!editable) {
+ return;
+ }
+
+ if (has_selection()) {
+ DisplayServer::get_singleton()->clipboard_set(get_selected_text());
+ delete_selection();
+ cut_copy_line = "";
+ return;
+ }
+
+ int cl = get_caret_line();
+
+ String clipboard = text[cl];
+ DisplayServer::get_singleton()->clipboard_set(clipboard);
+ set_caret_line(cl);
+ set_caret_column(0);
+
+ if (cl == 0 && get_line_count() > 1) {
+ _remove_text(cl, 0, cl + 1, 0);
+ } else {
+ _remove_text(cl, 0, cl, text[cl].length());
+ backspace();
+ set_caret_line(get_caret_line() + 1);
+ }
+
+ cut_copy_line = clipboard;
+}
+
+void TextEdit::_copy_internal() {
+ if (has_selection()) {
+ DisplayServer::get_singleton()->clipboard_set(get_selected_text());
+ cut_copy_line = "";
+ return;
+ }
+
+ int cl = get_caret_line();
+ if (text[cl].length() != 0) {
+ String clipboard = _base_get_text(cl, 0, cl, text[cl].length());
+ DisplayServer::get_singleton()->clipboard_set(clipboard);
+ cut_copy_line = clipboard;
+ }
+}
+
+void TextEdit::_paste_internal() {
+ if (!editable) {
+ return;
+ }
+
+ String clipboard = DisplayServer::get_singleton()->clipboard_get();
+
+ begin_complex_operation();
+ if (has_selection()) {
+ delete_selection();
+ } else if (!cut_copy_line.is_empty() && cut_copy_line == clipboard) {
+ set_caret_column(0);
+ String ins = "\n";
+ clipboard += ins;
+ }
+
+ insert_text_at_caret(clipboard);
+ end_complex_operation();
+}
+
+/* Text. */
+// Context menu.
+void TextEdit::_generate_context_menu() {
if (!menu) {
menu = memnew(PopupMenu);
- add_child(menu);
+ add_child(menu, false, INTERNAL_MODE_FRONT);
menu_dir = memnew(PopupMenu);
menu_dir->set_name("DirMenu");
@@ -5622,7 +5105,7 @@ void TextEdit::_ensure_menu() {
menu_dir->add_radio_check_item(RTR("Auto-detect direction"), MENU_DIR_AUTO);
menu_dir->add_radio_check_item(RTR("Left-to-right"), MENU_DIR_LTR);
menu_dir->add_radio_check_item(RTR("Right-to-left"), MENU_DIR_RTL);
- menu->add_child(menu_dir);
+ menu->add_child(menu_dir, false, INTERNAL_MODE_FRONT);
menu_ctl = memnew(PopupMenu);
menu_ctl->set_name("CTLMenu");
@@ -5644,7 +5127,7 @@ void TextEdit::_ensure_menu() {
menu_ctl->add_item(RTR("Zero width non-joiner (ZWNJ)"), MENU_INSERT_ZWNJ);
menu_ctl->add_item(RTR("Word joiner (WJ)"), MENU_INSERT_WJ);
menu_ctl->add_item(RTR("Soft hyphen (SHY)"), MENU_INSERT_SHY);
- menu->add_child(menu_ctl);
+ menu->add_child(menu_ctl, false, INTERNAL_MODE_FRONT);
menu->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
menu_dir->connect("id_pressed", callable_mp(this, &TextEdit::menu_option));
@@ -5653,18 +5136,18 @@ void TextEdit::_ensure_menu() {
// Reorganize context menu.
menu->clear();
- if (!readonly) {
+ if (editable) {
menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : 0);
}
menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : 0);
- if (!readonly) {
+ if (editable) {
menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : 0);
}
menu->add_separator();
if (is_selecting_enabled()) {
menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : 0);
}
- if (!readonly) {
+ if (editable) {
menu->add_item(RTR("Clear"), MENU_CLEAR);
menu->add_separator();
menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : 0);
@@ -5675,13 +5158,898 @@ void TextEdit::_ensure_menu() {
menu->add_separator();
menu->add_check_item(RTR("Display control characters"), MENU_DISPLAY_UCC);
menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars);
- if (!readonly) {
+ if (editable) {
menu->add_submenu_item(RTR("Insert control character"), "CTLMenu");
}
menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), text_direction == TEXT_DIRECTION_INHERITED);
menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_AUTO), text_direction == TEXT_DIRECTION_AUTO);
menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR);
menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_RTL), text_direction == TEXT_DIRECTION_RTL);
+
+ if (editable) {
+ menu->set_item_disabled(menu->get_item_index(MENU_UNDO), !has_undo());
+ menu->set_item_disabled(menu->get_item_index(MENU_REDO), !has_redo());
+ }
+}
+
+int TextEdit::_get_menu_action_accelerator(const String &p_action) {
+ const List<Ref<InputEvent>> *events = InputMap::get_singleton()->action_get_events(p_action);
+ if (!events) {
+ return 0;
+ }
+
+ // Use first event in the list for the accelerator.
+ const List<Ref<InputEvent>>::Element *first_event = events->front();
+ if (!first_event) {
+ return 0;
+ }
+
+ const Ref<InputEventKey> event = first_event->get();
+ if (event.is_null()) {
+ return 0;
+ }
+
+ // Use physical keycode if non-zero
+ if (event->get_physical_keycode() != 0) {
+ return event->get_physical_keycode_with_modifiers();
+ } else {
+ return event->get_keycode_with_modifiers();
+ }
+}
+
+/* Versioning */
+void TextEdit::_push_current_op() {
+ if (current_op.type == TextOperation::TYPE_NONE) {
+ return; // Nothing to do.
+ }
+
+ if (next_operation_is_complex) {
+ current_op.chain_forward = true;
+ next_operation_is_complex = false;
+ }
+
+ undo_stack.push_back(current_op);
+ current_op.type = TextOperation::TYPE_NONE;
+ current_op.text = "";
+ current_op.chain_forward = false;
+
+ if (undo_stack.size() > undo_stack_max_size) {
+ undo_stack.pop_front();
+ }
+}
+
+void TextEdit::_do_text_op(const TextOperation &p_op, bool p_reverse) {
+ ERR_FAIL_COND(p_op.type == TextOperation::TYPE_NONE);
+
+ bool insert = p_op.type == TextOperation::TYPE_INSERT;
+ if (p_reverse) {
+ insert = !insert;
+ }
+
+ if (insert) {
+ int check_line;
+ int check_column;
+ _base_insert_text(p_op.from_line, p_op.from_column, p_op.text, check_line, check_column);
+ ERR_FAIL_COND(check_line != p_op.to_line); // BUG.
+ ERR_FAIL_COND(check_column != p_op.to_column); // BUG.
+ } else {
+ _base_remove_text(p_op.from_line, p_op.from_column, p_op.to_line, p_op.to_column);
+ }
+}
+
+void TextEdit::_clear_redo() {
+ if (undo_stack_pos == nullptr) {
+ return; // Nothing to clear.
+ }
+
+ _push_current_op();
+
+ while (undo_stack_pos) {
+ List<TextOperation>::Element *elem = undo_stack_pos;
+ undo_stack_pos = undo_stack_pos->next();
+ undo_stack.erase(elem);
+ }
+}
+
+/* Search */
+int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column) const {
+ int col = -1;
+
+ if (p_key.length() > 0 && p_search.length() > 0) {
+ if (p_from_column < 0 || p_from_column > p_search.length()) {
+ p_from_column = 0;
+ }
+
+ while (col == -1 && p_from_column <= p_search.length()) {
+ if (p_search_flags & SEARCH_MATCH_CASE) {
+ col = p_search.find(p_key, p_from_column);
+ } else {
+ col = p_search.findn(p_key, p_from_column);
+ }
+
+ // Whole words only.
+ if (col != -1 && p_search_flags & SEARCH_WHOLE_WORDS) {
+ p_from_column = col;
+
+ if (col > 0 && _is_text_char(p_search[col - 1])) {
+ col = -1;
+ } else if ((col + p_key.length()) < p_search.length() && _is_text_char(p_search[col + p_key.length()])) {
+ col = -1;
+ }
+ }
+
+ p_from_column += 1;
+ }
+ }
+ return col;
+}
+
+/* Mouse */
+int TextEdit::_get_char_pos_for_line(int p_px, int p_line, int p_wrap_index) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), 0);
+ p_wrap_index = MIN(p_wrap_index, text.get_line_data(p_line)->get_line_count() - 1);
+
+ RID text_rid = text.get_line_data(p_line)->get_line_rid(p_wrap_index);
+ if (is_layout_rtl()) {
+ p_px = TS->shaped_text_get_size(text_rid).x - p_px;
+ }
+ return TS->shaped_text_hit_test_position(text_rid, p_px);
+}
+
+/* Caret */
+void TextEdit::_emit_caret_changed() {
+ emit_signal(SNAME("caret_changed"));
+ caret_pos_dirty = false;
+}
+
+void TextEdit::_reset_caret_blink_timer() {
+ if (!caret_blink_enabled) {
+ return;
+ }
+
+ draw_caret = true;
+ if (has_focus()) {
+ caret_blink_timer->stop();
+ caret_blink_timer->start();
+ update();
+ }
+}
+
+void TextEdit::_toggle_draw_caret() {
+ draw_caret = !draw_caret;
+ if (is_visible_in_tree() && has_focus() && window_has_focus) {
+ update();
+ }
+}
+
+int TextEdit::_get_column_x_offset_for_line(int p_char, int p_line) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), 0);
+
+ int row = 0;
+ Vector<Vector2i> rows2 = text.get_line_wrap_ranges(p_line);
+ for (int i = 0; i < rows2.size(); i++) {
+ if ((p_char >= rows2[i].x) && (p_char < rows2[i].y)) {
+ row = i;
+ break;
+ }
+ }
+
+ Rect2 l_caret, t_caret;
+ TextServer::Direction l_dir, t_dir;
+ RID text_rid = text.get_line_data(p_line)->get_line_rid(row);
+ TS->shaped_text_get_carets(text_rid, caret.column, l_caret, l_dir, t_caret, t_dir);
+ if ((l_caret != Rect2() && (l_dir == TextServer::DIRECTION_AUTO || l_dir == (TextServer::Direction)input_direction)) || (t_caret == Rect2())) {
+ return l_caret.position.x;
+ } else {
+ return t_caret.position.x;
+ }
+}
+
+/* Selection */
+void TextEdit::_click_selection_held() {
+ // Warning: is_mouse_button_pressed(MOUSE_BUTTON_LEFT) returns false for double+ clicks, so this doesn't work for MODE_WORD
+ // and MODE_LINE. However, moving the mouse triggers _gui_input, which calls these functions too, so that's not a huge problem.
+ // I'm unsure if there's an actual fix that doesn't have a ton of side effects.
+ if (Input::get_singleton()->is_mouse_button_pressed(MOUSE_BUTTON_LEFT) && selection.selecting_mode != SelectionMode::SELECTION_MODE_NONE) {
+ switch (selection.selecting_mode) {
+ case SelectionMode::SELECTION_MODE_POINTER: {
+ _update_selection_mode_pointer();
+ } break;
+ case SelectionMode::SELECTION_MODE_WORD: {
+ _update_selection_mode_word();
+ } break;
+ case SelectionMode::SELECTION_MODE_LINE: {
+ _update_selection_mode_line();
+ } break;
+ default: {
+ break;
+ }
+ }
+ } else {
+ click_select_held->stop();
+ }
+}
+
+void TextEdit::_update_selection_mode_pointer() {
+ dragging_selection = true;
+ Point2 mp = get_local_mouse_pos();
+
+ Point2i pos = get_line_column_at_pos(Point2i(mp.x, mp.y));
+ int line = pos.y;
+ int col = pos.x;
+
+ select(selection.selecting_line, selection.selecting_column, line, col);
+
+ set_caret_line(line, false);
+ set_caret_column(col);
+ update();
+
+ click_select_held->start();
+}
+
+void TextEdit::_update_selection_mode_word() {
+ dragging_selection = true;
+ Point2 mp = get_local_mouse_pos();
+
+ Point2i pos = get_line_column_at_pos(Point2i(mp.x, mp.y));
+ int line = pos.y;
+ int col = pos.x;
+
+ int caret_pos = CLAMP(col, 0, text[line].length());
+ int beg = caret_pos;
+ int end = beg;
+ Vector<Vector2i> words = TS->shaped_text_get_word_breaks(text.get_line_data(line)->get_rid());
+ for (int i = 0; i < words.size(); i++) {
+ if (words[i].x < caret_pos && words[i].y > caret_pos) {
+ beg = words[i].x;
+ end = words[i].y;
+ break;
+ }
+ }
+
+ /* Initial selection. */
+ if (!selection.active) {
+ select(line, beg, line, end);
+ selection.selecting_column = beg;
+ selection.selected_word_beg = beg;
+ selection.selected_word_end = end;
+ selection.selected_word_origin = beg;
+ set_caret_line(selection.to_line, false);
+ set_caret_column(selection.to_column);
+ } else {
+ if ((col <= selection.selected_word_origin && line == selection.selecting_line) || line < selection.selecting_line) {
+ selection.selecting_column = selection.selected_word_end;
+ select(line, beg, selection.selecting_line, selection.selected_word_end);
+ set_caret_line(selection.from_line, false);
+ set_caret_column(selection.from_column);
+ } else {
+ selection.selecting_column = selection.selected_word_beg;
+ select(selection.selecting_line, selection.selected_word_beg, line, end);
+ set_caret_line(selection.to_line, false);
+ set_caret_column(selection.to_column);
+ }
+ }
+
+ update();
+
+ click_select_held->start();
+}
+
+void TextEdit::_update_selection_mode_line() {
+ dragging_selection = true;
+ Point2 mp = get_local_mouse_pos();
+
+ Point2i pos = get_line_column_at_pos(Point2i(mp.x, mp.y));
+ int line = pos.y;
+ int col = pos.x;
+
+ col = 0;
+ if (line < selection.selecting_line) {
+ /* Caret is above us. */
+ set_caret_line(line - 1, false);
+ selection.selecting_column = text[selection.selecting_line].length();
+ } else {
+ /* Caret is below us. */
+ set_caret_line(line + 1, false);
+ selection.selecting_column = 0;
+ col = text[line].length();
+ }
+ set_caret_column(0);
+
+ select(selection.selecting_line, selection.selecting_column, line, col);
+ update();
+
+ click_select_held->start();
+}
+
+void TextEdit::_pre_shift_selection() {
+ if (!selection.active || selection.selecting_mode == SelectionMode::SELECTION_MODE_NONE) {
+ selection.selecting_line = caret.line;
+ selection.selecting_column = caret.column;
+ selection.active = true;
+ }
+
+ selection.selecting_mode = SelectionMode::SELECTION_MODE_SHIFT;
+}
+
+void TextEdit::_post_shift_selection() {
+ if (selection.active && selection.selecting_mode == SelectionMode::SELECTION_MODE_SHIFT) {
+ select(selection.selecting_line, selection.selecting_column, caret.line, caret.column);
+ update();
+ }
+
+ selection.selecting_text = true;
+}
+
+/* Line Wrapping */
+void TextEdit::_update_wrap_at_column(bool p_force) {
+ int new_wrap_at = get_size().width - style_normal->get_minimum_size().width - gutters_width - gutter_padding;
+ if (draw_minimap) {
+ new_wrap_at -= minimap_width;
+ }
+ if (v_scroll->is_visible_in_tree()) {
+ new_wrap_at -= v_scroll->get_combined_minimum_size().width;
+ }
+ /* Give it a little more space. */
+ new_wrap_at -= wrap_right_offset;
+
+ if ((wrap_at_column != new_wrap_at) || p_force) {
+ wrap_at_column = new_wrap_at;
+ if (line_wrapping_mode) {
+ text.set_width(wrap_at_column);
+ } else {
+ text.set_width(-1);
+ }
+ text.invalidate_all_lines();
+ }
+
+ _update_caret_wrap_offset();
+}
+
+void TextEdit::_update_caret_wrap_offset() {
+ int first_vis_line = get_first_visible_line();
+ if (is_line_wrapped(first_vis_line)) {
+ caret.wrap_ofs = MIN(caret.wrap_ofs, get_line_wrap_count(first_vis_line));
+ } else {
+ caret.wrap_ofs = 0;
+ }
+ set_line_as_first_visible(caret.line_ofs, caret.wrap_ofs);
+}
+
+/* Viewport. */
+void TextEdit::_update_scrollbars() {
+ Size2 size = get_size();
+ Size2 hmin = h_scroll->get_combined_minimum_size();
+ Size2 vmin = v_scroll->get_combined_minimum_size();
+
+ v_scroll->set_begin(Point2(size.width - vmin.width, style_normal->get_margin(SIDE_TOP)));
+ v_scroll->set_end(Point2(size.width, size.height - style_normal->get_margin(SIDE_TOP) - style_normal->get_margin(SIDE_BOTTOM)));
+
+ h_scroll->set_begin(Point2(0, size.height - hmin.height));
+ h_scroll->set_end(Point2(size.width - vmin.width, size.height));
+
+ int visible_rows = get_visible_line_count();
+ int total_rows = get_total_visible_line_count();
+ if (scroll_past_end_of_file_enabled) {
+ total_rows += visible_rows - 1;
+ }
+
+ int visible_width = size.width - style_normal->get_minimum_size().width;
+ int total_width = text.get_max_width() + vmin.x + gutters_width + gutter_padding;
+
+ if (draw_minimap) {
+ total_width += minimap_width;
+ }
+
+ updating_scrolls = true;
+
+ if (total_rows > visible_rows) {
+ v_scroll->show();
+ v_scroll->set_max(total_rows + _get_visible_lines_offset());
+ v_scroll->set_page(visible_rows + _get_visible_lines_offset());
+ if (smooth_scroll_enabled) {
+ v_scroll->set_step(0.25);
+ } else {
+ v_scroll->set_step(1);
+ }
+ set_v_scroll(get_v_scroll());
+
+ } else {
+ caret.line_ofs = 0;
+ caret.wrap_ofs = 0;
+ v_scroll->set_value(0);
+ v_scroll->hide();
+ }
+
+ if (total_width > visible_width && get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE) {
+ h_scroll->show();
+ h_scroll->set_max(total_width);
+ h_scroll->set_page(visible_width);
+ if (caret.x_ofs > (total_width - visible_width)) {
+ caret.x_ofs = (total_width - visible_width);
+ }
+ if (fabs(h_scroll->get_value() - (double)caret.x_ofs) >= 1) {
+ h_scroll->set_value(caret.x_ofs);
+ }
+
+ } else {
+ caret.x_ofs = 0;
+ h_scroll->set_value(0);
+ h_scroll->hide();
+ }
+
+ updating_scrolls = false;
+}
+
+int TextEdit::_get_control_height() const {
+ int control_height = get_size().height;
+ control_height -= style_normal->get_minimum_size().height;
+ if (h_scroll->is_visible_in_tree()) {
+ control_height -= h_scroll->get_size().height;
+ }
+ return control_height;
+}
+
+void TextEdit::_v_scroll_input() {
+ scrolling = false;
+ minimap_clicked = false;
+}
+
+void TextEdit::_scroll_moved(double p_to_val) {
+ if (updating_scrolls) {
+ return;
+ }
+
+ if (h_scroll->is_visible_in_tree()) {
+ caret.x_ofs = h_scroll->get_value();
+ }
+ if (v_scroll->is_visible_in_tree()) {
+ // Set line ofs and wrap ofs.
+ int v_scroll_i = floor(get_v_scroll());
+ int sc = 0;
+ int n_line;
+ for (n_line = 0; n_line < text.size(); n_line++) {
+ if (!_is_line_hidden(n_line)) {
+ sc++;
+ sc += get_line_wrap_count(n_line);
+ if (sc > v_scroll_i) {
+ break;
+ }
+ }
+ }
+ n_line = MIN(n_line, text.size() - 1);
+ int line_wrap_amount = get_line_wrap_count(n_line);
+ int wi = line_wrap_amount - (sc - v_scroll_i - 1);
+ wi = CLAMP(wi, 0, line_wrap_amount);
+
+ caret.line_ofs = n_line;
+ caret.wrap_ofs = wi;
+ }
+ update();
+}
+
+double TextEdit::_get_visible_lines_offset() const {
+ double total = _get_control_height();
+ total /= (double)get_line_height();
+ total = total - floor(total);
+ total = -CLAMP(total, 0.001, 1) + 1;
+ return total;
+}
+
+double TextEdit::_get_v_scroll_offset() const {
+ double val = get_v_scroll() - floor(get_v_scroll());
+ return CLAMP(val, 0, 1);
+}
+
+void TextEdit::_scroll_up(real_t p_delta) {
+ if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(-p_delta)) {
+ scrolling = false;
+ minimap_clicked = false;
+ }
+
+ if (scrolling) {
+ target_v_scroll = (target_v_scroll - p_delta);
+ } else {
+ target_v_scroll = (get_v_scroll() - p_delta);
+ }
+
+ if (smooth_scroll_enabled) {
+ if (target_v_scroll <= 0) {
+ target_v_scroll = 0;
+ }
+ if (Math::abs(target_v_scroll - v_scroll->get_value()) < 1.0) {
+ v_scroll->set_value(target_v_scroll);
+ } else {
+ scrolling = true;
+ set_physics_process_internal(true);
+ }
+ } else {
+ set_v_scroll(target_v_scroll);
+ }
+}
+
+void TextEdit::_scroll_down(real_t p_delta) {
+ if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(p_delta)) {
+ scrolling = false;
+ minimap_clicked = false;
+ }
+
+ if (scrolling) {
+ target_v_scroll = (target_v_scroll + p_delta);
+ } else {
+ target_v_scroll = (get_v_scroll() + p_delta);
+ }
+
+ if (smooth_scroll_enabled) {
+ int max_v_scroll = round(v_scroll->get_max() - v_scroll->get_page());
+ if (target_v_scroll > max_v_scroll) {
+ target_v_scroll = max_v_scroll;
+ }
+ if (Math::abs(target_v_scroll - v_scroll->get_value()) < 1.0) {
+ v_scroll->set_value(target_v_scroll);
+ } else {
+ scrolling = true;
+ set_physics_process_internal(true);
+ }
+ } else {
+ set_v_scroll(target_v_scroll);
+ }
+}
+
+void TextEdit::_scroll_lines_up() {
+ scrolling = false;
+ minimap_clicked = false;
+
+ // Adjust the vertical scroll.
+ set_v_scroll(get_v_scroll() - 1);
+
+ // Adjust the caret to viewport.
+ if (!selection.active) {
+ int cur_line = caret.line;
+ int cur_wrap = get_caret_wrap_index();
+ int last_vis_line = get_last_full_visible_line();
+ int last_vis_wrap = get_last_full_visible_line_wrap_index();
+
+ if (cur_line > last_vis_line || (cur_line == last_vis_line && cur_wrap > last_vis_wrap)) {
+ set_caret_line(last_vis_line, false, false, last_vis_wrap);
+ }
+ }
+}
+
+void TextEdit::_scroll_lines_down() {
+ scrolling = false;
+ minimap_clicked = false;
+
+ // Adjust the vertical scroll.
+ set_v_scroll(get_v_scroll() + 1);
+
+ // Adjust the caret to viewport.
+ if (!selection.active) {
+ int cur_line = caret.line;
+ int cur_wrap = get_caret_wrap_index();
+ int first_vis_line = get_first_visible_line();
+ int first_vis_wrap = caret.wrap_ofs;
+
+ if (cur_line < first_vis_line || (cur_line == first_vis_line && cur_wrap < first_vis_wrap)) {
+ set_caret_line(first_vis_line, false, false, first_vis_wrap);
+ }
+ }
+}
+
+// Minimap
+
+void TextEdit::_update_minimap_hover() {
+ const Point2 mp = get_local_mouse_pos();
+ const int xmargin_end = get_size().width - style_normal->get_margin(SIDE_RIGHT);
+
+ const bool hovering_sidebar = mp.x > xmargin_end - minimap_width && mp.x < xmargin_end;
+ if (!hovering_sidebar) {
+ if (hovering_minimap) {
+ // Only redraw if the hovering status changed.
+ hovering_minimap = false;
+ update();
+ }
+
+ // Return early to avoid running the operations below when not needed.
+ return;
+ }
+
+ const int row = get_minimap_line_at_pos(Point2i(mp.x, mp.y));
+
+ const bool new_hovering_minimap = row >= get_first_visible_line() && row <= get_last_full_visible_line();
+ if (new_hovering_minimap != hovering_minimap) {
+ // Only redraw if the hovering status changed.
+ hovering_minimap = new_hovering_minimap;
+ update();
+ }
+}
+
+void TextEdit::_update_minimap_click() {
+ Point2 mp = get_local_mouse_pos();
+
+ int xmargin_end = get_size().width - style_normal->get_margin(SIDE_RIGHT);
+ if (!dragging_minimap && (mp.x < xmargin_end - minimap_width || mp.y > xmargin_end)) {
+ minimap_clicked = false;
+ return;
+ }
+ minimap_clicked = true;
+ dragging_minimap = true;
+
+ int row = get_minimap_line_at_pos(Point2i(mp.x, mp.y));
+
+ if (row >= get_first_visible_line() && (row < get_last_full_visible_line() || row >= (text.size() - 1))) {
+ minimap_scroll_ratio = v_scroll->get_as_ratio();
+ minimap_scroll_click_pos = mp.y;
+ can_drag_minimap = true;
+ return;
+ }
+
+ Point2i next_line = get_next_visible_line_index_offset_from(row, 0, -get_visible_line_count() / 2);
+ int first_line = row - next_line.x + 1;
+ double delta = get_scroll_pos_for_line(first_line, next_line.y) - get_v_scroll();
+ if (delta < 0) {
+ _scroll_up(-delta);
+ } else {
+ _scroll_down(delta);
+ }
+}
+
+void TextEdit::_update_minimap_drag() {
+ if (!can_drag_minimap) {
+ return;
+ }
+
+ int control_height = _get_control_height();
+ int scroll_height = v_scroll->get_max() * (minimap_char_size.y + minimap_line_spacing);
+ if (control_height > scroll_height) {
+ control_height = scroll_height;
+ }
+
+ Point2 mp = get_local_mouse_pos();
+
+ double diff = (mp.y - minimap_scroll_click_pos) / control_height;
+ v_scroll->set_as_ratio(minimap_scroll_ratio + diff);
+}
+
+/* Gutters. */
+void TextEdit::_update_gutter_width() {
+ gutters_width = 0;
+ for (int i = 0; i < gutters.size(); i++) {
+ if (gutters[i].draw) {
+ gutters_width += gutters[i].width;
+ }
+ }
+ if (gutters_width > 0) {
+ gutter_padding = 2;
+ }
+ update();
+}
+
+/* Syntax highlighting. */
+Dictionary TextEdit::_get_line_syntax_highlighting(int p_line) {
+ return syntax_highlighter.is_null() && !setting_text ? Dictionary() : syntax_highlighter->get_line_syntax_highlighting(p_line);
+}
+
+/*** Super internal Core API. Everything builds on it. ***/
+
+void TextEdit::_text_changed_emit() {
+ emit_signal(SNAME("text_changed"));
+ text_changed_dirty = false;
+}
+
+void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r_end_line, int *r_end_char) {
+ if (!setting_text && idle_detect->is_inside_tree()) {
+ idle_detect->start();
+ }
+
+ if (undo_enabled) {
+ _clear_redo();
+ }
+
+ int retline, retchar;
+ _base_insert_text(p_line, p_char, p_text, retline, retchar);
+ if (r_end_line) {
+ *r_end_line = retline;
+ }
+ if (r_end_char) {
+ *r_end_char = retchar;
+ }
+
+ if (!undo_enabled) {
+ return;
+ }
+
+ /* UNDO!! */
+ TextOperation op;
+ op.type = TextOperation::TYPE_INSERT;
+ op.from_line = p_line;
+ op.from_column = p_char;
+ op.to_line = retline;
+ op.to_column = retchar;
+ op.text = p_text;
+ op.version = ++version;
+ op.chain_forward = false;
+ op.chain_backward = false;
+
+ // See if it should just be set as current op.
+ if (current_op.type != op.type) {
+ op.prev_version = get_version();
+ _push_current_op();
+ current_op = op;
+
+ return; // Set as current op, return.
+ }
+ // See if it can be merged.
+ if (current_op.to_line != p_line || current_op.to_column != p_char) {
+ op.prev_version = get_version();
+ _push_current_op();
+ current_op = op;
+ return; // Set as current op, return.
+ }
+ // Merge current op.
+
+ current_op.text += p_text;
+ current_op.to_column = retchar;
+ current_op.to_line = retline;
+ current_op.version = op.version;
+}
+
+void TextEdit::_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
+ if (!setting_text && idle_detect->is_inside_tree()) {
+ idle_detect->start();
+ }
+
+ String text;
+ if (undo_enabled) {
+ _clear_redo();
+ text = _base_get_text(p_from_line, p_from_column, p_to_line, p_to_column);
+ }
+
+ _base_remove_text(p_from_line, p_from_column, p_to_line, p_to_column);
+
+ if (!undo_enabled) {
+ return;
+ }
+
+ /* UNDO! */
+ TextOperation op;
+ op.type = TextOperation::TYPE_REMOVE;
+ op.from_line = p_from_line;
+ op.from_column = p_from_column;
+ op.to_line = p_to_line;
+ op.to_column = p_to_column;
+ op.text = text;
+ op.version = ++version;
+ op.chain_forward = false;
+ op.chain_backward = false;
+
+ // See if it should just be set as current op.
+ if (current_op.type != op.type) {
+ op.prev_version = get_version();
+ _push_current_op();
+ current_op = op;
+ return; // Set as current op, return.
+ }
+ // See if it can be merged.
+ if (current_op.from_line == p_to_line && current_op.from_column == p_to_column) {
+ // Backspace or similar.
+ current_op.text = text + current_op.text;
+ current_op.from_line = p_from_line;
+ current_op.from_column = p_from_column;
+ return; // Update current op.
+ }
+
+ op.prev_version = get_version();
+ _push_current_op();
+ current_op = op;
+}
+
+void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, int &r_end_line, int &r_end_column) {
+ // Save for undo.
+ ERR_FAIL_INDEX(p_line, text.size());
+ ERR_FAIL_COND(p_char < 0);
+
+ /* STEP 1: Remove \r from source text and separate in substrings. */
+
+ Vector<String> substrings = p_text.replace("\r", "").split("\n");
+
+ // Is this just a new empty line?
+ bool shift_first_line = p_char == 0 && p_text.replace("\r", "") == "\n";
+
+ /* STEP 2: Add spaces if the char is greater than the end of the line. */
+ while (p_char > text[p_line].length()) {
+ text.set(p_line, text[p_line] + String::chr(' '), structured_text_parser(st_parser, st_args, text[p_line] + String::chr(' ')));
+ }
+
+ /* STEP 3: Separate dest string in pre and post text. */
+
+ String preinsert_text = text[p_line].substr(0, p_char);
+ String postinsert_text = text[p_line].substr(p_char, text[p_line].size());
+
+ for (int j = 0; j < substrings.size(); j++) {
+ // Insert the substrings.
+
+ if (j == 0) {
+ text.set(p_line, preinsert_text + substrings[j], structured_text_parser(st_parser, st_args, preinsert_text + substrings[j]));
+ } else {
+ text.insert(p_line + j, substrings[j], structured_text_parser(st_parser, st_args, substrings[j]));
+ }
+
+ if (j == substrings.size() - 1) {
+ text.set(p_line + j, text[p_line + j] + postinsert_text, structured_text_parser(st_parser, st_args, text[p_line + j] + postinsert_text));
+ }
+ }
+
+ if (shift_first_line) {
+ text.move_gutters(p_line, p_line + 1);
+ text.set_hidden(p_line + 1, text.is_hidden(p_line));
+
+ 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();
+
+ TextServer::Direction dir = TS->shaped_text_get_dominant_direciton_in_range(text.get_line_data(r_end_line)->get_rid(), (r_end_line == p_line) ? caret.column : 0, r_end_column);
+ if (dir != TextServer::DIRECTION_AUTO) {
+ input_direction = (TextDirection)dir;
+ }
+
+ if (!text_changed_dirty && !setting_text) {
+ if (is_inside_tree()) {
+ MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ }
+ text_changed_dirty = true;
+ }
+ emit_signal(SNAME("lines_edited_from"), p_line, r_end_line);
+}
+
+String TextEdit::_base_get_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) const {
+ ERR_FAIL_INDEX_V(p_from_line, text.size(), String());
+ ERR_FAIL_INDEX_V(p_from_column, text[p_from_line].length() + 1, String());
+ ERR_FAIL_INDEX_V(p_to_line, text.size(), String());
+ ERR_FAIL_INDEX_V(p_to_column, text[p_to_line].length() + 1, String());
+ ERR_FAIL_COND_V(p_to_line < p_from_line, String()); // 'from > to'.
+ ERR_FAIL_COND_V(p_to_line == p_from_line && p_to_column < p_from_column, String()); // 'from > to'.
+
+ String ret;
+
+ for (int i = p_from_line; i <= p_to_line; i++) {
+ int begin = (i == p_from_line) ? p_from_column : 0;
+ int end = (i == p_to_line) ? p_to_column : text[i].length();
+
+ if (i > p_from_line) {
+ ret += "\n";
+ }
+ ret += text[i].substr(begin, end - begin);
+ }
+
+ return ret;
+}
+
+void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
+ ERR_FAIL_INDEX(p_from_line, text.size());
+ ERR_FAIL_INDEX(p_from_column, text[p_from_line].length() + 1);
+ ERR_FAIL_INDEX(p_to_line, text.size());
+ ERR_FAIL_INDEX(p_to_column, text[p_to_line].length() + 1);
+ ERR_FAIL_COND(p_to_line < p_from_line); // 'from > to'.
+ ERR_FAIL_COND(p_to_line == p_from_line && p_to_column < p_from_column); // 'from > to'.
+
+ String pre_text = text[p_from_line].substr(0, p_from_column);
+ String post_text = text[p_to_line].substr(p_to_column, text[p_to_line].length());
+
+ for (int i = p_from_line; i < p_to_line; i++) {
+ text.remove(p_from_line + 1);
+ }
+ text.set(p_from_line, pre_text + post_text, structured_text_parser(st_parser, st_args, pre_text + post_text));
+
+ if (!text_changed_dirty && !setting_text) {
+ if (is_inside_tree()) {
+ MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
+ }
+ text_changed_dirty = true;
+ }
+ emit_signal(SNAME("lines_edited_from"), p_to_line, p_from_line);
}
TextEdit::TextEdit() {
@@ -5691,46 +6059,38 @@ TextEdit::TextEdit() {
set_default_cursor_shape(CURSOR_IBEAM);
text.set_tab_size(text.get_tab_size());
- text.clear();
h_scroll = memnew(HScrollBar);
v_scroll = memnew(VScrollBar);
- add_child(h_scroll);
- add_child(v_scroll);
+ add_child(h_scroll, false, INTERNAL_MODE_FRONT);
+ add_child(v_scroll, false, INTERNAL_MODE_FRONT);
h_scroll->connect("value_changed", callable_mp(this, &TextEdit::_scroll_moved));
v_scroll->connect("value_changed", callable_mp(this, &TextEdit::_scroll_moved));
v_scroll->connect("scrolling", callable_mp(this, &TextEdit::_v_scroll_input));
+ /* Caret. */
caret_blink_timer = memnew(Timer);
- add_child(caret_blink_timer);
+ add_child(caret_blink_timer, false, INTERNAL_MODE_FRONT);
caret_blink_timer->set_wait_time(0.65);
caret_blink_timer->connect("timeout", callable_mp(this, &TextEdit::_toggle_draw_caret));
- cursor_set_blink_enabled(false);
+ set_caret_blink_enabled(false);
+
+ /* Selection. */
+ click_select_held = memnew(Timer);
+ add_child(click_select_held, false, INTERNAL_MODE_FRONT);
+ click_select_held->set_wait_time(0.05);
+ click_select_held->connect("timeout", callable_mp(this, &TextEdit::_click_selection_held));
idle_detect = memnew(Timer);
- add_child(idle_detect);
+ add_child(idle_detect, false, INTERNAL_MODE_FRONT);
idle_detect->set_one_shot(true);
idle_detect->set_wait_time(GLOBAL_GET("gui/timers/text_edit_idle_detect_sec"));
idle_detect->connect("timeout", callable_mp(this, &TextEdit::_push_current_op));
- click_select_held = memnew(Timer);
- add_child(click_select_held);
- click_select_held->set_wait_time(0.05);
- click_select_held->connect("timeout", callable_mp(this, &TextEdit::_click_selection_held));
-
undo_stack_max_size = GLOBAL_GET("gui/common/text_edit_undo_stack_max_size");
- set_readonly(false);
-}
-
-TextEdit::~TextEdit() {
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-Dictionary TextEdit::_get_line_syntax_highlighting(int p_line) {
- return syntax_highlighter.is_null() && !setting_text ? Dictionary() : syntax_highlighter->get_line_syntax_highlighting(p_line);
+ set_editable(true);
}
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 9e6dedb267..e996bba983 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -42,12 +42,13 @@ class TextEdit : public Control {
GDCLASS(TextEdit, Control);
public:
- enum GutterType {
- GUTTER_TYPE_STRING,
- GUTTER_TYPE_ICON,
- GUTTER_TYPE_CUSTOM
+ /* Caret. */
+ enum CaretType {
+ CARET_TYPE_LINE,
+ CARET_TYPE_BLOCK
};
+ /* Selection */
enum SelectionMode {
SELECTION_MODE_NONE,
SELECTION_MODE_SHIFT,
@@ -56,6 +57,60 @@ public:
SELECTION_MODE_LINE
};
+ /* Line Wrapping.*/
+ enum LineWrappingMode {
+ LINE_WRAPPING_NONE,
+ LINE_WRAPPING_BOUNDARY
+ };
+
+ /* Gutters. */
+ enum GutterType {
+ GUTTER_TYPE_STRING,
+ GUTTER_TYPE_ICON,
+ GUTTER_TYPE_CUSTOM
+ };
+
+ /* Contex Menu. */
+ enum MenuItems {
+ MENU_CUT,
+ MENU_COPY,
+ MENU_PASTE,
+ MENU_CLEAR,
+ MENU_SELECT_ALL,
+ MENU_UNDO,
+ MENU_REDO,
+ MENU_DIR_INHERITED,
+ MENU_DIR_AUTO,
+ MENU_DIR_LTR,
+ MENU_DIR_RTL,
+ MENU_DISPLAY_UCC,
+ MENU_INSERT_LRM,
+ MENU_INSERT_RLM,
+ MENU_INSERT_LRE,
+ MENU_INSERT_RLE,
+ MENU_INSERT_LRO,
+ MENU_INSERT_RLO,
+ MENU_INSERT_PDF,
+ MENU_INSERT_ALM,
+ MENU_INSERT_LRI,
+ MENU_INSERT_RLI,
+ MENU_INSERT_FSI,
+ MENU_INSERT_PDI,
+ MENU_INSERT_ZWJ,
+ MENU_INSERT_ZWNJ,
+ MENU_INSERT_WJ,
+ MENU_INSERT_SHY,
+ MENU_MAX
+
+ };
+
+ /* Search. */
+ enum SearchFlags {
+ SEARCH_MATCH_CASE = 1,
+ SEARCH_WHOLE_WORDS = 2,
+ SEARCH_BACKWARDS = 4
+ };
+
private:
struct GutterInfo {
GutterType type = GutterType::GUTTER_TYPE_STRING;
@@ -68,11 +123,6 @@ private:
ObjectID custom_draw_obj = ObjectID();
StringName custom_draw_callback;
};
- Vector<GutterInfo> gutters;
- int gutters_width = 0;
- int gutter_padding = 0;
-
- void _update_gutter_width();
class Text {
public:
@@ -94,6 +144,8 @@ private:
Color background_color = Color(0, 0, 0, 0);
bool hidden = false;
+ int height = 0;
+ int width = 0;
Line() {
data_buf.instantiate();
@@ -101,6 +153,9 @@ private:
};
private:
+ bool is_dirty = false;
+ bool tab_size_dirty = false;
+
mutable Vector<Line> text;
Ref<Font> font;
int font_size = -1;
@@ -110,23 +165,28 @@ private:
TextServer::Direction direction = TextServer::DIRECTION_AUTO;
bool draw_control_chars = false;
+ int line_height = -1;
+ int max_width = -1;
int width = -1;
int tab_size = 4;
int gutter_count = 0;
+ void _calculate_line_height();
+ void _calculate_max_line_width();
+
public:
void set_tab_size(int p_tab_size);
int get_tab_size() const;
void set_font(const Ref<Font> &p_font);
void set_font_size(int p_font_size);
void set_font_features(const Dictionary &p_features);
- void set_direction_and_language(TextServer::Direction p_direction, String p_language);
+ void set_direction_and_language(TextServer::Direction p_direction, const String &p_language);
void set_draw_control_chars(bool p_draw_control_chars);
- int get_line_height(int p_line, int p_wrap_index) const;
+ int get_line_height() const;
int get_line_width(int p_line, int p_wrap_index = -1) const;
- int get_max_width(bool p_exclude_hidden = false) const;
+ int get_max_width() const;
void set_width(float p_width);
int get_line_wrap_amount(int p_line) const;
@@ -135,7 +195,14 @@ private:
const Ref<TextParagraph> get_line_data(int p_line) const;
void set(int p_line, const String &p_text, const Vector<Vector2i> &p_bidi_override);
- void set_hidden(int p_line, bool p_hidden) { text.write[p_line].hidden = p_hidden; }
+ void set_hidden(int p_line, bool p_hidden) {
+ text.write[p_line].hidden = p_hidden;
+ if (!p_hidden && text[p_line].width > max_width) {
+ max_width = text[p_line].width;
+ } else if (p_hidden && text[p_line].width == max_width) {
+ _calculate_max_line_width();
+ }
+ }
bool is_hidden(int p_line) const { return text[p_line].hidden; }
void insert(int p_at, const String &p_text, const Vector<Vector2i> &p_bidi_override);
void remove(int p_at);
@@ -159,7 +226,7 @@ private:
void set_line_gutter_text(int p_line, int p_gutter, const String &p_text) { text.write[p_line].gutters.write[p_gutter].text = p_text; }
const String &get_line_gutter_text(int p_line, int p_gutter) const { return text[p_line].gutters[p_gutter].text; }
- void set_line_gutter_icon(int p_line, int p_gutter, Ref<Texture2D> p_icon) { text.write[p_line].gutters.write[p_gutter].icon = p_icon; }
+ void set_line_gutter_icon(int p_line, int p_gutter, const Ref<Texture2D> &p_icon) { text.write[p_line].gutters.write[p_gutter].icon = p_icon; }
const Ref<Texture2D> &get_line_gutter_icon(int p_line, int p_gutter) const { return text[p_line].gutters[p_gutter].icon; }
void set_line_gutter_item_color(int p_line, int p_gutter, const Color &p_color) { text.write[p_line].gutters.write[p_gutter].color = p_color; }
@@ -173,38 +240,48 @@ private:
const Color get_line_background_color(int p_line) const { return text[p_line].background_color; }
};
- struct Cursor {
- Point2 draw_pos;
- bool visible = false;
- int last_fit_x = 0;
- int line = 0;
- int column = 0; ///< cursor
- int x_ofs = 0;
- int line_ofs = 0;
- int wrap_ofs = 0;
- } cursor;
+ /* Text */
+ Text text;
- struct Selection {
- SelectionMode selecting_mode = SelectionMode::SELECTION_MODE_NONE;
- int selecting_line = 0;
- int selecting_column = 0;
- int selected_word_beg = 0;
- int selected_word_end = 0;
- int selected_word_origin = 0;
- bool selecting_text = false;
+ bool setting_text = false;
- bool active = false;
+ // Text properties.
+ String ime_text = "";
+ Point2 ime_selection;
- int from_line = 0;
- int from_column = 0;
- int to_line = 0;
- int to_column = 0;
+ /* Initialise to opposite first, so we get past the early-out in set_editable. */
+ bool editable = false;
- bool shiftclick_left = false;
- } selection;
+ TextDirection text_direction = TEXT_DIRECTION_AUTO;
+ TextDirection input_direction = TEXT_DIRECTION_LTR;
- Map<int, Dictionary> syntax_highlighting_cache;
+ Dictionary opentype_features;
+ String language = "";
+ Control::StructuredTextParser st_parser = STRUCTURED_TEXT_DEFAULT;
+ Array st_args;
+
+ void _clear();
+ void _update_caches();
+
+ // User control.
+ bool overtype_mode = false;
+ bool context_menu_enabled = true;
+ bool shortcut_keys_enabled = true;
+ bool virtual_keyboard_enabled = true;
+
+ // Overridable actions
+ String cut_copy_line = "";
+
+ // Context menu.
+ PopupMenu *menu = nullptr;
+ PopupMenu *menu_dir = nullptr;
+ PopupMenu *menu_ctl = nullptr;
+
+ void _generate_context_menu();
+ int _get_menu_action_accelerator(const String &p_action);
+
+ /* Versioning */
struct TextOperation {
enum Type {
TYPE_NONE,
@@ -224,247 +301,251 @@ private:
bool chain_backward = false;
};
- String ime_text;
- Point2 ime_selection;
+ bool undo_enabled = true;
+ int undo_stack_max_size = 50;
- TextOperation current_op;
+ bool next_operation_is_complex = false;
+ TextOperation current_op;
List<TextOperation> undo_stack;
List<TextOperation>::Element *undo_stack_pos = nullptr;
- int undo_stack_max_size;
- void _clear_redo();
+ Timer *idle_detect;
+
+ uint32_t version = 0;
+ uint32_t saved_version = 0;
+
+ void _push_current_op();
void _do_text_op(const TextOperation &p_op, bool p_reverse);
+ void _clear_redo();
- //syntax coloring
- Ref<SyntaxHighlighter> syntax_highlighter;
- Set<String> keywords;
+ /* Search */
+ Color search_result_color = Color(1, 1, 1);
+ Color search_result_border_color = Color(1, 1, 1);
- Dictionary _get_line_syntax_highlighting(int p_line);
+ String search_text = "";
+ uint32_t search_flags = 0;
- bool setting_text = false;
+ int _get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column) const;
- // data
- Text text;
+ /* Tooltip. */
+ Object *tooltip_obj = nullptr;
+ StringName tooltip_func;
+ Variant tooltip_ud;
- Dictionary opentype_features;
- String language;
- TextDirection text_direction = TEXT_DIRECTION_AUTO;
- TextDirection input_direction = TEXT_DIRECTION_LTR;
- Control::StructuredTextParser st_parser = STRUCTURED_TEXT_DEFAULT;
- Array st_args;
- bool draw_control_chars = false;
+ /* Mouse */
+ int _get_char_pos_for_line(int p_px, int p_line, int p_wrap_index = 0) const;
- uint32_t version = 0;
- uint32_t saved_version = 0;
+ /* Caret. */
+ struct Caret {
+ Point2 draw_pos;
+ bool visible = false;
+ int last_fit_x = 0;
+ int line = 0;
+ int column = 0;
+ int x_ofs = 0;
+ int line_ofs = 0;
+ int wrap_ofs = 0;
+ } caret;
- bool readonly = true; // Initialise to opposite first, so we get past the early-out in set_readonly.
+ bool setting_caret_line = false;
+ bool caret_pos_dirty = false;
+
+ Color caret_color = Color(1, 1, 1);
+ Color caret_background_color = Color(0, 0, 0);
+
+ CaretType caret_type = CaretType::CARET_TYPE_LINE;
- Timer *caret_blink_timer;
- bool caret_blink_enabled = false;
bool draw_caret = true;
- bool window_has_focus = true;
- bool block_caret = false;
- bool right_click_moves_caret = true;
- bool mid_grapheme_caret_enabled = false;
- bool wrap_enabled = false;
- int wrap_at = 0;
- int wrap_right_offset = 10;
+ bool caret_blink_enabled = false;
+ Timer *caret_blink_timer;
- bool first_draw = true;
- bool setting_row = false;
- bool draw_tabs = false;
- bool draw_spaces = false;
- bool override_selected_font_color = false;
- bool cursor_changed_dirty = false;
- bool text_changed_dirty = false;
- bool undo_enabled = true;
- bool hiding_enabled = false;
- bool draw_minimap = false;
- int minimap_width = 80;
- Point2 minimap_char_size = Point2(1, 2);
- int minimap_line_spacing = 1;
+ bool move_caret_on_right_click = true;
- bool highlight_all_occurrences = false;
- bool scroll_past_end_of_file_enabled = false;
- bool highlight_current_line = false;
+ bool caret_mid_grapheme_enabled = false;
- String cut_copy_line;
- bool insert_mode = false;
- bool select_identifiers_enabled = false;
+ void _emit_caret_changed();
- bool smooth_scroll_enabled = false;
- bool scrolling = false;
- bool dragging_selection = false;
- bool dragging_minimap = false;
- bool can_drag_minimap = false;
- bool minimap_clicked = false;
- double minimap_scroll_ratio = 0.0;
- double minimap_scroll_click_pos = 0.0;
- float target_v_scroll = 0.0;
- float v_scroll_speed = 80.0;
+ void _reset_caret_blink_timer();
+ void _toggle_draw_caret();
- String lookup_symbol_word;
+ int _get_column_x_offset_for_line(int p_char, int p_line) const;
- uint64_t last_dblclk = 0;
+ /* Selection. */
+ struct Selection {
+ SelectionMode selecting_mode = SelectionMode::SELECTION_MODE_NONE;
+ int selecting_line = 0;
+ int selecting_column = 0;
+ int selected_word_beg = 0;
+ int selected_word_end = 0;
+ int selected_word_origin = 0;
+ bool selecting_text = false;
+
+ bool active = false;
+
+ int from_line = 0;
+ int from_column = 0;
+ int to_line = 0;
+ int to_column = 0;
+
+ bool shiftclick_left = false;
+ } selection;
+
+ bool selecting_enabled = true;
+
+ Color font_selected_color = Color(1, 1, 1);
+ Color selection_color = Color(1, 1, 1);
+ bool override_selected_font_color = false;
+
+ bool dragging_selection = false;
- Timer *idle_detect;
Timer *click_select_held;
- HScrollBar *h_scroll;
- VScrollBar *v_scroll;
- bool updating_scrolls = false;
+ uint64_t last_dblclk = 0;
+ Vector2 last_dblclk_pos;
+ void _click_selection_held();
- Object *tooltip_obj = nullptr;
- StringName tooltip_func;
- Variant tooltip_ud;
+ void _update_selection_mode_pointer();
+ void _update_selection_mode_word();
+ void _update_selection_mode_line();
- bool next_operation_is_complex = false;
+ void _pre_shift_selection();
+ void _post_shift_selection();
- String search_text;
- uint32_t search_flags = 0;
- int search_result_line = 0;
- int search_result_col = 0;
+ /* line wrapping. */
+ LineWrappingMode line_wrapping_mode = LineWrappingMode::LINE_WRAPPING_NONE;
- bool selecting_enabled = true;
+ int wrap_at_column = 0;
+ int wrap_right_offset = 10;
- bool context_menu_enabled = true;
- bool shortcut_keys_enabled = true;
- bool virtual_keyboard_enabled = true;
+ void _update_wrap_at_column(bool p_force = false);
- int get_visible_rows() const;
- int get_total_visible_rows() const;
+ void _update_caret_wrap_offset();
- int _get_minimap_visible_rows() const;
+ /* Viewport. */
+ HScrollBar *h_scroll;
+ VScrollBar *v_scroll;
- void update_cursor_wrap_offset();
- void _update_wrap_at(bool p_force = false);
- Vector<String> get_wrap_rows_text(int p_line) const;
- int get_cursor_wrap_index() const;
- int get_char_count();
+ bool scroll_past_end_of_file_enabled = false;
- double get_scroll_pos_for_line(int p_line, int p_wrap_index = 0) const;
- void set_line_as_first_visible(int p_line, int p_wrap_index = 0);
- void set_line_as_center_visible(int p_line, int p_wrap_index = 0);
- void set_line_as_last_visible(int p_line, int p_wrap_index = 0);
- int get_first_visible_line() const;
- int get_last_full_visible_line() const;
- int get_last_full_visible_line_wrap_index() const;
- double get_visible_rows_offset() const;
- double get_v_scroll_offset() const;
+ // Smooth scrolling.
+ bool smooth_scroll_enabled = false;
+ float target_v_scroll = 0.0;
+ float v_scroll_speed = 80.0;
- int get_char_pos_for_line(int p_px, int p_line, int p_wrap_index = 0) const;
- int get_column_x_offset_for_line(int p_char, int p_line) const;
+ // Scrolling.
+ bool scrolling = false;
+ bool updating_scrolls = false;
- void adjust_viewport_to_cursor();
- double get_scroll_line_diff() const;
- void _scroll_moved(double);
void _update_scrollbars();
+ int _get_control_height() const;
+
void _v_scroll_input();
- void _click_selection_held();
+ void _scroll_moved(double p_to_val);
- void _update_selection_mode_pointer();
- void _update_selection_mode_word();
- void _update_selection_mode_line();
+ double _get_visible_lines_offset() const;
+ double _get_v_scroll_offset() const;
- void _update_minimap_click();
- void _update_minimap_drag();
void _scroll_up(real_t p_delta);
void _scroll_down(real_t p_delta);
- void _pre_shift_selection();
- void _post_shift_selection();
-
void _scroll_lines_up();
void _scroll_lines_down();
- //void mouse_motion(const Point& p_pos, const Point& p_rel, int p_button_mask);
- Size2 get_minimum_size() const override;
- int _get_control_height() const;
+ // Minimap
+ bool draw_minimap = false;
- int _get_menu_action_accelerator(const String &p_action);
+ int minimap_width = 80;
+ Point2 minimap_char_size = Point2(1, 2);
+ int minimap_line_spacing = 1;
- void _reset_caret_blink_timer();
- void _toggle_draw_caret();
+ // minimap scroll
+ bool minimap_clicked = false;
+ bool hovering_minimap = false;
+ bool dragging_minimap = false;
+ bool can_drag_minimap = false;
- void _update_caches();
- void _cursor_changed_emit();
- void _text_changed_emit();
+ double minimap_scroll_ratio = 0.0;
+ double minimap_scroll_click_pos = 0.0;
- void _push_current_op();
+ void _update_minimap_hover();
+ void _update_minimap_click();
+ void _update_minimap_drag();
- /* super internal api, undo/redo builds on it */
+ /* Gutters. */
+ Vector<GutterInfo> gutters;
+ int gutters_width = 0;
+ int gutter_padding = 0;
- void _base_insert_text(int p_line, int p_char, const String &p_text, int &r_end_line, int &r_end_column);
- String _base_get_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) const;
- void _base_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
+ void _update_gutter_width();
- int _get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column);
+ /* Syntax highlighting. */
+ Ref<SyntaxHighlighter> syntax_highlighter;
+ Map<int, Dictionary> syntax_highlighting_cache;
- Dictionary _search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const;
+ Dictionary _get_line_syntax_highlighting(int p_line);
- PopupMenu *menu = nullptr;
- PopupMenu *menu_dir = nullptr;
- PopupMenu *menu_ctl = nullptr;
+ /* Visual. */
+ Ref<StyleBox> style_normal;
+ Ref<StyleBox> style_focus;
+ Ref<StyleBox> style_readonly;
- void _ensure_menu();
+ Ref<Texture2D> tab_icon;
+ Ref<Texture2D> space_icon;
- void _clear();
+ Ref<Font> font;
+ int font_size = 16;
+ Color font_color = Color(1, 1, 1);
+ Color font_readonly_color = Color(1, 1, 1);
- // Methods used in shortcuts
- void _swap_current_input_direction();
- void _new_line(bool p_split_current = true, bool p_above = false);
- void _move_cursor_left(bool p_select, bool p_move_by_word = false);
- void _move_cursor_right(bool p_select, bool p_move_by_word = false);
- void _move_cursor_up(bool p_select);
- void _move_cursor_down(bool p_select);
- void _move_cursor_to_line_start(bool p_select);
- void _move_cursor_to_line_end(bool p_select);
- void _move_cursor_page_up(bool p_select);
- void _move_cursor_page_down(bool p_select);
- void _do_backspace(bool p_word = false, bool p_all_to_left = false);
- void _delete(bool p_word = false, bool p_all_to_right = false);
- void _move_cursor_document_start(bool p_select);
- void _move_cursor_document_end(bool p_select);
+ int outline_size = 0;
+ Color outline_color = Color(1, 1, 1);
-protected:
- bool highlight_matching_braces_enabled = false;
+ int line_spacing = 1;
- struct Cache {
- Ref<Texture2D> tab_icon;
- Ref<Texture2D> space_icon;
- Ref<Texture2D> folded_eol_icon;
- Ref<StyleBox> style_normal;
- Ref<StyleBox> style_focus;
- Ref<StyleBox> style_readonly;
- Ref<Font> font;
- int font_size = 16;
- int outline_size = 0;
- Color outline_color;
- Color caret_color;
- Color caret_background_color;
- Color font_color;
- Color font_selected_color;
- Color font_readonly_color;
- Color selection_color;
- Color code_folding_color;
- Color current_line_color;
- Color brace_mismatch_color;
- Color word_highlighted_color;
- Color search_result_color;
- Color search_result_border_color;
- Color background_color;
-
- int line_spacing = 1;
- int minimap_width = 0;
- } cache;
+ Color background_color = Color(1, 1, 1);
+ Color current_line_color = Color(1, 1, 1);
+ Color word_highlighted_color = Color(1, 1, 1);
- virtual String get_tooltip(const Point2 &p_pos) const override;
+ bool window_has_focus = true;
+ bool first_draw = true;
+
+ bool highlight_current_line = false;
+ bool highlight_all_occurrences = false;
+ bool draw_control_chars = false;
+ bool draw_tabs = false;
+ bool draw_spaces = false;
+
+ /*** Super internal Core API. Everything builds on it. ***/
+ bool text_changed_dirty = false;
+ void _text_changed_emit();
void _insert_text(int p_line, int p_char, const String &p_text, int *r_end_line = nullptr, int *r_end_char = nullptr);
void _remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
- virtual void _gui_input(const Ref<InputEvent> &p_gui_input);
+
+ void _base_insert_text(int p_line, int p_char, const String &p_text, int &r_end_line, int &r_end_column);
+ String _base_get_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) const;
+ void _base_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
+
+ /* Input actions. */
+ void _swap_current_input_direction();
+ void _new_line(bool p_split_current = true, bool p_above = false);
+ void _move_caret_left(bool p_select, bool p_move_by_word = false);
+ void _move_caret_right(bool p_select, bool p_move_by_word = false);
+ void _move_caret_up(bool p_select);
+ void _move_caret_down(bool p_select);
+ void _move_caret_to_line_start(bool p_select);
+ void _move_caret_to_line_end(bool p_select);
+ void _move_caret_page_up(bool p_select);
+ void _move_caret_page_down(bool p_select);
+ void _do_backspace(bool p_word = false, bool p_all_to_left = false);
+ void _delete(bool p_word = false, bool p_all_to_right = false);
+ void _move_caret_document_start(bool p_select);
+ void _move_caret_document_end(bool p_select);
+
+protected:
void _notification(int p_what);
+ virtual void gui_input(const Ref<InputEvent> &p_gui_input) override;
static void _bind_methods();
@@ -472,304 +553,352 @@ protected:
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
+ /* Internal API for CodeEdit, pending public API. */
+ // brace matching
+ bool highlight_matching_braces_enabled = false;
+ Color brace_mismatch_color;
+
+ // Line hiding.
+ Color code_folding_color = Color(1, 1, 1);
+ Ref<Texture2D> folded_eol_icon;
+
+ bool hiding_enabled = false;
+
+ void _set_hiding_enabled(bool p_enabled);
+ bool _is_hiding_enabled() const;
+
+ void _set_line_as_hidden(int p_line, bool p_hidden);
+ bool _is_line_hidden(int p_line) const;
+
+ void _unhide_all_lines();
+
+ // Symbol lookup.
+ String lookup_symbol_word;
void _set_symbol_lookup_word(const String &p_symbol);
+ /* Text manipulation */
+
+ // Overridable actions
+ virtual void _handle_unicode_input_internal(const uint32_t p_unicode);
+ virtual void _backspace_internal();
+
+ virtual void _cut_internal();
+ virtual void _copy_internal();
+ virtual void _paste_internal();
+
+ GDVIRTUAL1(_handle_unicode_input, int)
+ GDVIRTUAL0(_backspace)
+ GDVIRTUAL0(_cut)
+ GDVIRTUAL0(_copy)
+ GDVIRTUAL0(_paste)
+
public:
- /* Syntax Highlighting. */
- Ref<SyntaxHighlighter> get_syntax_highlighter();
- void set_syntax_highlighter(Ref<SyntaxHighlighter> p_syntax_highlighter);
+ /* General overrides. */
+ virtual Size2 get_minimum_size() const override;
+ virtual bool is_text_field() const override;
+ virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override;
+ virtual String get_tooltip(const Point2 &p_pos) const override;
+ void set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata);
- /* Gutters. */
- void add_gutter(int p_at = -1);
- void remove_gutter(int p_gutter);
- int get_gutter_count() const;
+ /* Text */
+ // Text properties.
+ bool has_ime_text() const;
- void set_gutter_name(int p_gutter, const String &p_name);
- String get_gutter_name(int p_gutter) const;
+ void set_editable(const bool p_editable);
+ bool is_editable() const;
- void set_gutter_type(int p_gutter, GutterType p_type);
- GutterType get_gutter_type(int p_gutter) const;
+ void set_text_direction(TextDirection p_text_direction);
+ TextDirection get_text_direction() const;
- void set_gutter_width(int p_gutter, int p_width);
- int get_gutter_width(int p_gutter) const;
- int get_total_gutter_width() const;
+ void set_opentype_feature(const String &p_name, int p_value);
+ int get_opentype_feature(const String &p_name) const;
+ void clear_opentype_features();
- void set_gutter_draw(int p_gutter, bool p_draw);
- bool is_gutter_drawn(int p_gutter) const;
+ void set_language(const String &p_language);
+ String get_language() const;
- void set_gutter_clickable(int p_gutter, bool p_clickable);
- bool is_gutter_clickable(int p_gutter) const;
+ void set_structured_text_bidi_override(Control::StructuredTextParser p_parser);
+ Control::StructuredTextParser get_structured_text_bidi_override() const;
+ void set_structured_text_bidi_override_options(Array p_args);
+ Array get_structured_text_bidi_override_options() const;
- void set_gutter_overwritable(int p_gutter, bool p_overwritable);
- bool is_gutter_overwritable(int p_gutter) const;
+ void set_tab_size(const int p_size);
+ int get_tab_size() const;
- void merge_gutters(int p_from_line, int p_to_line);
+ // User controls
+ void set_overtype_mode_enabled(const bool p_enabled);
+ bool is_overtype_mode_enabled() const;
- void set_gutter_custom_draw(int p_gutter, Object *p_object, const StringName &p_callback);
+ void set_context_menu_enabled(bool p_enable);
+ bool is_context_menu_enabled() const;
- // Line gutters.
- void set_line_gutter_metadata(int p_line, int p_gutter, const Variant &p_metadata);
- Variant get_line_gutter_metadata(int p_line, int p_gutter) const;
+ void set_shortcut_keys_enabled(bool p_enabled);
+ bool is_shortcut_keys_enabled() const;
- void set_line_gutter_text(int p_line, int p_gutter, const String &p_text);
- String get_line_gutter_text(int p_line, int p_gutter) const;
+ void set_virtual_keyboard_enabled(bool p_enable);
+ bool is_virtual_keyboard_enabled() const;
- void set_line_gutter_icon(int p_line, int p_gutter, Ref<Texture2D> p_icon);
- Ref<Texture2D> get_line_gutter_icon(int p_line, int p_gutter) const;
+ // Text manipulation
+ void clear();
- void set_line_gutter_item_color(int p_line, int p_gutter, const Color &p_color);
- Color get_line_gutter_item_color(int p_line, int p_gutter);
+ void set_text(const String &p_text);
+ String get_text() const;
+ int get_line_count() const;
- void set_line_gutter_clickable(int p_line, int p_gutter, bool p_clickable);
- bool is_line_gutter_clickable(int p_line, int p_gutter) const;
+ void set_line(int p_line, const String &p_new_text);
+ String get_line(int p_line) const;
- // Line style
- void set_line_background_color(int p_line, const Color &p_color);
- Color get_line_background_color(int p_line);
+ int get_line_width(int p_line, int p_wrap_index = -1) const;
+ int get_line_height() const;
- enum MenuItems {
- MENU_CUT,
- MENU_COPY,
- MENU_PASTE,
- MENU_CLEAR,
- MENU_SELECT_ALL,
- MENU_UNDO,
- MENU_REDO,
- MENU_DIR_INHERITED,
- MENU_DIR_AUTO,
- MENU_DIR_LTR,
- MENU_DIR_RTL,
- MENU_DISPLAY_UCC,
- MENU_INSERT_LRM,
- MENU_INSERT_RLM,
- MENU_INSERT_LRE,
- MENU_INSERT_RLE,
- MENU_INSERT_LRO,
- MENU_INSERT_RLO,
- MENU_INSERT_PDF,
- MENU_INSERT_ALM,
- MENU_INSERT_LRI,
- MENU_INSERT_RLI,
- MENU_INSERT_FSI,
- MENU_INSERT_PDI,
- MENU_INSERT_ZWJ,
- MENU_INSERT_ZWNJ,
- MENU_INSERT_WJ,
- MENU_INSERT_SHY,
- MENU_MAX
+ int get_indent_level(int p_line) const;
+ int get_first_non_whitespace_column(int p_line) const;
- };
+ void swap_lines(int p_from_line, int p_to_line);
- enum SearchFlags {
- SEARCH_MATCH_CASE = 1,
- SEARCH_WHOLE_WORDS = 2,
- SEARCH_BACKWARDS = 4
- };
+ void insert_line_at(int p_at, const String &p_text);
+ void insert_text_at_caret(const String &p_text);
- virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override;
+ void remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
- Point2 _get_local_mouse_pos() const;
- void _get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const;
- void _get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const;
- bool is_dragging_cursor() const;
+ int get_last_unhidden_line() const;
+ int get_next_visible_line_offset_from(int p_line_from, int p_visible_amount) const;
+ Point2i get_next_visible_line_index_offset_from(int p_line_from, int p_wrap_index_from, int p_visible_amount) const;
- //void delete_char();
- //void delete_line();
+ // Overridable actions
+ void handle_unicode_input(const uint32_t p_unicode);
+ void backspace();
+ void cut();
+ void copy();
+ void paste();
+
+ // Context menu.
+ PopupMenu *get_menu() const;
+ bool is_menu_visible() const;
+ void menu_option(int p_option);
+
+ /* Versioning */
void begin_complex_operation();
void end_complex_operation();
- bool is_insert_text_operation();
-
- void set_text_direction(TextDirection p_text_direction);
- TextDirection get_text_direction() const;
+ bool has_undo() const;
+ bool has_redo() const;
+ void undo();
+ void redo();
+ void clear_undo_history();
- void set_opentype_feature(const String &p_name, int p_value);
- int get_opentype_feature(const String &p_name) const;
- void clear_opentype_features();
+ bool is_insert_text_operation() const;
- void set_language(const String &p_language);
- String get_language() const;
+ void tag_saved_version();
- void set_draw_control_chars(bool p_draw_control_chars);
- bool get_draw_control_chars() const;
+ uint32_t get_version() const;
+ uint32_t get_saved_version() const;
- void set_structured_text_bidi_override(Control::StructuredTextParser p_parser);
- Control::StructuredTextParser get_structured_text_bidi_override() const;
+ /* Search */
+ void set_search_text(const String &p_search_text);
+ void set_search_flags(uint32_t p_flags);
- void set_structured_text_bidi_override_options(Array p_args);
- Array get_structured_text_bidi_override_options() const;
+ Point2i search(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const;
- void set_text(String p_text);
- void insert_text_at_cursor(const String &p_text);
- void insert_at(const String &p_text, int at);
- int get_line_count() const;
- int get_line_width(int p_line, int p_wrap_offset = -1) const;
- int get_line_wrap_index_at_col(int p_line, int p_column) const;
-
- void set_line_as_hidden(int p_line, bool p_hidden);
- bool is_line_hidden(int p_line) const;
- void unhide_all_lines();
- int num_lines_from(int p_line_from, int visible_amount) const;
- int num_lines_from_rows(int p_line_from, int p_wrap_index_from, int visible_amount, int &wrap_index) const;
- int get_last_unhidden_line() const;
+ /* Mouse */
+ Point2 get_local_mouse_pos() const;
- String get_text();
- String get_line(int line) const;
- bool has_ime_text() const;
- void set_line(int line, String new_text);
- int get_row_height() const;
+ String get_word_at_pos(const Vector2 &p_pos) const;
- int get_indent_level(int p_line) const;
- int get_first_non_whitespace_column(int p_line) const;
+ Point2i get_line_column_at_pos(const Point2i &p_pos) const;
+ int get_minimap_line_at_pos(const Point2i &p_pos) const;
- inline void set_scroll_pass_end_of_file(bool p_enabled) {
- scroll_past_end_of_file_enabled = p_enabled;
- update();
- }
+ bool is_dragging_cursor() const;
- void center_viewport_to_cursor();
+ /* Caret */
+ void set_caret_type(CaretType p_type);
+ CaretType get_caret_type() const;
- void set_mid_grapheme_caret_enabled(const bool p_enabled);
- bool get_mid_grapheme_caret_enabled() const;
+ void set_caret_blink_enabled(const bool p_enabled);
+ bool is_caret_blink_enabled() const;
- void cursor_set_column(int p_col, bool p_adjust_viewport = true);
- void cursor_set_line(int p_row, bool p_adjust_viewport = true, bool p_can_be_hidden = true, int p_wrap_index = 0);
+ void set_caret_blink_speed(const float p_speed);
+ float get_caret_blink_speed() const;
- Point2 get_caret_draw_pos() const;
- bool is_caret_visible() const;
- int cursor_get_column() const;
- int cursor_get_line() const;
- Vector2i _get_cursor_pixel_pos(bool p_adjust_viewport = true);
+ void set_move_caret_on_right_click_enabled(const bool p_enable);
+ bool is_move_caret_on_right_click_enabled() const;
- bool cursor_get_blink_enabled() const;
- void cursor_set_blink_enabled(const bool p_enabled);
+ void set_caret_mid_grapheme_enabled(const bool p_enabled);
+ bool is_caret_mid_grapheme_enabled() const;
- float cursor_get_blink_speed() const;
- void cursor_set_blink_speed(const float p_speed);
+ bool is_caret_visible() const;
+ Point2 get_caret_draw_pos() const;
- void cursor_set_block_mode(const bool p_enable);
- bool cursor_is_block_mode() const;
+ void set_caret_line(int p_line, bool p_adjust_viewport = true, bool p_can_be_hidden = true, int p_wrap_index = 0);
+ int get_caret_line() const;
- void set_right_click_moves_caret(bool p_enable);
- bool is_right_click_moving_caret() const;
+ void set_caret_column(int p_col, bool p_adjust_viewport = true);
+ int get_caret_column() const;
- SelectionMode get_selection_mode() const;
- void set_selection_mode(SelectionMode p_mode, int p_line = -1, int p_column = -1);
- int get_selection_line() const;
- int get_selection_column() const;
+ int get_caret_wrap_index() const;
- void set_readonly(bool p_readonly);
- bool is_readonly() const;
+ String get_word_under_caret() const;
- void set_wrap_enabled(bool p_wrap_enabled);
- bool is_wrap_enabled() const;
- bool line_wraps(int line) const;
- int times_line_wraps(int line) const;
+ /* Selection. */
+ void set_selecting_enabled(const bool p_enabled);
+ bool is_selecting_enabled() const;
- void clear();
+ void set_override_selected_font_color(bool p_override_selected_font_color);
+ bool is_overriding_selected_font_color() const;
- void delete_selection();
+ void set_selection_mode(SelectionMode p_mode, int p_line = -1, int p_column = -1);
+ SelectionMode get_selection_mode() const;
- virtual void handle_unicode_input(uint32_t p_unicode);
- virtual void backspace();
- void cut();
- void copy();
- void paste();
void select_all();
void select_word_under_caret();
void select(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
- void deselect();
- void swap_lines(int line1, int line2);
- void set_search_text(const String &p_search_text);
- void set_search_flags(uint32_t p_flags);
- void set_current_search_result(int line, int col);
+ bool has_selection() const;
+
+ String get_selected_text() const;
+
+ int get_selection_line() const;
+ int get_selection_column() const;
- void set_highlight_all_occurrences(const bool p_enabled);
- bool is_highlight_all_occurrences_enabled() const;
- bool is_selection_active() const;
int get_selection_from_line() const;
int get_selection_from_column() const;
int get_selection_to_line() const;
int get_selection_to_column() const;
- String get_selection_text() const;
- String get_word_under_cursor() const;
- String get_word_at_pos(const Vector2 &p_pos) const;
+ void deselect();
+ void delete_selection();
- bool search(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column, int &r_line, int &r_column) const;
+ /* line wrapping. */
+ void set_line_wrapping_mode(LineWrappingMode p_wrapping_mode);
+ LineWrappingMode get_line_wrapping_mode() const;
- void undo();
- void redo();
- void clear_undo_history();
+ bool is_line_wrapped(int p_line) const;
+ int get_line_wrap_count(int p_line) const;
+ int get_line_wrap_index_at_column(int p_line, int p_column) const;
- void set_tab_size(const int p_size);
- int get_tab_size() const;
- void set_draw_tabs(bool p_draw);
- bool is_drawing_tabs() const;
- void set_draw_spaces(bool p_draw);
- bool is_drawing_spaces() const;
- void set_override_selected_font_color(bool p_override_selected_font_color);
- bool is_overriding_selected_font_color() const;
+ Vector<String> get_line_wrapped_text(int p_line) const;
- void set_insert_mode(bool p_enabled);
- bool is_insert_mode() const;
+ /* Viewport. */
+ // Scrolling.
+ void set_smooth_scroll_enabled(const bool p_enable);
+ bool is_smooth_scroll_enabled() const;
+
+ void set_scroll_past_end_of_file_enabled(const bool p_enabled);
+ bool is_scroll_past_end_of_file_enabled() const;
- double get_v_scroll() const;
void set_v_scroll(double p_scroll);
+ double get_v_scroll() const;
- int get_h_scroll() const;
void set_h_scroll(int p_scroll);
-
- void set_smooth_scroll_enabled(bool p_enable);
- bool is_smooth_scroll_enabled() const;
+ int get_h_scroll() const;
void set_v_scroll_speed(float p_speed);
float get_v_scroll_speed() const;
- uint32_t get_version() const;
- uint32_t get_saved_version() const;
- void tag_saved_version();
+ double get_scroll_pos_for_line(int p_line, int p_wrap_index = 0) const;
- void menu_option(int p_option);
+ // Visible lines.
+ void set_line_as_first_visible(int p_line, int p_wrap_index = 0);
+ int get_first_visible_line() const;
- void set_highlight_current_line(bool p_enabled);
- bool is_highlight_current_line_enabled() const;
+ void set_line_as_center_visible(int p_line, int p_wrap_index = 0);
+
+ void set_line_as_last_visible(int p_line, int p_wrap_index = 0);
+ int get_last_full_visible_line() const;
+ int get_last_full_visible_line_wrap_index() const;
+
+ int get_visible_line_count() const;
+ int get_total_visible_line_count() const;
+
+ // Auto Adjust
+ void adjust_viewport_to_caret();
+ void center_viewport_to_caret();
+ // Minimap
void set_draw_minimap(bool p_draw);
bool is_drawing_minimap() const;
void set_minimap_width(int p_minimap_width);
int get_minimap_width() const;
- void set_hiding_enabled(bool p_enabled);
- bool is_hiding_enabled() const;
+ int get_minimap_visible_lines() const;
- void set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata);
+ /* Gutters. */
+ void add_gutter(int p_at = -1);
+ void remove_gutter(int p_gutter);
+ int get_gutter_count() const;
- void set_context_menu_enabled(bool p_enable);
- bool is_context_menu_enabled();
+ void set_gutter_name(int p_gutter, const String &p_name);
+ String get_gutter_name(int p_gutter) const;
- void set_selecting_enabled(bool p_enabled);
- bool is_selecting_enabled() const;
+ void set_gutter_type(int p_gutter, GutterType p_type);
+ GutterType get_gutter_type(int p_gutter) const;
- void set_shortcut_keys_enabled(bool p_enabled);
- bool is_shortcut_keys_enabled() const;
+ void set_gutter_width(int p_gutter, int p_width);
+ int get_gutter_width(int p_gutter) const;
+ int get_total_gutter_width() const;
- void set_virtual_keyboard_enabled(bool p_enable);
- bool is_virtual_keyboard_enabled() const;
+ void set_gutter_draw(int p_gutter, bool p_draw);
+ bool is_gutter_drawn(int p_gutter) const;
- bool is_menu_visible() const;
- PopupMenu *get_menu() const;
+ void set_gutter_clickable(int p_gutter, bool p_clickable);
+ bool is_gutter_clickable(int p_gutter) const;
+
+ void set_gutter_overwritable(int p_gutter, bool p_overwritable);
+ bool is_gutter_overwritable(int p_gutter) const;
+
+ void merge_gutters(int p_from_line, int p_to_line);
+
+ void set_gutter_custom_draw(int p_gutter, Object *p_object, const StringName &p_callback);
+
+ // Line gutters.
+ void set_line_gutter_metadata(int p_line, int p_gutter, const Variant &p_metadata);
+ Variant get_line_gutter_metadata(int p_line, int p_gutter) const;
+
+ void set_line_gutter_text(int p_line, int p_gutter, const String &p_text);
+ String get_line_gutter_text(int p_line, int p_gutter) const;
+
+ void set_line_gutter_icon(int p_line, int p_gutter, const Ref<Texture2D> &p_icon);
+ Ref<Texture2D> get_line_gutter_icon(int p_line, int p_gutter) const;
+
+ void set_line_gutter_item_color(int p_line, int p_gutter, const Color &p_color);
+ Color get_line_gutter_item_color(int p_line, int p_gutter) const;
+
+ void set_line_gutter_clickable(int p_line, int p_gutter, bool p_clickable);
+ bool is_line_gutter_clickable(int p_line, int p_gutter) const;
+
+ // Line style
+ void set_line_background_color(int p_line, const Color &p_color);
+ Color get_line_background_color(int p_line) const;
+
+ /* Syntax Highlighting. */
+ void set_syntax_highlighter(Ref<SyntaxHighlighter> p_syntax_highlighter);
+ Ref<SyntaxHighlighter> get_syntax_highlighter() const;
+
+ /* Visual. */
+ void set_highlight_current_line(bool p_enabled);
+ bool is_highlight_current_line_enabled() const;
+
+ void set_highlight_all_occurrences(const bool p_enabled);
+ bool is_highlight_all_occurrences_enabled() const;
+
+ void set_draw_control_chars(bool p_draw_control_chars);
+ bool get_draw_control_chars() const;
+
+ void set_draw_tabs(bool p_draw);
+ bool is_drawing_tabs() const;
+
+ void set_draw_spaces(bool p_draw);
+ bool is_drawing_spaces() const;
- virtual bool is_text_field() const override;
TextEdit();
- ~TextEdit();
};
-VARIANT_ENUM_CAST(TextEdit::GutterType);
+VARIANT_ENUM_CAST(TextEdit::CaretType);
+VARIANT_ENUM_CAST(TextEdit::LineWrappingMode);
VARIANT_ENUM_CAST(TextEdit::SelectionMode);
+VARIANT_ENUM_CAST(TextEdit::GutterType);
VARIANT_ENUM_CAST(TextEdit::MenuItems);
VARIANT_ENUM_CAST(TextEdit::SearchFlags);
diff --git a/scene/gui/texture_progress_bar.cpp b/scene/gui/texture_progress_bar.cpp
index 5e5dec3579..286f01ee33 100644
--- a/scene/gui/texture_progress_bar.cpp
+++ b/scene/gui/texture_progress_bar.cpp
@@ -100,6 +100,15 @@ Ref<Texture2D> TextureProgressBar::get_progress_texture() const {
return progress;
}
+void TextureProgressBar::set_progress_offset(Point2 p_offset) {
+ progress_offset = p_offset;
+ update();
+}
+
+Point2 TextureProgressBar::get_progress_offset() const {
+ return progress_offset;
+}
+
void TextureProgressBar::set_tint_under(const Color &p_tint) {
tint_under = p_tint;
update();
@@ -360,6 +369,9 @@ void TextureProgressBar::draw_nine_patch_stretched(const Ref<Texture2D> &p_textu
}
}
+ if (p_texture == progress) {
+ dst_rect.position += progress_offset;
+ }
p_texture->get_rect_region(dst_rect, src_rect, dst_rect, src_rect);
RID ci = get_canvas_item();
@@ -403,20 +415,24 @@ void TextureProgressBar::_notification(int p_what) {
Size2 s = progress->get_size();
switch (mode) {
case FILL_LEFT_TO_RIGHT: {
- Rect2 region = Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y));
- draw_texture_rect_region(progress, region, region, tint_progress);
+ Rect2 region = Rect2(progress_offset, Size2(s.x * get_as_ratio(), s.y));
+ Rect2 source = Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y));
+ draw_texture_rect_region(progress, region, source, tint_progress);
} break;
case FILL_RIGHT_TO_LEFT: {
- Rect2 region = Rect2(Point2(s.x - s.x * get_as_ratio(), 0), Size2(s.x * get_as_ratio(), s.y));
- draw_texture_rect_region(progress, region, region, tint_progress);
+ Rect2 region = Rect2(progress_offset + Point2(s.x - s.x * get_as_ratio(), 0), Size2(s.x * get_as_ratio(), s.y));
+ Rect2 source = Rect2(Point2(s.x - s.x * get_as_ratio(), 0), Size2(s.x * get_as_ratio(), s.y));
+ draw_texture_rect_region(progress, region, source, tint_progress);
} break;
case FILL_TOP_TO_BOTTOM: {
- Rect2 region = Rect2(Point2(), Size2(s.x, s.y * get_as_ratio()));
- draw_texture_rect_region(progress, region, region, tint_progress);
+ Rect2 region = Rect2(progress_offset + Point2(), Size2(s.x, s.y * get_as_ratio()));
+ Rect2 source = Rect2(Point2(), Size2(s.x, s.y * get_as_ratio()));
+ draw_texture_rect_region(progress, region, source, tint_progress);
} break;
case FILL_BOTTOM_TO_TOP: {
- Rect2 region = Rect2(Point2(0, s.y - s.y * get_as_ratio()), Size2(s.x, s.y * get_as_ratio()));
- draw_texture_rect_region(progress, region, region, tint_progress);
+ Rect2 region = Rect2(progress_offset + Point2(0, s.y - s.y * get_as_ratio()), Size2(s.x, s.y * get_as_ratio()));
+ Rect2 source = Rect2(Point2(0, s.y - s.y * get_as_ratio()), Size2(s.x, s.y * get_as_ratio()));
+ draw_texture_rect_region(progress, region, source, tint_progress);
} break;
case FILL_CLOCKWISE:
case FILL_COUNTER_CLOCKWISE:
@@ -427,8 +443,9 @@ void TextureProgressBar::_notification(int p_what) {
float val = get_as_ratio() * rad_max_degrees / 360;
if (val == 1) {
- Rect2 region = Rect2(Point2(), s);
- draw_texture_rect(progress, region, false, tint_progress);
+ Rect2 region = Rect2(progress_offset, s);
+ Rect2 source = Rect2(Point2(), s);
+ draw_texture_rect_region(progress, region, source, tint_progress);
} else if (val != 0) {
Array pts;
float direction = mode == FILL_COUNTER_CLOCKWISE ? -1 : 1;
@@ -454,14 +471,14 @@ void TextureProgressBar::_notification(int p_what) {
Vector<Point2> uvs;
Vector<Point2> points;
uvs.push_back(get_relative_center());
- points.push_back(Point2(s.x * get_relative_center().x, s.y * get_relative_center().y));
+ points.push_back(progress_offset + Point2(s.x * get_relative_center().x, s.y * get_relative_center().y));
for (int i = 0; i < pts.size(); i++) {
Point2 uv = unit_val_to_uv(pts[i]);
if (uvs.find(uv) >= 0) {
continue;
}
uvs.push_back(uv);
- points.push_back(Point2(uv.x * s.x, uv.y * s.y));
+ points.push_back(progress_offset + Point2(uv.x * s.x, uv.y * s.y));
}
Vector<Color> colors;
colors.push_back(tint_progress);
@@ -484,17 +501,19 @@ void TextureProgressBar::_notification(int p_what) {
}
} break;
case FILL_BILINEAR_LEFT_AND_RIGHT: {
- Rect2 region = Rect2(Point2(s.x / 2 - s.x * get_as_ratio() / 2, 0), Size2(s.x * get_as_ratio(), s.y));
- draw_texture_rect_region(progress, region, region, tint_progress);
+ Rect2 region = Rect2(progress_offset + Point2(s.x / 2 - s.x * get_as_ratio() / 2, 0), Size2(s.x * get_as_ratio(), s.y));
+ Rect2 source = Rect2(Point2(s.x / 2 - s.x * get_as_ratio() / 2, 0), Size2(s.x * get_as_ratio(), s.y));
+ draw_texture_rect_region(progress, region, source, tint_progress);
} break;
case FILL_BILINEAR_TOP_AND_BOTTOM: {
- Rect2 region = Rect2(Point2(0, s.y / 2 - s.y * get_as_ratio() / 2), Size2(s.x, s.y * get_as_ratio()));
- draw_texture_rect_region(progress, region, region, tint_progress);
+ Rect2 region = Rect2(progress_offset + Point2(0, s.y / 2 - s.y * get_as_ratio() / 2), Size2(s.x, s.y * get_as_ratio()));
+ Rect2 source = Rect2(Point2(0, s.y / 2 - s.y * get_as_ratio() / 2), Size2(s.x, s.y * get_as_ratio()));
+ draw_texture_rect_region(progress, region, source, tint_progress);
} break;
case FILL_MODE_MAX:
break;
default:
- draw_texture_rect_region(progress, Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), tint_progress);
+ draw_texture_rect_region(progress, Rect2(progress_offset, Size2(s.x * get_as_ratio(), s.y)), Rect2(Point2(), Size2(s.x * get_as_ratio(), s.y)), tint_progress);
}
}
if (over.is_valid()) {
@@ -585,6 +604,9 @@ void TextureProgressBar::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_tint_over", "tint"), &TextureProgressBar::set_tint_over);
ClassDB::bind_method(D_METHOD("get_tint_over"), &TextureProgressBar::get_tint_over);
+ ClassDB::bind_method(D_METHOD("set_texture_progress_offset", "offset"), &TextureProgressBar::set_progress_offset);
+ ClassDB::bind_method(D_METHOD("get_texture_progress_offset"), &TextureProgressBar::get_progress_offset);
+
ClassDB::bind_method(D_METHOD("set_radial_initial_angle", "mode"), &TextureProgressBar::set_radial_initial_angle);
ClassDB::bind_method(D_METHOD("get_radial_initial_angle"), &TextureProgressBar::get_radial_initial_angle);
@@ -604,6 +626,7 @@ void TextureProgressBar::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_under", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_under_texture", "get_under_texture");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_over", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_over_texture", "get_over_texture");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_progress", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_progress_texture", "get_progress_texture");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_progress_offset"), "set_texture_progress_offset", "get_texture_progress_offset");
ADD_PROPERTY(PropertyInfo(Variant::INT, "fill_mode", PROPERTY_HINT_ENUM, "Left to Right,Right to Left,Top to Bottom,Bottom to Top,Clockwise,Counter Clockwise,Bilinear (Left and Right),Bilinear (Top and Bottom),Clockwise and Counter Clockwise"), "set_fill_mode", "get_fill_mode");
ADD_GROUP("Tint", "tint_");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "tint_under"), "set_tint_under", "get_tint_under");
diff --git a/scene/gui/texture_progress_bar.h b/scene/gui/texture_progress_bar.h
index d147c43a26..c508f41387 100644
--- a/scene/gui/texture_progress_bar.h
+++ b/scene/gui/texture_progress_bar.h
@@ -61,6 +61,9 @@ public:
void set_fill_mode(int p_fill);
int get_fill_mode();
+ void set_progress_offset(Point2 p_offset);
+ Point2 get_progress_offset() const;
+
void set_radial_initial_angle(float p_angle);
float get_radial_initial_angle();
@@ -100,6 +103,7 @@ public:
private:
FillMode mode = FILL_LEFT_TO_RIGHT;
+ Point2 progress_offset;
float rad_init_angle = 0.0;
float rad_max_degrees = 360.0;
Point2 rad_center_off;
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 09db3205d9..cb990892ed 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -167,6 +167,18 @@ TreeItem::TreeCellMode TreeItem::get_cell_mode(int p_column) const {
void TreeItem::set_checked(int p_column, bool p_checked) {
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].checked = p_checked;
+ cells.write[p_column].indeterminate = false;
+ _changed_notify(p_column);
+}
+
+void TreeItem::set_indeterminate(int p_column, bool p_indeterminate) {
+ ERR_FAIL_INDEX(p_column, cells.size());
+ // Prevent uncheck if indeterminate set to false twice
+ if (p_indeterminate == cells[p_column].indeterminate) {
+ return;
+ }
+ cells.write[p_column].indeterminate = p_indeterminate;
+ cells.write[p_column].checked = false;
_changed_notify(p_column);
}
@@ -175,6 +187,11 @@ bool TreeItem::is_checked(int p_column) const {
return cells[p_column].checked;
}
+bool TreeItem::is_indeterminate(int p_column) const {
+ ERR_FAIL_INDEX_V(p_column, cells.size(), false);
+ return cells[p_column].indeterminate;
+}
+
void TreeItem::set_text(int p_column, String p_text) {
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].text = p_text;
@@ -872,11 +889,22 @@ void TreeItem::set_custom_font(int p_column, const Ref<Font> &p_font) {
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].custom_font = p_font;
}
+
Ref<Font> TreeItem::get_custom_font(int p_column) const {
ERR_FAIL_INDEX_V(p_column, cells.size(), Ref<Font>());
return cells[p_column].custom_font;
}
+void TreeItem::set_custom_font_size(int p_column, int p_font_size) {
+ ERR_FAIL_INDEX(p_column, cells.size());
+ cells.write[p_column].custom_font_size = p_font_size;
+}
+
+int TreeItem::get_custom_font_size(int p_column) const {
+ ERR_FAIL_INDEX_V(p_column, cells.size(), -1);
+ return cells[p_column].custom_font_size;
+}
+
void TreeItem::set_tooltip(int p_column, const String &p_tooltip) {
ERR_FAIL_INDEX(p_column, cells.size());
cells.write[p_column].tooltip = p_tooltip;
@@ -1042,7 +1070,9 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_cell_mode", "column"), &TreeItem::get_cell_mode);
ClassDB::bind_method(D_METHOD("set_checked", "column", "checked"), &TreeItem::set_checked);
+ ClassDB::bind_method(D_METHOD("set_indeterminate", "column", "indeterminate"), &TreeItem::set_indeterminate);
ClassDB::bind_method(D_METHOD("is_checked", "column"), &TreeItem::is_checked);
+ ClassDB::bind_method(D_METHOD("is_indeterminate", "column"), &TreeItem::is_indeterminate);
ClassDB::bind_method(D_METHOD("set_text", "column", "text"), &TreeItem::set_text);
ClassDB::bind_method(D_METHOD("get_text", "column"), &TreeItem::get_text);
@@ -1113,6 +1143,9 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_custom_font", "column", "font"), &TreeItem::set_custom_font);
ClassDB::bind_method(D_METHOD("get_custom_font", "column"), &TreeItem::get_custom_font);
+ ClassDB::bind_method(D_METHOD("set_custom_font_size", "column", "font_size"), &TreeItem::set_custom_font_size);
+ ClassDB::bind_method(D_METHOD("get_custom_font_size", "column"), &TreeItem::get_custom_font_size);
+
ClassDB::bind_method(D_METHOD("set_custom_bg_color", "column", "color", "just_outline"), &TreeItem::set_custom_bg_color, DEFVAL(false));
ClassDB::bind_method(D_METHOD("clear_custom_bg_color", "column"), &TreeItem::clear_custom_bg_color);
ClassDB::bind_method(D_METHOD("get_custom_bg_color", "column"), &TreeItem::get_custom_bg_color);
@@ -1228,6 +1261,7 @@ void Tree::update_cache() {
cache.checked = get_theme_icon(SNAME("checked"));
cache.unchecked = get_theme_icon(SNAME("unchecked"));
+ cache.indeterminate = get_theme_icon(SNAME("indeterminate"));
if (is_layout_rtl()) {
cache.arrow_collapsed = get_theme_icon(SNAME("arrow_collapsed_mirrored"));
} else {
@@ -1487,7 +1521,14 @@ void Tree::update_item_cell(TreeItem *p_item, int p_col) {
} else {
font = cache.font;
}
- p_item->cells.write[p_col].text_buf->add_string(valtext, font, cache.font_size, p_item->cells[p_col].opentype_features, (p_item->cells[p_col].language != "") ? p_item->cells[p_col].language : TranslationServer::get_singleton()->get_tool_locale());
+
+ int font_size;
+ if (p_item->cells[p_col].custom_font_size > 0) {
+ font_size = p_item->cells[p_col].custom_font_size;
+ } else {
+ font_size = cache.font_size;
+ }
+ p_item->cells.write[p_col].text_buf->add_string(valtext, font, font_size, p_item->cells[p_col].opentype_features, (p_item->cells[p_col].language != "") ? p_item->cells[p_col].language : TranslationServer::get_singleton()->get_tool_locale());
TS->shaped_text_set_bidi_override(p_item->cells[p_col].text_buf->get_rid(), structured_text_parser(p_item->cells[p_col].st_parser, p_item->cells[p_col].st_args, valtext));
p_item->cells.write[p_col].dirty = false;
}
@@ -1676,24 +1717,30 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
}
}
- if (drop_mode_flags && drop_mode_over == p_item) {
+ if (drop_mode_flags && drop_mode_over) {
Rect2 r = cell_rect;
- bool has_parent = p_item->get_first_child() != nullptr;
if (rtl) {
r.position.x = get_size().width - r.position.x - r.size.x;
}
-
- if (drop_mode_section == -1 || has_parent || drop_mode_section == 0) {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), cache.drop_position_color);
- }
-
- if (drop_mode_section == 0) {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), cache.drop_position_color);
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), cache.drop_position_color);
- }
-
- if ((drop_mode_section == 1 && !has_parent) || drop_mode_section == 0) {
- RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y, r.size.x, 1), cache.drop_position_color);
+ if (drop_mode_over == p_item) {
+ if (drop_mode_section == 0 || drop_mode_section == -1) {
+ // Line above.
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), cache.drop_position_color);
+ }
+ if (drop_mode_section == 0) {
+ // Side lines.
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, 1, r.size.y), cache.drop_position_color);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x + r.size.x - 1, r.position.y, 1, r.size.y), cache.drop_position_color);
+ }
+ if (drop_mode_section == 0 || (drop_mode_section == 1 && (!p_item->get_first_child() || p_item->is_collapsed()))) {
+ // Line below.
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y + r.size.y, r.size.x, 1), cache.drop_position_color);
+ }
+ } else if (drop_mode_over == p_item->get_parent()) {
+ if (drop_mode_section == 1 && !p_item->get_prev() /* && !drop_mode_over->is_collapsed() */) { // The drop_mode_over shouldn't ever be collapsed in here, otherwise we would be drawing a child of a collapsed item.
+ // Line above.
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(r.position.x, r.position.y, r.size.x, 1), cache.drop_position_color);
+ }
}
}
@@ -1721,10 +1768,13 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
case TreeItem::CELL_MODE_CHECK: {
Ref<Texture2D> checked = cache.checked;
Ref<Texture2D> unchecked = cache.unchecked;
+ Ref<Texture2D> indeterminate = cache.indeterminate;
Point2i check_ofs = item_rect.position;
check_ofs.y += Math::floor((real_t)(item_rect.size.y - checked->get_height()) / 2);
- if (p_item->cells[i].checked) {
+ if (p_item->cells[i].indeterminate) {
+ indeterminate->draw(ci, check_ofs);
+ } else if (p_item->cells[i].checked) {
checked->draw(ci, check_ofs);
} else {
unchecked->draw(ci, check_ofs);
@@ -2745,7 +2795,7 @@ void Tree::_go_down() {
accept_event();
}
-void Tree::_gui_input(Ref<InputEvent> p_event) {
+void Tree::gui_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(p_event.is_null());
Ref<InputEventKey> k = p_event;
@@ -4627,8 +4677,6 @@ bool Tree::get_allow_reselect() const {
}
void Tree::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_gui_input"), &Tree::_gui_input);
-
ClassDB::bind_method(D_METHOD("clear"), &Tree::clear);
ClassDB::bind_method(D_METHOD("create_item", "parent", "idx"), &Tree::_create_item, DEFVAL(Variant()), DEFVAL(-1));
@@ -4747,12 +4795,11 @@ Tree::Tree() {
popup_menu = memnew(PopupMenu);
popup_menu->hide();
- add_child(popup_menu);
- // popup_menu->set_as_top_level(true);
+ add_child(popup_menu, false, INTERNAL_MODE_FRONT);
popup_editor = memnew(Popup);
popup_editor->set_wrap_controls(true);
- add_child(popup_editor);
+ add_child(popup_editor, false, INTERNAL_MODE_FRONT);
popup_editor_vb = memnew(VBoxContainer);
popup_editor->add_child(popup_editor_vb);
popup_editor_vb->add_theme_constant_override("separation", 0);
@@ -4770,12 +4817,12 @@ Tree::Tree() {
h_scroll = memnew(HScrollBar);
v_scroll = memnew(VScrollBar);
- add_child(h_scroll);
- add_child(v_scroll);
+ add_child(h_scroll, false, INTERNAL_MODE_FRONT);
+ add_child(v_scroll, false, INTERNAL_MODE_FRONT);
range_click_timer = memnew(Timer);
range_click_timer->connect("timeout", callable_mp(this, &Tree::_range_click_timeout));
- add_child(range_click_timer);
+ add_child(range_click_timer, false, INTERNAL_MODE_FRONT);
h_scroll->connect("value_changed", callable_mp(this, &Tree::_scroll_moved));
v_scroll->connect("value_changed", callable_mp(this, &Tree::_scroll_moved));
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index be711b4c4f..8b7ddc3faf 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -82,6 +82,7 @@ private:
int icon_max_w = 0;
bool expr = false;
bool checked = false;
+ bool indeterminate = false;
bool editable = false;
bool selected = false;
bool selectable = true;
@@ -113,6 +114,7 @@ private:
Vector<Button> buttons;
Ref<Font> custom_font;
+ int custom_font_size = -1;
Cell() {
text_buf.instantiate();
@@ -209,7 +211,9 @@ public:
/* check mode */
void set_checked(int p_column, bool p_checked);
+ void set_indeterminate(int p_column, bool p_indeterminate);
bool is_checked(int p_column) const;
+ bool is_indeterminate(int p_column) const;
void set_text(int p_column, String p_text);
String get_text(int p_column) const;
@@ -296,6 +300,9 @@ public:
void set_custom_font(int p_column, const Ref<Font> &p_font);
Ref<Font> get_custom_font(int p_column) const;
+ void set_custom_font_size(int p_column, int p_font_size);
+ int get_custom_font_size(int p_column) const;
+
void set_custom_bg_color(int p_column, const Color &p_color, bool p_bg_outline = false);
void clear_custom_bg_color(int p_column);
Color get_custom_bg_color(int p_column) const;
@@ -459,7 +466,6 @@ private:
void popup_select(int p_option);
- void _gui_input(Ref<InputEvent> p_event);
void _notification(int p_what);
void item_edited(int p_column, TreeItem *p_item, bool p_lmb = true);
@@ -491,6 +497,7 @@ private:
Ref<Texture2D> checked;
Ref<Texture2D> unchecked;
+ Ref<Texture2D> indeterminate;
Ref<Texture2D> arrow_collapsed;
Ref<Texture2D> arrow;
Ref<Texture2D> select_arrow;
@@ -622,6 +629,8 @@ protected:
}
public:
+ virtual void gui_input(const Ref<InputEvent> &p_event) override;
+
virtual String get_tooltip(const Point2 &p_pos) const override;
TreeItem *get_item_at_position(const Point2 &p_pos) const;
diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp
index 229b5384ea..8734037a57 100644
--- a/scene/gui/video_player.cpp
+++ b/scene/gui/video_player.cpp
@@ -129,7 +129,7 @@ void VideoPlayer::_mix_audio() {
void VideoPlayer::_notification(int p_notification) {
switch (p_notification) {
case NOTIFICATION_ENTER_TREE: {
- AudioServer::get_singleton()->add_callback(_mix_audios, this);
+ AudioServer::get_singleton()->add_mix_callback(_mix_audios, this);
if (stream.is_valid() && autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
@@ -138,8 +138,7 @@ void VideoPlayer::_notification(int p_notification) {
} break;
case NOTIFICATION_EXIT_TREE: {
- AudioServer::get_singleton()->remove_callback(_mix_audios, this);
-
+ AudioServer::get_singleton()->remove_mix_callback(_mix_audios, this);
} break;
case NOTIFICATION_INTERNAL_PROCESS: {