mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Rename corner_radius to rounding
Also update changelogs and clean up other aspects of https://github.com/emilk/egui/pull/1206
This commit is contained in:
@@ -46,23 +46,23 @@ impl Shadow {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tessellate(&self, rect: emath::Rect, corner_radius: impl Into<Rounding>) -> Mesh {
|
||||
pub fn tessellate(&self, rect: emath::Rect, rounding: impl Into<Rounding>) -> Mesh {
|
||||
// tessellator.clip_rect = clip_rect; // TODO: culling
|
||||
|
||||
let Self { extrusion, color } = *self;
|
||||
|
||||
let cr: Rounding = corner_radius.into();
|
||||
let rounding: Rounding = rounding.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,
|
||||
let ext_rounding = Rounding {
|
||||
nw: rounding.nw + half_ext,
|
||||
ne: rounding.ne + half_ext,
|
||||
sw: rounding.sw + half_ext,
|
||||
se: rounding.se + half_ext,
|
||||
};
|
||||
|
||||
use crate::tessellator::*;
|
||||
let rect = RectShape::filled(rect.expand(half_ext), ext_corner_radius, color);
|
||||
let rect = RectShape::filled(rect.expand(half_ext), ext_rounding, color);
|
||||
let mut tessellator = Tessellator::from_options(TessellationOptions {
|
||||
aa_size: extrusion,
|
||||
anti_alias: true,
|
||||
|
||||
@@ -116,19 +116,19 @@ impl Shape {
|
||||
#[inline]
|
||||
pub fn rect_filled(
|
||||
rect: Rect,
|
||||
corner_radius: impl Into<Rounding>,
|
||||
rounding: impl Into<Rounding>,
|
||||
fill_color: impl Into<Color32>,
|
||||
) -> Self {
|
||||
Self::Rect(RectShape::filled(rect, corner_radius, fill_color))
|
||||
Self::Rect(RectShape::filled(rect, rounding, fill_color))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn rect_stroke(
|
||||
rect: Rect,
|
||||
corner_radius: impl Into<Rounding>,
|
||||
rounding: impl Into<Rounding>,
|
||||
stroke: impl Into<Stroke>,
|
||||
) -> Self {
|
||||
Self::Rect(RectShape::stroke(rect, corner_radius, stroke))
|
||||
Self::Rect(RectShape::stroke(rect, rounding, stroke))
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
@@ -330,7 +330,7 @@ impl From<PathShape> for Shape {
|
||||
pub struct RectShape {
|
||||
pub rect: Rect,
|
||||
/// How rounded the corners are. Use `Rounding::none()` for no rounding.
|
||||
pub corner_radius: Rounding,
|
||||
pub rounding: Rounding,
|
||||
pub fill: Color32,
|
||||
pub stroke: Stroke,
|
||||
}
|
||||
@@ -339,26 +339,22 @@ impl RectShape {
|
||||
#[inline]
|
||||
pub fn filled(
|
||||
rect: Rect,
|
||||
corner_radius: impl Into<Rounding>,
|
||||
rounding: impl Into<Rounding>,
|
||||
fill_color: impl Into<Color32>,
|
||||
) -> Self {
|
||||
Self {
|
||||
rect,
|
||||
corner_radius: corner_radius.into(),
|
||||
rounding: rounding.into(),
|
||||
fill: fill_color.into(),
|
||||
stroke: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn stroke(
|
||||
rect: Rect,
|
||||
corner_radius: impl Into<Rounding>,
|
||||
stroke: impl Into<Stroke>,
|
||||
) -> Self {
|
||||
pub fn stroke(rect: Rect, rounding: impl Into<Rounding>, stroke: impl Into<Stroke>) -> Self {
|
||||
Self {
|
||||
rect,
|
||||
corner_radius: corner_radius.into(),
|
||||
rounding: rounding.into(),
|
||||
fill: Default::default(),
|
||||
stroke: stroke.into(),
|
||||
}
|
||||
@@ -382,9 +378,13 @@ impl From<RectShape> for Shape {
|
||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||
/// How rounded the corners of things should be
|
||||
pub struct Rounding {
|
||||
/// Radius of the rounding of the North-West (left top) corner.
|
||||
pub nw: f32,
|
||||
/// Radius of the rounding of the North-East (right top) corner.
|
||||
pub ne: f32,
|
||||
/// Radius of the rounding of the South-West (left bottom) corner.
|
||||
pub sw: f32,
|
||||
/// Radius of the rounding of the South-East (right bottom) corner.
|
||||
pub se: f32,
|
||||
}
|
||||
|
||||
@@ -427,6 +427,12 @@ impl Rounding {
|
||||
se: 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Do all corners have the same rounding?
|
||||
#[inline]
|
||||
pub fn is_same(&self) -> bool {
|
||||
self.nw == self.ne && self.nw == self.sw && self.nw == self.se
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -184,15 +184,15 @@ pub mod path {
|
||||
use super::*;
|
||||
|
||||
/// overwrites existing points
|
||||
pub fn rounded_rectangle(path: &mut Vec<Pos2>, rect: Rect, corner_radius: Rounding) {
|
||||
pub fn rounded_rectangle(path: &mut Vec<Pos2>, rect: Rect, rounding: Rounding) {
|
||||
path.clear();
|
||||
|
||||
let min = rect.min;
|
||||
let max = rect.max;
|
||||
|
||||
let cr = clamp_radius(corner_radius, rect);
|
||||
let r = clamp_radius(rounding, rect);
|
||||
|
||||
if cr == Rounding::none() {
|
||||
if r == Rounding::none() {
|
||||
let min = rect.min;
|
||||
let max = rect.max;
|
||||
path.reserve(4);
|
||||
@@ -201,10 +201,10 @@ pub mod path {
|
||||
path.push(pos2(max.x, max.y));
|
||||
path.push(pos2(min.x, max.y));
|
||||
} else {
|
||||
add_circle_quadrant(path, pos2(max.x - cr.se, max.y - cr.se), cr.se, 0.0);
|
||||
add_circle_quadrant(path, pos2(min.x + cr.sw, max.y - cr.sw), cr.sw, 1.0);
|
||||
add_circle_quadrant(path, pos2(min.x + cr.nw, min.y + cr.nw), cr.nw, 2.0);
|
||||
add_circle_quadrant(path, pos2(max.x - cr.ne, min.y + cr.ne), cr.ne, 3.0);
|
||||
add_circle_quadrant(path, pos2(max.x - r.se, max.y - r.se), r.se, 0.0);
|
||||
add_circle_quadrant(path, pos2(min.x + r.sw, max.y - r.sw), r.sw, 1.0);
|
||||
add_circle_quadrant(path, pos2(min.x + r.nw, min.y + r.nw), r.nw, 2.0);
|
||||
add_circle_quadrant(path, pos2(max.x - r.ne, min.y + r.ne), r.ne, 3.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,16 +244,16 @@ pub mod path {
|
||||
}
|
||||
|
||||
// Ensures the radius of each corner is within a valid range
|
||||
fn clamp_radius(corner_radius: Rounding, rect: Rect) -> Rounding {
|
||||
fn clamp_radius(rounding: Rounding, rect: Rect) -> Rounding {
|
||||
let half_width = rect.width() * 0.5;
|
||||
let half_height = rect.height() * 0.5;
|
||||
let max_cr = half_width.min(half_height);
|
||||
|
||||
Rounding {
|
||||
nw: corner_radius.nw.at_most(max_cr),
|
||||
ne: corner_radius.ne.at_most(max_cr),
|
||||
sw: corner_radius.sw.at_most(max_cr),
|
||||
se: corner_radius.se.at_most(max_cr),
|
||||
nw: rounding.nw.at_most(max_cr).at_least(0.0),
|
||||
ne: rounding.ne.at_most(max_cr).at_least(0.0),
|
||||
sw: rounding.sw.at_most(max_cr).at_least(0.0),
|
||||
se: rounding.se.at_most(max_cr).at_least(0.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -862,7 +862,7 @@ impl Tessellator {
|
||||
pub(crate) fn tessellate_rect(&mut self, rect: &RectShape, out: &mut Mesh) {
|
||||
let RectShape {
|
||||
mut rect,
|
||||
corner_radius,
|
||||
rounding,
|
||||
fill,
|
||||
stroke,
|
||||
} = *rect;
|
||||
@@ -883,7 +883,7 @@ impl Tessellator {
|
||||
|
||||
let path = &mut self.scratchpad_path;
|
||||
path.clear();
|
||||
path::rounded_rectangle(&mut self.scratchpad_points, rect, corner_radius);
|
||||
path::rounded_rectangle(&mut self.scratchpad_points, rect, rounding);
|
||||
path.add_line_loop(&self.scratchpad_points);
|
||||
path.fill(fill, &self.options, out);
|
||||
path.stroke_closed(stroke, &self.options, out);
|
||||
|
||||
Reference in New Issue
Block a user