Skip to content

Commit fc1ffeb

Browse files
committed
Merge pull request #105870 from bruvzg/te_margin_round
[TextEdit] Fix margin rounding at sub 100% scale.
2 parents 80eba98 + 1794098 commit fc1ffeb

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

scene/gui/text_edit.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ void TextEdit::_notification(int p_what) {
694694

695695
int first_vis_line = get_first_visible_line();
696696
int row_height = get_line_height();
697-
int xmargin_beg = theme_cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding;
697+
int xmargin_beg = Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT)) + gutters_width + gutter_padding;
698698
Size2 size = get_size();
699699
bool rtl = is_layout_rtl();
700700
int lines_drawn = 0;
@@ -863,9 +863,9 @@ void TextEdit::_notification(int p_what) {
863863
_update_scrollbars();
864864

865865
RID ci = get_canvas_item();
866-
int xmargin_beg = theme_cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding;
866+
int xmargin_beg = Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT)) + gutters_width + gutter_padding;
867867

868-
int xmargin_end = size.width - theme_cache.style_normal->get_margin(SIDE_RIGHT);
868+
int xmargin_end = size.width - Math::ceil(theme_cache.style_normal->get_margin(SIDE_RIGHT));
869869
if (draw_minimap) {
870870
xmargin_end -= minimap_width;
871871
}
@@ -1353,7 +1353,7 @@ void TextEdit::_notification(int p_what) {
13531353

13541354
cache_entry.y_offset = ofs_y;
13551355

1356-
int gutter_offset = theme_cache.style_normal->get_margin(SIDE_LEFT);
1356+
int gutter_offset = Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT));
13571357
for (int g = 0; g < gutters.size(); g++) {
13581358
const GutterInfo &gutter = gutters[g];
13591359

@@ -2194,7 +2194,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
21942194
emit_signal(SNAME("gutter_clicked"), hovered_gutter.y, hovered_gutter.x);
21952195
return;
21962196
}
2197-
int left_margin = theme_cache.style_normal->get_margin(SIDE_LEFT);
2197+
int left_margin = Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT));
21982198
if (mpos.x < left_margin + gutters_width + gutter_padding) {
21992199
return;
22002200
}
@@ -3476,12 +3476,12 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
34763476
return CURSOR_ARROW;
34773477
}
34783478
}
3479-
int left_margin = theme_cache.style_normal->get_margin(SIDE_LEFT);
3479+
int left_margin = Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT));
34803480
if (p_pos.x < left_margin + gutters_width + gutter_padding) {
34813481
return CURSOR_ARROW;
34823482
}
34833483

3484-
int xmargin_end = get_size().width - theme_cache.style_normal->get_margin(SIDE_RIGHT);
3484+
int xmargin_end = get_size().width - Math::ceil(theme_cache.style_normal->get_margin(SIDE_RIGHT));
34853485
if (draw_minimap && p_pos.x > xmargin_end - minimap_width && p_pos.x <= xmargin_end) {
34863486
return CURSOR_ARROW;
34873487
}
@@ -4880,7 +4880,7 @@ Point2i TextEdit::get_line_column_at_pos(const Point2i &p_pos, bool p_clamp_line
48804880
return Point2i(-1, -1);
48814881
}
48824882

4883-
int colx = p_pos.x - (theme_cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding);
4883+
int colx = p_pos.x - (Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT)) + gutters_width + gutter_padding);
48844884
colx += first_visible_col;
48854885
if (!editable) {
48864886
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 {
49494949

49504950
Point2i pos, size;
49514951
pos.y = cache_entry.y_offset + get_line_height() * wrap_index;
4952-
pos.x = get_total_gutter_width() + theme_cache.style_normal->get_margin(SIDE_LEFT) - get_h_scroll();
4952+
pos.x = get_total_gutter_width() + Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT)) - get_h_scroll();
49534953

49544954
RID text_rid = text.get_line_data(p_line)->get_line_rid(wrap_index);
49554955
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
87268726

87278727
void TextEdit::_update_minimap_hover() {
87288728
const Point2 mp = get_local_mouse_pos();
8729-
const int xmargin_end = get_size().width - theme_cache.style_normal->get_margin(SIDE_RIGHT);
8729+
const int xmargin_end = get_size().width - Math::ceil(theme_cache.style_normal->get_margin(SIDE_RIGHT));
87308730

87318731
bool hovering_sidebar = mp.x > xmargin_end - minimap_width && mp.x < xmargin_end;
87328732
if (!hovering_sidebar) {
@@ -8753,7 +8753,7 @@ void TextEdit::_update_minimap_hover() {
87538753
void TextEdit::_update_minimap_click() {
87548754
Point2 mp = get_local_mouse_pos();
87558755

8756-
int xmargin_end = get_size().width - theme_cache.style_normal->get_margin(SIDE_RIGHT);
8756+
int xmargin_end = get_size().width - Math::ceil(theme_cache.style_normal->get_margin(SIDE_RIGHT));
87578757
if (!dragging_minimap && (mp.x < xmargin_end - minimap_width || mp.x > xmargin_end)) {
87588758
minimap_clicked = false;
87598759
return;
@@ -8816,7 +8816,7 @@ void TextEdit::_update_gutter_width() {
88168816
}
88178817

88188818
Vector2i TextEdit::_get_hovered_gutter(const Point2 &p_mouse_pos) const {
8819-
int left_margin = theme_cache.style_normal->get_margin(SIDE_LEFT);
8819+
int left_margin = Math::ceil(theme_cache.style_normal->get_margin(SIDE_LEFT));
88208820
if (p_mouse_pos.x > left_margin + gutters_width + gutter_padding) {
88218821
return Vector2i(-1, -1);
88228822
}

0 commit comments

Comments
 (0)