Merge pull request #19735 from Paulb23/text_offset_issue_15688

Fixed text drawing too high in TextEdit, issue 15688
This commit is contained in:
Max Hilbrunner 2018-07-05 04:04:39 +02:00 committed by GitHub
commit 16f1a77319
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -711,7 +711,8 @@ void LineEdit::_notification(int p_what) {
if (selected) if (selected)
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color); VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color);
drawer.draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, selected ? font_color_selected : font_color); int yofs = y_ofs + (caret_height - font->get_height()) / 2;
drawer.draw_char(ci, Point2(x_ofs, yofs + font_ascent), cchar, next, selected ? font_color_selected : font_color);
if (char_ofs == cursor_pos && draw_caret) { if (char_ofs == cursor_pos && draw_caret) {
if (ime_text.length() == 0) { if (ime_text.length() == 0) {

View File

@ -966,12 +966,13 @@ void TextEdit::_notification(int p_what) {
// draw line numbers // draw line numbers
if (cache.line_number_w) { if (cache.line_number_w) {
int yofs = ofs_y + (get_row_height() - cache.font->get_height()) / 2;
String fc = String::num(line + 1); String fc = String::num(line + 1);
while (fc.length() < line_number_char_count) { while (fc.length() < line_number_char_count) {
fc = line_num_padding + fc; fc = line_num_padding + fc;
} }
cache.font->draw(ci, Point2(cache.style_normal->get_margin(MARGIN_LEFT) + cache.breakpoint_gutter_width + ofs_x, ofs_y + cache.font->get_ascent()), fc, cache.line_number_color); cache.font->draw(ci, Point2(cache.style_normal->get_margin(MARGIN_LEFT) + cache.breakpoint_gutter_width + ofs_x, yofs + cache.font->get_ascent()), fc, cache.line_number_color);
} }
} }
@ -1094,12 +1095,13 @@ void TextEdit::_notification(int p_what) {
} }
if (brace_matching_enabled) { if (brace_matching_enabled) {
int yofs = ofs_y + (get_row_height() - cache.font->get_height()) / 2;
if ((brace_open_match_line == line && brace_open_match_column == last_wrap_column + j) || if ((brace_open_match_line == line && brace_open_match_column == last_wrap_column + j) ||
(cursor.column == last_wrap_column + j && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_open_matching || brace_open_mismatch))) { (cursor.column == last_wrap_column + j && cursor.line == line && cursor_wrap_index == line_wrap_index && (brace_open_matching || brace_open_mismatch))) {
if (brace_open_mismatch) if (brace_open_mismatch)
color = cache.brace_mismatch_color; color = cache.brace_mismatch_color;
drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, ofs_y + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color); drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, yofs + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color);
} }
if ((brace_close_match_line == line && brace_close_match_column == last_wrap_column + j) || if ((brace_close_match_line == line && brace_close_match_column == last_wrap_column + j) ||
@ -1107,7 +1109,7 @@ void TextEdit::_notification(int p_what) {
if (brace_close_mismatch) if (brace_close_mismatch)
color = cache.brace_mismatch_color; color = cache.brace_mismatch_color;
drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, ofs_y + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color); drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, yofs + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color);
} }
} }
@ -1167,9 +1169,10 @@ void TextEdit::_notification(int p_what) {
} }
if (str[j] >= 32) { if (str[j] >= 32) {
int w = drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, ofs_y + ascent), str[j], str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color); int yofs = ofs_y + (get_row_height() - cache.font->get_height()) / 2;
int w = drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, yofs + ascent), str[j], str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color);
if (underlined) { if (underlined) {
draw_rect(Rect2(char_ofs + char_margin + ofs_x, ofs_y + ascent + 2, w, 1), in_selection && override_selected_font_color ? cache.font_selected_color : color); 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 && str[j] == '\t') {
int yofs = (get_row_height() - cache.tab_icon->get_height()) / 2; int yofs = (get_row_height() - cache.tab_icon->get_height()) / 2;