From 6554fbb1517b8a0d7a3fe4fb59b3c83baa4778f3 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 19 Dec 2022 10:33:03 +0100 Subject: [PATCH] epaint: Improve rendering of very thin rectangles --- crates/epaint/CHANGELOG.md | 1 + crates/epaint/src/tessellator.rs | 32 ++++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/crates/epaint/CHANGELOG.md b/crates/epaint/CHANGELOG.md index 78be61c3..c3e6ea7f 100644 --- a/crates/epaint/CHANGELOG.md +++ b/crates/epaint/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to the epaint crate will be documented in this file. * Improve the look of thin white lines ([#2437](https://github.com/emilk/egui/pull/2437)). * Don't render `\r` (Carriage Return) ([#2452](https://github.com/emilk/egui/pull/2452)). * Fix bug in `Mesh::split_to_u16` ([#2459](https://github.com/emilk/egui/pull/2459)). +* Improve rendering of very thin rectangles. ## 0.20.0 - 2022-12-08 diff --git a/crates/epaint/src/tessellator.rs b/crates/epaint/src/tessellator.rs index 37c89e6f..fd4b2edd 100644 --- a/crates/epaint/src/tessellator.rs +++ b/crates/epaint/src/tessellator.rs @@ -1309,12 +1309,32 @@ impl Tessellator { rect.min = rect.min.at_least(pos2(-1e7, -1e7)); rect.max = rect.max.at_most(pos2(1e7, 1e7)); - let path = &mut self.scratchpad_path; - path.clear(); - path::rounded_rectangle(&mut self.scratchpad_points, rect, rounding); - path.add_line_loop(&self.scratchpad_points); - path.fill(self.feathering, fill, out); - path.stroke_closed(self.feathering, stroke, out); + if rect.width() < self.feathering { + // Very thin - approximate by a vertial line-segment: + let line = [rect.center_top(), rect.center_bottom()]; + if fill != Color32::TRANSPARENT { + self.tessellate_line(line, Stroke::new(rect.width(), fill), out); + } + if !stroke.is_empty() { + self.tessellate_line(line, stroke, out); + } + } else if rect.height() < self.feathering { + // Very thin - approximate by a horizontal line-segment: + let line = [rect.left_center(), rect.right_center()]; + if fill != Color32::TRANSPARENT { + self.tessellate_line(line, Stroke::new(rect.width(), fill), out); + } + if !stroke.is_empty() { + self.tessellate_line(line, stroke, out); + } + } else { + let path = &mut self.scratchpad_path; + path.clear(); + path::rounded_rectangle(&mut self.scratchpad_points, rect, rounding); + path.add_line_loop(&self.scratchpad_points); + path.fill(self.feathering, fill, out); + path.stroke_closed(self.feathering, stroke, out); + } } /// Tessellate a single [`TextShape`] into a [`Mesh`].