summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/button.cpp4
-rw-r--r--scene/gui/code_edit.cpp515
-rw-r--r--scene/gui/code_edit.h55
-rw-r--r--scene/gui/control.cpp210
-rw-r--r--scene/gui/control.h8
-rw-r--r--scene/gui/dialogs.cpp3
-rw-r--r--scene/gui/file_dialog.cpp6
-rw-r--r--scene/gui/graph_edit.cpp76
-rw-r--r--scene/gui/label.cpp4
-rw-r--r--scene/gui/line_edit.cpp4
-rw-r--r--scene/gui/menu_button.cpp54
-rw-r--r--scene/gui/menu_button.h4
-rw-r--r--scene/gui/popup.cpp1
-rw-r--r--scene/gui/popup_menu.cpp32
-rw-r--r--scene/gui/popup_menu.h1
-rw-r--r--scene/gui/rich_text_label.cpp42
-rw-r--r--scene/gui/tab_container.cpp11
-rw-r--r--scene/gui/tabs.cpp6
-rw-r--r--scene/gui/text_edit.cpp376
-rw-r--r--scene/gui/text_edit.h37
-rw-r--r--scene/gui/tree.h4
21 files changed, 823 insertions, 630 deletions
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index 4b6c0ef697..9cdf3bf210 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -79,7 +79,7 @@ void Button::_notification(int p_what) {
update();
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
- xl_text = tr(text);
+ xl_text = atr(text);
_shape();
minimum_size_changed();
@@ -355,7 +355,7 @@ void Button::_shape() {
void Button::set_text(const String &p_text) {
if (text != p_text) {
text = p_text;
- xl_text = tr(text);
+ xl_text = atr(text);
_shape();
update();
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index f302f64224..32922f609d 100644
--- a/scene/gui/code_edit.cpp
+++ b/scene/gui/code_edit.cpp
@@ -72,13 +72,34 @@ void CodeEdit::_notification(int p_what) {
code_completion_background_color = get_theme_color(SNAME("completion_background_color"));
code_completion_selected_color = get_theme_color(SNAME("completion_selected_color"));
code_completion_existing_color = get_theme_color(SNAME("completion_existing_color"));
+
+ line_length_guideline_color = get_theme_color(SNAME("line_length_guideline_color"));
} break;
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
+ 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();
+ 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;
+
+ 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();
+ if (xoffset > xmargin_beg && xoffset < xmargin_end) {
+ Color guideline_color = (i == 0) ? line_length_guideline_color : line_length_guideline_color * Color(1, 1, 1, 0.5);
+ if (rtl) {
+ RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(size.width - xoffset, 0), Point2(size.width - xoffset, size.height), guideline_color);
+ continue;
+ }
+ RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(xoffset, 0), Point2(xoffset, size.height), guideline_color);
+ }
+ }
+ }
+
bool code_completion_below = false;
if (caret_visible && code_completion_active && code_completion_options.size() > 0) {
Ref<StyleBox> csb = get_theme_stylebox(SNAME("completion"));
@@ -204,8 +225,15 @@ void CodeEdit::_notification(int p_what) {
round_ofs = round_ofs.round();
draw_string(font, round_ofs, line.replace(String::chr(0xFFFF), ""), HALIGN_LEFT, -1, cache.font_size, font_color);
if (end > 0) {
- Vector2 b = hint_ofs + sb->get_offset() + Vector2(begin, font_height + font_height * i + line_spacing - 1);
- draw_line(b, b + Vector2(end - begin, 0), font_color);
+ // 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);
+ draw_line(b, b + Vector2(end - begin, 0), font_color, 2);
+
+ // Draw a translucent text highlight as well.
+ const Rect2 highlight_rect = Rect2(
+ hint_ofs + sb->get_offset() + Vector2(begin, 0),
+ Vector2(end - begin, font_height));
+ draw_rect(highlight_rect, font_color * Color(1, 1, 1, 0.2));
}
line_spacing += cache.line_spacing;
}
@@ -278,6 +306,39 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
}
+ } else {
+ if (mb->get_button_index() == MOUSE_BUTTON_LEFT) {
+ if (mb->is_command_pressed() && symbol_lookup_word != String()) {
+ Vector2i mpos = mb->get_position();
+ if (is_layout_rtl()) {
+ mpos.x = get_size().x - mpos.x;
+ }
+ int line, col;
+ _get_mouse_pos(Point2i(mpos.x, mpos.y), line, col);
+
+ emit_signal(SNAME("symbol_lookup"), symbol_lookup_word, line, col);
+ return;
+ }
+ }
+ }
+ }
+
+ Ref<InputEventMouseMotion> mm = p_gui_input;
+ if (mm.is_valid()) {
+ Vector2i mpos = mm->get_position();
+ if (is_layout_rtl()) {
+ mpos.x = get_size().x - mpos.x;
+ }
+
+ if (symbol_lookup_on_click_enabled) {
+ if (mm->is_command_pressed() && mm->get_button_mask() == 0 && !is_dragging_cursor()) {
+ symbol_lookup_new_word = get_word_at_pos(mpos);
+ if (symbol_lookup_new_word != symbol_lookup_word) {
+ emit_signal(SNAME("symbol_validate"), symbol_lookup_new_word);
+ }
+ } else {
+ set_symbol_lookup_word_as_valid(false);
+ }
}
}
@@ -288,6 +349,25 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
return;
}
+ /* Ctrl + Hover symbols */
+#ifdef OSX_ENABLED
+ if (k->get_keycode() == KEY_META) {
+#else
+ if (k->get_keycode() == KEY_CTRL) {
+#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());
+ if (symbol_lookup_new_word != symbol_lookup_word) {
+ emit_signal(SNAME("symbol_validate"), symbol_lookup_new_word);
+ }
+ } else {
+ set_symbol_lookup_word_as_valid(false);
+ }
+ }
+ return;
+ }
+
/* If a modifier has been pressed, and nothing else, return. */
if (!k->is_pressed() || k->get_keycode() == KEY_CTRL || k->get_keycode() == KEY_ALT || k->get_keycode() == KEY_SHIFT || k->get_keycode() == KEY_META) {
return;
@@ -437,7 +517,12 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
+/* General overrides */
Control::CursorShape CodeEdit::get_cursor_shape(const Point2 &p_pos) const {
+ if (symbol_lookup_word != String()) {
+ return CURSOR_POINTING_HAND;
+ }
+
if ((code_completion_active && code_completion_rect.has_point(p_pos)) || (is_readonly() && (!is_selecting_enabled() || get_line_count() == 0))) {
return CURSOR_ARROW;
}
@@ -459,6 +544,58 @@ 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();
+ 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) {
+ 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);
+ }
+ }
+
+ 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 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);
+ } else if (cc < get_line(cl).length() && _is_char(get_line(cl)[cc])) {
+ insert_text_at_cursor(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);
+ } else {
+ insert_text_at_cursor(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);
+ }
+ }
+ cursor_set_column(cc + caret_move_offset);
+ } else {
+ insert_text_at_cursor(chr);
+ }
+
+ if ((is_insert_mode() && !had_selection) || (had_selection)) {
+ end_complex_operation();
+ }
+}
+
/* 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.");
@@ -527,13 +664,13 @@ void CodeEdit::do_indent() {
}
if (!indent_using_spaces) {
- _insert_text_at_cursor("\t");
+ insert_text_at_cursor("\t");
return;
}
int spaces_to_add = _calculate_spaces_till_next_right_indent(cursor_get_column());
if (spaces_to_add > 0) {
- _insert_text_at_cursor(String(" ").repeat(spaces_to_add));
+ insert_text_at_cursor(String(" ").repeat(spaces_to_add));
}
}
@@ -713,34 +850,6 @@ int CodeEdit::_calculate_spaces_till_next_right_indent(int p_column) const {
return indent_size - p_column % indent_size;
}
-/* TODO: remove once brace completion is refactored. */
-static char32_t _get_right_pair_symbol(char32_t c) {
- if (c == '"') {
- return '"';
- }
- if (c == '\'') {
- return '\'';
- }
- if (c == '(') {
- return ')';
- }
- if (c == '[') {
- return ']';
- }
- if (c == '{') {
- return '}';
- }
- return 0;
-}
-
-static bool _is_pair_left_symbol(char32_t c) {
- return c == '"' ||
- c == '\'' ||
- c == '(' ||
- c == '[' ||
- c == '{';
-}
-
void CodeEdit::_new_line(bool p_split_current_line, bool p_above) {
if (is_readonly()) {
return;
@@ -803,9 +912,8 @@ void CodeEdit::_new_line(bool p_split_current_line, bool p_above) {
if (should_indent) {
ins += indent_text;
- /* TODO: Change when brace completion is refactored. */
- char32_t closing_char = _get_right_pair_symbol(indent_char);
- if (closing_char != 0 && closing_char == line[cc]) {
+ String closing_pair = get_auto_brace_completion_close_key(String::chr(indent_char));
+ if (!closing_pair.is_empty() && line.find(closing_pair, cc) == cc) {
/* No need to move the brace below if we are not taking the text with us. */
if (p_split_current_line) {
brace_indent = true;
@@ -873,12 +981,20 @@ void CodeEdit::backspace() {
merge_gutters(cl, prev_line);
- /* TODO: Change when brace completion is refactored. */
- if (auto_brace_completion_enabled && cc > 0 && _is_pair_left_symbol(get_line(cl)[cc - 1])) {
- _consume_backspace_for_pair_symbol(prev_line, prev_column);
- cursor_set_line(prev_line, false, true);
- cursor_set_column(prev_column);
- return;
+ 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 */
@@ -896,6 +1012,93 @@ void CodeEdit::backspace() {
cursor_set_column(prev_column);
}
+/* Auto brace completion */
+void CodeEdit::set_auto_brace_completion_enabled(bool p_enabled) {
+ auto_brace_completion_enabled = p_enabled;
+}
+
+bool CodeEdit::is_auto_brace_completion_enabled() const {
+ return auto_brace_completion_enabled;
+}
+
+void CodeEdit::set_highlight_matching_braces_enabled(bool p_enabled) {
+ highlight_matching_braces_enabled = p_enabled;
+ update();
+}
+
+bool CodeEdit::is_highlight_matching_braces_enabled() const {
+ return highlight_matching_braces_enabled;
+}
+
+void CodeEdit::add_auto_brace_completion_pair(const String &p_open_key, const String &p_close_key) {
+ ERR_FAIL_COND_MSG(p_open_key.is_empty(), "auto brace completion open key cannot be empty");
+ ERR_FAIL_COND_MSG(p_close_key.is_empty(), "auto brace completion close key cannot be empty");
+
+ for (int i = 0; i < p_open_key.length(); i++) {
+ ERR_FAIL_COND_MSG(!is_symbol(p_open_key[i]), "auto brace completion open key must be a symbol");
+ }
+ for (int i = 0; i < p_close_key.length(); i++) {
+ ERR_FAIL_COND_MSG(!is_symbol(p_close_key[i]), "auto brace completion close key must be a symbol");
+ }
+
+ int at = 0;
+ for (int i = 0; i < auto_brace_completion_pairs.size(); i++) {
+ ERR_FAIL_COND_MSG(auto_brace_completion_pairs[i].open_key == p_open_key, "auto brace completion open key '" + p_open_key + "' already exists.");
+ if (p_open_key.length() < auto_brace_completion_pairs[i].open_key.length()) {
+ at++;
+ }
+ }
+
+ BracePair brace_pair;
+ brace_pair.open_key = p_open_key;
+ brace_pair.close_key = p_close_key;
+ auto_brace_completion_pairs.insert(at, brace_pair);
+}
+
+void CodeEdit::set_auto_brace_completion_pairs(const Dictionary &p_auto_brace_completion_pairs) {
+ auto_brace_completion_pairs.clear();
+
+ Array keys = p_auto_brace_completion_pairs.keys();
+ for (int i = 0; i < keys.size(); i++) {
+ add_auto_brace_completion_pair(keys[i], p_auto_brace_completion_pairs[keys[i]]);
+ }
+}
+
+Dictionary CodeEdit::get_auto_brace_completion_pairs() const {
+ Dictionary brace_pairs;
+ for (int i = 0; i < auto_brace_completion_pairs.size(); i++) {
+ brace_pairs[auto_brace_completion_pairs[i].open_key] = auto_brace_completion_pairs[i].close_key;
+ }
+ return brace_pairs;
+}
+
+bool CodeEdit::has_auto_brace_completion_open_key(const String &p_open_key) const {
+ for (int i = 0; i < auto_brace_completion_pairs.size(); i++) {
+ if (auto_brace_completion_pairs[i].open_key == p_open_key) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool CodeEdit::has_auto_brace_completion_close_key(const String &p_close_key) const {
+ for (int i = 0; i < auto_brace_completion_pairs.size(); i++) {
+ if (auto_brace_completion_pairs[i].close_key == p_close_key) {
+ return true;
+ }
+ }
+ return false;
+}
+
+String CodeEdit::get_auto_brace_completion_close_key(const String &p_open_key) const {
+ for (int i = 0; i < auto_brace_completion_pairs.size(); i++) {
+ if (auto_brace_completion_pairs[i].open_key == p_open_key) {
+ return auto_brace_completion_pairs[i].close_key;
+ }
+ }
+ return String();
+}
+
/* Main Gutter */
void CodeEdit::_update_draw_main_gutter() {
set_gutter_draw(main_gutter, draw_breakpoints || draw_bookmarks || draw_executing_lines);
@@ -1700,35 +1903,40 @@ void CodeEdit::confirm_code_completion(bool p_replace) {
insert_text_at_cursor(insert_text.substr(matching_chars));
}
- /* TODO: merge with autobrace completion, when in CodeEdit. */
/* Handle merging of symbols eg strings, brackets. */
const String line = get_line(caret_line);
char32_t next_char = line[cursor_get_column()];
char32_t last_completion_char = insert_text[insert_text.length() - 1];
char32_t last_completion_char_display = display_text[display_text.length() - 1];
- if ((last_completion_char == '"' || last_completion_char == '\'') && (last_completion_char == next_char || last_completion_char_display == next_char)) {
+ 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;
+
+ 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);
}
- if (last_completion_char == '(') {
- if (next_char == last_completion_char) {
- _remove_text(caret_line, cursor_get_column() - 1, caret_line, cursor_get_column());
- } else if (auto_brace_completion_enabled) {
- insert_text_at_cursor(")");
- cursor_set_column(cursor_get_column() - 1);
- }
- } else if (last_completion_char == ')' && next_char == '(') {
- _remove_text(caret_line, cursor_get_column() - 2, caret_line, cursor_get_column());
- if (line[cursor_get_column() + 1] != ')') {
- cursor_set_column(cursor_get_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);
+ } 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());
+ }
+
+ 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);
+ }
}
}
end_complex_operation();
cancel_code_completion();
- if (last_completion_char == '(') {
+ if (code_completion_prefixes.has(String::chr(last_completion_char))) {
request_code_completion();
}
}
@@ -1742,6 +1950,58 @@ void CodeEdit::cancel_code_completion() {
update();
}
+/* Line length guidelines */
+void CodeEdit::set_line_length_guidelines(TypedArray<int> p_guideline_columns) {
+ line_length_guideline_columns = p_guideline_columns;
+ update();
+}
+
+TypedArray<int> CodeEdit::get_line_length_guidelines() const {
+ return line_length_guideline_columns;
+}
+
+/* Symbol lookup */
+void CodeEdit::set_symbol_lookup_on_click_enabled(bool p_enabled) {
+ symbol_lookup_on_click_enabled = p_enabled;
+ set_symbol_lookup_word_as_valid(false);
+}
+
+bool CodeEdit::is_symbol_lookup_on_click_enabled() const {
+ return symbol_lookup_on_click_enabled;
+}
+
+String CodeEdit::get_text_for_symbol_lookup() {
+ int line, col;
+ Point2i mp = _get_local_mouse_pos();
+ _get_mouse_pos(mp, line, col);
+
+ StringBuilder lookup_text;
+ const int text_size = get_line_count();
+ for (int i = 0; i < text_size; i++) {
+ String text = get_line(i);
+
+ if (i == line) {
+ lookup_text += text.substr(0, col);
+ /* Not unicode, represents the cursor. */
+ lookup_text += String::chr(0xFFFF);
+ lookup_text += text.substr(col, text.size());
+ } else {
+ lookup_text += text;
+ }
+
+ if (i != text_size - 1) {
+ lookup_text += "\n";
+ }
+ }
+ return lookup_text.as_string();
+}
+
+void CodeEdit::set_symbol_lookup_word_as_valid(bool p_valid) {
+ symbol_lookup_word = p_valid ? symbol_lookup_new_word : "";
+ symbol_lookup_new_word = "";
+ _set_symbol_lookup_word(symbol_lookup_word);
+}
+
void CodeEdit::_bind_methods() {
/* Indent management */
ClassDB::bind_method(D_METHOD("set_indent_size", "size"), &CodeEdit::set_indent_size);
@@ -1762,6 +2022,22 @@ void CodeEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("indent_lines"), &CodeEdit::indent_lines);
ClassDB::bind_method(D_METHOD("unindent_lines"), &CodeEdit::unindent_lines);
+ /* Auto brace completion */
+ ClassDB::bind_method(D_METHOD("set_auto_brace_completion_enabled", "enable"), &CodeEdit::set_auto_brace_completion_enabled);
+ ClassDB::bind_method(D_METHOD("is_auto_brace_completion_enabled"), &CodeEdit::is_auto_brace_completion_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_highlight_matching_braces_enabled", "enable"), &CodeEdit::set_highlight_matching_braces_enabled);
+ ClassDB::bind_method(D_METHOD("is_highlight_matching_braces_enabled"), &CodeEdit::is_highlight_matching_braces_enabled);
+
+ ClassDB::bind_method(D_METHOD("add_auto_brace_completion_pair", "start_key", "end_key"), &CodeEdit::add_auto_brace_completion_pair);
+ ClassDB::bind_method(D_METHOD("set_auto_brace_completion_pairs", "pairs"), &CodeEdit::set_auto_brace_completion_pairs);
+ ClassDB::bind_method(D_METHOD("get_auto_brace_completion_pairs"), &CodeEdit::get_auto_brace_completion_pairs);
+
+ ClassDB::bind_method(D_METHOD("has_auto_brace_completion_open_key", "open_key"), &CodeEdit::has_auto_brace_completion_open_key);
+ ClassDB::bind_method(D_METHOD("has_auto_brace_completion_close_key", "close_key"), &CodeEdit::has_auto_brace_completion_close_key);
+
+ ClassDB::bind_method(D_METHOD("get_auto_brace_completion_close_key", "open_key"), &CodeEdit::get_auto_brace_completion_close_key);
+
/* Main Gutter */
ClassDB::bind_method(D_METHOD("_main_gutter_draw_callback"), &CodeEdit::_main_gutter_draw_callback);
@@ -1890,19 +2166,35 @@ void CodeEdit::_bind_methods() {
BIND_VMETHOD(MethodInfo("_request_code_completion", PropertyInfo(Variant::BOOL, "force")));
BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_filter_code_completion_candidates", PropertyInfo(Variant::ARRAY, "candidates")));
+ /* Line length guidelines */
+ ClassDB::bind_method(D_METHOD("set_line_length_guidelines", "guideline_columns"), &CodeEdit::set_line_length_guidelines);
+ ClassDB::bind_method(D_METHOD("get_line_length_guidelines"), &CodeEdit::get_line_length_guidelines);
+
+ /* Symbol lookup */
+ ClassDB::bind_method(D_METHOD("set_symbol_lookup_on_click_enabled", "enable"), &CodeEdit::set_symbol_lookup_on_click_enabled);
+ ClassDB::bind_method(D_METHOD("is_symbol_lookup_on_click_enabled"), &CodeEdit::is_symbol_lookup_on_click_enabled);
+
+ ClassDB::bind_method(D_METHOD("get_text_for_symbol_lookup"), &CodeEdit::get_text_for_symbol_lookup);
+
+ ClassDB::bind_method(D_METHOD("set_symbol_lookup_word_as_valid", "valid"), &CodeEdit::set_symbol_lookup_word_as_valid);
+
/* Inspector */
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_breakpoints_gutter"), "set_draw_breakpoints_gutter", "is_drawing_breakpoints_gutter");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "symbol_lookup_on_click"), "set_symbol_lookup_on_click_enabled", "is_symbol_lookup_on_click_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "line_folding"), "set_line_folding_enabled", "is_line_folding_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_bookmarks"), "set_draw_bookmarks_gutter", "is_drawing_bookmarks_gutter");
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "line_length_guidelines"), "set_line_length_guidelines", "get_line_length_guidelines");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_executing_lines"), "set_draw_executing_lines_gutter", "is_drawing_executing_lines_gutter");
+ ADD_GROUP("Gutters", "gutters_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_breakpoints_gutter"), "set_draw_breakpoints_gutter", "is_drawing_breakpoints_gutter");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_line_numbers"), "set_draw_line_numbers", "is_draw_line_numbers_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "zero_pad_line_numbers"), "set_line_numbers_zero_padded", "is_line_numbers_zero_padded");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_bookmarks"), "set_draw_bookmarks_gutter", "is_drawing_bookmarks_gutter");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_fold_gutter"), "set_draw_fold_gutter", "is_drawing_fold_gutter");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_executing_lines"), "set_draw_executing_lines_gutter", "is_drawing_executing_lines_gutter");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "line_folding"), "set_line_folding_enabled", "is_line_folding_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_line_numbers"), "set_draw_line_numbers", "is_draw_line_numbers_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_zero_pad_line_numbers"), "set_line_numbers_zero_padded", "is_line_numbers_zero_padded");
+
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gutters_draw_fold_gutter"), "set_draw_fold_gutter", "is_drawing_fold_gutter");
ADD_GROUP("Delimiters", "delimiter_");
ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "delimiter_strings"), "set_string_delimiters", "get_string_delimiters");
@@ -1918,11 +2210,74 @@ void CodeEdit::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "indent_automatic"), "set_auto_indent_enabled", "is_auto_indent_enabled");
ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "indent_automatic_prefixes"), "set_auto_indent_prefixes", "get_auto_indent_prefixes");
+ ADD_GROUP("Auto brace completion", "auto_brace_completion_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_brace_completion_enabled"), "set_auto_brace_completion_enabled", "is_auto_brace_completion_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_brace_completion_highlight_matching"), "set_highlight_matching_braces_enabled", "is_highlight_matching_braces_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "auto_brace_completion_pairs"), "set_auto_brace_completion_pairs", "get_auto_brace_completion_pairs");
+
/* Signals */
+ /* Gutters */
ADD_SIGNAL(MethodInfo("breakpoint_toggled", PropertyInfo(Variant::INT, "line")));
+
+ /* Code Completion */
ADD_SIGNAL(MethodInfo("request_code_completion"));
+
+ /* Symbol lookup */
+ ADD_SIGNAL(MethodInfo("symbol_lookup", PropertyInfo(Variant::STRING, "symbol"), PropertyInfo(Variant::INT, "line"), PropertyInfo(Variant::INT, "column")));
+ ADD_SIGNAL(MethodInfo("symbol_validate", PropertyInfo(Variant::STRING, "symbol")));
}
+/* Auto brace completion */
+int CodeEdit::_get_auto_brace_pair_open_at_pos(int p_line, int p_col) {
+ const String &line = get_line(p_line);
+
+ /* Should be fast enough, expecting low amount of pairs... */
+ for (int i = 0; i < auto_brace_completion_pairs.size(); i++) {
+ const String &open_key = auto_brace_completion_pairs[i].open_key;
+ if (p_col - open_key.length() < 0) {
+ continue;
+ }
+
+ bool is_match = true;
+ for (int j = 0; j < open_key.length(); j++) {
+ if (line[(p_col - 1) - j] != open_key[(open_key.length() - 1) - j]) {
+ is_match = false;
+ break;
+ }
+ }
+
+ if (is_match) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+int CodeEdit::_get_auto_brace_pair_close_at_pos(int p_line, int p_col) {
+ const String &line = get_line(p_line);
+
+ /* Should be fast enough, expecting low amount of pairs... */
+ for (int i = 0; i < auto_brace_completion_pairs.size(); i++) {
+ if (p_col + auto_brace_completion_pairs[i].close_key.length() > line.length()) {
+ continue;
+ }
+
+ bool is_match = true;
+ for (int j = 0; j < auto_brace_completion_pairs[i].close_key.length(); j++) {
+ if (line[p_col + j] != auto_brace_completion_pairs[i].close_key[j]) {
+ is_match = false;
+ break;
+ }
+ }
+
+ if (is_match) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+/* Gutters */
void CodeEdit::_gutter_clicked(int p_line, int p_gutter) {
if (p_gutter == main_gutter) {
if (draw_breakpoints) {
@@ -2128,7 +2483,7 @@ int CodeEdit::_is_in_delimiter(int p_line, int p_column, DelimiterType p_type) c
int region = (p_line <= 0 || delimiter_cache[p_line - 1].size() < 1) ? -1 : delimiter_cache[p_line - 1].back()->value();
bool in_region = region != -1 && delimiters[region].type == p_type;
for (Map<int, int>::Element *E = delimiter_cache[p_line].front(); E; E = E->next()) {
- /* If column is specified, loop untill the key is larger then the column. */
+ /* If column is specified, loop until the key is larger then the column. */
if (p_column != -1) {
if (E->key() > p_column) {
break;
@@ -2138,7 +2493,7 @@ int CodeEdit::_is_in_delimiter(int p_line, int p_column, DelimiterType p_type) c
continue;
}
- /* If no column, calulate if the entire line is a region */
+ /* If no column, calculate if the entire line is a region */
/* excluding whitespace. */
const String line = get_line(p_line);
if (!in_region) {
@@ -2288,14 +2643,14 @@ void CodeEdit::_filter_code_completion_candidates() {
TypedArray<Dictionary> completion_options_sources;
completion_options_sources.resize(code_completion_option_sources.size());
int i = 0;
- for (List<ScriptCodeCompletionOption>::Element *E = code_completion_option_sources.front(); E; E = E->next()) {
+ for (const ScriptCodeCompletionOption &E : code_completion_option_sources) {
Dictionary option;
- option["kind"] = E->get().kind;
- option["display_text"] = E->get().display;
- option["insert_text"] = E->get().insert_text;
- option["font_color"] = E->get().font_color;
- option["icon"] = E->get().icon;
- option["default_value"] = E->get().default_value;
+ option["kind"] = E.kind;
+ option["display_text"] = E.display;
+ option["insert_text"] = E.insert_text;
+ option["font_color"] = E.font_color;
+ option["icon"] = E.icon;
+ option["default_value"] = E.default_value;
completion_options_sources[i] = option;
i++;
}
@@ -2406,9 +2761,7 @@ void CodeEdit::_filter_code_completion_candidates() {
int max_width = 0;
String string_to_complete_lower = string_to_complete.to_lower();
- for (List<ScriptCodeCompletionOption>::Element *E = code_completion_option_sources.front(); E; E = E->next()) {
- ScriptCodeCompletionOption &option = E->get();
-
+ for (ScriptCodeCompletionOption &option : code_completion_option_sources) {
if (single_quote && option.display.is_quoted()) {
option.display = option.display.unquote().quote("'");
}
@@ -2527,8 +2880,7 @@ void CodeEdit::_lines_edited_from(int p_from_line, int p_to_line) {
int line_count = (p_to_line - p_from_line);
List<int> breakpoints;
breakpointed_lines.get_key_list(&breakpoints);
- for (const List<int>::Element *E = breakpoints.front(); E; E = E->next()) {
- int line = E->get();
+ for (const int line : breakpoints) {
if (line <= from_line) {
continue;
}
@@ -2550,6 +2902,17 @@ CodeEdit::CodeEdit() {
auto_indent_prefixes.insert('[');
auto_indent_prefixes.insert('(');
+ /* Auto brace completion */
+ add_auto_brace_completion_pair("(", ")");
+ add_auto_brace_completion_pair("{", "}");
+ add_auto_brace_completion_pair("[", "]");
+ add_auto_brace_completion_pair("\"", "\"");
+ add_auto_brace_completion_pair("\'", "\'");
+
+ /* Delimiter traking */
+ add_string_delimiter("\"", "\"", false);
+ add_string_delimiter("\'", "\'", false);
+
/* Text Direction */
set_layout_direction(LAYOUT_DIRECTION_LTR);
set_text_direction(TEXT_DIRECTION_LTR);
diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h
index 25b518402b..72fdc6e787 100644
--- a/scene/gui/code_edit.h
+++ b/scene/gui/code_edit.h
@@ -66,6 +66,19 @@ private:
void _new_line(bool p_split_current_line = true, bool p_above = false);
+ /* Auto brace completion */
+ bool auto_brace_completion_enabled = false;
+
+ /* BracePair open_key must be uniquie and ordered by length. */
+ struct BracePair {
+ String open_key = "";
+ String close_key = "";
+ };
+ Vector<BracePair> auto_brace_completion_pairs;
+
+ int _get_auto_brace_pair_open_at_pos(int p_line, int p_col);
+ int _get_auto_brace_pair_close_at_pos(int p_line, int p_col);
+
/* Main Gutter */
enum MainGutterType {
MAIN_GUTTER_BREAKPOINT = 0x01,
@@ -112,7 +125,7 @@ private:
void _update_gutter_indexes();
/* Line Folding */
- bool line_folding_enabled = true;
+ bool line_folding_enabled = false;
/* Delimiters */
enum DelimiterType {
@@ -210,6 +223,16 @@ private:
void _lines_edited_from(int p_from_line, int p_to_line);
+ /* Line length guidelines */
+ TypedArray<int> line_length_guideline_columns;
+ Color line_length_guideline_color;
+
+ /* Symbol lookup */
+ bool symbol_lookup_on_click_enabled = false;
+
+ String symbol_lookup_new_word = "";
+ String symbol_lookup_word = "";
+
protected:
void _gui_input(const Ref<InputEvent> &p_gui_input) override;
void _notification(int p_what);
@@ -217,7 +240,9 @@ protected:
static void _bind_methods();
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);
@@ -240,6 +265,22 @@ public:
virtual void backspace() override;
+ /* Auto brace completion */
+ void set_auto_brace_completion_enabled(bool p_enabled);
+ bool is_auto_brace_completion_enabled() const;
+
+ void set_highlight_matching_braces_enabled(bool p_enabled);
+ bool is_highlight_matching_braces_enabled() const;
+
+ void add_auto_brace_completion_pair(const String &p_open_key, const String &p_close_key);
+ void set_auto_brace_completion_pairs(const Dictionary &p_auto_brace_completion_pairs);
+ Dictionary get_auto_brace_completion_pairs() const;
+
+ bool has_auto_brace_completion_open_key(const String &p_open_key) const;
+ bool has_auto_brace_completion_close_key(const String &p_close_key) const;
+
+ String get_auto_brace_completion_close_key(const String &p_open_key) const;
+
/* Main Gutter */
void set_draw_breakpoints_gutter(bool p_draw);
bool is_drawing_breakpoints_gutter() const;
@@ -347,6 +388,18 @@ public:
void confirm_code_completion(bool p_replace = false);
void cancel_code_completion();
+ /* Line length guidelines */
+ void set_line_length_guidelines(TypedArray<int> p_guideline_columns);
+ TypedArray<int> get_line_length_guidelines() const;
+
+ /* Symbol lookup */
+ void set_symbol_lookup_on_click_enabled(bool p_enabled);
+ bool is_symbol_lookup_on_click_enabled() const;
+
+ String get_text_for_symbol_lookup();
+
+ void set_symbol_lookup_word_as_valid(bool p_valid);
+
CodeEdit();
~CodeEdit();
};
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 032533d4a9..a2e6872da6 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -222,41 +222,42 @@ Transform2D Control::_get_internal_transform() const {
bool Control::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name;
- if (!name.begins_with("custom")) {
+ // Prefixes "custom_*" are supported for compatibility with 3.x.
+ if (!name.begins_with("theme_override") && !name.begins_with("custom")) {
return false;
}
if (p_value.get_type() == Variant::NIL) {
- if (name.begins_with("custom_icons/")) {
+ if (name.begins_with("theme_override_icons/") || name.begins_with("custom_icons/")) {
String dname = name.get_slicec('/', 1);
if (data.icon_override.has(dname)) {
data.icon_override[dname]->disconnect("changed", callable_mp(this, &Control::_override_changed));
}
data.icon_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- } else if (name.begins_with("custom_styles/")) {
+ } else if (name.begins_with("theme_override_styles/") || name.begins_with("custom_styles/")) {
String dname = name.get_slicec('/', 1);
if (data.style_override.has(dname)) {
data.style_override[dname]->disconnect("changed", callable_mp(this, &Control::_override_changed));
}
data.style_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- } else if (name.begins_with("custom_fonts/")) {
+ } else if (name.begins_with("theme_override_fonts/") || name.begins_with("custom_fonts/")) {
String dname = name.get_slicec('/', 1);
if (data.font_override.has(dname)) {
data.font_override[dname]->disconnect("changed", callable_mp(this, &Control::_override_changed));
}
data.font_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- } else if (name.begins_with("custom_font_sizes/")) {
+ } else if (name.begins_with("theme_override_font_sizes/") || name.begins_with("custom_font_sizes/")) {
String dname = name.get_slicec('/', 1);
data.font_size_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- } else if (name.begins_with("custom_colors/")) {
+ } else if (name.begins_with("theme_override_colors/") || name.begins_with("custom_colors/")) {
String dname = name.get_slicec('/', 1);
data.color_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- } else if (name.begins_with("custom_constants/")) {
+ } else if (name.begins_with("theme_override_constants/") || name.begins_with("custom_constants/")) {
String dname = name.get_slicec('/', 1);
data.constant_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
@@ -265,22 +266,22 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) {
}
} else {
- if (name.begins_with("custom_icons/")) {
+ if (name.begins_with("theme_override_icons/") || name.begins_with("custom_icons/")) {
String dname = name.get_slicec('/', 1);
add_theme_icon_override(dname, p_value);
- } else if (name.begins_with("custom_styles/")) {
+ } else if (name.begins_with("theme_override_styles/") || name.begins_with("custom_styles/")) {
String dname = name.get_slicec('/', 1);
add_theme_style_override(dname, p_value);
- } else if (name.begins_with("custom_fonts/")) {
+ } else if (name.begins_with("theme_override_fonts/") || name.begins_with("custom_fonts/")) {
String dname = name.get_slicec('/', 1);
add_theme_font_override(dname, p_value);
- } else if (name.begins_with("custom_font_sizes/")) {
+ } else if (name.begins_with("theme_override_font_sizes/") || name.begins_with("custom_font_sizes/")) {
String dname = name.get_slicec('/', 1);
add_theme_font_size_override(dname, p_value);
- } else if (name.begins_with("custom_colors/")) {
+ } else if (name.begins_with("theme_override_colors/") || name.begins_with("custom_colors/")) {
String dname = name.get_slicec('/', 1);
add_theme_color_override(dname, p_value);
- } else if (name.begins_with("custom_constants/")) {
+ } else if (name.begins_with("theme_override_constants/") || name.begins_with("custom_constants/")) {
String dname = name.get_slicec('/', 1);
add_theme_constant_override(dname, p_value);
} else {
@@ -307,27 +308,26 @@ void Control::_update_minimum_size() {
bool Control::_get(const StringName &p_name, Variant &r_ret) const {
String sname = p_name;
-
- if (!sname.begins_with("custom")) {
+ if (!sname.begins_with("theme_override")) {
return false;
}
- if (sname.begins_with("custom_icons/")) {
+ if (sname.begins_with("theme_override_icons/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.icon_override.has(name) ? Variant(data.icon_override[name]) : Variant();
- } else if (sname.begins_with("custom_styles/")) {
+ } else if (sname.begins_with("theme_override_styles/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.style_override.has(name) ? Variant(data.style_override[name]) : Variant();
- } else if (sname.begins_with("custom_fonts/")) {
+ } else if (sname.begins_with("theme_override_fonts/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.font_override.has(name) ? Variant(data.font_override[name]) : Variant();
- } else if (sname.begins_with("custom_font_sizes/")) {
+ } else if (sname.begins_with("theme_override_font_sizes/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.font_size_override.has(name) ? Variant(data.font_size_override[name]) : Variant();
- } else if (sname.begins_with("custom_colors/")) {
+ } else if (sname.begins_with("theme_override_colors/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.color_override.has(name) ? Variant(data.color_override[name]) : Variant();
- } else if (sname.begins_with("custom_constants/")) {
+ } else if (sname.begins_with("theme_override_constants/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.constant_override.has(name) ? Variant(data.constant_override[name]) : Variant();
} else {
@@ -340,76 +340,78 @@ bool Control::_get(const StringName &p_name, Variant &r_ret) const {
void Control::_get_property_list(List<PropertyInfo> *p_list) const {
Ref<Theme> theme = Theme::get_default();
+ p_list->push_back(PropertyInfo(Variant::NIL, "Theme Overrides", PROPERTY_HINT_NONE, "theme_override_", PROPERTY_USAGE_GROUP));
+
{
List<StringName> names;
- theme->get_icon_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ theme->get_color_list(get_class_name(), &names);
+ for (const StringName &E : names) {
uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.icon_override.has(E->get())) {
+ if (data.color_override.has(E)) {
usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
}
- p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage));
+ p_list->push_back(PropertyInfo(Variant::COLOR, "theme_override_colors/" + E, PROPERTY_HINT_NONE, "", usage));
}
}
{
List<StringName> names;
- theme->get_stylebox_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ theme->get_constant_list(get_class_name(), &names);
+ for (const StringName &E : names) {
uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.style_override.has(E->get())) {
+ if (data.constant_override.has(E)) {
usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
}
- p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_styles/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage));
+ p_list->push_back(PropertyInfo(Variant::INT, "theme_override_constants/" + E, PROPERTY_HINT_RANGE, "-16384,16384", usage));
}
}
{
List<StringName> names;
theme->get_font_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ for (const StringName &E : names) {
uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.font_override.has(E->get())) {
+ if (data.font_override.has(E)) {
usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
}
- p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_fonts/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Font", usage));
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "theme_override_fonts/" + E, PROPERTY_HINT_RESOURCE_TYPE, "Font", usage));
}
}
{
List<StringName> names;
theme->get_font_size_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ for (const StringName &E : names) {
uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.font_size_override.has(E->get())) {
+ if (data.font_size_override.has(E)) {
usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
}
- p_list->push_back(PropertyInfo(Variant::INT, "custom_font_sizes/" + E->get(), PROPERTY_HINT_NONE, "", usage));
+ p_list->push_back(PropertyInfo(Variant::INT, "theme_override_font_sizes/" + E, PROPERTY_HINT_NONE, "", usage));
}
}
{
List<StringName> names;
- theme->get_color_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ theme->get_icon_list(get_class_name(), &names);
+ for (const StringName &E : names) {
uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.color_override.has(E->get())) {
+ if (data.icon_override.has(E)) {
usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
}
- p_list->push_back(PropertyInfo(Variant::COLOR, "custom_colors/" + E->get(), PROPERTY_HINT_NONE, "", usage));
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "theme_override_icons/" + E, PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage));
}
}
{
List<StringName> names;
- theme->get_constant_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ theme->get_stylebox_list(get_class_name(), &names);
+ for (const StringName &E : names) {
uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.constant_override.has(E->get())) {
+ if (data.style_override.has(E)) {
usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
}
- p_list->push_back(PropertyInfo(Variant::INT, "custom_constants/" + E->get(), PROPERTY_HINT_RANGE, "-16384,16384", usage));
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "theme_override_styles/" + E, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage));
}
}
}
@@ -428,14 +430,14 @@ void Control::_validate_property(PropertyInfo &property) const {
Vector<StringName> unique_names;
String hint_string;
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
+ for (const StringName &E : names) {
// Skip duplicate values.
- if (unique_names.has(E->get())) {
+ if (unique_names.has(E)) {
continue;
}
- hint_string += String(E->get()) + ",";
- unique_names.append(E->get());
+ hint_string += String(E) + ",";
+ unique_names.append(E);
}
property.hint_string = hint_string;
@@ -454,6 +456,8 @@ void Control::set_layout_direction(Control::LayoutDirection p_direction) {
ERR_FAIL_INDEX((int)p_direction, 4);
data.layout_dir = p_direction;
+ data.is_rtl_dirty = true;
+
propagate_notification(NOTIFICATION_LAYOUT_DIRECTION_CHANGED);
}
@@ -462,29 +466,49 @@ Control::LayoutDirection Control::get_layout_direction() const {
}
bool Control::is_layout_rtl() const {
- if (data.layout_dir == LAYOUT_DIRECTION_INHERITED) {
- Window *parent_window = get_parent_window();
- Control *parent_control = get_parent_control();
- if (parent_control) {
- return parent_control->is_layout_rtl();
- } else if (parent_window) {
- return parent_window->is_layout_rtl();
- } else {
+ if (data.is_rtl_dirty) {
+ const_cast<Control *>(this)->data.is_rtl_dirty = false;
+ if (data.layout_dir == LAYOUT_DIRECTION_INHERITED) {
+ Window *parent_window = get_parent_window();
+ Control *parent_control = get_parent_control();
+ if (parent_control) {
+ const_cast<Control *>(this)->data.is_rtl = parent_control->is_layout_rtl();
+ } else if (parent_window) {
+ const_cast<Control *>(this)->data.is_rtl = parent_window->is_layout_rtl();
+ } else {
+ if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
+ const_cast<Control *>(this)->data.is_rtl = true;
+ } else {
+ String locale = TranslationServer::get_singleton()->get_tool_locale();
+ const_cast<Control *>(this)->data.is_rtl = TS->is_locale_right_to_left(locale);
+ }
+ }
+ } else if (data.layout_dir == LAYOUT_DIRECTION_LOCALE) {
if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
- return true;
+ const_cast<Control *>(this)->data.is_rtl = true;
+ } else {
+ String locale = TranslationServer::get_singleton()->get_tool_locale();
+ const_cast<Control *>(this)->data.is_rtl = TS->is_locale_right_to_left(locale);
}
- String locale = TranslationServer::get_singleton()->get_tool_locale();
- return TS->is_locale_right_to_left(locale);
- }
- } else if (data.layout_dir == LAYOUT_DIRECTION_LOCALE) {
- if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
- return true;
+ } else {
+ const_cast<Control *>(this)->data.is_rtl = (data.layout_dir == LAYOUT_DIRECTION_RTL);
}
- String locale = TranslationServer::get_singleton()->get_tool_locale();
- return TS->is_locale_right_to_left(locale);
- } else {
- return (data.layout_dir == LAYOUT_DIRECTION_RTL);
}
+ return data.is_rtl;
+}
+
+void Control::set_auto_translate(bool p_enable) {
+ if (p_enable == data.auto_translate) {
+ return;
+ }
+
+ data.auto_translate = p_enable;
+
+ notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED);
+}
+
+bool Control::is_auto_translating() const {
+ return data.auto_translate;
}
void Control::_clear_size_warning() {
@@ -534,6 +558,7 @@ void Control::_notification(int p_notification) {
} break;
case NOTIFICATION_POST_ENTER_TREE: {
data.minimum_size_valid = false;
+ data.is_rtl_dirty = true;
_size_changed();
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -548,6 +573,7 @@ void Control::_notification(int p_notification) {
case NOTIFICATION_ENTER_CANVAS: {
data.parent = Object::cast_to<Control>(get_parent());
data.parent_window = Object::cast_to<Window>(get_parent());
+ data.is_rtl_dirty = true;
Node *parent = this; //meh
Control *parent_control = nullptr;
@@ -613,6 +639,7 @@ void Control::_notification(int p_notification) {
data.parent = nullptr;
data.parent_canvas_item = nullptr;
data.parent_window = nullptr;
+ data.is_rtl_dirty = true;
} break;
case NOTIFICATION_MOVED_IN_PARENT: {
@@ -672,6 +699,7 @@ void Control::_notification(int p_notification) {
} break;
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
+ data.is_rtl_dirty = true;
_size_changed();
} break;
}
@@ -793,13 +821,13 @@ T Control::get_theme_item_in_types(Control *p_theme_owner, Window *p_theme_owner
Window *theme_owner_window = p_theme_owner_window;
while (theme_owner || theme_owner_window) {
- for (List<StringName>::Element *E = p_theme_types.front(); E; E = E->next()) {
- if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E->get())) {
- return theme_owner->data.theme->get_theme_item(p_data_type, p_name, E->get());
+ for (const StringName &E : p_theme_types) {
+ if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E)) {
+ return theme_owner->data.theme->get_theme_item(p_data_type, p_name, E);
}
- if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E->get())) {
- return theme_owner_window->theme->get_theme_item(p_data_type, p_name, E->get());
+ if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E)) {
+ return theme_owner_window->theme->get_theme_item(p_data_type, p_name, E);
}
}
@@ -822,17 +850,17 @@ T Control::get_theme_item_in_types(Control *p_theme_owner, Window *p_theme_owner
// Secondly, check the project-defined Theme resource.
if (Theme::get_project_default().is_valid()) {
- for (List<StringName>::Element *E = p_theme_types.front(); E; E = E->next()) {
- if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E->get())) {
- return Theme::get_project_default()->get_theme_item(p_data_type, p_name, E->get());
+ for (const StringName &E : p_theme_types) {
+ if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E)) {
+ return Theme::get_project_default()->get_theme_item(p_data_type, p_name, E);
}
}
}
// Lastly, fall back on the items defined in the default Theme, if they exist.
- for (List<StringName>::Element *E = p_theme_types.front(); E; E = E->next()) {
- if (Theme::get_default()->has_theme_item(p_data_type, p_name, E->get())) {
- return Theme::get_default()->get_theme_item(p_data_type, p_name, E->get());
+ for (const StringName &E : p_theme_types) {
+ if (Theme::get_default()->has_theme_item(p_data_type, p_name, E)) {
+ return Theme::get_default()->get_theme_item(p_data_type, p_name, E);
}
}
// If they don't exist, use any type to return the default/empty value.
@@ -848,12 +876,12 @@ bool Control::has_theme_item_in_types(Control *p_theme_owner, Window *p_theme_ow
Window *theme_owner_window = p_theme_owner_window;
while (theme_owner || theme_owner_window) {
- for (List<StringName>::Element *E = p_theme_types.front(); E; E = E->next()) {
- if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E->get())) {
+ for (const StringName &E : p_theme_types) {
+ if (theme_owner && theme_owner->data.theme->has_theme_item(p_data_type, p_name, E)) {
return true;
}
- if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E->get())) {
+ if (theme_owner_window && theme_owner_window->theme->has_theme_item(p_data_type, p_name, E)) {
return true;
}
}
@@ -877,16 +905,16 @@ bool Control::has_theme_item_in_types(Control *p_theme_owner, Window *p_theme_ow
// Secondly, check the project-defined Theme resource.
if (Theme::get_project_default().is_valid()) {
- for (List<StringName>::Element *E = p_theme_types.front(); E; E = E->next()) {
- if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E->get())) {
+ for (const StringName &E : p_theme_types) {
+ if (Theme::get_project_default()->has_theme_item(p_data_type, p_name, E)) {
return true;
}
}
}
// Lastly, fall back on the items defined in the default Theme, if they exist.
- for (List<StringName>::Element *E = p_theme_types.front(); E; E = E->next()) {
- if (Theme::get_default()->has_theme_item(p_data_type, p_name, E->get())) {
+ for (const StringName &E : p_theme_types) {
+ if (Theme::get_default()->has_theme_item(p_data_type, p_name, E)) {
return true;
}
}
@@ -1594,7 +1622,7 @@ void Control::set_rect(const Rect2 &p_rect) {
void Control::_set_size(const Size2 &p_size) {
#ifdef DEBUG_ENABLED
if (data.size_warning && (data.anchor[SIDE_LEFT] != data.anchor[SIDE_RIGHT] || data.anchor[SIDE_TOP] != data.anchor[SIDE_BOTTOM])) {
- WARN_PRINT("Nodes with non-equal opposite anchors will have their size overriden after _ready(). \nIf you want to set size, change the anchors or consider using set_deferred().");
+ WARN_PRINT("Nodes with non-equal opposite anchors will have their size overridden after _ready(). \nIf you want to set size, change the anchors or consider using set_deferred().");
}
#endif
set_size(p_size);
@@ -2580,8 +2608,8 @@ void Control::get_argument_options(const StringName &p_function, int p_idx, List
}
sn.sort_custom<StringName::AlphCompare>();
- for (List<StringName>::Element *E = sn.front(); E; E = E->next()) {
- r_options->push_back(quote_style + E->get() + quote_style);
+ for (const StringName &E : sn) {
+ r_options->push_back(quote_style + E + quote_style);
}
}
}
@@ -2772,6 +2800,9 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_layout_direction"), &Control::get_layout_direction);
ClassDB::bind_method(D_METHOD("is_layout_rtl"), &Control::is_layout_rtl);
+ 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")));
@@ -2806,6 +2837,9 @@ void Control::_bind_methods() {
ADD_GROUP("Layout Direction", "layout_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "layout_direction", PROPERTY_HINT_ENUM, "Inherited,Locale,Left-to-Right,Right-to-Left"), "set_layout_direction", "get_layout_direction");
+ ADD_GROUP("Auto Translate", "");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating");
+
ADD_GROUP("Rect", "rect_");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_position", "get_position");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_global_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "_set_global_position", "get_global_position");
@@ -2836,10 +2870,10 @@ void Control::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags");
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio");
+
ADD_GROUP("Theme", "theme_");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_type_variation", PROPERTY_HINT_ENUM_SUGGESTION), "set_theme_type_variation", "get_theme_type_variation");
- ADD_GROUP("", "");
BIND_ENUM_CONSTANT(FOCUS_NONE);
BIND_ENUM_CONSTANT(FOCUS_CLICK);
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 51b454b334..8d669c7a6d 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -179,6 +179,10 @@ private:
GrowDirection v_grow = GROW_DIRECTION_END;
LayoutDirection layout_dir = LAYOUT_DIRECTION_INHERITED;
+ bool is_rtl_dirty = true;
+ bool is_rtl = false;
+
+ bool auto_translate = true;
real_t rotation = 0.0;
Vector2 scale = Vector2(1, 1);
@@ -349,6 +353,10 @@ public:
LayoutDirection get_layout_direction() const;
virtual bool is_layout_rtl() const;
+ void set_auto_translate(bool p_enable);
+ bool is_auto_translating() const;
+ _FORCE_INLINE_ String atr(const String p_string) const { return is_auto_translating() ? tr(p_string) : p_string; };
+
/* POSITIONING */
void set_anchors_preset(LayoutPreset p_preset, bool p_keep_offsets = true);
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index f5c764e9cc..da858e8e83 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -72,13 +72,10 @@ void AcceptDialog::_notification(int p_what) {
parent_visible = nullptr;
}
}
-
} break;
-
case NOTIFICATION_THEME_CHANGED: {
bg->add_theme_style_override("panel", bg->get_theme_stylebox(SNAME("panel"), SNAME("AcceptDialog")));
} break;
-
case NOTIFICATION_EXIT_TREE: {
if (parent_visible) {
parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused));
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 9ed3a2244e..2e4204e171 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -552,9 +552,9 @@ void FileDialog::update_file_list() {
bool match = patterns.is_empty();
String match_str;
- for (List<String>::Element *E = patterns.front(); E; E = E->next()) {
- if (files.front()->get().matchn(E->get())) {
- match_str = E->get();
+ for (const String &E : patterns) {
+ if (files.front()->get().matchn(E)) {
+ match_str = E;
match = true;
break;
}
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 2281fb19c6..1fac2b9129 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -217,8 +217,8 @@ Error GraphEdit::connect_node(const StringName &p_from, int p_from_port, const S
}
bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) {
+ for (const Connection &E : connections) {
+ if (E.from == p_from && E.from_port == p_from_port && E.to == p_to && E.to_port == p_to_port) {
return true;
}
}
@@ -227,7 +227,7 @@ bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, con
}
void GraphEdit::disconnect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
+ for (const List<Connection>::Element *E = connections.front(); E; E = E->next()) {
if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) {
connections.erase(E);
top_layer->update();
@@ -561,20 +561,20 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
if (is_in_hot_zone(pos / zoom, click_pos)) {
if (valid_left_disconnect_types.has(gn->get_connection_output_type(j))) {
//check disconnect
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- if (E->get().from == gn->get_name() && E->get().from_port == j) {
- Node *to = get_node(String(E->get().to));
+ for (const Connection &E : connections) {
+ if (E.from == gn->get_name() && E.from_port == j) {
+ Node *to = get_node(String(E.to));
if (Object::cast_to<GraphNode>(to)) {
- connecting_from = E->get().to;
- connecting_index = E->get().to_port;
+ connecting_from = E.to;
+ connecting_index = E.to_port;
connecting_out = false;
- connecting_type = Object::cast_to<GraphNode>(to)->get_connection_input_type(E->get().to_port);
- connecting_color = Object::cast_to<GraphNode>(to)->get_connection_input_color(E->get().to_port);
+ connecting_type = Object::cast_to<GraphNode>(to)->get_connection_input_type(E.to_port);
+ connecting_color = Object::cast_to<GraphNode>(to)->get_connection_input_color(E.to_port);
connecting_target = false;
connecting_to = pos;
just_disconnected = true;
- emit_signal(SNAME("disconnection_request"), E->get().from, E->get().from_port, E->get().to, E->get().to_port);
+ emit_signal(SNAME("disconnection_request"), E.from, E.from_port, E.to, E.to_port);
to = get_node(String(connecting_from)); //maybe it was erased
if (Object::cast_to<GraphNode>(to)) {
connecting = true;
@@ -603,20 +603,20 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
if (is_in_hot_zone(pos / zoom, click_pos)) {
if (right_disconnects || valid_right_disconnect_types.has(gn->get_connection_input_type(j))) {
//check disconnect
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- if (E->get().to == gn->get_name() && E->get().to_port == j) {
- Node *fr = get_node(String(E->get().from));
+ for (const Connection &E : connections) {
+ if (E.to == gn->get_name() && E.to_port == j) {
+ Node *fr = get_node(String(E.from));
if (Object::cast_to<GraphNode>(fr)) {
- connecting_from = E->get().from;
- connecting_index = E->get().from_port;
+ connecting_from = E.from;
+ connecting_index = E.from_port;
connecting_out = true;
- connecting_type = Object::cast_to<GraphNode>(fr)->get_connection_output_type(E->get().from_port);
- connecting_color = Object::cast_to<GraphNode>(fr)->get_connection_output_color(E->get().from_port);
+ connecting_type = Object::cast_to<GraphNode>(fr)->get_connection_output_type(E.from_port);
+ connecting_color = Object::cast_to<GraphNode>(fr)->get_connection_output_color(E.from_port);
connecting_target = false;
connecting_to = pos;
just_disconnected = true;
- emit_signal(SNAME("disconnection_request"), E->get().from, E->get().from_port, E->get().to, E->get().to_port);
+ emit_signal(SNAME("disconnection_request"), E.from, E.from_port, E.to, E.to_port);
fr = get_node(String(connecting_from)); //maybe it was erased
if (Object::cast_to<GraphNode>(fr)) {
connecting = true;
@@ -1001,8 +1001,8 @@ void GraphEdit::_minimap_draw() {
// Draw node connections.
Color activity_color = get_theme_color(SNAME("activity"));
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- NodePath fromnp(E->get().from);
+ for (const Connection &E : connections) {
+ NodePath fromnp(E.from);
Node *from = get_node(fromnp);
if (!from) {
@@ -1013,7 +1013,7 @@ void GraphEdit::_minimap_draw() {
continue;
}
- NodePath tonp(E->get().to);
+ NodePath tonp(E.to);
Node *to = get_node(tonp);
if (!to) {
continue;
@@ -1023,16 +1023,16 @@ void GraphEdit::_minimap_draw() {
continue;
}
- Vector2 from_slot_position = gfrom->get_position_offset() * zoom + gfrom->get_connection_output_position(E->get().from_port);
+ Vector2 from_slot_position = gfrom->get_position_offset() * zoom + gfrom->get_connection_output_position(E.from_port);
Vector2 from_position = minimap->_convert_from_graph_position(from_slot_position - graph_offset) + minimap_offset;
- Color from_color = gfrom->get_connection_output_color(E->get().from_port);
- Vector2 to_slot_position = gto->get_position_offset() * zoom + gto->get_connection_input_position(E->get().to_port);
+ Color from_color = gfrom->get_connection_output_color(E.from_port);
+ Vector2 to_slot_position = gto->get_position_offset() * zoom + gto->get_connection_input_position(E.to_port);
Vector2 to_position = minimap->_convert_from_graph_position(to_slot_position - graph_offset) + minimap_offset;
- Color to_color = gto->get_connection_input_color(E->get().to_port);
+ Color to_color = gto->get_connection_input_color(E.to_port);
- if (E->get().activity > 0) {
- from_color = from_color.lerp(activity_color, E->get().activity);
- to_color = to_color.lerp(activity_color, E->get().activity);
+ if (E.activity > 0) {
+ 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);
}
@@ -1360,15 +1360,15 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
void GraphEdit::set_connection_activity(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port, float p_activity) {
- for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
- if (E->get().from == p_from && E->get().from_port == p_from_port && E->get().to == p_to && E->get().to_port == p_to_port) {
- if (Math::is_equal_approx(E->get().activity, p_activity)) {
+ for (Connection &E : connections) {
+ if (E.from == p_from && E.from_port == p_from_port && E.to == p_to && E.to_port == p_to_port) {
+ if (Math::is_equal_approx(E.activity, p_activity)) {
//update only if changed
top_layer->update();
minimap->update();
connections_layer->update();
}
- E->get().activity = p_activity;
+ E.activity = p_activity;
return;
}
}
@@ -1500,12 +1500,12 @@ Array GraphEdit::_get_connection_list() const {
List<Connection> conns;
get_connection_list(&conns);
Array arr;
- for (List<Connection>::Element *E = conns.front(); E; E = E->next()) {
+ for (const Connection &E : conns) {
Dictionary d;
- d["from"] = E->get().from;
- d["from_port"] = E->get().from_port;
- d["to"] = E->get().to;
- d["to_port"] = E->get().to_port;
+ d["from"] = E.from;
+ d["from_port"] = E.from_port;
+ d["to"] = E.to;
+ d["to_port"] = E.to_port;
arr.push_back(d);
}
return arr;
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index 06faf3fa3e..1603989243 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -221,7 +221,7 @@ void Label::_update_visible() {
void Label::_notification(int p_what) {
if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
- String new_text = tr(text);
+ String new_text = atr(text);
if (new_text == xl_text) {
return; //nothing new
}
@@ -509,7 +509,7 @@ void Label::set_text(const String &p_string) {
return;
}
text = p_string;
- xl_text = tr(p_string);
+ xl_text = atr(p_string);
dirty = true;
if (percent_visible < 1) {
visible_chars = get_total_character_count() * percent_visible;
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 19ffcfca6d..68e9171c15 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -597,7 +597,7 @@ void LineEdit::_notification(int p_what) {
update();
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
- placeholder_translated = tr(placeholder);
+ placeholder_translated = atr(placeholder);
_shape();
update();
} break;
@@ -1364,7 +1364,7 @@ String LineEdit::get_text() const {
void LineEdit::set_placeholder(String p_text) {
placeholder = p_text;
- placeholder_translated = tr(placeholder);
+ placeholder_translated = atr(placeholder);
_shape();
update();
}
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index 1e9baa77fc..cf1f41d0fc 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -55,6 +55,36 @@ void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) {
}
}
+void MenuButton::_popup_visibility_changed(bool p_visible) {
+ set_pressed(p_visible);
+
+ if (!p_visible) {
+ set_process_internal(false);
+ return;
+ }
+
+ if (switch_on_hover) {
+ Window *window = Object::cast_to<Window>(get_viewport());
+ if (window) {
+ mouse_pos_adjusted = window->get_position();
+
+ if (window->is_embedded()) {
+ Window *window_parent = Object::cast_to<Window>(window->get_parent()->get_viewport());
+ while (window_parent) {
+ if (!window_parent->is_embedded()) {
+ mouse_pos_adjusted += window_parent->get_position();
+ break;
+ }
+
+ window_parent = Object::cast_to<Window>(window_parent->get_parent()->get_viewport());
+ }
+ }
+
+ set_process_internal(true);
+ }
+ }
+}
+
void MenuButton::pressed() {
Size2 size = get_size();
@@ -94,10 +124,22 @@ bool MenuButton::is_switch_on_hover() {
}
void MenuButton::_notification(int p_what) {
- if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- if (!is_visible_in_tree()) {
- popup->hide();
- }
+ switch (p_what) {
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ if (!is_visible_in_tree()) {
+ popup->hide();
+ }
+ } break;
+ case NOTIFICATION_INTERNAL_PROCESS: {
+ Vector2i mouse_pos = DisplayServer::get_singleton()->mouse_get_position() - mouse_pos_adjusted;
+ MenuButton *menu_btn_other = Object::cast_to<MenuButton>(get_viewport()->gui_find_control(mouse_pos));
+
+ if (menu_btn_other && menu_btn_other != this && menu_btn_other->is_switch_on_hover() && !menu_btn_other->is_disabled() &&
+ (get_parent()->is_ancestor_of(menu_btn_other) || menu_btn_other->get_parent()->is_ancestor_of(popup))) {
+ popup->hide();
+ menu_btn_other->pressed();
+ }
+ } break;
}
}
@@ -130,8 +172,8 @@ MenuButton::MenuButton() {
popup = memnew(PopupMenu);
popup->hide();
add_child(popup);
- popup->connect("about_to_popup", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(true)); // For when switching from another MenuButton.
- popup->connect("popup_hide", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(false));
+ 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));
}
MenuButton::~MenuButton() {
diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h
index fd9ae6021e..cc2ca117c4 100644
--- a/scene/gui/menu_button.h
+++ b/scene/gui/menu_button.h
@@ -42,11 +42,15 @@ class MenuButton : public Button {
bool disable_shortcuts = false;
PopupMenu *popup;
+ Vector2i mouse_pos_adjusted;
+
Array _get_items() const;
void _set_items(const Array &p_items);
void _gui_input(Ref<InputEvent> p_event) override;
+ void _popup_visibility_changed(bool p_visible);
+
protected:
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 5e1c8cec37..f7e7e1cd60 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -72,6 +72,7 @@ void Popup::_notification(int p_what) {
} else {
_deinitialize_visible_parents();
emit_signal(SNAME("popup_hide"));
+ popped_up = false;
}
} break;
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index ee9e0e8ab8..490548fce0 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -397,17 +397,17 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> m = p_event;
if (m.is_valid()) {
- if (!item_clickable_area.has_point(m->get_position())) {
- return;
- }
-
- for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {
- if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E->get().has_point(m->get_position())) {
+ for (const Rect2 &E : autohide_areas) {
+ if (!Rect2(Point2(), get_size()).has_point(m->get_position()) && E.has_point(m->get_position())) {
_close_pressed();
return;
}
}
+ if (!item_clickable_area.has_point(m->get_position())) {
+ return;
+ }
+
int over = _get_mouse_over(m->get_position());
int id = (over < 0 || items[over].separator || items[over].disabled) ? -1 : (items[over].id >= 0 ? items[over].id : over);
@@ -722,7 +722,7 @@ void PopupMenu::_notification(int p_what) {
case Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED: {
for (int i = 0; i < items.size(); i++) {
- items.write[i].xl_text = tr(items[i].text);
+ items.write[i].xl_text = atr(items[i].text);
items.write[i].dirty = true;
_shape_item(i);
}
@@ -747,12 +747,12 @@ void PopupMenu::_notification(int p_what) {
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
//only used when using operating system windows
- if (get_window_id() != DisplayServer::INVALID_WINDOW_ID && autohide_areas.size()) {
+ if (!is_embedded() && autohide_areas.size()) {
Point2 mouse_pos = DisplayServer::get_singleton()->mouse_get_position();
mouse_pos -= get_position();
- for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {
- if (!Rect2(Point2(), get_size()).has_point(mouse_pos) && E->get().has_point(mouse_pos)) {
+ for (const Rect2 &E : autohide_areas) {
+ if (!Rect2(Point2(), get_size()).has_point(mouse_pos) && E.has_point(mouse_pos)) {
_close_pressed();
return;
}
@@ -786,7 +786,7 @@ void PopupMenu::_notification(int p_what) {
set_process_internal(false);
} else {
- if (get_window_id() != DisplayServer::INVALID_WINDOW_ID) {
+ if (!is_embedded()) {
set_process_internal(true);
}
@@ -807,7 +807,7 @@ void PopupMenu::_notification(int p_what) {
#define ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel) \
item.text = p_label; \
- item.xl_text = tr(p_label); \
+ item.xl_text = atr(p_label); \
item.id = p_id == -1 ? items.size() : p_id; \
item.accel = p_accel;
@@ -887,7 +887,7 @@ void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int
ERR_FAIL_COND_MSG(p_shortcut.is_null(), "Cannot add item with invalid Shortcut."); \
_ref_shortcut(p_shortcut); \
item.text = p_shortcut->get_name(); \
- item.xl_text = tr(item.text); \
+ item.xl_text = atr(item.text); \
item.id = p_id == -1 ? items.size() : p_id; \
item.shortcut = p_shortcut; \
item.shortcut_is_global = p_global;
@@ -956,7 +956,7 @@ void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, cons
void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu, int p_id) {
Item item;
item.text = p_label;
- item.xl_text = tr(p_label);
+ item.xl_text = atr(p_label);
item.id = p_id == -1 ? items.size() : p_id;
item.submenu = p_submenu;
items.push_back(item);
@@ -973,7 +973,7 @@ void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu,
void PopupMenu::set_item_text(int p_idx, const String &p_text) {
ERR_FAIL_INDEX(p_idx, items.size());
items.write[p_idx].text = p_text;
- items.write[p_idx].xl_text = tr(p_text);
+ items.write[p_idx].xl_text = atr(p_text);
_shape_item(p_idx);
control->update();
@@ -1402,7 +1402,7 @@ void PopupMenu::add_separator(const String &p_text, int p_id) {
sep.id = p_id;
if (p_text != String()) {
sep.text = p_text;
- sep.xl_text = tr(p_text);
+ sep.xl_text = atr(p_text);
}
items.push_back(sep);
control->update();
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index 74718395d3..aedc5d0155 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -140,7 +140,6 @@ class PopupMenu : public Popup {
void _close_pressed();
protected:
- friend class MenuButton;
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 99395aae30..3925e0c38e 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -238,9 +238,9 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
}
int idx = 0;
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (Item *E : table->subitems) {
+ ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
for (int i = 0; i < frame->lines.size(); i++) {
_resize_line(frame, i, p_base_font, p_base_font_size, 1);
}
@@ -316,9 +316,9 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
Vector2 offset;
float row_height = 0.0;
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (Item *E : table->subitems) {
+ ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
int column = idx % col_count;
@@ -472,9 +472,9 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
const int available_width = p_width - hseparation * (col_count - 1);
int idx = 0;
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (Item *E : table->subitems) {
+ ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
int column = idx % col_count;
for (int i = 0; i < frame->lines.size(); i++) {
@@ -556,7 +556,7 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
Vector2 offset;
float row_height = 0.0;
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
+ for (const List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
ItemFrame *frame = static_cast<ItemFrame *>(E->get());
@@ -783,8 +783,8 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
int row_count = table->rows.size();
int idx = 0;
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (Item *E : table->subitems) {
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
int col = idx % col_count;
int row = idx / col_count;
@@ -1203,8 +1203,8 @@ float RichTextLabel::_find_click_in_line(ItemFrame *p_frame, int p_line, const V
int col_count = table->columns.size();
int row_count = table->rows.size();
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (Item *E : table->subitems) {
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
int col = idx % col_count;
int row = idx / col_count;
@@ -2080,8 +2080,8 @@ bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) {
return true;
}
- for (List<Item *>::Element *E = from->subitems.front(); E; E = E->next()) {
- bool layout = _find_layout_subitem(E->get(), to);
+ for (Item *E : from->subitems) {
+ bool layout = _find_layout_subitem(E, to);
if (layout) {
return true;
@@ -3448,8 +3448,8 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
}
Vector<ItemFX *> fx_items;
- for (List<Item *>::Element *E = main->subitems.front(); E; E = E->next()) {
- Item *subitem = static_cast<Item *>(E->get());
+ for (Item *E : main->subitems) {
+ Item *subitem = static_cast<Item *>(E);
_fetch_item_fx_stack(subitem, fx_items);
if (fx_items.size()) {
@@ -3719,9 +3719,9 @@ String RichTextLabel::_get_line_text(ItemFrame *p_frame, int p_line, Selection p
ItemTable *table = static_cast<ItemTable *>(it);
int idx = 0;
int col_count = table->columns.size();
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (Item *E : table->subitems) {
+ ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E);
int column = idx % col_count;
for (int i = 0; i < frame->lines.size(); i++) {
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 8f84585f9b..cc41d961f6 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -550,7 +550,7 @@ void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, in
// Draw the tab contents.
Control *control = Object::cast_to<Control>(tabs[p_index]);
- String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name()));
+ 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);
int top_margin = p_tab_style->get_margin(SIDE_TOP);
@@ -584,7 +584,8 @@ void TabContainer::_refresh_texts() {
int font_size = get_theme_font_size(SNAME("font_size"));
for (int i = 0; i < tabs.size(); i++) {
Control *control = Object::cast_to<Control>(tabs[i]);
- String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name()));
+ String text = control->has_meta("_tab_name") ? String(atr(String(control->get_meta("_tab_name")))) : String(atr(control->get_name()));
+
Ref<TextLine> name;
name.instantiate();
name->set_direction(rtl ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
@@ -648,7 +649,7 @@ int TabContainer::_get_tab_width(int p_index) const {
// Get the width of the text displayed on the tab.
Ref<Font> font = get_theme_font(SNAME("font"));
int font_size = get_theme_font_size(SNAME("font_size"));
- String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name()));
+ String text = control->has_meta("_tab_name") ? String(atr(String(control->get_meta("_tab_name")))) : String(atr(control->get_name()));
int width = font->get_string_size(text, font_size).width;
// Add space for a tab icon.
@@ -898,7 +899,7 @@ void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
if (hover_now < 0) {
hover_now = get_tab_count() - 1;
}
- move_child(get_tab_control(tab_from_id), hover_now);
+ move_child(get_tab_control(tab_from_id), get_tab_control(hover_now)->get_index());
set_current_tab(hover_now);
} else if (get_tabs_rearrange_group() != -1) {
// drag and drop between TabContainers
@@ -911,7 +912,7 @@ void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
if (hover_now < 0) {
hover_now = get_tab_count() - 1;
}
- move_child(moving_tabc, hover_now);
+ move_child(moving_tabc, get_tab_control(hover_now)->get_index());
set_current_tab(hover_now);
emit_signal(SNAME("tab_changed"), hover_now);
}
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 9e8fe27ffb..103860ad78 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -239,7 +239,7 @@ void Tabs::_shape(int p_tab) {
Ref<Font> font = get_theme_font(SNAME("font"));
int font_size = get_theme_font_size(SNAME("font_size"));
- tabs.write[p_tab].xl_text = tr(tabs[p_tab].text);
+ tabs.write[p_tab].xl_text = atr(tabs[p_tab].text);
tabs.write[p_tab].text_buf->clear();
if (tabs[p_tab].text_direction == Control::TEXT_DIRECTION_INHERITED) {
tabs.write[p_tab].text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
@@ -529,7 +529,7 @@ bool Tabs::get_offset_buttons_visible() const {
void Tabs::set_tab_title(int p_tab, const String &p_title) {
ERR_FAIL_INDEX(p_tab, tabs.size());
tabs.write[p_tab].text = p_title;
- tabs.write[p_tab].xl_text = tr(p_title);
+ tabs.write[p_tab].xl_text = atr(p_title);
_shape(p_tab);
update();
minimum_size_changed();
@@ -742,7 +742,7 @@ void Tabs::_on_mouse_exited() {
void Tabs::add_tab(const String &p_str, const Ref<Texture2D> &p_icon) {
Tab t;
t.text = p_str;
- t.xl_text = tr(p_str);
+ t.xl_text = atr(p_str);
t.text_buf.instantiate();
t.text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
t.text_buf->add_string(t.xl_text, get_theme_font(SNAME("font")), get_theme_font_size(SNAME("font_size")), Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index be3edccc99..1b3935dd25 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -63,45 +63,6 @@ static bool _is_char(char32_t c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
}
-static bool _is_pair_right_symbol(char32_t c) {
- return c == '"' ||
- c == '\'' ||
- c == ')' ||
- c == ']' ||
- c == '}';
-}
-
-static bool _is_pair_left_symbol(char32_t c) {
- return c == '"' ||
- c == '\'' ||
- c == '(' ||
- c == '[' ||
- c == '{';
-}
-
-static bool _is_pair_symbol(char32_t c) {
- return _is_pair_left_symbol(c) || _is_pair_right_symbol(c);
-}
-
-static char32_t _get_right_pair_symbol(char32_t c) {
- if (c == '"') {
- return '"';
- }
- if (c == '\'') {
- return '\'';
- }
- if (c == '(') {
- return ')';
- }
- if (c == '[') {
- return ']';
- }
- if (c == '{') {
- return '}';
- }
- return 0;
-}
-
///////////////////////////////////////////////////////////////////////////////
void TextEdit::Text::set_font(const Ref<Font> &p_font) {
@@ -633,29 +594,6 @@ void TextEdit::_notification(int p_what) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(), get_size()), cache.background_color);
}
- if (line_length_guidelines) {
- const int hard_x = xmargin_beg + (int)cache.font->get_char_size('0', 0, cache.font_size).width * line_length_guideline_hard_col - cursor.x_ofs;
- if (hard_x > xmargin_beg && hard_x < xmargin_end) {
- if (rtl) {
- RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(size.width - hard_x, 0), Point2(size.width - hard_x, size.height), cache.line_length_guideline_color);
- } else {
- RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(hard_x, 0), Point2(hard_x, size.height), cache.line_length_guideline_color);
- }
- }
-
- // Draw a "Soft" line length guideline, less visible than the hard line length guideline.
- // It's usually set to a lower column compared to the hard line length guideline.
- // Only drawn if its column differs from the hard line length guideline.
- const int soft_x = xmargin_beg + (int)cache.font->get_char_size('0', 0, cache.font_size).width * line_length_guideline_soft_col - cursor.x_ofs;
- if (hard_x != soft_x && soft_x > xmargin_beg && soft_x < xmargin_end) {
- if (rtl) {
- RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(size.width - soft_x, 0), Point2(size.width - soft_x, size.height), cache.line_length_guideline_color * Color(1, 1, 1, 0.5));
- } else {
- RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(soft_x, 0), Point2(soft_x, size.height), cache.line_length_guideline_color * Color(1, 1, 1, 0.5));
- }
- }
- }
-
int brace_open_match_line = -1;
int brace_open_match_column = -1;
bool brace_open_matching = false;
@@ -665,7 +603,7 @@ void TextEdit::_notification(int p_what) {
bool brace_close_matching = false;
bool brace_close_mismatch = false;
- if (brace_matching_enabled && cursor.line >= 0 && cursor.line < text.size() && cursor.column >= 0) {
+ if (highlight_matching_braces_enabled && cursor.line >= 0 && cursor.line < text.size() && cursor.column >= 0) {
if (cursor.column < text[cursor.line].length()) {
// Check for open.
char32_t c = text[cursor.line][cursor.column];
@@ -1239,11 +1177,11 @@ void TextEdit::_notification(int p_what) {
}
}
- if (!clipped && select_identifiers_enabled && highlighted_word.length() != 0) { // Highlight word
- if (_is_char(highlighted_word[0]) || highlighted_word[0] == '.') {
- int highlighted_word_col = _get_column_pos_of_word(highlighted_word, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0);
+ if (!clipped && lookup_symbol_word.length() != 0) { // Highlight word
+ if (_is_char(lookup_symbol_word[0]) || lookup_symbol_word[0] == '.') {
+ int highlighted_word_col = _get_column_pos_of_word(lookup_symbol_word, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0);
while (highlighted_word_col != -1) {
- Vector<Vector2> sel = TS->shaped_text_get_selection(rid, highlighted_word_col + start, highlighted_word_col + highlighted_word.length() + start);
+ Vector<Vector2> sel = TS->shaped_text_get_selection(rid, highlighted_word_col + start, highlighted_word_col + lookup_symbol_word.length() + start);
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, row_height);
if (rect.position.x + rect.size.x <= xmargin_beg || rect.position.x > xmargin_end) {
@@ -1260,7 +1198,7 @@ void TextEdit::_notification(int p_what) {
draw_rect(rect, cache.font_selected_color);
}
- highlighted_word_col = _get_column_pos_of_word(highlighted_word, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, highlighted_word_col + 1);
+ highlighted_word_col = _get_column_pos_of_word(lookup_symbol_word, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, highlighted_word_col + 1);
}
}
}
@@ -1308,7 +1246,7 @@ void TextEdit::_notification(int p_what) {
int char_pos = char_ofs + char_margin + ofs_x;
if (char_pos >= xmargin_beg) {
- if (brace_matching_enabled) {
+ 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))) {
if (brace_open_mismatch) {
@@ -1567,130 +1505,6 @@ void TextEdit::_notification(int p_what) {
}
}
-void TextEdit::_consume_pair_symbol(char32_t ch) {
- int cursor_position_to_move = cursor_get_column() + 1;
-
- char32_t ch_single[2] = { ch, 0 };
- char32_t ch_single_pair[2] = { _get_right_pair_symbol(ch), 0 };
- char32_t ch_pair[3] = { ch, _get_right_pair_symbol(ch), 0 };
-
- if (is_selection_active()) {
- int new_column, new_line;
-
- begin_complex_operation();
- _insert_text(get_selection_from_line(), get_selection_from_column(),
- ch_single,
- &new_line, &new_column);
-
- int to_col_offset = 0;
- if (get_selection_from_line() == get_selection_to_line()) {
- to_col_offset = 1;
- }
-
- _insert_text(get_selection_to_line(),
- get_selection_to_column() + to_col_offset,
- ch_single_pair,
- &new_line, &new_column);
- end_complex_operation();
-
- cursor_set_line(get_selection_to_line());
- cursor_set_column(get_selection_to_column() + to_col_offset);
-
- deselect();
- update();
- return;
- }
-
- if ((ch == '\'' || ch == '"') &&
- cursor_get_column() > 0 && _is_text_char(text[cursor.line][cursor_get_column() - 1]) && !_is_pair_right_symbol(text[cursor.line][cursor_get_column()])) {
- insert_text_at_cursor(ch_single);
- cursor_set_column(cursor_position_to_move);
- return;
- }
-
- if (cursor_get_column() < text[cursor.line].length()) {
- if (_is_text_char(text[cursor.line][cursor_get_column()])) {
- insert_text_at_cursor(ch_single);
- cursor_set_column(cursor_position_to_move);
- return;
- }
- if (_is_pair_right_symbol(ch) &&
- text[cursor.line][cursor_get_column()] == ch) {
- cursor_set_column(cursor_position_to_move);
- return;
- }
- }
-
- String line = text[cursor.line];
-
- bool in_single_quote = false;
- bool in_double_quote = false;
- bool found_comment = false;
-
- int c = 0;
- while (c < line.length()) {
- if (line[c] == '\\') {
- c++; // Skip quoted anything.
-
- if (cursor.column == c) {
- break;
- }
- } else if (!in_single_quote && !in_double_quote && line[c] == '#') {
- found_comment = true;
- break;
- } else {
- if (line[c] == '\'' && !in_double_quote) {
- in_single_quote = !in_single_quote;
- } else if (line[c] == '"' && !in_single_quote) {
- in_double_quote = !in_double_quote;
- }
- }
-
- c++;
-
- if (cursor.column == c) {
- break;
- }
- }
-
- // Do not need to duplicate quotes while in comments
- if (found_comment) {
- insert_text_at_cursor(ch_single);
- cursor_set_column(cursor_position_to_move);
-
- return;
- }
-
- // Disallow inserting duplicated quotes while already in string
- if ((in_single_quote || in_double_quote) && (ch == '"' || ch == '\'')) {
- insert_text_at_cursor(ch_single);
- cursor_set_column(cursor_position_to_move);
-
- return;
- }
-
- insert_text_at_cursor(ch_pair);
- cursor_set_column(cursor_position_to_move);
-}
-
-void TextEdit::_consume_backspace_for_pair_symbol(int prev_line, int prev_column) {
- bool remove_right_symbol = false;
-
- if (cursor.column < text[cursor.line].length() && cursor.column > 0) {
- char32_t left_char = text[cursor.line][cursor.column - 1];
- char32_t right_char = text[cursor.line][cursor.column];
-
- if (right_char == _get_right_pair_symbol(left_char)) {
- remove_right_symbol = true;
- }
- }
- if (remove_right_symbol) {
- _remove_text(prev_line, prev_column, cursor.line, cursor.column + 1);
- } else {
- _remove_text(prev_line, prev_column, cursor.line, cursor.column);
- }
-}
-
void TextEdit::backspace() {
ScriptInstance *si = get_script_instance();
if (si && si->has_method("_backspace")) {
@@ -1719,14 +1533,7 @@ void TextEdit::backspace() {
if (is_line_hidden(cursor.line)) {
set_line_as_hidden(prev_line, true);
}
-
- if (auto_brace_completion_enabled &&
- cursor.column > 0 &&
- _is_pair_left_symbol(text[cursor.line][cursor.column - 1])) {
- _consume_backspace_for_pair_symbol(prev_line, prev_column);
- } else {
- _remove_text(prev_line, prev_column, cursor.line, cursor.column);
- }
+ _remove_text(prev_line, prev_column, cursor.line, cursor.column);
cursor_set_line(prev_line, false, true);
cursor_set_column(prev_column);
@@ -2101,6 +1908,7 @@ void TextEdit::delete_selection() {
}
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);
@@ -2137,13 +1945,21 @@ void TextEdit::_move_cursor_document_end(bool p_select) {
}
}
-void TextEdit::_handle_unicode_character(uint32_t unicode, bool p_had_selection) {
- if (p_had_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 && !p_had_selection) {
+ if (insert_mode && !had_selection) {
begin_complex_operation();
// Make sure we don't try and remove empty space.
@@ -2152,15 +1968,10 @@ void TextEdit::_handle_unicode_character(uint32_t unicode, bool p_had_selection)
}
}
- const char32_t chr[2] = { (char32_t)unicode, 0 };
+ const char32_t chr[2] = { (char32_t)p_unicode, 0 };
+ insert_text_at_cursor(chr);
- if (auto_brace_completion_enabled && _is_pair_symbol(chr[0])) {
- _consume_pair_symbol(chr[0]);
- } else {
- _insert_text_at_cursor(chr);
- }
-
- if ((insert_mode && !p_had_selection) || (selection.active != p_had_selection)) {
+ if ((insert_mode && !had_selection) || (had_selection)) {
end_complex_operation();
}
}
@@ -2301,6 +2112,10 @@ void TextEdit::_get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const
r_row = row;
}
+bool TextEdit::is_dragging_cursor() const {
+ return dragging_selection || dragging_minimap;
+}
+
void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
ERR_FAIL_COND(p_gui_input.is_null());
@@ -2478,14 +2293,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
} else {
if (mb->get_button_index() == MOUSE_BUTTON_LEFT) {
- if (mb->is_command_pressed() && highlighted_word != String()) {
- int row, col;
- _get_mouse_pos(Point2i(mpos.x, mpos.y), row, col);
-
- emit_signal(SNAME("symbol_lookup"), highlighted_word, row, col);
- return;
- }
-
dragging_minimap = false;
dragging_selection = false;
can_drag_minimap = false;
@@ -2520,18 +2327,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (is_layout_rtl()) {
mpos.x = get_size().x - mpos.x;
}
- if (select_identifiers_enabled) {
- if (!dragging_minimap && !dragging_selection && mm->is_command_pressed() && mm->get_button_mask() == 0) {
- String new_word = get_word_at_pos(mpos);
- if (new_word != highlighted_word) {
- emit_signal(SNAME("symbol_validate"), new_word);
- }
- } else {
- if (highlighted_word != String()) {
- set_highlighted_word(String());
- }
- }
- }
if (mm->get_button_mask() & MOUSE_BUTTON_MASK_LEFT && get_viewport()->gui_get_drag_data() == Variant()) { // Ignore if dragging.
_reset_caret_blink_timer();
@@ -2566,23 +2361,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
Ref<InputEventKey> k = p_gui_input;
if (k.is_valid()) {
- // Ctrl + Hover symbols
-#ifdef OSX_ENABLED
- if (k->get_keycode() == KEY_META) {
-#else
- if (k->get_keycode() == KEY_CTRL) {
-#endif
- if (select_identifiers_enabled) {
- if (k->is_pressed() && !dragging_minimap && !dragging_selection) {
- Point2 mp = _get_local_mouse_pos();
- emit_signal(SNAME("symbol_validate"), get_word_at_pos(mp));
- } else {
- set_highlighted_word(String());
- }
- }
- return;
- }
-
if (!k->is_pressed()) {
return;
}
@@ -2598,9 +2376,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
// * No Modifiers are pressed (except shift)
bool allow_unicode_handling = !(k->is_command_pressed() || k->is_ctrl_pressed() || k->is_alt_pressed() || k->is_meta_pressed());
- // Save here for insert mode, just in case it is cleared in the following section.
- bool had_selection = selection.active;
-
selection.selecting_text = false;
// Check and handle all built in shortcuts.
@@ -2806,9 +2581,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
return;
}
+ // Handle Unicode (if no modifiers active).
if (allow_unicode_handling && !readonly && k->get_unicode() >= 32) {
- // Handle Unicode (if no modifiers active).
- _handle_unicode_character(k->get_unicode(), had_selection);
+ handle_unicode_input(k->get_unicode());
accept_event();
return;
}
@@ -3151,16 +2926,6 @@ void TextEdit::_remove_text(int p_from_line, int p_from_column, int p_to_line, i
current_op = op;
}
-void TextEdit::_insert_text_at_cursor(const String &p_text) {
- int new_column, new_line;
- _insert_text(cursor.line, cursor.column, p_text, &new_line, &new_column);
- _update_scrollbars();
- cursor_set_line(new_line, false);
- cursor_set_column(new_column);
-
- update();
-}
-
int TextEdit::get_char_count() {
int totalsize = 0;
@@ -3704,23 +3469,19 @@ int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
void TextEdit::insert_text_at_cursor(const String &p_text) {
if (selection.active) {
- cursor_set_line(selection.from_line, false);
- cursor_set_column(selection.from_column);
-
- _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
- selection.active = false;
- selection.selecting_mode = SelectionMode::SELECTION_MODE_NONE;
+ delete_selection();
}
- _insert_text_at_cursor(p_text);
+ int new_column, new_line;
+ _insert_text(cursor.line, cursor.column, p_text, &new_line, &new_column);
+ _update_scrollbars();
+
+ cursor_set_line(new_line, false);
+ cursor_set_column(new_column);
update();
}
Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
- if (highlighted_word != String()) {
- return CURSOR_POINTING_HAND;
- }
-
int row, col;
_get_mouse_pos(p_pos, row, col);
@@ -3753,7 +3514,7 @@ void TextEdit::set_text(String p_text) {
setting_text = true;
if (!undo_enabled) {
_clear();
- _insert_text_at_cursor(p_text);
+ insert_text_at_cursor(p_text);
}
if (undo_enabled) {
@@ -3762,7 +3523,7 @@ void TextEdit::set_text(String p_text) {
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);
+ insert_text_at_cursor(p_text);
end_complex_operation();
selection.active = false;
}
@@ -3903,30 +3664,6 @@ bool TextEdit::get_draw_control_chars() const {
return draw_control_chars;
}
-String TextEdit::get_text_for_lookup_completion() {
- int row, col;
- Point2i mp = _get_local_mouse_pos();
- _get_mouse_pos(mp, row, col);
-
- String longthing;
- int len = text.size();
- for (int i = 0; i < len; i++) {
- if (i == row) {
- longthing += text[i].substr(0, col);
- longthing += String::chr(0xFFFF); // Not unicode, represents the cursor.
- longthing += text[i].substr(col, text[i].size());
- } else {
- longthing += text[i];
- }
-
- if (i != len - 1) {
- longthing += "\n";
- }
- }
-
- return longthing;
-}
-
String TextEdit::get_line(int line) const {
if (line < 0 || line >= text.size()) {
return "";
@@ -4015,9 +3752,8 @@ void TextEdit::_update_caches() {
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.line_length_guideline_color = get_theme_color(SNAME("line_length_guideline_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"));
+ 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"));
@@ -4364,7 +4100,7 @@ void TextEdit::paste() {
clipboard += ins;
}
- _insert_text_at_cursor(clipboard);
+ insert_text_at_cursor(clipboard);
end_complex_operation();
update();
@@ -5324,21 +5060,6 @@ void TextEdit::insert_at(const String &p_text, int at) {
}
}
-void TextEdit::set_show_line_length_guidelines(bool p_show) {
- line_length_guidelines = p_show;
- update();
-}
-
-void TextEdit::set_line_length_guideline_soft_column(int p_column) {
- line_length_guideline_soft_col = p_column;
- update();
-}
-
-void TextEdit::set_line_length_guideline_hard_column(int p_column) {
- line_length_guideline_hard_col = p_column;
- update();
-}
-
void TextEdit::set_draw_minimap(bool p_draw) {
if (draw_minimap != p_draw) {
draw_minimap = p_draw;
@@ -5515,19 +5236,11 @@ void TextEdit::menu_option(int p_option) {
}
}
-void TextEdit::set_highlighted_word(const String &new_word) {
- highlighted_word = new_word;
+void TextEdit::_set_symbol_lookup_word(const String &p_symbol) {
+ lookup_symbol_word = p_symbol;
update();
}
-void TextEdit::set_select_identifiers_on_hover(bool p_enable) {
- select_identifiers_enabled = p_enable;
-}
-
-bool TextEdit::is_selecting_identifiers_on_hover_enabled() const {
- return select_identifiers_enabled;
-}
-
void TextEdit::set_context_menu_enabled(bool p_enable) {
context_menu_enabled = p_enable;
}
@@ -5719,6 +5432,7 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("delete_selection"), &TextEdit::delete_selection);
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);
@@ -5727,6 +5441,7 @@ void TextEdit::_bind_methods() {
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);
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);
@@ -5777,6 +5492,7 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_gutter_overwritable", "gutter"), &TextEdit::is_gutter_overwritable);
ClassDB::bind_method(D_METHOD("merge_gutters", "from_line", "to_line"), &TextEdit::merge_gutters);
ClassDB::bind_method(D_METHOD("set_gutter_custom_draw", "column", "object", "callback"), &TextEdit::set_gutter_custom_draw);
+ ClassDB::bind_method(D_METHOD("get_total_gutter_width"), &TextEdit::get_total_gutter_width);
// Line gutters.
ClassDB::bind_method(D_METHOD("set_line_gutter_metadata", "line", "gutter", "metadata"), &TextEdit::set_line_gutter_metadata);
@@ -5858,8 +5574,6 @@ void TextEdit::_bind_methods() {
ADD_SIGNAL(MethodInfo("gutter_clicked", PropertyInfo(Variant::INT, "line"), PropertyInfo(Variant::INT, "gutter")));
ADD_SIGNAL(MethodInfo("gutter_added"));
ADD_SIGNAL(MethodInfo("gutter_removed"));
- ADD_SIGNAL(MethodInfo("symbol_lookup", PropertyInfo(Variant::STRING, "symbol"), PropertyInfo(Variant::INT, "row"), PropertyInfo(Variant::INT, "column")));
- ADD_SIGNAL(MethodInfo("symbol_validate", PropertyInfo(Variant::STRING, "symbol")));
BIND_ENUM_CONSTANT(MENU_CUT);
BIND_ENUM_CONSTANT(MENU_COPY);
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 62d576b48a..9e6dedb267 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -280,9 +280,6 @@ private:
bool cursor_changed_dirty = false;
bool text_changed_dirty = false;
bool undo_enabled = true;
- bool line_length_guidelines = false;
- int line_length_guideline_soft_col = 80;
- int line_length_guideline_hard_col = 100;
bool hiding_enabled = false;
bool draw_minimap = false;
int minimap_width = 80;
@@ -291,7 +288,6 @@ private:
bool highlight_all_occurrences = false;
bool scroll_past_end_of_file_enabled = false;
- bool brace_matching_enabled = false;
bool highlight_current_line = false;
String cut_copy_line;
@@ -309,7 +305,7 @@ private:
float target_v_scroll = 0.0;
float v_scroll_speed = 80.0;
- String highlighted_word;
+ String lookup_symbol_word;
uint64_t last_dblclk = 0;
@@ -386,7 +382,6 @@ private:
Size2 get_minimum_size() const override;
int _get_control_height() const;
- Point2 _get_local_mouse_pos() const;
int _get_menu_action_accelerator(const String &p_action);
void _reset_caret_blink_timer();
@@ -431,10 +426,9 @@ private:
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);
- void _handle_unicode_character(uint32_t unicode, bool p_had_selection);
protected:
- bool auto_brace_completion_enabled = false;
+ bool highlight_matching_braces_enabled = false;
struct Cache {
Ref<Texture2D> tab_icon;
@@ -455,7 +449,6 @@ protected:
Color selection_color;
Color code_folding_color;
Color current_line_color;
- Color line_length_guideline_color;
Color brace_mismatch_color;
Color word_highlighted_color;
Color search_result_color;
@@ -470,19 +463,17 @@ protected:
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);
- void _insert_text_at_cursor(const String &p_text);
virtual void _gui_input(const Ref<InputEvent> &p_gui_input);
void _notification(int p_what);
- void _consume_pair_symbol(char32_t ch);
- void _consume_backspace_for_pair_symbol(int prev_line, int prev_column);
-
static void _bind_methods();
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
+ void _set_symbol_lookup_word(const String &p_symbol);
+
public:
/* Syntax Highlighting. */
Ref<SyntaxHighlighter> get_syntax_highlighter();
@@ -577,8 +568,10 @@ public:
virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override;
+ 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;
//void delete_char();
//void delete_line();
@@ -607,7 +600,6 @@ public:
void set_structured_text_bidi_override_options(Array p_args);
Array get_structured_text_bidi_override_options() const;
- void set_highlighted_word(const String &new_word);
void set_text(String p_text);
void insert_text_at_cursor(const String &p_text);
void insert_at(const String &p_text, int at);
@@ -635,13 +627,6 @@ public:
scroll_past_end_of_file_enabled = p_enabled;
update();
}
- inline void set_auto_brace_completion(bool p_enabled) {
- auto_brace_completion_enabled = p_enabled;
- }
- inline void set_brace_matching(bool p_enabled) {
- brace_matching_enabled = p_enabled;
- update();
- }
void center_viewport_to_cursor();
@@ -686,6 +671,7 @@ public:
void delete_selection();
+ virtual void handle_unicode_input(uint32_t p_unicode);
virtual void backspace();
void cut();
void copy();
@@ -751,10 +737,6 @@ public:
void set_highlight_current_line(bool p_enabled);
bool is_highlight_current_line_enabled() const;
- void set_show_line_length_guidelines(bool p_show);
- void set_line_length_guideline_soft_column(int p_column);
- void set_line_length_guideline_hard_column(int p_column);
-
void set_draw_minimap(bool p_draw);
bool is_drawing_minimap() const;
@@ -766,9 +748,6 @@ public:
void set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata);
- void set_select_identifiers_on_hover(bool p_enable);
- bool is_selecting_identifiers_on_hover_enabled() const;
-
void set_context_menu_enabled(bool p_enable);
bool is_context_menu_enabled();
@@ -784,8 +763,6 @@ public:
bool is_menu_visible() const;
PopupMenu *get_menu() const;
- String get_text_for_lookup_completion();
-
virtual bool is_text_field() const override;
TextEdit();
~TextEdit();
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 10e6642303..be711b4c4f 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -462,8 +462,6 @@ private:
void _gui_input(Ref<InputEvent> p_event);
void _notification(int p_what);
- Size2 get_minimum_size() const override;
-
void item_edited(int p_column, TreeItem *p_item, bool p_lmb = true);
void item_changed(int p_column, TreeItem *p_item);
void item_selected(int p_column, TreeItem *p_item);
@@ -721,6 +719,8 @@ public:
void set_allow_reselect(bool p_allow);
bool get_allow_reselect() const;
+ Size2 get_minimum_size() const override;
+
Tree();
~Tree();
};