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:
Emil Ernerfeldt 2022-02-05 18:13:46 +01:00
parent ace2ac00da
commit 9ed96155e9
26 changed files with 187 additions and 148 deletions

View file

@ -38,6 +38,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w
* Replaced `Style::body_text_style` with more generic `Style::text_styles` ([#1154](https://github.com/emilk/egui/pull/1154)). * Replaced `Style::body_text_style` with more generic `Style::text_styles` ([#1154](https://github.com/emilk/egui/pull/1154)).
* `TextStyle` is no longer `Copy` ([#1154](https://github.com/emilk/egui/pull/1154)). * `TextStyle` is no longer `Copy` ([#1154](https://github.com/emilk/egui/pull/1154)).
* Replaced `TextEdit::text_style` with `TextEdit::font` ([#1154](https://github.com/emilk/egui/pull/1154)). * Replaced `TextEdit::text_style` with `TextEdit::font` ([#1154](https://github.com/emilk/egui/pull/1154)).
* Replaced `corner_radius: f32` with `rounding: Rounding`, allowing per-corner rounding settings ([#1206](https://github.com/emilk/egui/pull/1206)).
* `Plot::highlight` now takes a `bool` argument ([#1159](https://github.com/emilk/egui/pull/1159)). * `Plot::highlight` now takes a `bool` argument ([#1159](https://github.com/emilk/egui/pull/1159)).
* `ScrollArea::show` now returns a `ScrollAreaOutput`, so you might need to add `.inner` after the call to it ([#1166](https://github.com/emilk/egui/pull/1166)). * `ScrollArea::show` now returns a `ScrollAreaOutput`, so you might need to add `.inner` after the call to it ([#1166](https://github.com/emilk/egui/pull/1166)).

View file

@ -338,7 +338,7 @@ impl CollapsingHeader {
if ui.visuals().collapsing_header_frame || self.show_background { if ui.visuals().collapsing_header_frame || self.show_background {
ui.painter().add(epaint::RectShape { ui.painter().add(epaint::RectShape {
rect: header_response.rect.expand(visuals.expansion), rect: header_response.rect.expand(visuals.expansion),
corner_radius: visuals.corner_radius, rounding: visuals.rounding,
fill: visuals.bg_fill, fill: visuals.bg_fill,
stroke: visuals.bg_stroke, stroke: visuals.bg_stroke,
// stroke: Default::default(), // stroke: Default::default(),
@ -350,12 +350,8 @@ impl CollapsingHeader {
{ {
let rect = rect.expand(visuals.expansion); let rect = rect.expand(visuals.expansion);
ui.painter().rect( ui.painter()
rect, .rect(rect, visuals.rounding, visuals.bg_fill, visuals.bg_stroke);
visuals.corner_radius,
visuals.bg_fill,
visuals.bg_stroke,
);
} }
{ {

View file

@ -250,7 +250,7 @@ fn button_frame(
where_to_put_background, where_to_put_background,
epaint::RectShape { epaint::RectShape {
rect: outer_rect.expand(visuals.expansion), rect: outer_rect.expand(visuals.expansion),
corner_radius: visuals.corner_radius, rounding: visuals.rounding,
fill: visuals.bg_fill, fill: visuals.bg_fill,
stroke: visuals.bg_stroke, stroke: visuals.bg_stroke,
}, },

View file

@ -9,7 +9,7 @@ use epaint::*;
pub struct Frame { pub struct Frame {
/// On each side /// On each side
pub margin: Vec2, pub margin: Vec2,
pub corner_radius: Rounding, pub rounding: Rounding,
pub shadow: Shadow, pub shadow: Shadow,
pub fill: Color32, pub fill: Color32,
pub stroke: Stroke, pub stroke: Stroke,
@ -24,7 +24,7 @@ impl Frame {
pub fn group(style: &Style) -> Self { pub fn group(style: &Style) -> Self {
Self { Self {
margin: Vec2::splat(6.0), // symmetric looks best in corners when nesting margin: Vec2::splat(6.0), // symmetric looks best in corners when nesting
corner_radius: style.visuals.widgets.noninteractive.corner_radius, rounding: style.visuals.widgets.noninteractive.rounding,
stroke: style.visuals.widgets.noninteractive.bg_stroke, stroke: style.visuals.widgets.noninteractive.bg_stroke,
..Default::default() ..Default::default()
} }
@ -33,7 +33,7 @@ impl Frame {
pub(crate) fn side_top_panel(style: &Style) -> Self { pub(crate) fn side_top_panel(style: &Style) -> Self {
Self { Self {
margin: Vec2::new(8.0, 2.0), margin: Vec2::new(8.0, 2.0),
corner_radius: Rounding::none(), rounding: Rounding::none(),
fill: style.visuals.window_fill(), fill: style.visuals.window_fill(),
stroke: style.visuals.window_stroke(), stroke: style.visuals.window_stroke(),
..Default::default() ..Default::default()
@ -43,7 +43,7 @@ impl Frame {
pub(crate) fn central_panel(style: &Style) -> Self { pub(crate) fn central_panel(style: &Style) -> Self {
Self { Self {
margin: Vec2::new(8.0, 8.0), margin: Vec2::new(8.0, 8.0),
corner_radius: Rounding::none(), rounding: Rounding::none(),
fill: style.visuals.window_fill(), fill: style.visuals.window_fill(),
stroke: Default::default(), stroke: Default::default(),
..Default::default() ..Default::default()
@ -53,7 +53,7 @@ impl Frame {
pub fn window(style: &Style) -> Self { pub fn window(style: &Style) -> Self {
Self { Self {
margin: style.spacing.window_padding, margin: style.spacing.window_padding,
corner_radius: style.visuals.window_corner_radius, rounding: style.visuals.window_rounding,
shadow: style.visuals.window_shadow, shadow: style.visuals.window_shadow,
fill: style.visuals.window_fill(), fill: style.visuals.window_fill(),
stroke: style.visuals.window_stroke(), stroke: style.visuals.window_stroke(),
@ -63,7 +63,7 @@ impl Frame {
pub fn menu(style: &Style) -> Self { pub fn menu(style: &Style) -> Self {
Self { Self {
margin: Vec2::splat(1.0), margin: Vec2::splat(1.0),
corner_radius: style.visuals.widgets.noninteractive.corner_radius, rounding: style.visuals.widgets.noninteractive.rounding,
shadow: style.visuals.popup_shadow, shadow: style.visuals.popup_shadow,
fill: style.visuals.window_fill(), fill: style.visuals.window_fill(),
stroke: style.visuals.window_stroke(), stroke: style.visuals.window_stroke(),
@ -73,7 +73,7 @@ impl Frame {
pub fn popup(style: &Style) -> Self { pub fn popup(style: &Style) -> Self {
Self { Self {
margin: style.spacing.window_padding, margin: style.spacing.window_padding,
corner_radius: style.visuals.widgets.noninteractive.corner_radius, rounding: style.visuals.widgets.noninteractive.rounding,
shadow: style.visuals.popup_shadow, shadow: style.visuals.popup_shadow,
fill: style.visuals.window_fill(), fill: style.visuals.window_fill(),
stroke: style.visuals.window_stroke(), stroke: style.visuals.window_stroke(),
@ -84,7 +84,7 @@ impl Frame {
pub fn dark_canvas(style: &Style) -> Self { pub fn dark_canvas(style: &Style) -> Self {
Self { Self {
margin: Vec2::new(10.0, 10.0), margin: Vec2::new(10.0, 10.0),
corner_radius: style.visuals.widgets.noninteractive.corner_radius, rounding: style.visuals.widgets.noninteractive.rounding,
fill: Color32::from_black_alpha(250), fill: Color32::from_black_alpha(250),
stroke: style.visuals.window_stroke(), stroke: style.visuals.window_stroke(),
..Default::default() ..Default::default()
@ -103,8 +103,8 @@ impl Frame {
self self
} }
pub fn corner_radius(mut self, corner_radius: impl Into<Rounding>) -> Self { pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
self.corner_radius = corner_radius.into(); self.rounding = rounding.into();
self self
} }
@ -172,7 +172,7 @@ impl Frame {
pub fn paint(&self, outer_rect: Rect) -> Shape { pub fn paint(&self, outer_rect: Rect) -> Shape {
let Self { let Self {
margin: _, margin: _,
corner_radius, rounding,
shadow, shadow,
fill, fill,
stroke, stroke,
@ -180,7 +180,7 @@ impl Frame {
let frame_shape = Shape::Rect(epaint::RectShape { let frame_shape = Shape::Rect(epaint::RectShape {
rect: outer_rect, rect: outer_rect,
corner_radius, rounding,
fill, fill,
stroke, stroke,
}); });
@ -188,7 +188,7 @@ impl Frame {
if shadow == Default::default() { if shadow == Default::default() {
frame_shape frame_shape
} else { } else {
let shadow = shadow.tessellate(outer_rect, corner_radius); let shadow = shadow.tessellate(outer_rect, rounding);
let shadow = Shape::Mesh(shadow); let shadow = Shape::Mesh(shadow);
Shape::Vec(vec![shadow, frame_shape]) Shape::Vec(vec![shadow, frame_shape])
} }

View file

@ -740,13 +740,13 @@ impl Prepared {
ui.painter().add(epaint::Shape::rect_filled( ui.painter().add(epaint::Shape::rect_filled(
outer_scroll_rect, outer_scroll_rect,
visuals.corner_radius, visuals.rounding,
ui.visuals().extreme_bg_color, ui.visuals().extreme_bg_color,
)); ));
ui.painter().add(epaint::Shape::rect_filled( ui.painter().add(epaint::Shape::rect_filled(
handle_rect, handle_rect,
visuals.corner_radius, visuals.rounding,
visuals.bg_fill, visuals.bg_fill,
)); ));
} }

View file

@ -699,42 +699,62 @@ fn paint_frame_interaction(
) { ) {
use epaint::tessellator::path::add_circle_quadrant; use epaint::tessellator::path::add_circle_quadrant;
let cr = ui.visuals().window_corner_radius; let rounding = ui.visuals().window_rounding;
let Rect { min, max } = rect; let Rect { min, max } = rect;
let mut points = Vec::new(); let mut points = Vec::new();
if interaction.right && !interaction.bottom && !interaction.top { if interaction.right && !interaction.bottom && !interaction.top {
points.push(pos2(max.x, min.y + cr.ne)); points.push(pos2(max.x, min.y + rounding.ne));
points.push(pos2(max.x, max.y - cr.se)); points.push(pos2(max.x, max.y - rounding.se));
} }
if interaction.right && interaction.bottom { if interaction.right && interaction.bottom {
points.push(pos2(max.x, min.y + cr.ne)); points.push(pos2(max.x, min.y + rounding.ne));
points.push(pos2(max.x, max.y - cr.se)); points.push(pos2(max.x, max.y - rounding.se));
add_circle_quadrant(&mut points, pos2(max.x - cr.se, max.y - cr.se), cr.se, 0.0); add_circle_quadrant(
&mut points,
pos2(max.x - rounding.se, max.y - rounding.se),
rounding.se,
0.0,
);
} }
if interaction.bottom { if interaction.bottom {
points.push(pos2(max.x - cr.se, max.y)); points.push(pos2(max.x - rounding.se, max.y));
points.push(pos2(min.x + cr.sw, max.y)); points.push(pos2(min.x + rounding.sw, max.y));
} }
if interaction.left && interaction.bottom { if interaction.left && interaction.bottom {
add_circle_quadrant(&mut points, pos2(min.x + cr.sw, max.y - cr.sw), cr.sw, 1.0); add_circle_quadrant(
&mut points,
pos2(min.x + rounding.sw, max.y - rounding.sw),
rounding.sw,
1.0,
);
} }
if interaction.left { if interaction.left {
points.push(pos2(min.x, max.y - cr.sw)); points.push(pos2(min.x, max.y - rounding.sw));
points.push(pos2(min.x, min.y + cr.nw)); points.push(pos2(min.x, min.y + rounding.nw));
} }
if interaction.left && interaction.top { if interaction.left && interaction.top {
add_circle_quadrant(&mut points, pos2(min.x + cr.nw, min.y + cr.nw), cr.nw, 2.0); add_circle_quadrant(
&mut points,
pos2(min.x + rounding.nw, min.y + rounding.nw),
rounding.nw,
2.0,
);
} }
if interaction.top { if interaction.top {
points.push(pos2(min.x + cr.nw, min.y)); points.push(pos2(min.x + rounding.nw, min.y));
points.push(pos2(max.x - cr.ne, min.y)); points.push(pos2(max.x - rounding.ne, min.y));
} }
if interaction.right && interaction.top { if interaction.right && interaction.top {
add_circle_quadrant(&mut points, pos2(max.x - cr.ne, min.y + cr.ne), cr.ne, 3.0); add_circle_quadrant(
points.push(pos2(max.x, min.y + cr.ne)); &mut points,
points.push(pos2(max.x, max.y - cr.se)); pos2(max.x - rounding.ne, min.y + rounding.ne),
rounding.ne,
3.0,
);
points.push(pos2(max.x, min.y + rounding.ne));
points.push(pos2(max.x, max.y - rounding.se));
} }
ui.painter().add(Shape::line(points, visuals.bg_stroke)); ui.painter().add(Shape::line(points, visuals.bg_stroke));
} }

View file

@ -438,7 +438,7 @@ impl SubMenuButton {
ui.painter().rect_filled( ui.painter().rect_filled(
rect.expand(visuals.expansion), rect.expand(visuals.expansion),
visuals.corner_radius, visuals.rounding,
visuals.bg_fill, visuals.bg_fill,
); );

View file

@ -278,13 +278,13 @@ impl Painter {
pub fn rect( pub fn rect(
&self, &self,
rect: Rect, rect: Rect,
corner_radius: impl Into<Rounding>, rounding: impl Into<Rounding>,
fill_color: impl Into<Color32>, fill_color: impl Into<Color32>,
stroke: impl Into<Stroke>, stroke: impl Into<Stroke>,
) { ) {
self.add(RectShape { self.add(RectShape {
rect, rect,
corner_radius: corner_radius.into(), rounding: rounding.into(),
fill: fill_color.into(), fill: fill_color.into(),
stroke: stroke.into(), stroke: stroke.into(),
}); });
@ -293,12 +293,12 @@ impl Painter {
pub fn rect_filled( pub fn rect_filled(
&self, &self,
rect: Rect, rect: Rect,
corner_radius: impl Into<Rounding>, rounding: impl Into<Rounding>,
fill_color: impl Into<Color32>, fill_color: impl Into<Color32>,
) { ) {
self.add(RectShape { self.add(RectShape {
rect, rect,
corner_radius: corner_radius.into(), rounding: rounding.into(),
fill: fill_color.into(), fill: fill_color.into(),
stroke: Default::default(), stroke: Default::default(),
}); });
@ -307,12 +307,12 @@ impl Painter {
pub fn rect_stroke( pub fn rect_stroke(
&self, &self,
rect: Rect, rect: Rect,
corner_radius: impl Into<Rounding>, rounding: impl Into<Rounding>,
stroke: impl Into<Stroke>, stroke: impl Into<Stroke>,
) { ) {
self.add(RectShape { self.add(RectShape {
rect, rect,
corner_radius: corner_radius.into(), rounding: rounding.into(),
fill: Default::default(), fill: Default::default(),
stroke: stroke.into(), stroke: stroke.into(),
}); });

View file

@ -344,7 +344,7 @@ pub struct Visuals {
/// Background color behind code-styled monospaced labels. /// Background color behind code-styled monospaced labels.
pub code_bg_color: Color32, pub code_bg_color: Color32,
pub window_corner_radius: Rounding, pub window_rounding: Rounding,
pub window_shadow: Shadow, pub window_shadow: Shadow,
pub popup_shadow: Shadow, pub popup_shadow: Shadow,
@ -453,7 +453,7 @@ pub struct WidgetVisuals {
pub bg_stroke: Stroke, pub bg_stroke: Stroke,
/// Button frames etc. /// Button frames etc.
pub corner_radius: Rounding, pub rounding: Rounding,
/// Stroke and text color of the interactive part of a component (button text, slider grab, check-mark, …). /// Stroke and text color of the interactive part of a component (button text, slider grab, check-mark, …).
pub fg_stroke: Stroke, pub fg_stroke: Stroke,
@ -566,7 +566,7 @@ impl Visuals {
faint_bg_color: Color32::from_gray(24), faint_bg_color: Color32::from_gray(24),
extreme_bg_color: Color32::from_gray(10), extreme_bg_color: Color32::from_gray(10),
code_bg_color: Color32::from_gray(64), code_bg_color: Color32::from_gray(64),
window_corner_radius: Rounding::same(6.0), window_rounding: Rounding::same(6.0),
window_shadow: Shadow::big_dark(), window_shadow: Shadow::big_dark(),
popup_shadow: Shadow::small_dark(), popup_shadow: Shadow::small_dark(),
resize_corner_size: 12.0, resize_corner_size: 12.0,
@ -629,35 +629,35 @@ impl Widgets {
bg_fill: Color32::from_gray(27), // window background bg_fill: Color32::from_gray(27), // window background
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // separators, indentation lines, windows outlines bg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // separators, indentation lines, windows outlines
fg_stroke: Stroke::new(1.0, Color32::from_gray(140)), // normal text color fg_stroke: Stroke::new(1.0, Color32::from_gray(140)), // normal text color
corner_radius: Rounding::same(2.0), rounding: Rounding::same(2.0),
expansion: 0.0, expansion: 0.0,
}, },
inactive: WidgetVisuals { inactive: WidgetVisuals {
bg_fill: Color32::from_gray(60), // button background bg_fill: Color32::from_gray(60), // button background
bg_stroke: Default::default(), bg_stroke: Default::default(),
fg_stroke: Stroke::new(1.0, Color32::from_gray(180)), // button text fg_stroke: Stroke::new(1.0, Color32::from_gray(180)), // button text
corner_radius: Rounding::same(2.0), rounding: Rounding::same(2.0),
expansion: 0.0, expansion: 0.0,
}, },
hovered: WidgetVisuals { hovered: WidgetVisuals {
bg_fill: Color32::from_gray(70), bg_fill: Color32::from_gray(70),
bg_stroke: Stroke::new(1.0, Color32::from_gray(150)), // e.g. hover over window edge or button bg_stroke: Stroke::new(1.0, Color32::from_gray(150)), // e.g. hover over window edge or button
fg_stroke: Stroke::new(1.5, Color32::from_gray(240)), fg_stroke: Stroke::new(1.5, Color32::from_gray(240)),
corner_radius: Rounding::same(3.0), rounding: Rounding::same(3.0),
expansion: 1.0, expansion: 1.0,
}, },
active: WidgetVisuals { active: WidgetVisuals {
bg_fill: Color32::from_gray(55), bg_fill: Color32::from_gray(55),
bg_stroke: Stroke::new(1.0, Color32::WHITE), bg_stroke: Stroke::new(1.0, Color32::WHITE),
fg_stroke: Stroke::new(2.0, Color32::WHITE), fg_stroke: Stroke::new(2.0, Color32::WHITE),
corner_radius: Rounding::same(2.0), rounding: Rounding::same(2.0),
expansion: 1.0, expansion: 1.0,
}, },
open: WidgetVisuals { open: WidgetVisuals {
bg_fill: Color32::from_gray(27), bg_fill: Color32::from_gray(27),
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)), bg_stroke: Stroke::new(1.0, Color32::from_gray(60)),
fg_stroke: Stroke::new(1.0, Color32::from_gray(210)), fg_stroke: Stroke::new(1.0, Color32::from_gray(210)),
corner_radius: Rounding::same(2.0), rounding: Rounding::same(2.0),
expansion: 0.0, expansion: 0.0,
}, },
} }
@ -669,35 +669,35 @@ impl Widgets {
bg_fill: Color32::from_gray(235), // window background bg_fill: Color32::from_gray(235), // window background
bg_stroke: Stroke::new(1.0, Color32::from_gray(190)), // separators, indentation lines, windows outlines bg_stroke: Stroke::new(1.0, Color32::from_gray(190)), // separators, indentation lines, windows outlines
fg_stroke: Stroke::new(1.0, Color32::from_gray(100)), // normal text color fg_stroke: Stroke::new(1.0, Color32::from_gray(100)), // normal text color
corner_radius: Rounding::same(2.0), rounding: Rounding::same(2.0),
expansion: 0.0, expansion: 0.0,
}, },
inactive: WidgetVisuals { inactive: WidgetVisuals {
bg_fill: Color32::from_gray(215), // button background bg_fill: Color32::from_gray(215), // button background
bg_stroke: Default::default(), bg_stroke: Default::default(),
fg_stroke: Stroke::new(1.0, Color32::from_gray(80)), // button text fg_stroke: Stroke::new(1.0, Color32::from_gray(80)), // button text
corner_radius: Rounding::same(2.0), rounding: Rounding::same(2.0),
expansion: 0.0, expansion: 0.0,
}, },
hovered: WidgetVisuals { hovered: WidgetVisuals {
bg_fill: Color32::from_gray(210), bg_fill: Color32::from_gray(210),
bg_stroke: Stroke::new(1.0, Color32::from_gray(105)), // e.g. hover over window edge or button bg_stroke: Stroke::new(1.0, Color32::from_gray(105)), // e.g. hover over window edge or button
fg_stroke: Stroke::new(1.5, Color32::BLACK), fg_stroke: Stroke::new(1.5, Color32::BLACK),
corner_radius: Rounding::same(3.0), rounding: Rounding::same(3.0),
expansion: 1.0, expansion: 1.0,
}, },
active: WidgetVisuals { active: WidgetVisuals {
bg_fill: Color32::from_gray(165), bg_fill: Color32::from_gray(165),
bg_stroke: Stroke::new(1.0, Color32::BLACK), bg_stroke: Stroke::new(1.0, Color32::BLACK),
fg_stroke: Stroke::new(2.0, Color32::BLACK), fg_stroke: Stroke::new(2.0, Color32::BLACK),
corner_radius: Rounding::same(2.0), rounding: Rounding::same(2.0),
expansion: 1.0, expansion: 1.0,
}, },
open: WidgetVisuals { open: WidgetVisuals {
bg_fill: Color32::from_gray(220), bg_fill: Color32::from_gray(220),
bg_stroke: Stroke::new(1.0, Color32::from_gray(160)), bg_stroke: Stroke::new(1.0, Color32::from_gray(160)),
fg_stroke: Stroke::new(1.0, Color32::BLACK), fg_stroke: Stroke::new(1.0, Color32::BLACK),
corner_radius: Rounding::same(2.0), rounding: Rounding::same(2.0),
expansion: 0.0, expansion: 0.0,
}, },
} }
@ -933,7 +933,7 @@ impl Selection {
pub fn ui(&mut self, ui: &mut crate::Ui) { pub fn ui(&mut self, ui: &mut crate::Ui) {
let Self { bg_fill, stroke } = self; let Self { bg_fill, stroke } = self;
ui.label("Selectable labels"); ui.label("Selectable labels");
ui_color(ui, bg_fill, "bg_fill"); ui_color(ui, bg_fill, "background fill");
stroke_ui(ui, stroke, "stroke"); stroke_ui(ui, stroke, "stroke");
} }
} }
@ -943,19 +943,16 @@ impl WidgetVisuals {
let Self { let Self {
bg_fill, bg_fill,
bg_stroke, bg_stroke,
corner_radius, rounding,
fg_stroke, fg_stroke,
expansion, expansion,
} = self; } = self;
ui_color(ui, bg_fill, "bg_fill"); ui_color(ui, bg_fill, "background fill");
stroke_ui(ui, bg_stroke, "bg_stroke"); stroke_ui(ui, bg_stroke, "background stroke");
ui.add(Slider::new(&mut corner_radius.nw, 0.0..=10.0).text("corner_radius_nw")); rounding_ui(ui, rounding);
ui.add(Slider::new(&mut corner_radius.ne, 0.0..=10.0).text("corner_radius_ne"));
ui.add(Slider::new(&mut corner_radius.sw, 0.0..=10.0).text("corner_radius_sw"));
ui.add(Slider::new(&mut corner_radius.se, 0.0..=10.0).text("corner_radius_se"));
stroke_ui(ui, fg_stroke, "fg_stroke (text)"); stroke_ui(ui, fg_stroke, "foreground stroke (text)");
ui.add(Slider::new(expansion, -5.0..=5.0).text("expansion")) ui.add(Slider::new(expansion, -5.0..=5.0).text("expansion"))
.on_hover_text("make shapes this much larger"); .on_hover_text("make shapes this much larger");
} }
@ -1004,7 +1001,7 @@ impl Visuals {
faint_bg_color, faint_bg_color,
extreme_bg_color, extreme_bg_color,
code_bg_color, code_bg_color,
window_corner_radius, window_rounding,
window_shadow, window_shadow,
popup_shadow, popup_shadow,
resize_corner_size, resize_corner_size,
@ -1030,11 +1027,7 @@ impl Visuals {
ui_color(ui, &mut widgets.noninteractive.bg_fill, "Fill"); ui_color(ui, &mut widgets.noninteractive.bg_fill, "Fill");
stroke_ui(ui, &mut widgets.noninteractive.bg_stroke, "Outline"); stroke_ui(ui, &mut widgets.noninteractive.bg_stroke, "Outline");
ui.label("Rounding"); rounding_ui(ui, window_rounding);
ui.add(Slider::new(&mut window_corner_radius.nw, 0.0..=20.0).text("Top Left"));
ui.add(Slider::new(&mut window_corner_radius.ne, 0.0..=20.0).text("Top Right"));
ui.add(Slider::new(&mut window_corner_radius.sw, 0.0..=20.0).text("Bottom Left"));
ui.add(Slider::new(&mut window_corner_radius.se, 0.0..=20.0).text("Bottom Right"));
shadow_ui(ui, window_shadow, "Shadow"); shadow_ui(ui, window_shadow, "Shadow");
shadow_ui(ui, popup_shadow, "Shadow (small menus and popups)"); shadow_ui(ui, popup_shadow, "Shadow (small menus and popups)");
@ -1125,3 +1118,29 @@ fn ui_color(ui: &mut Ui, srgba: &mut Color32, label: impl Into<WidgetText>) -> R
}) })
.response .response
} }
fn rounding_ui(ui: &mut Ui, rounding: &mut Rounding) {
const MAX: f32 = 20.0;
let mut same = rounding.is_same();
ui.group(|ui| {
ui.horizontal(|ui| {
ui.label("Rounding: ");
ui.radio_value(&mut same, true, "Same");
ui.radio_value(&mut same, false, "Separate");
});
if same {
let mut cr = rounding.nw;
ui.add(Slider::new(&mut cr, 0.0..=MAX));
*rounding = Rounding::same(cr);
} else {
ui.add(Slider::new(&mut rounding.nw, 0.0..=MAX).text("North-West"));
ui.add(Slider::new(&mut rounding.ne, 0.0..=MAX).text("North-East"));
ui.add(Slider::new(&mut rounding.sw, 0.0..=MAX).text("South-West"));
ui.add(Slider::new(&mut rounding.se, 0.0..=MAX).text("South-East"));
if rounding.is_same() {
rounding.se *= 1.00001;
}
}
});
}

View file

@ -180,7 +180,7 @@ impl Widget for Button {
let stroke = stroke.unwrap_or(visuals.bg_stroke); let stroke = stroke.unwrap_or(visuals.bg_stroke);
ui.painter().rect( ui.painter().rect(
rect.expand(visuals.expansion), rect.expand(visuals.expansion),
visuals.corner_radius, visuals.rounding,
fill, fill,
stroke, stroke,
); );
@ -265,7 +265,7 @@ impl<'a> Widget for Checkbox<'a> {
let (small_icon_rect, big_icon_rect) = ui.spacing().icon_rectangles(rect); let (small_icon_rect, big_icon_rect) = ui.spacing().icon_rectangles(rect);
ui.painter().add(epaint::RectShape { ui.painter().add(epaint::RectShape {
rect: big_icon_rect.expand(visuals.expansion), rect: big_icon_rect.expand(visuals.expansion),
corner_radius: visuals.corner_radius, rounding: visuals.rounding,
fill: visuals.bg_fill, fill: visuals.bg_fill,
stroke: visuals.bg_stroke, stroke: visuals.bg_stroke,
}); });
@ -455,7 +455,7 @@ impl Widget for ImageButton {
response.widget_info(|| WidgetInfo::new(WidgetType::ImageButton)); response.widget_info(|| WidgetInfo::new(WidgetType::ImageButton));
if ui.is_rect_visible(rect) { if ui.is_rect_visible(rect) {
let (expansion, corner_radius, fill, stroke) = if selected { let (expansion, rounding, fill, stroke) = if selected {
let selection = ui.visuals().selection; let selection = ui.visuals().selection;
( (
-padding, -padding,
@ -472,7 +472,7 @@ impl Widget for ImageButton {
}; };
( (
expansion, expansion,
visuals.corner_radius, visuals.rounding,
visuals.bg_fill, visuals.bg_fill,
visuals.bg_stroke, visuals.bg_stroke,
) )
@ -482,7 +482,7 @@ impl Widget for ImageButton {
// Draw frame background (for transparent images): // Draw frame background (for transparent images):
ui.painter() ui.painter()
.rect_filled(rect.expand2(expansion), corner_radius, fill); .rect_filled(rect.expand2(expansion), rounding, fill);
let image_rect = ui let image_rect = ui
.layout() .layout()
@ -492,7 +492,7 @@ impl Widget for ImageButton {
// Draw frame outline: // Draw frame outline:
ui.painter() ui.painter()
.rect_stroke(rect.expand2(expansion), corner_radius, stroke); .rect_stroke(rect.expand2(expansion), rounding, stroke);
} }
response response

View file

@ -61,7 +61,7 @@ fn show_hsva(ui: &mut Ui, color: Hsva, desired_size: Vec2) -> Response {
} else { } else {
ui.painter().add(RectShape { ui.painter().add(RectShape {
rect, rect,
corner_radius: Rounding::same(2.0), rounding: Rounding::same(2.0),
fill: color.into(), fill: color.into(),
stroke: Stroke::new(3.0, color.to_opaque()), stroke: Stroke::new(3.0, color.to_opaque()),
}); });
@ -90,15 +90,15 @@ fn color_button(ui: &mut Ui, color: Color32, open: bool) -> Response {
ui.painter().rect_filled(left_half, 0.0, color); ui.painter().rect_filled(left_half, 0.0, color);
ui.painter().rect_filled(right_half, 0.0, color.to_opaque()); ui.painter().rect_filled(right_half, 0.0, color.to_opaque());
let corner_radius = Rounding { let rounding = Rounding {
nw: visuals.corner_radius.nw.at_most(2.0), nw: visuals.rounding.nw.at_most(2.0),
ne: visuals.corner_radius.ne.at_most(2.0), ne: visuals.rounding.ne.at_most(2.0),
sw: visuals.corner_radius.sw.at_most(2.0), sw: visuals.rounding.sw.at_most(2.0),
se: visuals.corner_radius.se.at_most(2.0), se: visuals.rounding.se.at_most(2.0),
}; };
ui.painter() ui.painter()
.rect_stroke(rect, corner_radius, (2.0, visuals.bg_fill)); // fill is intentional, because default style has no border .rect_stroke(rect, rounding, (2.0, visuals.bg_fill)); // fill is intentional, because default style has no border
} }
response response

View file

@ -129,7 +129,7 @@ impl Bar {
let rect = transform.rect_from_values(&self.bounds_min(), &self.bounds_max()); let rect = transform.rect_from_values(&self.bounds_min(), &self.bounds_max());
let rect = Shape::Rect(RectShape { let rect = Shape::Rect(RectShape {
rect, rect,
corner_radius: Rounding::none(), rounding: Rounding::none(),
fill, fill,
stroke, stroke,
}); });

View file

@ -152,7 +152,7 @@ impl BoxElem {
); );
let rect = Shape::Rect(RectShape { let rect = Shape::Rect(RectShape {
rect, rect,
corner_radius: Rounding::none(), rounding: Rounding::none(),
fill, fill,
stroke, stroke,
}); });

View file

@ -240,7 +240,7 @@ impl Widget for &mut LegendWidget {
.scope(|ui| { .scope(|ui| {
let background_frame = Frame { let background_frame = Frame {
margin: vec2(8.0, 4.0), margin: vec2(8.0, 4.0),
corner_radius: ui.style().visuals.window_corner_radius, rounding: ui.style().visuals.window_rounding,
shadow: epaint::Shadow::default(), shadow: epaint::Shadow::default(),
fill: ui.style().visuals.extreme_bg_color, fill: ui.style().visuals.extreme_bg_color,
stroke: ui.style().visuals.window_stroke(), stroke: ui.style().visuals.window_stroke(),

View file

@ -479,7 +479,7 @@ impl Plot {
if show_background { if show_background {
ui.painter().sub_region(rect).add(epaint::RectShape { ui.painter().sub_region(rect).add(epaint::RectShape {
rect, rect,
corner_radius: Rounding::same(2.0), rounding: Rounding::same(2.0),
fill: ui.visuals().extreme_bg_color, fill: ui.visuals().extreme_bg_color,
stroke: ui.visuals().widgets.noninteractive.bg_stroke, stroke: ui.visuals().widgets.noninteractive.bg_stroke,
}); });

View file

@ -77,10 +77,10 @@ impl Widget for ProgressBar {
} }
let visuals = ui.style().visuals.clone(); let visuals = ui.style().visuals.clone();
let corner_radius = outer_rect.height() / 2.0; let rounding = outer_rect.height() / 2.0;
ui.painter().rect( ui.painter().rect(
outer_rect, outer_rect,
corner_radius, rounding,
visuals.extreme_bg_color, visuals.extreme_bg_color,
Stroke::none(), Stroke::none(),
); );
@ -101,7 +101,7 @@ impl Widget for ProgressBar {
ui.painter().rect( ui.painter().rect(
inner_rect, inner_rect,
corner_radius, rounding,
Color32::from(Rgba::from(visuals.selection.bg_fill) * color_factor as f32), Color32::from(Rgba::from(visuals.selection.bg_fill) * color_factor as f32),
Stroke::none(), Stroke::none(),
); );
@ -110,14 +110,14 @@ impl Widget for ProgressBar {
let n_points = 20; let n_points = 20;
let start_angle = ui.input().time as f64 * 360f64.to_radians(); let start_angle = ui.input().time as f64 * 360f64.to_radians();
let end_angle = start_angle + 240f64.to_radians() * ui.input().time.sin(); let end_angle = start_angle + 240f64.to_radians() * ui.input().time.sin();
let circle_radius = corner_radius - 2.0; let circle_radius = rounding - 2.0;
let points: Vec<Pos2> = (0..n_points) let points: Vec<Pos2> = (0..n_points)
.map(|i| { .map(|i| {
let angle = lerp(start_angle..=end_angle, i as f64 / n_points as f64); let angle = lerp(start_angle..=end_angle, i as f64 / n_points as f64);
let (sin, cos) = angle.sin_cos(); let (sin, cos) = angle.sin_cos();
inner_rect.right_center() inner_rect.right_center()
+ circle_radius * vec2(cos as f32, sin as f32) + circle_radius * vec2(cos as f32, sin as f32)
+ vec2(-corner_radius, 0.0) + vec2(-rounding, 0.0)
}) })
.collect(); .collect();
ui.painter().add(Shape::line( ui.painter().add(Shape::line(

View file

@ -64,12 +64,8 @@ impl Widget for SelectableLabel {
if selected || response.hovered() || response.has_focus() { if selected || response.hovered() || response.has_focus() {
let rect = rect.expand(visuals.expansion); let rect = rect.expand(visuals.expansion);
ui.painter().rect( ui.painter()
rect, .rect(rect, visuals.rounding, visuals.bg_fill, visuals.bg_stroke);
visuals.corner_radius,
visuals.bg_fill,
visuals.bg_stroke,
);
} }
text.paint_with_visuals(ui.painter(), text_pos, &visuals); text.paint_with_visuals(ui.painter(), text_pos, &visuals);

View file

@ -355,7 +355,7 @@ impl<'a> Slider<'a> {
let visuals = ui.style().interact(response); let visuals = ui.style().interact(response);
ui.painter().add(epaint::RectShape { ui.painter().add(epaint::RectShape {
rect: rail_rect, rect: rail_rect,
corner_radius: ui.visuals().widgets.inactive.corner_radius, rounding: ui.visuals().widgets.inactive.rounding,
fill: ui.visuals().widgets.inactive.bg_fill, fill: ui.visuals().widgets.inactive.bg_fill,
// fill: visuals.bg_fill, // fill: visuals.bg_fill,
// fill: ui.visuals().extreme_bg_color, // fill: ui.visuals().extreme_bg_color,

View file

@ -299,7 +299,7 @@ impl<'t> TextEdit<'t> {
if output.response.has_focus() { if output.response.has_focus() {
epaint::RectShape { epaint::RectShape {
rect: frame_rect, rect: frame_rect,
corner_radius: visuals.corner_radius, rounding: visuals.rounding,
// fill: ui.visuals().selection.bg_fill, // fill: ui.visuals().selection.bg_fill,
fill: ui.visuals().extreme_bg_color, fill: ui.visuals().extreme_bg_color,
stroke: ui.visuals().selection.stroke, stroke: ui.visuals().selection.stroke,
@ -307,7 +307,7 @@ impl<'t> TextEdit<'t> {
} else { } else {
epaint::RectShape { epaint::RectShape {
rect: frame_rect, rect: frame_rect,
corner_radius: visuals.corner_radius, rounding: visuals.rounding,
fill: ui.visuals().extreme_bg_color, fill: ui.visuals().extreme_bg_color,
stroke: visuals.bg_stroke, // TODO: we want to show something here, or a text-edit field doesn't "pop". stroke: visuals.bg_stroke, // TODO: we want to show something here, or a text-edit field doesn't "pop".
} }
@ -316,7 +316,7 @@ impl<'t> TextEdit<'t> {
let visuals = &ui.style().visuals.widgets.inactive; let visuals = &ui.style().visuals.widgets.inactive;
epaint::RectShape { epaint::RectShape {
rect: frame_rect, rect: frame_rect,
corner_radius: visuals.corner_radius, rounding: visuals.rounding,
// fill: ui.visuals().extreme_bg_color, // fill: ui.visuals().extreme_bg_color,
// fill: visuals.bg_fill, // fill: visuals.bg_fill,
fill: Color32::TRANSPARENT, fill: Color32::TRANSPARENT,

View file

@ -66,7 +66,7 @@ pub fn drop_target<R>(
ui.painter().set( ui.painter().set(
where_to_put_background, where_to_put_background,
epaint::RectShape { epaint::RectShape {
corner_radius: style.corner_radius, rounding: style.rounding,
fill, fill,
stroke, stroke,
rect, rect,

View file

@ -269,7 +269,7 @@ impl ColorWidgets {
#[cfg_attr(feature = "serde", serde(default))] #[cfg_attr(feature = "serde", serde(default))]
struct BoxPainting { struct BoxPainting {
size: Vec2, size: Vec2,
corner_radius: f32, rounding: f32,
stroke_width: f32, stroke_width: f32,
num_boxes: usize, num_boxes: usize,
} }
@ -278,7 +278,7 @@ impl Default for BoxPainting {
fn default() -> Self { fn default() -> Self {
Self { Self {
size: vec2(64.0, 32.0), size: vec2(64.0, 32.0),
corner_radius: 5.0, rounding: 5.0,
stroke_width: 2.0, stroke_width: 2.0,
num_boxes: 1, num_boxes: 1,
} }
@ -289,7 +289,7 @@ impl BoxPainting {
pub fn ui(&mut self, ui: &mut Ui) { pub fn ui(&mut self, ui: &mut Ui) {
ui.add(Slider::new(&mut self.size.x, 0.0..=500.0).text("width")); ui.add(Slider::new(&mut self.size.x, 0.0..=500.0).text("width"));
ui.add(Slider::new(&mut self.size.y, 0.0..=500.0).text("height")); ui.add(Slider::new(&mut self.size.y, 0.0..=500.0).text("height"));
ui.add(Slider::new(&mut self.corner_radius, 0.0..=50.0).text("corner_radius")); ui.add(Slider::new(&mut self.rounding, 0.0..=50.0).text("rounding"));
ui.add(Slider::new(&mut self.stroke_width, 0.0..=10.0).text("stroke_width")); ui.add(Slider::new(&mut self.stroke_width, 0.0..=10.0).text("stroke_width"));
ui.add(Slider::new(&mut self.num_boxes, 0..=8).text("num_boxes")); ui.add(Slider::new(&mut self.num_boxes, 0..=8).text("num_boxes"));
@ -298,7 +298,7 @@ impl BoxPainting {
let (rect, _response) = ui.allocate_at_least(self.size, Sense::hover()); let (rect, _response) = ui.allocate_at_least(self.size, Sense::hover());
ui.painter().rect( ui.painter().rect(
rect, rect,
self.corner_radius, self.rounding,
Color32::from_gray(64), Color32::from_gray(64),
Stroke::new(self.stroke_width, Color32::WHITE), Stroke::new(self.stroke_width, Color32::WHITE),
); );

View file

@ -76,7 +76,7 @@ impl FrameHistory {
let mut shapes = Vec::with_capacity(3 + 2 * history.len()); let mut shapes = Vec::with_capacity(3 + 2 * history.len());
shapes.push(Shape::Rect(epaint::RectShape { shapes.push(Shape::Rect(epaint::RectShape {
rect, rect,
corner_radius: style.corner_radius, rounding: style.rounding,
fill: ui.visuals().extreme_bg_color, fill: ui.visuals().extreme_bg_color,
stroke: ui.style().noninteractive().bg_stroke, stroke: ui.style().noninteractive().bg_stroke,
})); }));

View file

@ -9,6 +9,7 @@ All notable changes to the epaint crate will be documented in this file.
* Replaced `Fonts::font_image` with `font_image_delta` for partial font atlas updates. * Replaced `Fonts::font_image` with `font_image_delta` for partial font atlas updates.
* Added `ImageData` and `TextureManager` for loading images into textures ([#1110](https://github.com/emilk/egui/pull/1110)). * Added `ImageData` and `TextureManager` for loading images into textures ([#1110](https://github.com/emilk/egui/pull/1110)).
* Added `Shape::dashed_line_many` ([#1027](https://github.com/emilk/egui/pull/1027)). * Added `Shape::dashed_line_many` ([#1027](https://github.com/emilk/egui/pull/1027)).
* Replaced `corner_radius: f32` with `rounding: Rounding`, allowing per-corner rounding settings ([#1206](https://github.com/emilk/egui/pull/1206)).
## 0.16.0 - 2021-12-29 ## 0.16.0 - 2021-12-29

View file

@ -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 // tessellator.clip_rect = clip_rect; // TODO: culling
let Self { extrusion, color } = *self; let Self { extrusion, color } = *self;
let cr: Rounding = corner_radius.into(); let rounding: Rounding = rounding.into();
let half_ext = 0.5 * extrusion; let half_ext = 0.5 * extrusion;
let ext_corner_radius = Rounding { let ext_rounding = Rounding {
nw: cr.nw + half_ext, nw: rounding.nw + half_ext,
ne: cr.ne + half_ext, ne: rounding.ne + half_ext,
sw: cr.sw + half_ext, sw: rounding.sw + half_ext,
se: cr.se + half_ext, se: rounding.se + half_ext,
}; };
use crate::tessellator::*; 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 { let mut tessellator = Tessellator::from_options(TessellationOptions {
aa_size: extrusion, aa_size: extrusion,
anti_alias: true, anti_alias: true,

View file

@ -116,19 +116,19 @@ impl Shape {
#[inline] #[inline]
pub fn rect_filled( pub fn rect_filled(
rect: Rect, rect: Rect,
corner_radius: impl Into<Rounding>, rounding: impl Into<Rounding>,
fill_color: impl Into<Color32>, fill_color: impl Into<Color32>,
) -> Self { ) -> Self {
Self::Rect(RectShape::filled(rect, corner_radius, fill_color)) Self::Rect(RectShape::filled(rect, rounding, fill_color))
} }
#[inline] #[inline]
pub fn rect_stroke( pub fn rect_stroke(
rect: Rect, rect: Rect,
corner_radius: impl Into<Rounding>, rounding: impl Into<Rounding>,
stroke: impl Into<Stroke>, stroke: impl Into<Stroke>,
) -> Self { ) -> Self {
Self::Rect(RectShape::stroke(rect, corner_radius, stroke)) Self::Rect(RectShape::stroke(rect, rounding, stroke))
} }
#[allow(clippy::needless_pass_by_value)] #[allow(clippy::needless_pass_by_value)]
@ -330,7 +330,7 @@ impl From<PathShape> for Shape {
pub struct RectShape { pub struct RectShape {
pub rect: Rect, pub rect: Rect,
/// How rounded the corners are. Use `Rounding::none()` for no rounding. /// How rounded the corners are. Use `Rounding::none()` for no rounding.
pub corner_radius: Rounding, pub rounding: Rounding,
pub fill: Color32, pub fill: Color32,
pub stroke: Stroke, pub stroke: Stroke,
} }
@ -339,26 +339,22 @@ impl RectShape {
#[inline] #[inline]
pub fn filled( pub fn filled(
rect: Rect, rect: Rect,
corner_radius: impl Into<Rounding>, rounding: impl Into<Rounding>,
fill_color: impl Into<Color32>, fill_color: impl Into<Color32>,
) -> Self { ) -> Self {
Self { Self {
rect, rect,
corner_radius: corner_radius.into(), rounding: rounding.into(),
fill: fill_color.into(), fill: fill_color.into(),
stroke: Default::default(), stroke: Default::default(),
} }
} }
#[inline] #[inline]
pub fn stroke( pub fn stroke(rect: Rect, rounding: impl Into<Rounding>, stroke: impl Into<Stroke>) -> Self {
rect: Rect,
corner_radius: impl Into<Rounding>,
stroke: impl Into<Stroke>,
) -> Self {
Self { Self {
rect, rect,
corner_radius: corner_radius.into(), rounding: rounding.into(),
fill: Default::default(), fill: Default::default(),
stroke: stroke.into(), stroke: stroke.into(),
} }
@ -382,9 +378,13 @@ impl From<RectShape> for Shape {
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
/// How rounded the corners of things should be /// How rounded the corners of things should be
pub struct Rounding { pub struct Rounding {
/// Radius of the rounding of the North-West (left top) corner.
pub nw: f32, pub nw: f32,
/// Radius of the rounding of the North-East (right top) corner.
pub ne: f32, pub ne: f32,
/// Radius of the rounding of the South-West (left bottom) corner.
pub sw: f32, pub sw: f32,
/// Radius of the rounding of the South-East (right bottom) corner.
pub se: f32, pub se: f32,
} }
@ -427,6 +427,12 @@ impl Rounding {
se: 0.0, 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
}
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View file

@ -184,15 +184,15 @@ pub mod path {
use super::*; use super::*;
/// overwrites existing points /// 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(); path.clear();
let min = rect.min; let min = rect.min;
let max = rect.max; 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 min = rect.min;
let max = rect.max; let max = rect.max;
path.reserve(4); path.reserve(4);
@ -201,10 +201,10 @@ pub mod path {
path.push(pos2(max.x, max.y)); path.push(pos2(max.x, max.y));
path.push(pos2(min.x, max.y)); path.push(pos2(min.x, max.y));
} else { } else {
add_circle_quadrant(path, pos2(max.x - cr.se, max.y - cr.se), cr.se, 0.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 + cr.sw, max.y - cr.sw), cr.sw, 1.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 + cr.nw, min.y + cr.nw), cr.nw, 2.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 - cr.ne, min.y + cr.ne), cr.ne, 3.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 // 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_width = rect.width() * 0.5;
let half_height = rect.height() * 0.5; let half_height = rect.height() * 0.5;
let max_cr = half_width.min(half_height); let max_cr = half_width.min(half_height);
Rounding { Rounding {
nw: corner_radius.nw.at_most(max_cr), nw: rounding.nw.at_most(max_cr).at_least(0.0),
ne: corner_radius.ne.at_most(max_cr), ne: rounding.ne.at_most(max_cr).at_least(0.0),
sw: corner_radius.sw.at_most(max_cr), sw: rounding.sw.at_most(max_cr).at_least(0.0),
se: corner_radius.se.at_most(max_cr), 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) { pub(crate) fn tessellate_rect(&mut self, rect: &RectShape, out: &mut Mesh) {
let RectShape { let RectShape {
mut rect, mut rect,
corner_radius, rounding,
fill, fill,
stroke, stroke,
} = *rect; } = *rect;
@ -883,7 +883,7 @@ impl Tessellator {
let path = &mut self.scratchpad_path; let path = &mut self.scratchpad_path;
path.clear(); 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.add_line_loop(&self.scratchpad_points);
path.fill(fill, &self.options, out); path.fill(fill, &self.options, out);
path.stroke_closed(stroke, &self.options, out); path.stroke_closed(stroke, &self.options, out);