From 1794098b47a42237452963bb6a641cfe6af46a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Mon, 28 Apr 2025 17:22:58 +0300 Subject: [PATCH] [TextEdit] Fix margin rounding at sub 100% scale. --- scene/gui/text_edit.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 6afdb08533..49d0bacff5 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -694,7 +694,7 @@ void TextEdit::_notification(int p_what) { int first_vis_line = get_first_visible_line(); int row_height = get_line_height(); - int xmargin_beg = theme_cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding; + int xmargin_beg = Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT)) + gutters_width + gutter_padding; Size2 size = get_size(); bool rtl = is_layout_rtl(); int lines_drawn = 0; @@ -855,9 +855,9 @@ void TextEdit::_notification(int p_what) { _update_scrollbars(); RID ci = get_canvas_item(); - int xmargin_beg = theme_cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding; + int xmargin_beg = Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT)) + gutters_width + gutter_padding; - int xmargin_end = size.width - theme_cache.style_normal->get_margin(SIDE_RIGHT); + int xmargin_end = size.width - Math::ceil(theme_cache.style_normal->get_margin(SIDE_RIGHT)); if (draw_minimap) { xmargin_end -= minimap_width; } @@ -1345,7 +1345,7 @@ void TextEdit::_notification(int p_what) { cache_entry.y_offset = ofs_y; - int gutter_offset = theme_cache.style_normal->get_margin(SIDE_LEFT); + int gutter_offset = Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT)); for (int g = 0; g < gutters.size(); g++) { const GutterInfo &gutter = gutters[g]; @@ -2186,7 +2186,7 @@ void TextEdit::gui_input(const Ref &p_gui_input) { emit_signal(SNAME("gutter_clicked"), hovered_gutter.y, hovered_gutter.x); return; } - int left_margin = theme_cache.style_normal->get_margin(SIDE_LEFT); + int left_margin = Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT)); if (mpos.x < left_margin + gutters_width + gutter_padding) { return; } @@ -3468,12 +3468,12 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const { return CURSOR_ARROW; } } - int left_margin = theme_cache.style_normal->get_margin(SIDE_LEFT); + int left_margin = Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT)); if (p_pos.x < left_margin + gutters_width + gutter_padding) { return CURSOR_ARROW; } - int xmargin_end = get_size().width - theme_cache.style_normal->get_margin(SIDE_RIGHT); + int xmargin_end = get_size().width - Math::ceil(theme_cache.style_normal->get_margin(SIDE_RIGHT)); if (draw_minimap && p_pos.x > xmargin_end - minimap_width && p_pos.x <= xmargin_end) { return CURSOR_ARROW; } @@ -4872,7 +4872,7 @@ Point2i TextEdit::get_line_column_at_pos(const Point2i &p_pos, bool p_clamp_line return Point2i(-1, -1); } - int colx = p_pos.x - (theme_cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding); + int colx = p_pos.x - (Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT)) + gutters_width + gutter_padding); colx += first_visible_col; if (!editable) { colx -= theme_cache.style_readonly->get_offset().x / 2; @@ -4941,7 +4941,7 @@ Rect2i TextEdit::get_rect_at_line_column(int p_line, int p_column) const { Point2i pos, size; pos.y = cache_entry.y_offset + get_line_height() * wrap_index; - pos.x = get_total_gutter_width() + theme_cache.style_normal->get_margin(SIDE_LEFT) - get_h_scroll(); + pos.x = get_total_gutter_width() + Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT)) - get_h_scroll(); RID text_rid = text.get_line_data(p_line)->get_line_rid(wrap_index); Vector2 col_bounds = TS->shaped_text_get_grapheme_bounds(text_rid, p_column); @@ -8718,7 +8718,7 @@ void TextEdit::_adjust_viewport_to_caret_horizontally(int p_caret, bool p_maximi void TextEdit::_update_minimap_hover() { const Point2 mp = get_local_mouse_pos(); - const int xmargin_end = get_size().width - theme_cache.style_normal->get_margin(SIDE_RIGHT); + const int xmargin_end = get_size().width - Math::ceil(theme_cache.style_normal->get_margin(SIDE_RIGHT)); bool hovering_sidebar = mp.x > xmargin_end - minimap_width && mp.x < xmargin_end; if (!hovering_sidebar) { @@ -8745,7 +8745,7 @@ void TextEdit::_update_minimap_hover() { void TextEdit::_update_minimap_click() { Point2 mp = get_local_mouse_pos(); - int xmargin_end = get_size().width - theme_cache.style_normal->get_margin(SIDE_RIGHT); + int xmargin_end = get_size().width - Math::ceil(theme_cache.style_normal->get_margin(SIDE_RIGHT)); if (!dragging_minimap && (mp.x < xmargin_end - minimap_width || mp.x > xmargin_end)) { minimap_clicked = false; return; @@ -8808,7 +8808,7 @@ void TextEdit::_update_gutter_width() { } Vector2i TextEdit::_get_hovered_gutter(const Point2 &p_mouse_pos) const { - int left_margin = theme_cache.style_normal->get_margin(SIDE_LEFT); + int left_margin = Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT)); if (p_mouse_pos.x > left_margin + gutters_width + gutter_padding) { return Vector2i(-1, -1); }