Skip to content

Commit 7498243

Browse files
committed
Merge pull request godotengine#108599 from bruvzg/te_guideline_order
[TextEdit] Draw guidelines under the text and caret.
2 parents eb0caa6 + 8624134 commit 7498243

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed

scene/gui/code_edit.cpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,10 @@ void CodeEdit::_notification(int p_what) {
7070

7171
case NOTIFICATION_DRAW: {
7272
RID ci = get_canvas_item();
73-
const Size2 size = get_size();
7473
const bool caret_visible = is_caret_visible();
7574
const bool rtl = is_layout_rtl();
7675
const int row_height = get_line_height();
7776

78-
if (line_length_guideline_columns.size() > 0) {
79-
const int xmargin_beg = theme_cache.style_normal->get_margin(SIDE_LEFT) + get_total_gutter_width();
80-
const int xmargin_end = size.width - theme_cache.style_normal->get_margin(SIDE_RIGHT) - (is_drawing_minimap() ? get_minimap_width() : 0);
81-
82-
for (int i = 0; i < line_length_guideline_columns.size(); i++) {
83-
const int column_pos = theme_cache.font->get_string_size(String("0").repeat((int)line_length_guideline_columns[i]), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size).x;
84-
const int xoffset = xmargin_beg + column_pos - get_h_scroll();
85-
if (xoffset > xmargin_beg && xoffset < xmargin_end) {
86-
Color guideline_color = (i == 0) ? theme_cache.line_length_guideline_color : theme_cache.line_length_guideline_color * Color(1, 1, 1, 0.5);
87-
if (rtl) {
88-
RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(size.width - xoffset, 0), Point2(size.width - xoffset, size.height), guideline_color);
89-
continue;
90-
}
91-
RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(xoffset, 0), Point2(xoffset, size.height), guideline_color);
92-
}
93-
}
94-
}
95-
9677
if (caret_visible) {
9778
const bool draw_code_completion = code_completion_active && !code_completion_options.is_empty();
9879
const bool draw_code_hint = !code_hint.is_empty();
@@ -280,6 +261,32 @@ void CodeEdit::_notification(int p_what) {
280261
}
281262
}
282263

264+
void CodeEdit::_draw_guidelines() {
265+
if (line_length_guideline_columns.is_empty()) {
266+
return;
267+
}
268+
269+
RID ci = get_canvas_item();
270+
const Size2 size = get_size();
271+
const bool rtl = is_layout_rtl();
272+
273+
const int xmargin_beg = theme_cache.style_normal->get_margin(SIDE_LEFT) + get_total_gutter_width();
274+
const int xmargin_end = size.width - theme_cache.style_normal->get_margin(SIDE_RIGHT) - (is_drawing_minimap() ? get_minimap_width() : 0);
275+
276+
for (int i = 0; i < line_length_guideline_columns.size(); i++) {
277+
const int column_pos = theme_cache.font->get_string_size(String("0").repeat((int)line_length_guideline_columns[i]), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size).x;
278+
const int xoffset = xmargin_beg + column_pos - get_h_scroll();
279+
if (xoffset > xmargin_beg && xoffset < xmargin_end) {
280+
Color guideline_color = (i == 0) ? theme_cache.line_length_guideline_color : theme_cache.line_length_guideline_color * Color(1, 1, 1, 0.5);
281+
if (rtl) {
282+
RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(size.width - xoffset, 0), Point2(size.width - xoffset, size.height), guideline_color);
283+
continue;
284+
}
285+
RenderingServer::get_singleton()->canvas_item_add_line(ci, Point2(xoffset, 0), Point2(xoffset, size.height), guideline_color);
286+
}
287+
}
288+
}
289+
283290
void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
284291
Ref<InputEventPanGesture> pan_gesture = p_gui_input;
285292
if (pan_gesture.is_valid() && code_completion_active && code_completion_rect.has_point(pan_gesture->get_position())) {

scene/gui/code_edit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ class CodeEdit : public TextEdit {
325325

326326
virtual void _unhide_carets() override;
327327

328+
virtual void _draw_guidelines() override;
329+
328330
/* Text manipulation */
329331

330332
// Overridable actions

scene/gui/text_edit.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,9 @@ void TextEdit::_notification(int p_what) {
13041304
bottom_limit_y -= theme_cache.style_normal->get_margin(SIDE_BOTTOM);
13051305
}
13061306

1307+
// Draw guidelines.
1308+
_draw_guidelines();
1309+
13071310
// Draw main text.
13081311
line_drawing_cache.clear();
13091312
int row_height = draw_placeholder ? placeholder_line_height + theme_cache.line_spacing : get_line_height();

scene/gui/text_edit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ class TextEdit : public Control {
696696
static void _bind_compatibility_methods();
697697
#endif // DISABLE_DEPRECATED
698698

699+
virtual void _draw_guidelines() {}
699700
virtual void _update_theme_item_cache() override;
700701

701702
/* Internal API for CodeEdit, pending public API. */

0 commit comments

Comments
 (0)