summaryrefslogtreecommitdiffstats
path: root/scene/gui/text_edit.cpp
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2018-08-05 00:42:45 +0200
committerHugo Locurcio <hugo.locurcio@hugo.pro>2018-10-03 00:00:25 +0200
commit9c1d4f9da2e4e2ab3f754d9d544c01b1da532ccc (patch)
treed9eac294e66d16e4c122f06f67ca681765b177d7 /scene/gui/text_edit.cpp
parent7c712a25bc40c4d8e09867b61c941af06c6799f5 (diff)
downloadredot-engine-9c1d4f9da2e4e2ab3f754d9d544c01b1da532ccc.tar.gz
Use more subtle indentation guides in the script editor
Diffstat (limited to 'scene/gui/text_edit.cpp')
-rw-r--r--scene/gui/text_edit.cpp41
1 files changed, 39 insertions, 2 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index c9dcf058aa..5e3827b1a8 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
@@ -923,6 +924,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) {
if (underlined) {
draw_rect(Rect2(char_ofs + char_margin + ofs_x, yofs + ascent + 2, w, 1), 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;
@@ -4324,6 +4350,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");
@@ -5430,6 +5457,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;