Merge pull request #105870 from bruvzg/te_margin_round

[TextEdit] Fix margin rounding at sub 100% scale.
This commit is contained in:
Thaddeus Crews
2025-04-28 14:10:52 -05:00

View File

@ -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;
@ -863,9 +863,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;
}
@ -1353,7 +1353,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];
@ -2194,7 +2194,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &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;
}
@ -3476,12 +3476,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;
}
@ -4880,7 +4880,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;
@ -4949,7 +4949,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);
@ -8726,7 +8726,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) {
@ -8753,7 +8753,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;
@ -8816,7 +8816,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);
}