From f36c90b82f132358a233fa7093d10028ea699a14 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 27 Feb 2020 21:10:42 +0100 Subject: [PATCH] Add a soft line length guideline to the script editor The default value is 80. The hard line length guideline's default column has been moved to 100 to account for the new soft line length guideline. It can be disabled by setting its value to the same column as the hard line length guideline. --- editor/code_editor.cpp | 5 ++-- editor/editor_settings.cpp | 8 +++--- editor/plugins/shader_editor_plugin.cpp | 5 ++-- scene/gui/text_edit.cpp | 34 +++++++++++++++++-------- scene/gui/text_edit.h | 10 +++++--- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index f7d719e408f..4a63d6d3025 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -933,8 +933,9 @@ void CodeTextEditor::update_editor_settings() { text_editor->set_hiding_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding")); text_editor->set_draw_fold_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding")); text_editor->set_wrap_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/word_wrap")); - text_editor->set_show_line_length_guideline(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_length_guideline")); - text_editor->set_line_length_guideline_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_column")); + text_editor->set_show_line_length_guidelines(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_length_guidelines")); + text_editor->set_line_length_guideline_soft_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_soft_column")); + text_editor->set_line_length_guideline_hard_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_hard_column")); text_editor->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file")); text_editor->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret")); text_editor->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink")); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index e7df987e4e6..343c736923b 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -470,9 +470,11 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { _initial_set("text_editor/appearance/show_info_gutter", true); _initial_set("text_editor/appearance/code_folding", true); _initial_set("text_editor/appearance/word_wrap", false); - _initial_set("text_editor/appearance/show_line_length_guideline", true); - _initial_set("text_editor/appearance/line_length_guideline_column", 80); - hints["text_editor/appearance/line_length_guideline_column"] = PropertyInfo(Variant::INT, "text_editor/appearance/line_length_guideline_column", PROPERTY_HINT_RANGE, "20, 160, 1"); + _initial_set("text_editor/appearance/show_line_length_guidelines", true); + _initial_set("text_editor/appearance/line_length_guideline_soft_column", 80); + hints["text_editor/appearance/line_length_guideline_soft_column"] = PropertyInfo(Variant::INT, "text_editor/appearance/line_length_guideline_soft_column", PROPERTY_HINT_RANGE, "20, 160, 1"); + _initial_set("text_editor/appearance/line_length_guideline_hard_column", 100); + hints["text_editor/appearance/line_length_guideline_hard_column"] = PropertyInfo(Variant::INT, "text_editor/appearance/line_length_guideline_hard_column", PROPERTY_HINT_RANGE, "20, 160, 1"); // Script list _initial_set("text_editor/script_list/show_members_overview", true); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index ab19a3d299e..b851dae2552 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -375,8 +375,9 @@ void ShaderEditor::_editor_settings_changed() { shader_editor->get_text_edit()->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/navigation/v_scroll_speed")); shader_editor->get_text_edit()->set_draw_minimap(EditorSettings::get_singleton()->get("text_editor/navigation/show_minimap")); shader_editor->get_text_edit()->set_minimap_width((int)EditorSettings::get_singleton()->get("text_editor/navigation/minimap_width") * EDSCALE); - shader_editor->get_text_edit()->set_show_line_length_guideline(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_length_guideline")); - shader_editor->get_text_edit()->set_line_length_guideline_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_column")); + shader_editor->get_text_edit()->set_show_line_length_guidelines(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_length_guidelines")); + shader_editor->get_text_edit()->set_line_length_guideline_soft_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_soft_column")); + shader_editor->get_text_edit()->set_line_length_guideline_hard_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_hard_column")); shader_editor->get_text_edit()->set_breakpoint_gutter_enabled(false); } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 434c208980e..17740f9f56b 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -716,10 +716,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)); } } @@ -6795,13 +6803,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_column(int p_column) { - line_length_guideline_col = p_column; +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(); } @@ -7287,8 +7300,9 @@ TextEdit::TextEdit() { tooltip_obj = nullptr; 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 3a35705843b..01c167d2656 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -364,8 +364,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; @@ -762,8 +763,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;