From d46b3434a4f9f0f6ae5ad3d899a4974d43236013 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 26 Dec 2024 19:06:40 +0100 Subject: [PATCH] Remove egui-side pixel-rounding --- crates/egui/src/containers/resize.rs | 4 +++- crates/egui/src/containers/window.rs | 2 +- crates/egui/src/painter.rs | 5 +++++ crates/egui/src/style.rs | 8 ++------ crates/egui/src/text_selection/visuals.rs | 15 ++------------- crates/egui/src/ui.rs | 2 -- crates/egui/src/widgets/separator.rs | 4 ++-- .../tests/snapshots/demos/Misc Demos.png | 4 ++-- .../tests/snapshots/rendering_test/dpi_1.50.png | 4 ++-- .../tests/snapshots/rendering_test/dpi_1.67.png | 4 ++-- .../tests/snapshots/rendering_test/dpi_1.75.png | 4 ++-- .../tests/snapshots/rendering_test/dpi_2.00.png | 4 ++-- .../tests/snapshots/widget_gallery.png | 4 ++-- 13 files changed, 27 insertions(+), 37 deletions(-) diff --git a/crates/egui/src/containers/resize.rs b/crates/egui/src/containers/resize.rs index 0165eba996a..bbb86dfbf36 100644 --- a/crates/egui/src/containers/resize.rs +++ b/crates/egui/src/containers/resize.rs @@ -400,7 +400,9 @@ pub fn paint_resize_corner_with_style( corner: Align2, ) { let painter = ui.painter(); - let cp = painter.round_pos_to_pixels(corner.pos_in_rect(rect)); + let cp = corner + .pos_in_rect(rect) + .round_to_pixels(ui.pixels_per_point()); let mut w = 2.0; let stroke = Stroke { width: 1.0, // Set width to 1.0 to prevent overlapping diff --git a/crates/egui/src/containers/window.rs b/crates/egui/src/containers/window.rs index 44c3dda58c1..414c58cfae7 100644 --- a/crates/egui/src/containers/window.rs +++ b/crates/egui/src/containers/window.rs @@ -596,7 +596,7 @@ impl<'open> Window<'open> { }, ); - title_rect = area_content_ui.painter().round_rect_to_pixels(title_rect); + title_rect = title_rect.round_to_pixels(area_content_ui.pixels_per_point()); if on_top && area_content_ui.visuals().window_highlight_topmost { let mut round = window_frame.rounding; diff --git a/crates/egui/src/painter.rs b/crates/egui/src/painter.rs index cec69b710f4..56bd4ce9dca 100644 --- a/crates/egui/src/painter.rs +++ b/crates/egui/src/painter.rs @@ -187,30 +187,35 @@ impl Painter { } /// Useful for pixel-perfect rendering of lines that are one pixel wide (or any odd number of pixels). + #[deprecated = "Use `emath::GuiRounding` with `painter.pixels_per_point()` instead"] #[inline] pub fn round_pos_to_pixel_center(&self, pos: Pos2) -> Pos2 { pos.round_to_pixel_center(self.pixels_per_point()) } /// Useful for pixel-perfect rendering of filled shapes. + #[deprecated = "Use `emath::GuiRounding` with `painter.pixels_per_point()` instead"] #[inline] pub fn round_to_pixel(&self, point: f32) -> f32 { point.round_to_pixels(self.pixels_per_point()) } /// Useful for pixel-perfect rendering. + #[deprecated = "Use `emath::GuiRounding` with `painter.pixels_per_point()` instead"] #[inline] pub fn round_vec_to_pixels(&self, vec: Vec2) -> Vec2 { vec.round_to_pixels(self.pixels_per_point()) } /// Useful for pixel-perfect rendering. + #[deprecated = "Use `emath::GuiRounding` with `painter.pixels_per_point()` instead"] #[inline] pub fn round_pos_to_pixels(&self, pos: Pos2) -> Pos2 { pos.round_to_pixels(self.pixels_per_point()) } /// Useful for pixel-perfect rendering. + #[deprecated = "Use `emath::GuiRounding` with `painter.pixels_per_point()` instead"] #[inline] pub fn round_rect_to_pixels(&self, rect: Rect) -> Rect { rect.round_to_pixels(self.pixels_per_point()) diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 91c0e09dbfa..33ab21a6837 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -2485,12 +2485,8 @@ impl Widget for &mut Stroke { // stroke preview: let (_id, stroke_rect) = ui.allocate_space(ui.spacing().interact_size); - let left = ui - .painter() - .round_pos_to_pixel_center(stroke_rect.left_center()); - let right = ui - .painter() - .round_pos_to_pixel_center(stroke_rect.right_center()); + let left = stroke_rect.left_center(); + let right = stroke_rect.right_center(); ui.painter().line_segment([left, right], (*width, *color)); }) .response diff --git a/crates/egui/src/text_selection/visuals.rs b/crates/egui/src/text_selection/visuals.rs index 2a31d1e1270..dd7c867a222 100644 --- a/crates/egui/src/text_selection/visuals.rs +++ b/crates/egui/src/text_selection/visuals.rs @@ -96,19 +96,8 @@ pub fn paint_text_selection( pub fn paint_cursor_end(painter: &Painter, visuals: &Visuals, cursor_rect: Rect) { let stroke = visuals.text_cursor.stroke; - // Ensure the cursor is aligned to the pixel grid for whole number widths. - // See https://github.com/emilk/egui/issues/5164 - let (top, bottom) = if (stroke.width as usize) % 2 == 0 { - ( - painter.round_pos_to_pixels(cursor_rect.center_top()), - painter.round_pos_to_pixels(cursor_rect.center_bottom()), - ) - } else { - ( - painter.round_pos_to_pixel_center(cursor_rect.center_top()), - painter.round_pos_to_pixel_center(cursor_rect.center_bottom()), - ) - }; + let top = cursor_rect.center_top(); + let bottom = cursor_rect.center_bottom(); painter.line_segment([top, bottom], (stroke.width, stroke.color)); diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index b6cc28c7549..19fda5d0fee 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -2391,9 +2391,7 @@ impl Ui { let stroke = self.visuals().widgets.noninteractive.bg_stroke; let left_top = child_rect.min - 0.5 * indent * Vec2::X; - let left_top = self.painter().round_pos_to_pixel_center(left_top); let left_bottom = pos2(left_top.x, child_ui.min_rect().bottom() - 2.0); - let left_bottom = self.painter().round_pos_to_pixel_center(left_bottom); if left_vline { // draw a faint line on the left to mark the indented section diff --git a/crates/egui/src/widgets/separator.rs b/crates/egui/src/widgets/separator.rs index 2cc3a857ce6..d018cfa4d0d 100644 --- a/crates/egui/src/widgets/separator.rs +++ b/crates/egui/src/widgets/separator.rs @@ -116,12 +116,12 @@ impl Widget for Separator { if is_horizontal_line { painter.hline( (rect.left() - grow)..=(rect.right() + grow), - painter.round_to_pixel_center(rect.center().y), + rect.center().y, stroke, ); } else { painter.vline( - painter.round_to_pixel_center(rect.center().x), + rect.center().x, (rect.top() - grow)..=(rect.bottom() + grow), stroke, ); diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Misc Demos.png b/crates/egui_demo_lib/tests/snapshots/demos/Misc Demos.png index fae60223acf..f094024e22a 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Misc Demos.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Misc Demos.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:333b7eaa076d4037b960857f604409f975269017c8b84fa5a31ae68a96e07f4f -size 65321 +oid sha256:7638d0c3e28e1c5e9f094990c85eca8e37c31ba6895eabeebddd3d9e596a8ac9 +size 65332 diff --git a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.50.png b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.50.png index b5aca1dfb3e..52ee518f04b 100644 --- a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.50.png +++ b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.50.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d6560fd4da0fa7eceb55eec8d6df27358ef22bab9ddaa7647012629caaef3444 -size 884469 +oid sha256:6aa8d37f047ec28d63d6403edcab9bc642cdaaf71296336f523451720fea5358 +size 884476 diff --git a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.67.png b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.67.png index 8300bebd7d1..f2f8f77cbe6 100644 --- a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.67.png +++ b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.67.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:307b1cda56c664c06bcdde27eceec4fd2bcf2f4a4a8fe80a1be9917eddb8688d -size 993116 +oid sha256:667ab76a9cc1cc5920f39bfdf69634d3040b7381b2b3f2326abd000e254056e2 +size 993127 diff --git a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.75.png b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.75.png index b527bc9d9cd..ac55af435aa 100644 --- a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.75.png +++ b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.75.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bf6746b95fd85b9c8d6a232f0dac523acda935944d78de0a37d0541e742b2666 -size 1085191 +oid sha256:7a350e19fcba9820fdd451e04c4e5e5504f255db4b6fe016a841673acb44a2b8 +size 1085206 diff --git a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_2.00.png b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_2.00.png index 0ec1770bb7c..4d76639461c 100644 --- a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_2.00.png +++ b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_2.00.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ab132016b79df25658d3c356b3f2d1eadbe9a17a33c27dd959e09a763ca0bc4d -size 1235578 +oid sha256:08fc1c89fd2d04aa12c75a1829dacfff090e322c65ad969648799833e1b072eb +size 1235574 diff --git a/crates/egui_demo_lib/tests/snapshots/widget_gallery.png b/crates/egui_demo_lib/tests/snapshots/widget_gallery.png index d1b20630be6..51596247499 100644 --- a/crates/egui_demo_lib/tests/snapshots/widget_gallery.png +++ b/crates/egui_demo_lib/tests/snapshots/widget_gallery.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ffd768e6f655d1d4a3c7ffe82c6621e880d436a18a3044b700f54a46a14d5e48 -size 160536 +oid sha256:d122b1a995e691b5049c57d65c9f222a5f1639b1e4f6f96f91823444339693cc +size 160540