1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

Use u8 in Rounding, and introduce Roundingf (#5563)

* Part of https://github.com/emilk/egui/issues/4019

As part of the work on adding a custom `Border` to everything, I want to
make sure that the size of `RectShape`, `Frame` and the future `Border`
is kept small (for performance reasons).

This PR changes the storage of the corner radius of rectangles from four
`f32` (one for each corner) into four `u8`. This mean the corner radius
can only be an integer in the range 0-255 (in ui points). This should be
enough for most people.

If you want to manipulate rounding using `f32`, there is a new
`Roundingf` to fill that niche.
This commit is contained in:
Emil Ernerfeldt
2025-01-02 14:29:50 +01:00
committed by GitHub
parent 3ffe1ed774
commit 249f8bcb93
13 changed files with 508 additions and 242 deletions

View File

@@ -525,7 +525,7 @@ impl Path {
pub mod path {
//! Helpers for constructing paths
use crate::shape::Rounding;
use crate::Rounding;
use emath::{pos2, Pos2, Rect};
/// overwrites existing points
@@ -548,6 +548,8 @@ pub mod path {
// Duplicated vertices can happen when one side is all rounding, with no straight edge between.
let eps = f32::EPSILON * rect.size().max_elem();
let r = crate::Roundingf::from(r);
add_circle_quadrant(path, pos2(max.x - r.se, max.y - r.se), r.se, 0.0); // south east
if rect.width() <= r.se + r.sw + eps {
@@ -628,7 +630,7 @@ pub mod path {
let half_width = rect.width() * 0.5;
let half_height = rect.height() * 0.5;
let max_cr = half_width.min(half_height);
rounding.at_most(max_cr).at_least(0.0)
rounding.at_most(max_cr.floor() as _).at_least(0)
}
}
@@ -1741,7 +1743,7 @@ impl Tessellator {
.at_most(rect.size().min_elem() - eps)
.at_least(0.0);
rounding += Rounding::same(0.5 * blur_width);
rounding += Rounding::from(0.5 * blur_width);
self.feathering = self.feathering.max(blur_width);
}