Skip to content

Commit

Permalink
Rename corner_radius to rounding
Browse files Browse the repository at this point in the history
Also update changelogs and clean up other aspects of
#1206
  • Loading branch information
emilk committed Feb 5, 2022
1 parent ace2ac0 commit 9ed9615
Show file tree
Hide file tree
Showing 26 changed files with 187 additions and 148 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
* `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 `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)).
* `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)).

Expand Down
10 changes: 3 additions & 7 deletions egui/src/containers/collapsing_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl CollapsingHeader {
if ui.visuals().collapsing_header_frame || self.show_background {
ui.painter().add(epaint::RectShape {
rect: header_response.rect.expand(visuals.expansion),
corner_radius: visuals.corner_radius,
rounding: visuals.rounding,
fill: visuals.bg_fill,
stroke: visuals.bg_stroke,
// stroke: Default::default(),
Expand All @@ -350,12 +350,8 @@ impl CollapsingHeader {
{
let rect = rect.expand(visuals.expansion);

ui.painter().rect(
rect,
visuals.corner_radius,
visuals.bg_fill,
visuals.bg_stroke,
);
ui.painter()
.rect(rect, visuals.rounding, visuals.bg_fill, visuals.bg_stroke);
}

{
Expand Down
2 changes: 1 addition & 1 deletion egui/src/containers/combo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ fn button_frame(
where_to_put_background,
epaint::RectShape {
rect: outer_rect.expand(visuals.expansion),
corner_radius: visuals.corner_radius,
rounding: visuals.rounding,
fill: visuals.bg_fill,
stroke: visuals.bg_stroke,
},
Expand Down
26 changes: 13 additions & 13 deletions egui/src/containers/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use epaint::*;
pub struct Frame {
/// On each side
pub margin: Vec2,
pub corner_radius: Rounding,
pub rounding: Rounding,
pub shadow: Shadow,
pub fill: Color32,
pub stroke: Stroke,
Expand All @@ -24,7 +24,7 @@ impl Frame {
pub fn group(style: &Style) -> Self {
Self {
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,
..Default::default()
}
Expand All @@ -33,7 +33,7 @@ impl Frame {
pub(crate) fn side_top_panel(style: &Style) -> Self {
Self {
margin: Vec2::new(8.0, 2.0),
corner_radius: Rounding::none(),
rounding: Rounding::none(),
fill: style.visuals.window_fill(),
stroke: style.visuals.window_stroke(),
..Default::default()
Expand All @@ -43,7 +43,7 @@ impl Frame {
pub(crate) fn central_panel(style: &Style) -> Self {
Self {
margin: Vec2::new(8.0, 8.0),
corner_radius: Rounding::none(),
rounding: Rounding::none(),
fill: style.visuals.window_fill(),
stroke: Default::default(),
..Default::default()
Expand All @@ -53,7 +53,7 @@ impl Frame {
pub fn window(style: &Style) -> Self {
Self {
margin: style.spacing.window_padding,
corner_radius: style.visuals.window_corner_radius,
rounding: style.visuals.window_rounding,
shadow: style.visuals.window_shadow,
fill: style.visuals.window_fill(),
stroke: style.visuals.window_stroke(),
Expand All @@ -63,7 +63,7 @@ impl Frame {
pub fn menu(style: &Style) -> Self {
Self {
margin: Vec2::splat(1.0),
corner_radius: style.visuals.widgets.noninteractive.corner_radius,
rounding: style.visuals.widgets.noninteractive.rounding,
shadow: style.visuals.popup_shadow,
fill: style.visuals.window_fill(),
stroke: style.visuals.window_stroke(),
Expand All @@ -73,7 +73,7 @@ impl Frame {
pub fn popup(style: &Style) -> Self {
Self {
margin: style.spacing.window_padding,
corner_radius: style.visuals.widgets.noninteractive.corner_radius,
rounding: style.visuals.widgets.noninteractive.rounding,
shadow: style.visuals.popup_shadow,
fill: style.visuals.window_fill(),
stroke: style.visuals.window_stroke(),
Expand All @@ -84,7 +84,7 @@ impl Frame {
pub fn dark_canvas(style: &Style) -> Self {
Self {
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),
stroke: style.visuals.window_stroke(),
..Default::default()
Expand All @@ -103,8 +103,8 @@ impl Frame {
self
}

pub fn corner_radius(mut self, corner_radius: impl Into<Rounding>) -> Self {
self.corner_radius = corner_radius.into();
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
self.rounding = rounding.into();
self
}

Expand Down Expand Up @@ -172,23 +172,23 @@ impl Frame {
pub fn paint(&self, outer_rect: Rect) -> Shape {
let Self {
margin: _,
corner_radius,
rounding,
shadow,
fill,
stroke,
} = *self;

let frame_shape = Shape::Rect(epaint::RectShape {
rect: outer_rect,
corner_radius,
rounding,
fill,
stroke,
});

if shadow == Default::default() {
frame_shape
} else {
let shadow = shadow.tessellate(outer_rect, corner_radius);
let shadow = shadow.tessellate(outer_rect, rounding);
let shadow = Shape::Mesh(shadow);
Shape::Vec(vec![shadow, frame_shape])
}
Expand Down
4 changes: 2 additions & 2 deletions egui/src/containers/scroll_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,13 +740,13 @@ impl Prepared {

ui.painter().add(epaint::Shape::rect_filled(
outer_scroll_rect,
visuals.corner_radius,
visuals.rounding,
ui.visuals().extreme_bg_color,
));

ui.painter().add(epaint::Shape::rect_filled(
handle_rect,
visuals.corner_radius,
visuals.rounding,
visuals.bg_fill,
));
}
Expand Down
54 changes: 37 additions & 17 deletions egui/src/containers/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,42 +699,62 @@ fn paint_frame_interaction(
) {
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 mut points = Vec::new();

if interaction.right && !interaction.bottom && !interaction.top {
points.push(pos2(max.x, min.y + cr.ne));
points.push(pos2(max.x, max.y - cr.se));
points.push(pos2(max.x, min.y + rounding.ne));
points.push(pos2(max.x, max.y - rounding.se));
}
if interaction.right && interaction.bottom {
points.push(pos2(max.x, min.y + cr.ne));
points.push(pos2(max.x, max.y - cr.se));
add_circle_quadrant(&mut points, pos2(max.x - cr.se, max.y - cr.se), cr.se, 0.0);
points.push(pos2(max.x, min.y + rounding.ne));
points.push(pos2(max.x, max.y - rounding.se));
add_circle_quadrant(
&mut points,
pos2(max.x - rounding.se, max.y - rounding.se),
rounding.se,
0.0,
);
}
if interaction.bottom {
points.push(pos2(max.x - cr.se, max.y));
points.push(pos2(min.x + cr.sw, max.y));
points.push(pos2(max.x - rounding.se, max.y));
points.push(pos2(min.x + rounding.sw, max.y));
}
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 {
points.push(pos2(min.x, max.y - cr.sw));
points.push(pos2(min.x, min.y + cr.nw));
points.push(pos2(min.x, max.y - rounding.sw));
points.push(pos2(min.x, min.y + rounding.nw));
}
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 {
points.push(pos2(min.x + cr.nw, min.y));
points.push(pos2(max.x - cr.ne, min.y));
points.push(pos2(min.x + rounding.nw, min.y));
points.push(pos2(max.x - rounding.ne, min.y));
}
if interaction.right && interaction.top {
add_circle_quadrant(&mut points, pos2(max.x - cr.ne, min.y + cr.ne), cr.ne, 3.0);
points.push(pos2(max.x, min.y + cr.ne));
points.push(pos2(max.x, max.y - cr.se));
add_circle_quadrant(
&mut points,
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));
}
Expand Down
2 changes: 1 addition & 1 deletion egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ impl SubMenuButton {

ui.painter().rect_filled(
rect.expand(visuals.expansion),
visuals.corner_radius,
visuals.rounding,
visuals.bg_fill,
);

Expand Down
12 changes: 6 additions & 6 deletions egui/src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ impl Painter {
pub fn rect(
&self,
rect: Rect,
corner_radius: impl Into<Rounding>,
rounding: impl Into<Rounding>,
fill_color: impl Into<Color32>,
stroke: impl Into<Stroke>,
) {
self.add(RectShape {
rect,
corner_radius: corner_radius.into(),
rounding: rounding.into(),
fill: fill_color.into(),
stroke: stroke.into(),
});
Expand All @@ -293,12 +293,12 @@ impl Painter {
pub fn rect_filled(
&self,
rect: Rect,
corner_radius: impl Into<Rounding>,
rounding: impl Into<Rounding>,
fill_color: impl Into<Color32>,
) {
self.add(RectShape {
rect,
corner_radius: corner_radius.into(),
rounding: rounding.into(),
fill: fill_color.into(),
stroke: Default::default(),
});
Expand All @@ -307,12 +307,12 @@ impl Painter {
pub fn rect_stroke(
&self,
rect: Rect,
corner_radius: impl Into<Rounding>,
rounding: impl Into<Rounding>,
stroke: impl Into<Stroke>,
) {
self.add(RectShape {
rect,
corner_radius: corner_radius.into(),
rounding: rounding.into(),
fill: Default::default(),
stroke: stroke.into(),
});
Expand Down
Loading

0 comments on commit 9ed9615

Please sign in to comment.