1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 13:50:04 -04:00

Per-corner rounding of rectangles (#1206)

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
4JX
2022-02-05 17:48:55 +01:00
committed by GitHub
parent 0fa4bb9c64
commit 7e7b9e1919
14 changed files with 197 additions and 78 deletions

View File

@@ -46,17 +46,23 @@ impl Shadow {
}
}
pub fn tessellate(&self, rect: emath::Rect, corner_radius: f32) -> Mesh {
pub fn tessellate(&self, rect: emath::Rect, corner_radius: impl Into<Rounding>) -> Mesh {
// tessellator.clip_rect = clip_rect; // TODO: culling
let Self { extrusion, color } = *self;
let cr: Rounding = corner_radius.into();
let half_ext = 0.5 * extrusion;
let ext_corner_radius = Rounding {
nw: cr.nw + half_ext,
ne: cr.ne + half_ext,
sw: cr.sw + half_ext,
se: cr.se + half_ext,
};
use crate::tessellator::*;
let rect = RectShape::filled(
rect.expand(0.5 * extrusion),
corner_radius + 0.5 * extrusion,
color,
);
let rect = RectShape::filled(rect.expand(half_ext), ext_corner_radius, color);
let mut tessellator = Tessellator::from_options(TessellationOptions {
aa_size: extrusion,
anti_alias: true,