Browse Source

epaint: Improve rendering of very thin rectangles

pull/2480/head
Emil Ernerfeldt 2 years ago
parent
commit
6554fbb151
  1. 1
      crates/epaint/CHANGELOG.md
  2. 32
      crates/epaint/src/tessellator.rs

1
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)). * 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)). * 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)). * 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 ## 0.20.0 - 2022-12-08

32
crates/epaint/src/tessellator.rs

@ -1309,12 +1309,32 @@ impl Tessellator {
rect.min = rect.min.at_least(pos2(-1e7, -1e7)); rect.min = rect.min.at_least(pos2(-1e7, -1e7));
rect.max = rect.max.at_most(pos2(1e7, 1e7)); rect.max = rect.max.at_most(pos2(1e7, 1e7));
let path = &mut self.scratchpad_path; if rect.width() < self.feathering {
path.clear(); // Very thin - approximate by a vertial line-segment:
path::rounded_rectangle(&mut self.scratchpad_points, rect, rounding); let line = [rect.center_top(), rect.center_bottom()];
path.add_line_loop(&self.scratchpad_points); if fill != Color32::TRANSPARENT {
path.fill(self.feathering, fill, out); self.tessellate_line(line, Stroke::new(rect.width(), fill), out);
path.stroke_closed(self.feathering, stroke, 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`]. /// Tessellate a single [`TextShape`] into a [`Mesh`].

Loading…
Cancel
Save