summaryrefslogtreecommitdiff
path: root/scene/gui/text_edit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/text_edit.cpp')
-rw-r--r--scene/gui/text_edit.cpp57
1 files changed, 45 insertions, 12 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index c339cf6374..1504ad7bf1 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -39,6 +39,7 @@
#ifdef TOOLS_ENABLED
#include "editor/editor_scale.h"
+#include "editor_settings.h"
#endif
#define TAB_PIXELS
@@ -918,6 +919,26 @@ void TextEdit::_notification(int p_what) {
}
}
+ int indent_level = get_indent_level(i);
+ if (draw_indent_guides && indent_level > 0) {
+#ifdef TOOLS_ENABLED
+ int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size");
+ float line_width = Math::round(EDSCALE);
+#else
+ int indent_size = 4;
+ float line_width = 1.0;
+#endif
+ int guides = 1 + (indent_level - 1) / indent_size;
+
+ for (int guide = 0; guide < guides; guide++) {
+ draw_line(
+ Point2(guide * indent_size * cache.font->get_char_size(' ').width + char_margin, ofs_y),
+ Point2(guide * indent_size * cache.font->get_char_size(' ').width + char_margin, ofs_y + get_row_height()),
+ cache.indent_guide_color,
+ line_width);
+ }
+ }
+
if (line_wrap_index == 0) {
// only do these if we are on the first wrapped part of a line
@@ -1179,9 +1200,14 @@ void TextEdit::_notification(int p_what) {
draw_rect(Rect2(char_ofs + char_margin + ofs_x, yofs + ascent + 2, w, line_width), in_selection && override_selected_font_color ? cache.font_selected_color : color);
}
- } else if (draw_tabs && str[j] == '\t') {
+ } else if (draw_tabs && (j > get_indent_level(i) || !draw_indent_guides) && str[j] == '\t') {
+ // If indent guides are enabled, only draw trailing or alignment tabs
+ // Otherwise, draw all tabs (including those used for indentation)
int yofs = (get_row_height() - cache.tab_icon->get_height()) / 2;
- cache.tab_icon->draw(ci, Point2(char_ofs + char_margin + ofs_x, ofs_y + yofs), in_selection && override_selected_font_color ? cache.font_selected_color : color);
+ cache.tab_icon->draw(
+ ci,
+ Point2(char_ofs + char_margin + ofs_x, ofs_y + yofs),
+ in_selection && override_selected_font_color ? cache.font_selected_color : color);
}
char_ofs += char_w;
@@ -1412,7 +1438,6 @@ void TextEdit::_notification(int p_what) {
if (has_focus()) {
OS::get_singleton()->set_ime_active(true);
OS::get_singleton()->set_ime_position(get_global_position() + cursor_pos + Point2(0, get_row_height()));
- OS::get_singleton()->set_ime_intermediate_text_callback(_ime_text_callback, this);
}
} break;
@@ -1425,7 +1450,6 @@ void TextEdit::_notification(int p_what) {
OS::get_singleton()->set_ime_active(true);
Point2 cursor_pos = Point2(cursor_get_column(), cursor_get_line()) * get_row_height();
OS::get_singleton()->set_ime_position(get_global_position() + cursor_pos);
- OS::get_singleton()->set_ime_intermediate_text_callback(_ime_text_callback, this);
if (OS::get_singleton()->has_virtual_keyboard())
OS::get_singleton()->show_virtual_keyboard(get_text(), get_global_rect());
@@ -1433,7 +1457,6 @@ void TextEdit::_notification(int p_what) {
case NOTIFICATION_FOCUS_EXIT: {
OS::get_singleton()->set_ime_position(Point2());
- OS::get_singleton()->set_ime_intermediate_text_callback(NULL, NULL);
OS::get_singleton()->set_ime_active(false);
ime_text = "";
ime_selection = Point2();
@@ -1441,14 +1464,13 @@ void TextEdit::_notification(int p_what) {
if (OS::get_singleton()->has_virtual_keyboard())
OS::get_singleton()->hide_virtual_keyboard();
} break;
- }
-}
+ case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
-void TextEdit::_ime_text_callback(void *p_self, String p_text, Point2 p_selection) {
- TextEdit *self = (TextEdit *)p_self;
- self->ime_text = p_text;
- self->ime_selection = p_selection;
- self->update();
+ ime_text = OS::get_singleton()->get_ime_text();
+ ime_selection = OS::get_singleton()->get_ime_selection();
+ update();
+ } break;
+ }
}
void TextEdit::_consume_pair_symbol(CharType ch) {
@@ -4333,6 +4355,7 @@ void TextEdit::_update_caches() {
cache.font = get_font("font");
cache.caret_color = get_color("caret_color");
cache.caret_background_color = get_color("caret_background_color");
+ cache.indent_guide_color = get_color("indent_guide_color");
cache.line_number_color = get_color("line_number_color");
cache.safe_line_number_color = get_color("safe_line_number_color");
cache.font_color = get_color("font_color");
@@ -5446,6 +5469,16 @@ int TextEdit::get_indent_size() {
return indent_size;
}
+void TextEdit::set_draw_indent_guides(bool p_draw) {
+
+ draw_indent_guides = p_draw;
+}
+
+bool TextEdit::is_drawing_indent_guides() const {
+
+ return draw_indent_guides;
+}
+
void TextEdit::set_draw_tabs(bool p_draw) {
draw_tabs = p_draw;