summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-02-27 21:10:42 +0100
committerGitHub <noreply@github.com>2020-02-27 21:10:42 +0100
commit2d904d2f8085967c1b6a606358a38c0bc2309dd0 (patch)
tree3b6d26d18dce7de333ad875f70e9ecfb4e81bfa6 /scene/gui
parentf9d93ee819d216048e9dc69d4481be7802fb53da (diff)
parent3e4b508c3b91ef7cc8769e1be178ef7a75b1ad58 (diff)
Merge pull request #36232 from Calinou/add-soft-line-length-guideline
Add a soft line length guideline to the script editor
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/text_edit.cpp34
-rw-r--r--scene/gui/text_edit.h10
2 files changed, 30 insertions, 14 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 2fd1ba5535..379e70b951 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -753,10 +753,18 @@ void TextEdit::_notification(int p_what) {
}
}
- if (line_length_guideline) {
- int x = xmargin_beg + (int)cache.font->get_char_size('0').width * line_length_guideline_col - cursor.x_ofs;
- if (x > xmargin_beg && x < xmargin_end) {
- VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(x, 0), Point2(x, size.height), cache.line_length_guideline_color);
+ if (line_length_guidelines) {
+ const int hard_x = xmargin_beg + (int)cache.font->get_char_size('0').width * line_length_guideline_hard_col - cursor.x_ofs;
+ if (hard_x > xmargin_beg && hard_x < xmargin_end) {
+ VisualServer::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').width * line_length_guideline_soft_col - cursor.x_ofs;
+ if (hard_x != soft_x && soft_x > xmargin_beg && soft_x < xmargin_end) {
+ VisualServer::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));
}
}
@@ -6834,13 +6842,18 @@ bool TextEdit::is_show_line_numbers_enabled() const {
return line_numbers;
}
-void TextEdit::set_show_line_length_guideline(bool p_show) {
- line_length_guideline = p_show;
+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_column(int p_column) {
- line_length_guideline_col = p_column;
+void TextEdit::set_line_length_guideline_hard_column(int p_column) {
+ line_length_guideline_hard_col = p_column;
update();
}
@@ -7309,8 +7322,9 @@ TextEdit::TextEdit() {
tooltip_obj = NULL;
line_numbers = false;
line_numbers_zero_padded = false;
- line_length_guideline = false;
- line_length_guideline_col = 80;
+ line_length_guidelines = false;
+ line_length_guideline_soft_col = 80;
+ line_length_guideline_hard_col = 100;
draw_bookmark_gutter = false;
draw_breakpoint_gutter = false;
draw_fold_gutter = false;
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 9986b80fd5..6e267f5a47 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -369,8 +369,9 @@ private:
bool undo_enabled;
bool line_numbers;
bool line_numbers_zero_padded;
- bool line_length_guideline;
- int line_length_guideline_col;
+ bool line_length_guidelines;
+ int line_length_guideline_soft_col;
+ int line_length_guideline_hard_col;
bool draw_bookmark_gutter;
bool draw_breakpoint_gutter;
int breakpoint_gutter_width;
@@ -765,8 +766,9 @@ public:
void set_line_numbers_zero_padded(bool p_zero_padded);
- void set_show_line_length_guideline(bool p_show);
- void set_line_length_guideline_column(int p_column);
+ 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_bookmark_gutter_enabled(bool p_draw);
bool is_bookmark_gutter_enabled() const;