Skip to content

Commit 5f464d3

Browse files
committed
Fix most of TextEdit visual issues.
1 parent e4e024a commit 5f464d3

File tree

5 files changed

+208
-178
lines changed

5 files changed

+208
-178
lines changed

doc/classes/TextEdit.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,6 @@
12741274
<member name="caret_type" type="int" setter="set_caret_type" getter="get_caret_type" enum="TextEdit.CaretType" default="0">
12751275
Set the type of caret to draw.
12761276
</member>
1277-
<member name="clip_contents" type="bool" setter="set_clip_contents" getter="is_clipping_contents" overrides="Control" default="true" />
12781277
<member name="context_menu_enabled" type="bool" setter="set_context_menu_enabled" getter="is_context_menu_enabled" default="true">
12791278
If [code]true[/code], a right-click displays the context menu.
12801279
</member>

scene/gui/code_edit.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ void CodeEdit::_notification(int p_what) {
5555
} break;
5656

5757
case NOTIFICATION_DRAW: {
58-
RID ci = get_canvas_item();
58+
RID ci = _get_text_canvas_item();
5959
const Size2 size = get_size();
6060
const bool caret_visible = is_caret_visible();
6161
const bool rtl = is_layout_rtl();
6262
const int row_height = get_line_height();
6363

6464
if (line_length_guideline_columns.size() > 0) {
65+
VScrollBar *v_scroll_bar = get_v_scroll_bar();
6566
const int xmargin_beg = theme_cache.style_normal->get_margin(SIDE_LEFT) + get_total_gutter_width();
66-
const int xmargin_end = size.width - theme_cache.style_normal->get_margin(SIDE_RIGHT) - (is_drawing_minimap() ? get_minimap_width() : 0);
67+
const int xmargin_end = size.width - theme_cache.style_normal->get_margin(SIDE_RIGHT) - (is_drawing_minimap() ? get_minimap_width() : 0) - (v_scroll_bar->is_visible_in_tree() ? v_scroll_bar->get_combined_minimum_size().width : 0);
6768
const float char_size = theme_cache.font->get_char_size('0', theme_cache.font_size).width;
6869

6970
for (int i = 0; i < line_length_guideline_columns.size(); i++) {
@@ -108,7 +109,7 @@ void CodeEdit::_notification(int p_what) {
108109
hint_ofs.y -= (code_hint_minsize.y + row_height) - theme_cache.line_spacing;
109110
}
110111

111-
draw_style_box(theme_cache.code_hint_style, Rect2(hint_ofs, code_hint_minsize));
112+
theme_cache.code_hint_style->draw(ci, Rect2(hint_ofs, code_hint_minsize));
112113

113114
int yofs = 0;
114115
for (int i = 0; i < line_count; i++) {
@@ -123,17 +124,17 @@ void CodeEdit::_notification(int p_what) {
123124

124125
Point2 round_ofs = hint_ofs + theme_cache.code_hint_style->get_offset() + Vector2(0, theme_cache.font->get_ascent(theme_cache.font_size) + font_height * i + yofs);
125126
round_ofs = round_ofs.round();
126-
draw_string(theme_cache.font, round_ofs, line.replace(String::chr(0xFFFF), ""), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size, theme_cache.code_hint_color);
127+
theme_cache.font->draw_string(ci, round_ofs, line.replace(String::chr(0xFFFF), ""), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size, theme_cache.code_hint_color);
127128
if (end > 0) {
128129
// Draw an underline for the currently edited function parameter.
129130
const Vector2 b = hint_ofs + theme_cache.code_hint_style->get_offset() + Vector2(begin, font_height + font_height * i + yofs);
130-
draw_line(b, b + Vector2(end - begin, 0), theme_cache.code_hint_color, 2);
131+
RenderingServer::get_singleton()->canvas_item_add_line(ci, b, b + Vector2(end - begin, 0), theme_cache.code_hint_color, 2);
131132

132133
// Draw a translucent text highlight as well.
133134
const Rect2 highlight_rect = Rect2(
134135
b - Vector2(0, font_height),
135136
Vector2(end - begin, font_height));
136-
draw_rect(highlight_rect, theme_cache.code_hint_color * Color(1, 1, 1, 0.2));
137+
RenderingServer::get_singleton()->canvas_item_add_rect(ci, highlight_rect, theme_cache.code_hint_color * Color(1, 1, 1, 0.2));
137138
}
138139
yofs += theme_cache.line_spacing;
139140
}
@@ -182,7 +183,7 @@ void CodeEdit::_notification(int p_what) {
182183
code_completion_rect.position.x = caret_pos.x - code_completion_base_width;
183184
}
184185

185-
draw_style_box(theme_cache.code_completion_style, Rect2(code_completion_rect.position - theme_cache.code_completion_style->get_offset(), code_completion_rect.size + theme_cache.code_completion_style->get_minimum_size() + Size2(scroll_width, 0)));
186+
theme_cache.code_completion_style->draw(ci, Rect2(code_completion_rect.position - theme_cache.code_completion_style->get_offset(), code_completion_rect.size + theme_cache.code_completion_style->get_minimum_size() + Size2(scroll_width, 0)));
186187
if (theme_cache.code_completion_background_color.a > 0.01) {
187188
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(code_completion_rect.position, code_completion_rect.size + Size2(scroll_width, 0)), theme_cache.code_completion_background_color);
188189
}
@@ -216,18 +217,18 @@ void CodeEdit::_notification(int p_what) {
216217
tl->set_width(code_completion_rect.size.width - (icon_area_size.x + theme_cache.code_completion_icon_separation));
217218
if (rtl) {
218219
if (code_completion_options[l].default_value.get_type() == Variant::COLOR) {
219-
draw_rect(Rect2(Point2(code_completion_rect.position.x, icon_area.position.y), icon_area_size), (Color)code_completion_options[l].default_value);
220+
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(code_completion_rect.position.x, icon_area.position.y), icon_area_size), (Color)code_completion_options[l].default_value);
220221
}
221222
tl->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
222223
} else {
223224
if (code_completion_options[l].default_value.get_type() == Variant::COLOR) {
224225
const Color color = code_completion_options[l].default_value;
225226
const Rect2 rect = Rect2(Point2(code_completion_rect.position.x + code_completion_rect.size.width - icon_area_size.x, icon_area.position.y), icon_area_size);
226227
if (color.a < 1.0) {
227-
draw_texture_rect(theme_cache.completion_color_bg, rect, true);
228+
RenderingServer::get_singleton()->canvas_item_add_texture_rect(ci, rect, theme_cache.completion_color_bg->get_rid(), true);
228229
}
229230

230-
draw_rect(rect, color);
231+
RenderingServer::get_singleton()->canvas_item_add_rect(ci, rect, color);
231232
}
232233
tl->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT);
233234
}
@@ -239,7 +240,7 @@ void CodeEdit::_notification(int p_what) {
239240
int match_offset = theme_cache.font->get_string_size(code_completion_options[l].display.substr(0, match_segment.first), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size).width;
240241
int match_len = theme_cache.font->get_string_size(code_completion_options[l].display.substr(match_segment.first, match_segment.second), HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.font_size).width;
241242

242-
draw_rect(Rect2(match_pos + Point2(match_offset, 0), Size2(match_len, row_height)), theme_cache.code_completion_existing_color);
243+
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(match_pos + Point2(match_offset, 0), Size2(match_len, row_height)), theme_cache.code_completion_existing_color);
243244
}
244245
tl->draw(ci, title_pos, code_completion_options[l].font_color);
245246
}
@@ -250,7 +251,7 @@ void CodeEdit::_notification(int p_what) {
250251

251252
float r = (float)theme_cache.code_completion_max_lines / code_completion_options_count;
252253
float o = (float)code_completion_line_ofs / code_completion_options_count;
253-
draw_rect(Rect2(code_completion_rect.position.x + code_completion_rect.size.width, code_completion_rect.position.y + o * code_completion_rect.size.y, scroll_width, code_completion_rect.size.y * r), scroll_color);
254+
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(code_completion_rect.position.x + code_completion_rect.size.width, code_completion_rect.position.y + o * code_completion_rect.size.y, scroll_width, code_completion_rect.size.y * r), scroll_color);
254255
}
255256
}
256257
}
@@ -1298,6 +1299,7 @@ bool CodeEdit::is_drawing_executing_lines_gutter() const {
12981299

12991300
void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2 &p_region) {
13001301
bool hovering = get_hovered_gutter() == Vector2i(main_gutter, p_line);
1302+
RID ci = _get_text_canvas_item();
13011303
if (draw_breakpoints && theme_cache.breakpoint_icon.is_valid()) {
13021304
bool breakpointed = is_line_breakpointed(p_line);
13031305
bool shift_pressed = Input::get_singleton()->is_key_pressed(Key::SHIFT);
@@ -1312,7 +1314,7 @@ void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2
13121314
Rect2 icon_region = p_region;
13131315
icon_region.position += Point2(padding, padding);
13141316
icon_region.size -= Point2(padding, padding) * 2;
1315-
theme_cache.breakpoint_icon->draw_rect(get_canvas_item(), icon_region, false, use_color);
1317+
theme_cache.breakpoint_icon->draw_rect(ci, icon_region, false, use_color);
13161318
}
13171319
}
13181320

@@ -1331,7 +1333,7 @@ void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2
13311333
Rect2 icon_region = p_region;
13321334
icon_region.position += Point2(horizontal_padding, 0);
13331335
icon_region.size -= Point2(horizontal_padding * 1.1, vertical_padding);
1334-
theme_cache.bookmark_icon->draw_rect(get_canvas_item(), icon_region, false, use_color);
1336+
theme_cache.bookmark_icon->draw_rect(ci, icon_region, false, use_color);
13351337
}
13361338
}
13371339

@@ -1342,7 +1344,7 @@ void CodeEdit::_main_gutter_draw_callback(int p_line, int p_gutter, const Rect2
13421344
Rect2 icon_region = p_region;
13431345
icon_region.position += Point2(horizontal_padding, vertical_padding);
13441346
icon_region.size -= Point2(horizontal_padding, vertical_padding) * 2;
1345-
theme_cache.executing_line_icon->draw_rect(get_canvas_item(), icon_region, false, theme_cache.executing_line_color);
1347+
theme_cache.executing_line_icon->draw_rect(ci, icon_region, false, theme_cache.executing_line_color);
13461348
}
13471349
}
13481350

@@ -1503,7 +1505,7 @@ void CodeEdit::_line_number_draw_callback(int p_line, int p_gutter, const Rect2
15031505
number_color = theme_cache.line_number_color;
15041506
}
15051507

1506-
TS->shaped_text_draw(text_rid, get_canvas_item(), ofs, -1, -1, number_color);
1508+
TS->shaped_text_draw(text_rid, _get_text_canvas_item(), ofs, -1, -1, number_color);
15071509
}
15081510

15091511
void CodeEdit::_clear_line_number_text_cache() {
@@ -1532,6 +1534,7 @@ void CodeEdit::_fold_gutter_draw_callback(int p_line, int p_gutter, Rect2 p_regi
15321534
return;
15331535
}
15341536
set_line_gutter_clickable(p_line, fold_gutter, true);
1537+
RID ci = _get_text_canvas_item();
15351538

15361539
int horizontal_padding = p_region.size.x / 10;
15371540
int vertical_padding = p_region.size.y / 6;
@@ -1545,17 +1548,17 @@ void CodeEdit::_fold_gutter_draw_callback(int p_line, int p_gutter, Rect2 p_regi
15451548
Color region_icon_color = theme_cache.folded_code_region_color;
15461549
region_icon_color.a = MAX(region_icon_color.a, 0.4f);
15471550
if (can_fold) {
1548-
theme_cache.can_fold_code_region_icon->draw_rect(get_canvas_item(), p_region, false, region_icon_color);
1551+
theme_cache.can_fold_code_region_icon->draw_rect(ci, p_region, false, region_icon_color);
15491552
} else {
1550-
theme_cache.folded_code_region_icon->draw_rect(get_canvas_item(), p_region, false, region_icon_color);
1553+
theme_cache.folded_code_region_icon->draw_rect(ci, p_region, false, region_icon_color);
15511554
}
15521555
return;
15531556
}
15541557
if (can_fold) {
1555-
theme_cache.can_fold_icon->draw_rect(get_canvas_item(), p_region, false, theme_cache.code_folding_color);
1558+
theme_cache.can_fold_icon->draw_rect(ci, p_region, false, theme_cache.code_folding_color);
15561559
return;
15571560
}
1558-
theme_cache.folded_icon->draw_rect(get_canvas_item(), p_region, false, theme_cache.code_folding_color);
1561+
theme_cache.folded_icon->draw_rect(ci, p_region, false, theme_cache.code_folding_color);
15591562
}
15601563

15611564
/* Line Folding */

0 commit comments

Comments
 (0)