⚠️ Rename `Rounding` to `CornerRadius` (#5673)

Breaking change!

* `Rounding` -> `CornerRadius`
* `rounding` -> `corner_radius`

This is to:
* Clarify
* Conform to other systems (e.g. Figma)
* Avoid confusion with `GuiRounding`
This commit is contained in:
Emil Ernerfeldt 2025-02-04 12:53:18 +01:00 committed by GitHub
parent 3c07e01d08
commit 23ed49334e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
44 changed files with 378 additions and 330 deletions

View File

@ -573,7 +573,7 @@ impl CollapsingHeader {
if ui.visuals().collapsing_header_frame || show_background {
ui.painter().add(epaint::RectShape::new(
header_response.rect.expand(visuals.expansion),
visuals.rounding,
visuals.corner_radius,
visuals.weak_bg_fill,
visuals.bg_stroke,
StrokeKind::Inside,
@ -586,7 +586,7 @@ impl CollapsingHeader {
ui.painter().rect(
rect,
visuals.rounding,
visuals.corner_radius,
visuals.bg_fill,
visuals.bg_stroke,
StrokeKind::Inside,

View File

@ -471,7 +471,7 @@ fn button_frame(
where_to_put_background,
epaint::RectShape::new(
outer_rect.expand(visuals.expansion),
visuals.rounding,
visuals.corner_radius,
visuals.weak_bg_fill,
visuals.bg_stroke,
epaint::StrokeKind::Inside,

View File

@ -4,7 +4,7 @@ use crate::{
epaint, layers::ShapeIdx, InnerResponse, Response, Sense, Style, Ui, UiBuilder, UiKind,
UiStackInfo,
};
use epaint::{Color32, Margin, Marginf, Rect, Rounding, Shadow, Shape, Stroke};
use epaint::{Color32, CornerRadius, Margin, Marginf, Rect, Shadow, Shape, Stroke};
/// A frame around some content, including margin, colors, etc.
///
@ -119,7 +119,7 @@ pub struct Frame {
/// (or, if there is no stroke, the outer corner of [`Self::fill`]).
///
/// In other words, this is the corner radius of the _widget rect_.
pub rounding: Rounding,
pub corner_radius: CornerRadius,
/// Margin outside the painted frame.
///
@ -161,7 +161,7 @@ impl Frame {
inner_margin: Margin::ZERO,
stroke: Stroke::NONE,
fill: Color32::TRANSPARENT,
rounding: Rounding::ZERO,
corner_radius: CornerRadius::ZERO,
outer_margin: Margin::ZERO,
shadow: Shadow::NONE,
};
@ -182,7 +182,7 @@ impl Frame {
pub fn group(style: &Style) -> Self {
Self::new()
.inner_margin(6)
.rounding(style.visuals.widgets.noninteractive.rounding)
.corner_radius(style.visuals.widgets.noninteractive.corner_radius)
.stroke(style.visuals.widgets.noninteractive.bg_stroke)
}
@ -199,7 +199,7 @@ impl Frame {
pub fn window(style: &Style) -> Self {
Self::new()
.inner_margin(style.spacing.window_margin)
.rounding(style.visuals.window_rounding)
.corner_radius(style.visuals.window_corner_radius)
.shadow(style.visuals.window_shadow)
.fill(style.visuals.window_fill())
.stroke(style.visuals.window_stroke())
@ -208,7 +208,7 @@ impl Frame {
pub fn menu(style: &Style) -> Self {
Self::new()
.inner_margin(style.spacing.menu_margin)
.rounding(style.visuals.menu_rounding)
.corner_radius(style.visuals.menu_corner_radius)
.shadow(style.visuals.popup_shadow)
.fill(style.visuals.window_fill())
.stroke(style.visuals.window_stroke())
@ -217,7 +217,7 @@ impl Frame {
pub fn popup(style: &Style) -> Self {
Self::new()
.inner_margin(style.spacing.menu_margin)
.rounding(style.visuals.menu_rounding)
.corner_radius(style.visuals.menu_corner_radius)
.shadow(style.visuals.popup_shadow)
.fill(style.visuals.window_fill())
.stroke(style.visuals.window_stroke())
@ -230,7 +230,7 @@ impl Frame {
pub fn canvas(style: &Style) -> Self {
Self::new()
.inner_margin(2)
.rounding(style.visuals.widgets.noninteractive.rounding)
.corner_radius(style.visuals.widgets.noninteractive.corner_radius)
.fill(style.visuals.extreme_bg_color)
.stroke(style.visuals.window_stroke())
}
@ -277,11 +277,21 @@ impl Frame {
///
/// In other words, this is the corner radius of the _widget rect_.
#[inline]
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
self.rounding = rounding.into();
pub fn corner_radius(mut self, corner_radius: impl Into<CornerRadius>) -> Self {
self.corner_radius = corner_radius.into();
self
}
/// The rounding of the _outer_ corner of the [`Self::stroke`]
/// (or, if there is no stroke, the outer corner of [`Self::fill`]).
///
/// In other words, this is the corner radius of the _widget rect_.
#[inline]
#[deprecated = "Renamed to `corner_radius`"]
pub fn rounding(self, corner_radius: impl Into<CornerRadius>) -> Self {
self.corner_radius(corner_radius)
}
/// Margin outside the painted frame.
///
/// Similar to what is called `margin` in CSS.
@ -424,7 +434,7 @@ impl Frame {
inner_margin: _,
fill,
stroke,
rounding,
corner_radius,
outer_margin: _,
shadow,
} = *self;
@ -433,7 +443,7 @@ impl Frame {
let frame_shape = Shape::Rect(epaint::RectShape::new(
widget_rect,
rounding,
corner_radius,
fill,
stroke,
epaint::StrokeKind::Inside,
@ -442,7 +452,7 @@ impl Frame {
if shadow == Default::default() {
frame_shape
} else {
let shadow = shadow.as_shape(widget_rect, rounding);
let shadow = shadow.as_shape(widget_rect, corner_radius);
Shape::Vec(vec![Shape::from(shadow), frame_shape])
}
}

View File

@ -1240,7 +1240,7 @@ impl Prepared {
// Background:
ui.painter().add(epaint::Shape::rect_filled(
outer_scroll_bar_rect,
visuals.rounding,
visuals.corner_radius,
ui.visuals()
.extreme_bg_color
.gamma_multiply(background_opacity),
@ -1249,7 +1249,7 @@ impl Prepared {
// Handle:
ui.painter().add(epaint::Shape::rect_filled(
handle_rect,
visuals.rounding,
visuals.corner_radius,
handle_color.gamma_multiply(handle_opacity),
));
}

View File

@ -3,7 +3,7 @@
use std::sync::Arc;
use emath::GuiRounding as _;
use epaint::{RectShape, Roundingf};
use epaint::{CornerRadiusF32, RectShape};
use crate::collapsing_header::CollapsingState;
use crate::*;
@ -485,8 +485,8 @@ impl Window<'_> {
.at_least(style.spacing.interact_size.y);
let title_bar_inner_height = title_bar_inner_height + window_frame.inner_margin.sum().y;
let half_height = (title_bar_inner_height / 2.0).round() as _;
window_frame.rounding.ne = window_frame.rounding.ne.clamp(0, half_height);
window_frame.rounding.nw = window_frame.rounding.nw.clamp(0, half_height);
window_frame.corner_radius.ne = window_frame.corner_radius.ne.clamp(0, half_height);
window_frame.corner_radius.nw = window_frame.corner_radius.nw.clamp(0, half_height);
let title_content_spacing = if is_collapsed {
0.0
@ -612,7 +612,7 @@ impl Window<'_> {
if on_top && area_content_ui.visuals().window_highlight_topmost {
let mut round =
window_frame.rounding - window_frame.stroke.width.round() as u8;
window_frame.corner_radius - window_frame.stroke.width.round() as u8;
if !is_collapsed {
round.se = 0;
@ -667,28 +667,28 @@ fn paint_resize_corner(
window_frame: &Frame,
i: ResizeInteraction,
) {
let rounding = window_frame.rounding;
let cr = window_frame.corner_radius;
let (corner, radius, corner_response) = if possible.resize_right && possible.resize_bottom {
(Align2::RIGHT_BOTTOM, rounding.se, i.right & i.bottom)
(Align2::RIGHT_BOTTOM, cr.se, i.right & i.bottom)
} else if possible.resize_left && possible.resize_bottom {
(Align2::LEFT_BOTTOM, rounding.sw, i.left & i.bottom)
(Align2::LEFT_BOTTOM, cr.sw, i.left & i.bottom)
} else if possible.resize_left && possible.resize_top {
(Align2::LEFT_TOP, rounding.nw, i.left & i.top)
(Align2::LEFT_TOP, cr.nw, i.left & i.top)
} else if possible.resize_right && possible.resize_top {
(Align2::RIGHT_TOP, rounding.ne, i.right & i.top)
(Align2::RIGHT_TOP, cr.ne, i.right & i.top)
} else {
// We're not in two directions, but it is still nice to tell the user
// we're resizable by painting the resize corner in the expected place
// (i.e. for windows only resizable in one direction):
if possible.resize_right || possible.resize_bottom {
(Align2::RIGHT_BOTTOM, rounding.se, i.right & i.bottom)
(Align2::RIGHT_BOTTOM, cr.se, i.right & i.bottom)
} else if possible.resize_left || possible.resize_bottom {
(Align2::LEFT_BOTTOM, rounding.sw, i.left & i.bottom)
(Align2::LEFT_BOTTOM, cr.sw, i.left & i.bottom)
} else if possible.resize_left || possible.resize_top {
(Align2::LEFT_TOP, rounding.nw, i.left & i.top)
(Align2::LEFT_TOP, cr.nw, i.left & i.top)
} else if possible.resize_right || possible.resize_top {
(Align2::RIGHT_TOP, rounding.ne, i.right & i.top)
(Align2::RIGHT_TOP, cr.ne, i.right & i.top)
} else {
return;
}
@ -1054,7 +1054,7 @@ fn paint_frame_interaction(ui: &Ui, rect: Rect, interaction: ResizeInteraction)
bottom = interaction.bottom.hover;
}
let rounding = Roundingf::from(ui.visuals().window_rounding);
let cr = CornerRadiusF32::from(ui.visuals().window_corner_radius);
// Put the rect in the center of the fixed window stroke:
let rect = rect.shrink(interaction.window_frame.stroke.width / 2.0);
@ -1072,56 +1072,36 @@ fn paint_frame_interaction(ui: &Ui, rect: Rect, interaction: ResizeInteraction)
let mut points = Vec::new();
if right && !bottom && !top {
points.push(pos2(max.x, min.y + rounding.ne));
points.push(pos2(max.x, max.y - rounding.se));
points.push(pos2(max.x, min.y + cr.ne));
points.push(pos2(max.x, max.y - cr.se));
}
if right && bottom {
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,
);
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);
}
if bottom {
points.push(pos2(max.x - rounding.se, max.y));
points.push(pos2(min.x + rounding.sw, max.y));
points.push(pos2(max.x - cr.se, max.y));
points.push(pos2(min.x + cr.sw, max.y));
}
if left && bottom {
add_circle_quadrant(
&mut points,
pos2(min.x + rounding.sw, max.y - rounding.sw),
rounding.sw,
1.0,
);
add_circle_quadrant(&mut points, pos2(min.x + cr.sw, max.y - cr.sw), cr.sw, 1.0);
}
if left {
points.push(pos2(min.x, max.y - rounding.sw));
points.push(pos2(min.x, min.y + rounding.nw));
points.push(pos2(min.x, max.y - cr.sw));
points.push(pos2(min.x, min.y + cr.nw));
}
if left && top {
add_circle_quadrant(
&mut points,
pos2(min.x + rounding.nw, min.y + rounding.nw),
rounding.nw,
2.0,
);
add_circle_quadrant(&mut points, pos2(min.x + cr.nw, min.y + cr.nw), cr.nw, 2.0);
}
if top {
points.push(pos2(min.x + rounding.nw, min.y));
points.push(pos2(max.x - rounding.ne, min.y));
points.push(pos2(min.x + cr.nw, min.y));
points.push(pos2(max.x - cr.ne, min.y));
}
if right && top {
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));
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));
}
ui.painter().add(Shape::line(points, stroke));

View File

@ -464,8 +464,8 @@ pub use epaint::{
mutex,
text::{FontData, FontDefinitions, FontFamily, FontId, FontTweak},
textures::{TextureFilter, TextureOptions, TextureWrapMode, TexturesDelta},
ClippedPrimitive, ColorImage, FontImage, ImageData, Margin, Mesh, PaintCallback,
PaintCallbackInfo, Rounding, Shadow, Shape, Stroke, StrokeKind, TextureHandle, TextureId,
ClippedPrimitive, ColorImage, CornerRadius, FontImage, ImageData, Margin, Mesh, PaintCallback,
PaintCallbackInfo, Shadow, Shape, Stroke, StrokeKind, TextureHandle, TextureId,
};
pub mod text {
@ -510,6 +510,9 @@ pub use self::{
widgets::*,
};
#[deprecated = "Renamed to CornerRadius"]
pub type Rounding = CornerRadius;
// ----------------------------------------------------------------------------
/// Helper function that adds a label when compiling with debug assertions enabled.
@ -538,7 +541,7 @@ pub fn warn_if_debug_build(ui: &mut crate::Ui) {
/// ui.add(
/// egui::Image::new(egui::include_image!("../assets/ferris.png"))
/// .max_width(200.0)
/// .rounding(10.0),
/// .corner_radius(10),
/// );
///
/// let image_source: egui::ImageSource = egui::include_image!("../assets/ferris.png");

View File

@ -580,7 +580,7 @@ impl SubMenuButton {
if ui.visuals().button_frame {
ui.painter().rect_filled(
rect.expand(visuals.expansion),
visuals.rounding,
visuals.corner_radius,
visuals.weak_bg_fill,
);
}

View File

@ -3,7 +3,7 @@ use std::sync::Arc;
use emath::GuiRounding as _;
use epaint::{
text::{Fonts, Galley, LayoutJob},
CircleShape, ClippedShape, PathStroke, RectShape, Rounding, Shape, Stroke, StrokeKind,
CircleShape, ClippedShape, CornerRadius, PathStroke, RectShape, Shape, Stroke, StrokeKind,
};
use crate::{
@ -412,14 +412,14 @@ impl Painter {
pub fn rect(
&self,
rect: Rect,
rounding: impl Into<Rounding>,
corner_radius: impl Into<CornerRadius>,
fill_color: impl Into<Color32>,
stroke: impl Into<Stroke>,
stroke_kind: StrokeKind,
) -> ShapeIdx {
self.add(RectShape::new(
rect,
rounding,
corner_radius,
fill_color,
stroke,
stroke_kind,
@ -429,21 +429,21 @@ impl Painter {
pub fn rect_filled(
&self,
rect: Rect,
rounding: impl Into<Rounding>,
corner_radius: impl Into<CornerRadius>,
fill_color: impl Into<Color32>,
) -> ShapeIdx {
self.add(RectShape::filled(rect, rounding, fill_color))
self.add(RectShape::filled(rect, corner_radius, fill_color))
}
/// The stroke extends _outside_ the [`Rect`].
pub fn rect_stroke(
&self,
rect: Rect,
rounding: impl Into<Rounding>,
corner_radius: impl Into<CornerRadius>,
stroke: impl Into<Stroke>,
stroke_kind: StrokeKind,
) -> ShapeIdx {
self.add(RectShape::stroke(rect, rounding, stroke, stroke_kind))
self.add(RectShape::stroke(rect, corner_radius, stroke, stroke_kind))
}
/// Show an arrow starting at `origin` and going in the direction of `vec`, with the length `vec.length()`.
@ -472,7 +472,7 @@ impl Painter {
/// # egui::__run_test_ui(|ui| {
/// # let rect = egui::Rect::from_min_size(Default::default(), egui::Vec2::splat(100.0));
/// egui::Image::new(egui::include_image!("../assets/ferris.png"))
/// .rounding(5.0)
/// .corner_radius(5)
/// .tint(egui::Color32::LIGHT_BLUE)
/// .paint_at(ui, rect);
/// # });

View File

@ -5,7 +5,7 @@
use std::{collections::BTreeMap, ops::RangeInclusive, sync::Arc};
use emath::Align;
use epaint::{text::FontTweak, Rounding, Shadow, Stroke};
use epaint::{text::FontTweak, CornerRadius, Shadow, Stroke};
use crate::{
ecolor::Color32,
@ -915,7 +915,7 @@ pub struct Visuals {
/// A good color for error text (e.g. red).
pub error_fg_color: Color32,
pub window_rounding: Rounding,
pub window_corner_radius: CornerRadius,
pub window_shadow: Shadow,
pub window_fill: Color32,
pub window_stroke: Stroke,
@ -923,7 +923,7 @@ pub struct Visuals {
/// Highlight the topmost window.
pub window_highlight_topmost: bool,
pub menu_rounding: Rounding,
pub menu_corner_radius: CornerRadius,
/// Panel background color
pub panel_fill: Color32,
@ -1107,7 +1107,7 @@ pub struct WidgetVisuals {
pub bg_stroke: Stroke,
/// Button frames etc.
pub rounding: Rounding,
pub corner_radius: CornerRadius,
/// Stroke and text color of the interactive part of a component (button text, slider grab, check-mark, …).
pub fg_stroke: Stroke,
@ -1121,6 +1121,11 @@ impl WidgetVisuals {
pub fn text_color(&self) -> Color32 {
self.fg_stroke.color
}
#[deprecated = "Renamed to corner_radius"]
pub fn rounding(&self) -> CornerRadius {
self.corner_radius
}
}
/// Options for help debug egui by adding extra visualization
@ -1291,7 +1296,7 @@ impl Visuals {
warn_fg_color: Color32::from_rgb(255, 143, 0), // orange
error_fg_color: Color32::from_rgb(255, 0, 0), // red
window_rounding: Rounding::same(6),
window_corner_radius: CornerRadius::same(6),
window_shadow: Shadow {
offset: [10, 20],
blur: 15,
@ -1302,7 +1307,7 @@ impl Visuals {
window_stroke: Stroke::new(1.0, Color32::from_gray(60)),
window_highlight_topmost: true,
menu_rounding: Rounding::same(6),
menu_corner_radius: CornerRadius::same(6),
panel_fill: Color32::from_gray(27),
@ -1412,7 +1417,7 @@ impl Widgets {
bg_fill: Color32::from_gray(27),
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // separators, indentation lines
fg_stroke: Stroke::new(1.0, Color32::from_gray(140)), // normal text color
rounding: Rounding::same(2),
corner_radius: CornerRadius::same(2),
expansion: 0.0,
},
inactive: WidgetVisuals {
@ -1420,7 +1425,7 @@ impl Widgets {
bg_fill: Color32::from_gray(60), // checkbox background
bg_stroke: Default::default(),
fg_stroke: Stroke::new(1.0, Color32::from_gray(180)), // button text
rounding: Rounding::same(2),
corner_radius: CornerRadius::same(2),
expansion: 0.0,
},
hovered: WidgetVisuals {
@ -1428,7 +1433,7 @@ impl Widgets {
bg_fill: Color32::from_gray(70),
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)),
rounding: Rounding::same(3),
corner_radius: CornerRadius::same(3),
expansion: 1.0,
},
active: WidgetVisuals {
@ -1436,7 +1441,7 @@ impl Widgets {
bg_fill: Color32::from_gray(55),
bg_stroke: Stroke::new(1.0, Color32::WHITE),
fg_stroke: Stroke::new(2.0, Color32::WHITE),
rounding: Rounding::same(2),
corner_radius: CornerRadius::same(2),
expansion: 1.0,
},
open: WidgetVisuals {
@ -1444,7 +1449,7 @@ impl Widgets {
bg_fill: Color32::from_gray(27),
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)),
fg_stroke: Stroke::new(1.0, Color32::from_gray(210)),
rounding: Rounding::same(2),
corner_radius: CornerRadius::same(2),
expansion: 0.0,
},
}
@ -1457,7 +1462,7 @@ impl Widgets {
bg_fill: Color32::from_gray(248),
bg_stroke: Stroke::new(1.0, Color32::from_gray(190)), // separators, indentation lines
fg_stroke: Stroke::new(1.0, Color32::from_gray(80)), // normal text color
rounding: Rounding::same(2),
corner_radius: CornerRadius::same(2),
expansion: 0.0,
},
inactive: WidgetVisuals {
@ -1465,7 +1470,7 @@ impl Widgets {
bg_fill: Color32::from_gray(230), // checkbox background
bg_stroke: Default::default(),
fg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // button text
rounding: Rounding::same(2),
corner_radius: CornerRadius::same(2),
expansion: 0.0,
},
hovered: WidgetVisuals {
@ -1473,7 +1478,7 @@ impl Widgets {
bg_fill: Color32::from_gray(220),
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),
rounding: Rounding::same(3),
corner_radius: CornerRadius::same(3),
expansion: 1.0,
},
active: WidgetVisuals {
@ -1481,7 +1486,7 @@ impl Widgets {
bg_fill: Color32::from_gray(165),
bg_stroke: Stroke::new(1.0, Color32::BLACK),
fg_stroke: Stroke::new(2.0, Color32::BLACK),
rounding: Rounding::same(2),
corner_radius: CornerRadius::same(2),
expansion: 1.0,
},
open: WidgetVisuals {
@ -1489,7 +1494,7 @@ impl Widgets {
bg_fill: Color32::from_gray(220),
bg_stroke: Stroke::new(1.0, Color32::from_gray(160)),
fg_stroke: Stroke::new(1.0, Color32::BLACK),
rounding: Rounding::same(2),
corner_radius: CornerRadius::same(2),
expansion: 0.0,
},
}
@ -1924,7 +1929,7 @@ impl WidgetVisuals {
weak_bg_fill,
bg_fill: mandatory_bg_fill,
bg_stroke,
rounding,
corner_radius,
fg_stroke,
expansion,
} = self;
@ -1948,8 +1953,8 @@ impl WidgetVisuals {
ui.add(bg_stroke);
ui.end_row();
ui.label("Rounding");
ui.add(rounding);
ui.label("Corner radius");
ui.add(corner_radius);
ui.end_row();
ui.label("Foreground stroke (text)");
@ -1978,13 +1983,13 @@ impl Visuals {
warn_fg_color,
error_fg_color,
window_rounding,
window_corner_radius,
window_shadow,
window_fill,
window_stroke,
window_highlight_topmost,
menu_rounding,
menu_corner_radius,
panel_fill,
@ -2066,8 +2071,8 @@ impl Visuals {
ui.add(window_stroke);
ui.end_row();
ui.label("Rounding");
ui.add(window_rounding);
ui.label("Corner radius");
ui.add(window_corner_radius);
ui.end_row();
ui.label("Shadow");
@ -2084,8 +2089,8 @@ impl Visuals {
.spacing([12.0, 8.0])
.striped(true)
.show(ui, |ui| {
ui.label("Rounding");
ui.add(menu_rounding);
ui.label("Corner radius");
ui.add(menu_corner_radius);
ui.end_row();
ui.label("Shadow");
@ -2388,7 +2393,7 @@ impl Widget for &mut Margin {
}
}
impl Widget for &mut Rounding {
impl Widget for &mut CornerRadius {
fn ui(self, ui: &mut Ui) -> Response {
let mut same = self.is_same();
@ -2398,37 +2403,39 @@ impl Widget for &mut Rounding {
let mut cr = self.nw;
ui.add(DragValue::new(&mut cr).range(0.0..=f32::INFINITY));
*self = Rounding::same(cr);
*self = CornerRadius::same(cr);
})
.response
} else {
ui.vertical(|ui| {
ui.checkbox(&mut same, "same");
crate::Grid::new("rounding").num_columns(2).show(ui, |ui| {
ui.label("NW");
ui.add(DragValue::new(&mut self.nw).range(0.0..=f32::INFINITY));
ui.end_row();
crate::Grid::new("Corner radius")
.num_columns(2)
.show(ui, |ui| {
ui.label("NW");
ui.add(DragValue::new(&mut self.nw).range(0.0..=f32::INFINITY));
ui.end_row();
ui.label("NE");
ui.add(DragValue::new(&mut self.ne).range(0.0..=f32::INFINITY));
ui.end_row();
ui.label("NE");
ui.add(DragValue::new(&mut self.ne).range(0.0..=f32::INFINITY));
ui.end_row();
ui.label("SW");
ui.add(DragValue::new(&mut self.sw).range(0.0..=f32::INFINITY));
ui.end_row();
ui.label("SW");
ui.add(DragValue::new(&mut self.sw).range(0.0..=f32::INFINITY));
ui.end_row();
ui.label("SE");
ui.add(DragValue::new(&mut self.se).range(0.0..=f32::INFINITY));
ui.end_row();
});
ui.label("SE");
ui.add(DragValue::new(&mut self.se).range(0.0..=f32::INFINITY));
ui.end_row();
});
})
.response
};
// Apply the checkbox:
if same {
*self = Rounding::from(self.average());
*self = CornerRadius::from(self.average());
} else {
// Make sure we aren't same:
if self.is_same() {
@ -2513,7 +2520,7 @@ impl Widget for &mut crate::Frame {
let crate::Frame {
inner_margin,
outer_margin,
rounding,
corner_radius,
shadow,
fill,
stroke,
@ -2533,8 +2540,8 @@ impl Widget for &mut crate::Frame {
ui.push_id("outer", |ui| ui.add(outer_margin));
ui.end_row();
ui.label("Rounding");
ui.add(rounding);
ui.label("Corner radius");
ui.add(corner_radius);
ui.end_row();
ui.label("Shadow");

View File

@ -2127,7 +2127,7 @@ impl Ui {
/// ui.add(
/// egui::Image::new(egui::include_image!("../assets/ferris.png"))
/// .max_width(200.0)
/// .rounding(10.0),
/// .corner_radius(10),
/// );
/// # });
/// ```

View File

@ -1,5 +1,5 @@
use crate::{
widgets, Align, Color32, Image, NumExt, Rect, Response, Rounding, Sense, Stroke, TextStyle,
widgets, Align, Color32, CornerRadius, Image, NumExt, Rect, Response, Sense, Stroke, TextStyle,
TextWrapMode, Ui, Vec2, Widget, WidgetInfo, WidgetText, WidgetType,
};
@ -35,7 +35,7 @@ pub struct Button<'a> {
small: bool,
frame: Option<bool>,
min_size: Vec2,
rounding: Option<Rounding>,
corner_radius: Option<CornerRadius>,
selected: bool,
image_tint_follows_text_color: bool,
}
@ -69,7 +69,7 @@ impl<'a> Button<'a> {
small: false,
frame: None,
min_size: Vec2::ZERO,
rounding: None,
corner_radius: None,
selected: false,
image_tint_follows_text_color: false,
}
@ -153,11 +153,17 @@ impl<'a> Button<'a> {
/// Set the rounding of the button.
#[inline]
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
self.rounding = Some(rounding.into());
pub fn corner_radius(mut self, corner_radius: impl Into<CornerRadius>) -> Self {
self.corner_radius = Some(corner_radius.into());
self
}
#[inline]
#[deprecated = "Renamed to `corner_radius`"]
pub fn rounding(self, corner_radius: impl Into<CornerRadius>) -> Self {
self.corner_radius(corner_radius)
}
/// If true, the tint of the image is multiplied by the widget text color.
///
/// This makes sense for images that are white, that should have the same color as the text color.
@ -202,7 +208,7 @@ impl Widget for Button<'_> {
small,
frame,
min_size,
rounding,
corner_radius,
selected,
image_tint_follows_text_color,
} = self;
@ -292,11 +298,11 @@ impl Widget for Button<'_> {
if ui.is_rect_visible(rect) {
let visuals = ui.style().interact(&response);
let (frame_expansion, frame_rounding, frame_fill, frame_stroke) = if selected {
let (frame_expansion, frame_cr, frame_fill, frame_stroke) = if selected {
let selection = ui.visuals().selection;
(
Vec2::ZERO,
Rounding::ZERO,
CornerRadius::ZERO,
selection.bg_fill,
selection.stroke,
)
@ -304,19 +310,19 @@ impl Widget for Button<'_> {
let expansion = Vec2::splat(visuals.expansion);
(
expansion,
visuals.rounding,
visuals.corner_radius,
visuals.weak_bg_fill,
visuals.bg_stroke,
)
} else {
Default::default()
};
let frame_rounding = rounding.unwrap_or(frame_rounding);
let frame_cr = corner_radius.unwrap_or(frame_cr);
let frame_fill = fill.unwrap_or(frame_fill);
let frame_stroke = stroke.unwrap_or(frame_stroke);
ui.painter().rect(
rect.expand2(frame_expansion),
frame_rounding,
frame_cr,
frame_fill,
frame_stroke,
epaint::StrokeKind::Inside,

View File

@ -104,7 +104,7 @@ impl Widget for Checkbox<'_> {
let (small_icon_rect, big_icon_rect) = ui.spacing().icon_rectangles(rect);
ui.painter().add(epaint::RectShape::new(
big_icon_rect.expand(visuals.expansion),
visuals.rounding,
visuals.corner_radius,
visuals.bg_fill,
visuals.bg_stroke,
epaint::StrokeKind::Inside,

View File

@ -100,10 +100,10 @@ fn color_button(ui: &mut Ui, color: Color32, open: bool) -> Response {
let stroke_width = 1.0;
show_color_at(ui.painter(), color, rect.shrink(stroke_width));
let rounding = visuals.rounding.at_most(2); // Can't do more rounding because the background grid doesn't do any rounding
let corner_radius = visuals.corner_radius.at_most(2); // Can't do more rounding because the background grid doesn't do any rounding
ui.painter().rect_stroke(
rect,
rounding,
corner_radius,
(stroke_width, visuals.bg_fill), // Using fill for stroke is intentional, because default style has no border
StrokeKind::Inside,
);

View File

@ -8,7 +8,7 @@ use epaint::{
use crate::{
load::{Bytes, SizeHint, SizedTexture, TextureLoadResult, TexturePoll},
pos2, Color32, Context, Id, Mesh, Painter, Rect, Response, Rounding, Sense, Shape, Spinner,
pos2, Color32, Context, CornerRadius, Id, Mesh, Painter, Rect, Response, Sense, Shape, Spinner,
TextStyle, TextureOptions, Ui, Vec2, Widget, WidgetInfo, WidgetType,
};
@ -29,7 +29,7 @@ use crate::{
/// # egui::__run_test_ui(|ui| {
/// ui.add(
/// egui::Image::new(egui::include_image!("../../assets/ferris.png"))
/// .rounding(5.0)
/// .corner_radius(5)
/// );
/// # });
/// ```
@ -39,7 +39,7 @@ use crate::{
/// # egui::__run_test_ui(|ui| {
/// # let rect = egui::Rect::from_min_size(Default::default(), egui::Vec2::splat(100.0));
/// egui::Image::new(egui::include_image!("../../assets/ferris.png"))
/// .rounding(5.0)
/// .corner_radius(5)
/// .tint(egui::Color32::LIGHT_BLUE)
/// .paint_at(ui, rect);
/// # });
@ -233,25 +233,37 @@ impl<'a> Image<'a> {
#[inline]
pub fn rotate(mut self, angle: f32, origin: Vec2) -> Self {
self.image_options.rotation = Some((Rot2::from_angle(angle), origin));
self.image_options.rounding = Rounding::ZERO; // incompatible with rotation
self.image_options.corner_radius = CornerRadius::ZERO; // incompatible with rotation
self
}
/// Round the corners of the image.
///
/// The default is no rounding ([`Rounding::ZERO`]).
/// The default is no rounding ([`CornerRadius::ZERO`]).
///
/// Due to limitations in the current implementation,
/// this will turn off any rotation of the image.
#[inline]
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
self.image_options.rounding = rounding.into();
if self.image_options.rounding != Rounding::ZERO {
pub fn corner_radius(mut self, corner_radius: impl Into<CornerRadius>) -> Self {
self.image_options.corner_radius = corner_radius.into();
if self.image_options.corner_radius != CornerRadius::ZERO {
self.image_options.rotation = None; // incompatible with rounding
}
self
}
/// Round the corners of the image.
///
/// The default is no rounding ([`CornerRadius::ZERO`]).
///
/// Due to limitations in the current implementation,
/// this will turn off any rotation of the image.
#[inline]
#[deprecated = "Renamed to `corner_radius`"]
pub fn rounding(self, corner_radius: impl Into<CornerRadius>) -> Self {
self.corner_radius(corner_radius)
}
/// Show a spinner when the image is loading.
///
/// By default this uses the value of [`crate::Visuals::image_loading_spinners`].
@ -354,7 +366,7 @@ impl<'a> Image<'a> {
/// # egui::__run_test_ui(|ui| {
/// # let rect = egui::Rect::from_min_size(Default::default(), egui::Vec2::splat(100.0));
/// egui::Image::new(egui::include_image!("../../assets/ferris.png"))
/// .rounding(5.0)
/// .corner_radius(5)
/// .tint(egui::Color32::LIGHT_BLUE)
/// .paint_at(ui, rect);
/// # });
@ -778,11 +790,11 @@ pub struct ImageOptions {
/// Round the corners of the image.
///
/// The default is no rounding ([`Rounding::ZERO`]).
/// The default is no rounding ([`CornerRadius::ZERO`]).
///
/// Due to limitations in the current implementation,
/// this will turn off any rotation of the image.
pub rounding: Rounding,
pub corner_radius: CornerRadius,
}
impl Default for ImageOptions {
@ -792,7 +804,7 @@ impl Default for ImageOptions {
bg_fill: Default::default(),
tint: Color32::WHITE,
rotation: None,
rounding: Rounding::ZERO,
corner_radius: CornerRadius::ZERO,
}
}
}
@ -804,7 +816,11 @@ pub fn paint_texture_at(
texture: &SizedTexture,
) {
if options.bg_fill != Default::default() {
painter.add(RectShape::filled(rect, options.rounding, options.bg_fill));
painter.add(RectShape::filled(
rect,
options.corner_radius,
options.bg_fill,
));
}
match options.rotation {
@ -812,7 +828,7 @@ pub fn paint_texture_at(
// TODO(emilk): implement this using `PathShape` (add texture support to it).
// This will also give us anti-aliasing of rotated images.
debug_assert!(
options.rounding == Rounding::ZERO,
options.corner_radius == CornerRadius::ZERO,
"Image had both rounding and rotation. Please pick only one"
);
@ -823,7 +839,7 @@ pub fn paint_texture_at(
}
None => {
painter.add(
RectShape::filled(rect, options.rounding, options.tint)
RectShape::filled(rect, options.corner_radius, options.tint)
.with_texture(texture.id, options.uv),
);
}

View File

@ -1,5 +1,5 @@
use crate::{
widgets, Color32, Image, Rect, Response, Rounding, Sense, Ui, Vec2, Widget, WidgetInfo,
widgets, Color32, CornerRadius, Image, Rect, Response, Sense, Ui, Vec2, Widget, WidgetInfo,
WidgetType,
};
@ -62,13 +62,24 @@ impl<'a> ImageButton<'a> {
}
/// Set rounding for the `ImageButton`.
///
/// If the underlying image already has rounding, this
/// will override that value.
#[inline]
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
self.image = self.image.rounding(rounding.into());
pub fn corner_radius(mut self, corner_radius: impl Into<CornerRadius>) -> Self {
self.image = self.image.corner_radius(corner_radius.into());
self
}
/// Set rounding for the `ImageButton`.
///
/// If the underlying image already has rounding, this
/// will override that value.
#[inline]
#[deprecated = "Renamed to `corner_radius`"]
pub fn rounding(self, corner_radius: impl Into<CornerRadius>) -> Self {
self.corner_radius(corner_radius)
}
}
impl Widget for ImageButton<'_> {
@ -100,7 +111,7 @@ impl Widget for ImageButton<'_> {
let selection = ui.visuals().selection;
(
Vec2::ZERO,
self.image.image_options().rounding,
self.image.image_options().corner_radius,
selection.bg_fill,
selection.stroke,
)
@ -109,7 +120,7 @@ impl Widget for ImageButton<'_> {
let expansion = Vec2::splat(visuals.expansion);
(
expansion,
self.image.image_options().rounding,
self.image.image_options().corner_radius,
visuals.weak_bg_fill,
visuals.bg_stroke,
)

View File

@ -1,5 +1,5 @@
use crate::{
lerp, vec2, Color32, NumExt, Pos2, Rect, Response, Rgba, Rounding, Sense, Shape, Stroke,
lerp, vec2, Color32, CornerRadius, NumExt, Pos2, Rect, Response, Rgba, Sense, Shape, Stroke,
TextStyle, TextWrapMode, Ui, Vec2, Widget, WidgetInfo, WidgetText, WidgetType,
};
@ -19,7 +19,7 @@ pub struct ProgressBar {
text: Option<ProgressBarText>,
fill: Option<Color32>,
animate: bool,
rounding: Option<Rounding>,
corner_radius: Option<CornerRadius>,
}
impl ProgressBar {
@ -32,7 +32,7 @@ impl ProgressBar {
text: None,
fill: None,
animate: false,
rounding: None,
corner_radius: None,
}
}
@ -75,7 +75,7 @@ impl ProgressBar {
/// Note that this will cause the UI to be redrawn.
/// Defaults to `false`.
///
/// If [`Self::rounding`] and [`Self::animate`] are used simultaneously, the animation is not
/// If [`Self::corner_radius`] and [`Self::animate`] are used simultaneously, the animation is not
/// rendered, since it requires a perfect circle to render correctly. However, the UI is still
/// redrawn.
#[inline]
@ -86,14 +86,20 @@ impl ProgressBar {
/// Set the rounding of the progress bar.
///
/// If [`Self::rounding`] and [`Self::animate`] are used simultaneously, the animation is not
/// If [`Self::corner_radius`] and [`Self::animate`] are used simultaneously, the animation is not
/// rendered, since it requires a perfect circle to render correctly. However, the UI is still
/// redrawn.
#[inline]
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
self.rounding = Some(rounding.into());
pub fn corner_radius(mut self, corner_radius: impl Into<CornerRadius>) -> Self {
self.corner_radius = Some(corner_radius.into());
self
}
#[inline]
#[deprecated = "Renamed to `corner_radius`"]
pub fn rounding(self, corner_radius: impl Into<CornerRadius>) -> Self {
self.corner_radius(corner_radius)
}
}
impl Widget for ProgressBar {
@ -105,7 +111,7 @@ impl Widget for ProgressBar {
text,
fill,
animate,
rounding,
corner_radius,
} = self;
let animate = animate && progress < 1.0;
@ -133,13 +139,13 @@ impl Widget for ProgressBar {
}
let visuals = ui.style().visuals.clone();
let is_custom_rounding = rounding.is_some();
let corner_radius = outer_rect.height() / 2.0;
let rounding = rounding.unwrap_or_else(|| corner_radius.into());
let has_custom_cr = corner_radius.is_some();
let half_height = outer_rect.height() / 2.0;
let corner_radius = corner_radius.unwrap_or_else(|| half_height.into());
ui.painter()
.rect_filled(outer_rect, rounding, visuals.extreme_bg_color);
.rect_filled(outer_rect, corner_radius, visuals.extreme_bg_color);
let min_width =
2.0 * f32::max(rounding.sw as _, rounding.nw as _).at_most(corner_radius);
2.0 * f32::max(corner_radius.sw as _, corner_radius.nw as _).at_most(half_height);
let filled_width = (outer_rect.width() * progress).at_least(min_width);
let inner_rect =
Rect::from_min_size(outer_rect.min, vec2(filled_width, outer_rect.height()));
@ -154,25 +160,25 @@ impl Widget for ProgressBar {
ui.painter().rect_filled(
inner_rect,
rounding,
corner_radius,
Color32::from(
Rgba::from(fill.unwrap_or(visuals.selection.bg_fill)) * color_factor as f32,
),
);
if animate && !is_custom_rounding {
if animate && !has_custom_cr {
let n_points = 20;
let time = ui.input(|i| i.time);
let start_angle = time * std::f64::consts::TAU;
let end_angle = start_angle + 240f64.to_radians() * time.sin();
let circle_radius = corner_radius - 2.0;
let circle_radius = half_height - 2.0;
let points: Vec<Pos2> = (0..n_points)
.map(|i| {
let angle = lerp(start_angle..=end_angle, i as f64 / n_points as f64);
let (sin, cos) = angle.sin_cos();
inner_rect.right_center()
+ circle_radius * vec2(cos as f32, sin as f32)
+ vec2(-corner_radius, 0.0)
+ vec2(-half_height, 0.0)
})
.collect();
ui.painter()

View File

@ -71,7 +71,7 @@ impl Widget for SelectableLabel {
ui.painter().rect(
rect,
visuals.rounding,
visuals.corner_radius,
visuals.weak_bg_fill,
visuals.bg_stroke,
epaint::StrokeKind::Inside,

View File

@ -760,10 +760,10 @@ impl Slider<'_> {
let rail_radius = (spacing.slider_rail_height / 2.0).at_least(0.0);
let rail_rect = self.rail_rect(rect, rail_radius);
let rounding = widget_visuals.inactive.rounding;
let corner_radius = widget_visuals.inactive.corner_radius;
ui.painter()
.rect_filled(rail_rect, rounding, widget_visuals.inactive.bg_fill);
.rect_filled(rail_rect, corner_radius, widget_visuals.inactive.bg_fill);
let position_1d = self.position_from_value(value, position_range);
let center = self.marker_center(position_1d, &rail_rect);
@ -780,16 +780,16 @@ impl Slider<'_> {
// The trailing rect has to be drawn differently depending on the orientation.
match self.orientation {
SliderOrientation::Horizontal => {
trailing_rail_rect.max.x = center.x + rounding.nw as f32;
trailing_rail_rect.max.x = center.x + corner_radius.nw as f32;
}
SliderOrientation::Vertical => {
trailing_rail_rect.min.y = center.y - rounding.se as f32;
trailing_rail_rect.min.y = center.y - corner_radius.se as f32;
}
};
ui.painter().rect_filled(
trailing_rail_rect,
rounding,
corner_radius,
ui.visuals().selection.bg_fill,
);
}
@ -817,7 +817,7 @@ impl Slider<'_> {
let rect = Rect::from_center_size(center, 2.0 * v);
ui.painter().rect(
rect,
visuals.rounding,
visuals.corner_radius,
visuals.bg_fill,
visuals.fg_stroke,
epaint::StrokeKind::Inside,

View File

@ -442,7 +442,7 @@ impl TextEdit<'_> {
if output.response.has_focus() {
epaint::RectShape::new(
frame_rect,
visuals.rounding,
visuals.corner_radius,
background_color,
ui.visuals().selection.stroke,
StrokeKind::Inside,
@ -450,7 +450,7 @@ impl TextEdit<'_> {
} else {
epaint::RectShape::new(
frame_rect,
visuals.rounding,
visuals.corner_radius,
background_color,
visuals.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop".
StrokeKind::Inside,
@ -460,7 +460,7 @@ impl TextEdit<'_> {
let visuals = &ui.style().visuals.widgets.inactive;
epaint::RectShape::stroke(
frame_rect,
visuals.rounding,
visuals.corner_radius,
visuals.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop".
StrokeKind::Inside,
)

View File

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

View File

@ -47,7 +47,7 @@ impl eframe::App for FractalClockApp {
.frame(
egui::Frame::dark_canvas(&ctx.style())
.stroke(egui::Stroke::NONE)
.rounding(0),
.corner_radius(0),
)
.show(ctx, |ui| {
self.fractal_clock

View File

@ -10,7 +10,7 @@ impl Default for FrameDemo {
frame: egui::Frame::new()
.inner_margin(12)
.outer_margin(24)
.rounding(14)
.corner_radius(14)
.shadow(egui::Shadow {
offset: [8, 12],
blur: 16,
@ -56,7 +56,7 @@ impl crate::View for FrameDemo {
// We want to paint a background around the outer margin of the demonstration frame, so we use another frame around it:
egui::Frame::default()
.stroke(ui.visuals().widgets.noninteractive.bg_stroke)
.rounding(ui.visuals().widgets.noninteractive.rounding)
.corner_radius(ui.visuals().widgets.noninteractive.corner_radius)
.show(ui, |ui| {
self.frame.show(ui, |ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);

View File

@ -358,7 +358,7 @@ impl ColorWidgets {
#[cfg_attr(feature = "serde", serde(default))]
struct BoxPainting {
size: Vec2,
rounding: f32,
corner_radius: f32,
stroke_width: f32,
num_boxes: usize,
}
@ -367,7 +367,7 @@ impl Default for BoxPainting {
fn default() -> Self {
Self {
size: vec2(64.0, 32.0),
rounding: 5.0,
corner_radius: 5.0,
stroke_width: 2.0,
num_boxes: 1,
}
@ -378,7 +378,7 @@ impl BoxPainting {
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.y, 0.0..=500.0).text("height"));
ui.add(Slider::new(&mut self.rounding, 0.0..=50.0).text("rounding"));
ui.add(Slider::new(&mut self.corner_radius, 0.0..=50.0).text("corner_radius"));
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"));
@ -387,7 +387,7 @@ impl BoxPainting {
let (rect, _response) = ui.allocate_at_least(self.size, Sense::hover());
ui.painter().rect(
rect,
self.rounding,
self.corner_radius,
ui.visuals().text_color().gamma_multiply(0.5),
Stroke::new(self.stroke_width, Color32::WHITE),
egui::StrokeKind::Inside,

View File

@ -271,7 +271,7 @@ fn rect_shape_ui(ui: &mut egui::Ui, shape: &mut RectShape) {
let RectShape {
rect,
rounding,
corner_radius,
fill,
stroke,
stroke_kind,
@ -304,8 +304,8 @@ fn rect_shape_ui(ui: &mut egui::Ui, shape: &mut RectShape) {
});
ui.end_row();
ui.label("Rounding");
ui.add(rounding);
ui.label("Corner radius");
ui.add(corner_radius);
ui.end_row();
ui.label("Fill");

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f90f94a842a1d0f1386c3cdd28e60e6ad6efe968f510a11bde418b5bc70a81d2
size 23897
oid sha256:244d539111e994a4ed2aa95a2b4d0ff12b948e21843c8a1dddcf54cbb388f1aa
size 24280

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c39868f184364555ae90fbfc035aa668f61189be7aeee6bec4e45a8de438ad8e
size 87661
oid sha256:daa5ec4ddd2f983c4b9f2b0a73c973f58abcb186fbd0d68a9fd0ce7173e5d4e7
size 88031

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:dd029fdc49e6d4078337472c39b9d58bf69073c1b7750c6dd1b7ccd450d52395
size 119869
oid sha256:c09af9c7f4297e2d5b2305366ed57b3203807ca2426314acdf836e25f154d8eb
size 120244

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e698ba12efd129099877248f9630ba983d683e1b495b2523ed3569989341e905
size 51735
oid sha256:f621bcf7c8fd18156bef2428ab3b9994e6a4d475ae589eb734d50f9a4f3383bd
size 52101

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:18b81b5cd88372b65b1ecc62e9a5e894960279310b05a1bd5c8df5bffa244ad0
size 54922
oid sha256:f1476e105a3e9c1ff7b2f4a82481462795e4708e3fcf6d495a042faae537184e
size 55298

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bf5df173431d330e4b6045a72227c2bb7613ec98c63f013ea899a3a57cd6617a
size 55522
oid sha256:695a731d9e302db2c5b7f4a0ef44794cf55eb0be093c070b8ffaeb28121569bc
size 55888

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:987c162842a08271e833c41a55573d9f30cf045bf7ca3cb03e81d0cc13d5a16e
size 36763
oid sha256:854c12c69b31c0c82a9596d167772e00d7a051600e4151535e2cec04491e57a6
size 37139

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8c5c3055cd190823a4204aa6f23362a88bc5ab5ed5453d9be1b6077dded6cd54
size 36809
oid sha256:1aacb27847c2e942d56d60e4b72797d93f7265a6effe4e47437e1314e6477e6f
size 37184

View File

@ -128,7 +128,7 @@ impl<'l> StripLayout<'l> {
if flags.striped {
self.ui.painter().rect_filled(
gapless_rect,
egui::Rounding::ZERO,
egui::CornerRadius::ZERO,
self.ui.visuals().faint_bg_color,
);
}
@ -136,7 +136,7 @@ impl<'l> StripLayout<'l> {
if flags.selected {
self.ui.painter().rect_filled(
gapless_rect,
egui::Rounding::ZERO,
egui::CornerRadius::ZERO,
self.ui.visuals().selection.bg_fill,
);
}
@ -144,7 +144,7 @@ impl<'l> StripLayout<'l> {
if flags.hovered && !flags.selected && self.sense.interactive() {
self.ui.painter().rect_filled(
gapless_rect,
egui::Rounding::ZERO,
egui::CornerRadius::ZERO,
self.ui.visuals().widgets.hovered.bg_fill,
);
}

View File

@ -7,10 +7,10 @@
/// The rounding uses `u8` to save space,
/// so the amount of rounding is limited to integers in the range `[0, 255]`.
///
/// For calculations, you may want to use [`crate::Roundingf`] instead, which uses `f32`.
/// For calculations, you may want to use [`crate::CornerRadiusF32`] instead, which uses `f32`.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Rounding {
pub struct CornerRadius {
/// Radius of the rounding of the North-West (left top) corner.
pub nw: u8,
@ -24,28 +24,28 @@ pub struct Rounding {
pub se: u8,
}
impl Default for Rounding {
impl Default for CornerRadius {
#[inline]
fn default() -> Self {
Self::ZERO
}
}
impl From<u8> for Rounding {
impl From<u8> for CornerRadius {
#[inline]
fn from(radius: u8) -> Self {
Self::same(radius)
}
}
impl From<f32> for Rounding {
impl From<f32> for CornerRadius {
#[inline]
fn from(radius: f32) -> Self {
Self::same(radius.round() as u8)
}
}
impl Rounding {
impl CornerRadius {
/// No rounding on any corner.
pub const ZERO: Self = Self {
nw: 0,
@ -99,7 +99,7 @@ impl Rounding {
}
}
impl std::ops::Add for Rounding {
impl std::ops::Add for CornerRadius {
type Output = Self;
#[inline]
fn add(self, rhs: Self) -> Self {
@ -112,7 +112,7 @@ impl std::ops::Add for Rounding {
}
}
impl std::ops::Add<u8> for Rounding {
impl std::ops::Add<u8> for CornerRadius {
type Output = Self;
#[inline]
fn add(self, rhs: u8) -> Self {
@ -125,7 +125,7 @@ impl std::ops::Add<u8> for Rounding {
}
}
impl std::ops::AddAssign for Rounding {
impl std::ops::AddAssign for CornerRadius {
#[inline]
fn add_assign(&mut self, rhs: Self) {
*self = Self {
@ -137,7 +137,7 @@ impl std::ops::AddAssign for Rounding {
}
}
impl std::ops::AddAssign<u8> for Rounding {
impl std::ops::AddAssign<u8> for CornerRadius {
#[inline]
fn add_assign(&mut self, rhs: u8) {
*self = Self {
@ -149,7 +149,7 @@ impl std::ops::AddAssign<u8> for Rounding {
}
}
impl std::ops::Sub for Rounding {
impl std::ops::Sub for CornerRadius {
type Output = Self;
#[inline]
fn sub(self, rhs: Self) -> Self {
@ -162,7 +162,7 @@ impl std::ops::Sub for Rounding {
}
}
impl std::ops::Sub<u8> for Rounding {
impl std::ops::Sub<u8> for CornerRadius {
type Output = Self;
#[inline]
fn sub(self, rhs: u8) -> Self {
@ -175,7 +175,7 @@ impl std::ops::Sub<u8> for Rounding {
}
}
impl std::ops::SubAssign for Rounding {
impl std::ops::SubAssign for CornerRadius {
#[inline]
fn sub_assign(&mut self, rhs: Self) {
*self = Self {
@ -187,7 +187,7 @@ impl std::ops::SubAssign for Rounding {
}
}
impl std::ops::SubAssign<u8> for Rounding {
impl std::ops::SubAssign<u8> for CornerRadius {
#[inline]
fn sub_assign(&mut self, rhs: u8) {
*self = Self {
@ -199,7 +199,7 @@ impl std::ops::SubAssign<u8> for Rounding {
}
}
impl std::ops::Div<f32> for Rounding {
impl std::ops::Div<f32> for CornerRadius {
type Output = Self;
#[inline]
fn div(self, rhs: f32) -> Self {
@ -212,7 +212,7 @@ impl std::ops::Div<f32> for Rounding {
}
}
impl std::ops::DivAssign<f32> for Rounding {
impl std::ops::DivAssign<f32> for CornerRadius {
#[inline]
fn div_assign(&mut self, rhs: f32) {
*self = Self {
@ -224,7 +224,7 @@ impl std::ops::DivAssign<f32> for Rounding {
}
}
impl std::ops::Mul<f32> for Rounding {
impl std::ops::Mul<f32> for CornerRadius {
type Output = Self;
#[inline]
fn mul(self, rhs: f32) -> Self {
@ -237,7 +237,7 @@ impl std::ops::Mul<f32> for Rounding {
}
}
impl std::ops::MulAssign<f32> for Rounding {
impl std::ops::MulAssign<f32> for CornerRadius {
#[inline]
fn mul_assign(&mut self, rhs: f32) {
*self = Self {

View File

@ -1,11 +1,11 @@
use crate::Rounding;
use crate::CornerRadius;
/// How rounded the corners of things should be, in `f32`.
///
/// This is used for calculations, but storage is usually done with the more compact [`Rounding`].
/// This is used for calculations, but storage is usually done with the more compact [`CornerRadius`].
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Roundingf {
pub struct CornerRadiusF32 {
/// Radius of the rounding of the North-West (left top) corner.
pub nw: f32,
@ -19,38 +19,38 @@ pub struct Roundingf {
pub se: f32,
}
impl From<Rounding> for Roundingf {
impl From<CornerRadius> for CornerRadiusF32 {
#[inline]
fn from(rounding: Rounding) -> Self {
fn from(cr: CornerRadius) -> Self {
Self {
nw: rounding.nw as f32,
ne: rounding.ne as f32,
sw: rounding.sw as f32,
se: rounding.se as f32,
nw: cr.nw as f32,
ne: cr.ne as f32,
sw: cr.sw as f32,
se: cr.se as f32,
}
}
}
impl From<Roundingf> for Rounding {
impl From<CornerRadiusF32> for CornerRadius {
#[inline]
fn from(rounding: Roundingf) -> Self {
fn from(cr: CornerRadiusF32) -> Self {
Self {
nw: rounding.nw.round() as u8,
ne: rounding.ne.round() as u8,
sw: rounding.sw.round() as u8,
se: rounding.se.round() as u8,
nw: cr.nw.round() as u8,
ne: cr.ne.round() as u8,
sw: cr.sw.round() as u8,
se: cr.se.round() as u8,
}
}
}
impl Default for Roundingf {
impl Default for CornerRadiusF32 {
#[inline]
fn default() -> Self {
Self::ZERO
}
}
impl From<f32> for Roundingf {
impl From<f32> for CornerRadiusF32 {
#[inline]
fn from(radius: f32) -> Self {
Self {
@ -62,7 +62,7 @@ impl From<f32> for Roundingf {
}
}
impl Roundingf {
impl CornerRadiusF32 {
/// No rounding on any corner.
pub const ZERO: Self = Self {
nw: 0.0,
@ -111,7 +111,7 @@ impl Roundingf {
}
}
impl std::ops::Add for Roundingf {
impl std::ops::Add for CornerRadiusF32 {
type Output = Self;
#[inline]
fn add(self, rhs: Self) -> Self {
@ -124,7 +124,7 @@ impl std::ops::Add for Roundingf {
}
}
impl std::ops::AddAssign for Roundingf {
impl std::ops::AddAssign for CornerRadiusF32 {
#[inline]
fn add_assign(&mut self, rhs: Self) {
*self = Self {
@ -136,7 +136,7 @@ impl std::ops::AddAssign for Roundingf {
}
}
impl std::ops::AddAssign<f32> for Roundingf {
impl std::ops::AddAssign<f32> for CornerRadiusF32 {
#[inline]
fn add_assign(&mut self, rhs: f32) {
*self = Self {
@ -148,7 +148,7 @@ impl std::ops::AddAssign<f32> for Roundingf {
}
}
impl std::ops::Sub for Roundingf {
impl std::ops::Sub for CornerRadiusF32 {
type Output = Self;
#[inline]
fn sub(self, rhs: Self) -> Self {
@ -161,7 +161,7 @@ impl std::ops::Sub for Roundingf {
}
}
impl std::ops::SubAssign for Roundingf {
impl std::ops::SubAssign for CornerRadiusF32 {
#[inline]
fn sub_assign(&mut self, rhs: Self) {
*self = Self {
@ -173,7 +173,7 @@ impl std::ops::SubAssign for Roundingf {
}
}
impl std::ops::SubAssign<f32> for Roundingf {
impl std::ops::SubAssign<f32> for CornerRadiusF32 {
#[inline]
fn sub_assign(&mut self, rhs: f32) {
*self = Self {
@ -185,7 +185,7 @@ impl std::ops::SubAssign<f32> for Roundingf {
}
}
impl std::ops::Div<f32> for Roundingf {
impl std::ops::Div<f32> for CornerRadiusF32 {
type Output = Self;
#[inline]
fn div(self, rhs: f32) -> Self {
@ -198,7 +198,7 @@ impl std::ops::Div<f32> for Roundingf {
}
}
impl std::ops::DivAssign<f32> for Roundingf {
impl std::ops::DivAssign<f32> for CornerRadiusF32 {
#[inline]
fn div_assign(&mut self, rhs: f32) {
*self = Self {
@ -210,7 +210,7 @@ impl std::ops::DivAssign<f32> for Roundingf {
}
}
impl std::ops::Mul<f32> for Roundingf {
impl std::ops::Mul<f32> for CornerRadiusF32 {
type Output = Self;
#[inline]
fn mul(self, rhs: f32) -> Self {
@ -223,7 +223,7 @@ impl std::ops::Mul<f32> for Roundingf {
}
}
impl std::ops::MulAssign<f32> for Roundingf {
impl std::ops::MulAssign<f32> for CornerRadiusF32 {
#[inline]
fn mul_assign(&mut self, rhs: f32) {
*self = Self {

View File

@ -25,13 +25,13 @@
mod brush;
pub mod color;
mod corner_radius;
mod corner_radius_f32;
pub mod image;
mod margin;
mod marginf;
mod mesh;
pub mod mutex;
mod rounding;
mod roundingf;
mod shadow;
pub mod shape_transform;
mod shapes;
@ -48,12 +48,12 @@ mod viewport;
pub use self::{
brush::Brush,
color::ColorMode,
corner_radius::CornerRadius,
corner_radius_f32::CornerRadiusF32,
image::{ColorImage, FontImage, ImageData, ImageDelta},
margin::Margin,
marginf::Marginf,
mesh::{Mesh, Mesh16, Vertex},
rounding::Rounding,
roundingf::Roundingf,
shadow::Shadow,
shapes::{
CircleShape, CubicBezierShape, EllipseShape, PaintCallback, PaintCallbackInfo, PathShape,
@ -69,6 +69,9 @@ pub use self::{
viewport::ViewportInPixels,
};
#[deprecated = "Renamed to CornerRadius"]
pub type Rounding = CornerRadius;
#[allow(deprecated)]
pub use tessellator::tessellate_shapes;

View File

@ -1,4 +1,4 @@
use crate::{Color32, Marginf, Rect, RectShape, Rounding, Vec2};
use crate::{Color32, CornerRadius, Marginf, Rect, RectShape, Vec2};
/// The color and fuzziness of a fuzzy shape.
///
@ -44,7 +44,7 @@ impl Shadow {
};
/// The argument is the rectangle of the shadow caster.
pub fn as_shape(&self, rect: Rect, rounding: impl Into<Rounding>) -> RectShape {
pub fn as_shape(&self, rect: Rect, corner_radius: impl Into<CornerRadius>) -> RectShape {
// tessellator.clip_rect = clip_rect; // TODO(emilk): culling
let Self {
@ -58,9 +58,9 @@ impl Shadow {
let rect = rect
.translate(Vec2::new(offset_x as _, offset_y as _))
.expand(spread as _);
let rounding = rounding.into() + Rounding::from(spread);
let corner_radius = corner_radius.into() + CornerRadius::from(spread);
RectShape::filled(rect, rounding, color).with_blur_width(blur as _)
RectShape::filled(rect, corner_radius, color).with_blur_width(blur as _)
}
/// How much larger than the parent rect are we in each direction?

View File

@ -60,7 +60,7 @@ pub fn adjust_colors(
})
| Shape::Rect(RectShape {
rect: _,
rounding: _,
corner_radius: _,
fill,
stroke,
stroke_kind: _,

View File

@ -10,7 +10,7 @@ pub struct RectShape {
/// How rounded the corners of the rectangle are.
///
/// Use `Rounding::ZERO` for for sharp corners.
/// Use [`CornerRadius::ZERO`] for for sharp corners.
///
/// This is the corner radii of the rectangle.
/// If there is a stroke, then the stroke will have an inner and outer corner radius,
@ -18,7 +18,7 @@ pub struct RectShape {
///
/// For [`StrokeKind::Inside`], the outside of the stroke coincides with the rectangle,
/// so the rounding will in this case specify the outer corner radius.
pub rounding: Rounding,
pub corner_radius: CornerRadius,
/// How to fill the rectangle.
pub fill: Color32,
@ -73,14 +73,14 @@ impl RectShape {
#[inline]
pub fn new(
rect: Rect,
rounding: impl Into<Rounding>,
corner_radius: impl Into<CornerRadius>,
fill_color: impl Into<Color32>,
stroke: impl Into<Stroke>,
stroke_kind: StrokeKind,
) -> Self {
Self {
rect,
rounding: rounding.into(),
corner_radius: corner_radius.into(),
fill: fill_color.into(),
stroke: stroke.into(),
stroke_kind,
@ -93,12 +93,12 @@ impl RectShape {
#[inline]
pub fn filled(
rect: Rect,
rounding: impl Into<Rounding>,
corner_radius: impl Into<CornerRadius>,
fill_color: impl Into<Color32>,
) -> Self {
Self::new(
rect,
rounding,
corner_radius,
fill_color,
Stroke::NONE,
StrokeKind::Outside, // doesn't matter
@ -108,12 +108,12 @@ impl RectShape {
#[inline]
pub fn stroke(
rect: Rect,
rounding: impl Into<Rounding>,
corner_radius: impl Into<CornerRadius>,
stroke: impl Into<Stroke>,
stroke_kind: StrokeKind,
) -> Self {
let fill = Color32::TRANSPARENT;
Self::new(rect, rounding, fill, stroke, stroke_kind)
Self::new(rect, corner_radius, fill, stroke, stroke_kind)
}
/// Set if the stroke is on the inside, outside, or centered on the rectangle.

View File

@ -7,7 +7,7 @@ use emath::{pos2, Align2, Pos2, Rangef, Rect, TSTransform, Vec2};
use crate::{
stroke::PathStroke,
text::{FontId, Fonts, Galley},
Color32, Mesh, Rounding, Stroke, StrokeKind, TextureId,
Color32, CornerRadius, Mesh, Stroke, StrokeKind, TextureId,
};
use super::{
@ -279,21 +279,21 @@ impl Shape {
#[inline]
pub fn rect_filled(
rect: Rect,
rounding: impl Into<Rounding>,
corner_radius: impl Into<CornerRadius>,
fill_color: impl Into<Color32>,
) -> Self {
Self::Rect(RectShape::filled(rect, rounding, fill_color))
Self::Rect(RectShape::filled(rect, corner_radius, fill_color))
}
/// See also [`Self::rect_filled`].
#[inline]
pub fn rect_stroke(
rect: Rect,
rounding: impl Into<Rounding>,
corner_radius: impl Into<CornerRadius>,
stroke: impl Into<Stroke>,
stroke_kind: StrokeKind,
) -> Self {
Self::Rect(RectShape::stroke(rect, rounding, stroke, stroke_kind))
Self::Rect(RectShape::stroke(rect, corner_radius, stroke, stroke_kind))
}
#[allow(clippy::needless_pass_by_value)]
@ -451,7 +451,7 @@ impl Shape {
}
Self::Rect(rect_shape) => {
rect_shape.rect = transform * rect_shape.rect;
rect_shape.rounding *= transform.scaling;
rect_shape.corner_radius *= transform.scaling;
rect_shape.stroke.width *= transform.scaling;
rect_shape.blur_width *= transform.scaling;
}

View File

@ -9,8 +9,8 @@ use emath::{pos2, remap, vec2, GuiRounding as _, NumExt, Pos2, Rect, Rot2, Vec2}
use crate::{
color::ColorMode, emath, stroke::PathStroke, texture_atlas::PreparedDisc, CircleShape,
ClippedPrimitive, ClippedShape, Color32, CubicBezierShape, EllipseShape, Mesh, PathShape,
Primitive, QuadraticBezierShape, RectShape, Roundingf, Shape, Stroke, StrokeKind, TextShape,
ClippedPrimitive, ClippedShape, Color32, CornerRadiusF32, CubicBezierShape, EllipseShape, Mesh,
PathShape, Primitive, QuadraticBezierShape, RectShape, Shape, Stroke, StrokeKind, TextShape,
TextureId, Vertex, WHITE_UV,
};
@ -534,19 +534,19 @@ impl Path {
pub mod path {
//! Helpers for constructing paths
use crate::Roundingf;
use crate::CornerRadiusF32;
use emath::{pos2, Pos2, Rect};
/// overwrites existing points
pub fn rounded_rectangle(path: &mut Vec<Pos2>, rect: Rect, rounding: Roundingf) {
pub fn rounded_rectangle(path: &mut Vec<Pos2>, rect: Rect, cr: CornerRadiusF32) {
path.clear();
let min = rect.min;
let max = rect.max;
let r = clamp_rounding(rounding, rect);
let cr = clamp_corner_radius(cr, rect);
if r == Roundingf::ZERO {
if cr == CornerRadiusF32::ZERO {
path.reserve(4);
path.push(pos2(min.x, min.y)); // left top
path.push(pos2(max.x, min.y)); // right top
@ -557,27 +557,27 @@ 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();
add_circle_quadrant(path, pos2(max.x - r.se, max.y - r.se), r.se, 0.0); // south east
add_circle_quadrant(path, pos2(max.x - cr.se, max.y - cr.se), cr.se, 0.0); // south east
if rect.width() <= r.se + r.sw + eps {
if rect.width() <= cr.se + cr.sw + eps {
path.pop(); // avoid duplicated vertex
}
add_circle_quadrant(path, pos2(min.x + r.sw, max.y - r.sw), r.sw, 1.0); // south west
add_circle_quadrant(path, pos2(min.x + cr.sw, max.y - cr.sw), cr.sw, 1.0); // south west
if rect.height() <= r.sw + r.nw + eps {
if rect.height() <= cr.sw + cr.nw + eps {
path.pop(); // avoid duplicated vertex
}
add_circle_quadrant(path, pos2(min.x + r.nw, min.y + r.nw), r.nw, 2.0); // north west
add_circle_quadrant(path, pos2(min.x + cr.nw, min.y + cr.nw), cr.nw, 2.0); // north west
if rect.width() <= r.nw + r.ne + eps {
if rect.width() <= cr.nw + cr.ne + eps {
path.pop(); // avoid duplicated vertex
}
add_circle_quadrant(path, pos2(max.x - r.ne, min.y + r.ne), r.ne, 3.0); // north east
add_circle_quadrant(path, pos2(max.x - cr.ne, min.y + cr.ne), cr.ne, 3.0); // north east
if rect.height() <= r.ne + r.se + eps {
if rect.height() <= cr.ne + cr.se + eps {
path.pop(); // avoid duplicated vertex
}
}
@ -633,11 +633,11 @@ pub mod path {
}
// Ensures the radius of each corner is within a valid range
fn clamp_rounding(rounding: Roundingf, rect: Rect) -> Roundingf {
fn clamp_corner_radius(cr: CornerRadiusF32, rect: Rect) -> CornerRadiusF32 {
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)
cr.at_most(max_cr).at_least(0.0)
}
}
@ -1729,7 +1729,7 @@ impl Tessellator {
let brush = rect_shape.brush.as_ref();
let RectShape {
mut rect,
rounding,
corner_radius,
mut fill,
mut stroke,
mut stroke_kind,
@ -1738,7 +1738,7 @@ impl Tessellator {
brush: _, // brush is extracted on its own, because it is not Copy
} = *rect_shape;
let mut rounding = Roundingf::from(rounding);
let mut corner_radius = CornerRadiusF32::from(corner_radius);
let round_to_pixels = round_to_pixels.unwrap_or(self.options.round_rects_to_pixels);
let pixel_size = 1.0 / self.pixels_per_point;
@ -1848,7 +1848,7 @@ impl Tessellator {
.at_most(rect.size().min_elem() - eps - 2.0 * stroke.width)
.at_least(0.0);
rounding += 0.5 * blur_width;
corner_radius += 0.5 * blur_width;
self.feathering = self.feathering.max(blur_width);
}
@ -1858,54 +1858,54 @@ impl Tessellator {
// We do this because `path::rounded_rectangle` uses the
// corner radius to pick the fidelity/resolution of the corner.
let original_rounding = rounding;
let original_cr = corner_radius;
match stroke_kind {
StrokeKind::Inside => {}
StrokeKind::Middle => {
rect = rect.expand(stroke.width / 2.0);
rounding += stroke.width / 2.0;
corner_radius += stroke.width / 2.0;
}
StrokeKind::Outside => {
rect = rect.expand(stroke.width);
rounding += stroke.width;
corner_radius += stroke.width;
}
}
stroke_kind = StrokeKind::Inside;
// A small rounding is incompatible with a wide stroke,
// A small corner_radius is incompatible with a wide stroke,
// because the small bend will be extruded inwards and cross itself.
// There are two ways to solve this (wile maintaining constant stroke width):
// either we increase the rounding, or we set it to zero.
// We choose the former: if the user asks for _any_ rounding, they should get it.
// either we increase the corner_radius, or we set it to zero.
// We choose the former: if the user asks for _any_ corner_radius, they should get it.
let min_inside_rounding = 0.1; // Large enough to avoid numerical issues
let min_outside_rounding = stroke.width + min_inside_rounding;
let min_inside_cr = 0.1; // Large enough to avoid numerical issues
let min_outside_cr = stroke.width + min_inside_cr;
let extra_rounding_tweak = 0.4; // Otherwise is doesn't _feels_ enough.
let extra_cr_tweak = 0.4; // Otherwise is doesn't _feels_ enough.
if 0.0 < original_rounding.nw {
rounding.nw += extra_rounding_tweak;
rounding.nw = rounding.nw.at_least(min_outside_rounding);
if 0.0 < original_cr.nw {
corner_radius.nw += extra_cr_tweak;
corner_radius.nw = corner_radius.nw.at_least(min_outside_cr);
}
if 0.0 < original_rounding.ne {
rounding.ne += extra_rounding_tweak;
rounding.ne = rounding.ne.at_least(min_outside_rounding);
if 0.0 < original_cr.ne {
corner_radius.ne += extra_cr_tweak;
corner_radius.ne = corner_radius.ne.at_least(min_outside_cr);
}
if 0.0 < original_rounding.sw {
rounding.sw += extra_rounding_tweak;
rounding.sw = rounding.sw.at_least(min_outside_rounding);
if 0.0 < original_cr.sw {
corner_radius.sw += extra_cr_tweak;
corner_radius.sw = corner_radius.sw.at_least(min_outside_cr);
}
if 0.0 < original_rounding.se {
rounding.se += extra_rounding_tweak;
rounding.se = rounding.se.at_least(min_outside_rounding);
if 0.0 < original_cr.se {
corner_radius.se += extra_cr_tweak;
corner_radius.se = corner_radius.se.at_least(min_outside_cr);
}
}
let path = &mut self.scratchpad_path;
path.clear();
path::rounded_rectangle(&mut self.scratchpad_points, rect, rounding);
path::rounded_rectangle(&mut self.scratchpad_points, rect, corner_radius);
path.add_line_loop(&self.scratchpad_points);
let path_stroke = PathStroke::from(stroke).with_kind(stroke_kind);

View File

@ -47,7 +47,7 @@ fn custom_window_frame(ctx: &egui::Context, title: &str, add_contents: impl FnOn
let panel_frame = egui::Frame::new()
.fill(ctx.style().visuals.window_fill())
.rounding(10)
.corner_radius(10)
.stroke(ctx.style().visuals.widgets.noninteractive.fg_stroke)
.outer_margin(1); // so the stroke is within the bounds

View File

@ -35,7 +35,7 @@ impl eframe::App for MyApp {
.on_hover_text_at_pointer("Svg");
let url = "https://picsum.photos/seed/1.759706314/1024";
ui.add(egui::Image::new(url).rounding(10.0))
ui.add(egui::Image::new(url).corner_radius(10))
.on_hover_text_at_pointer(url);
});
});

View File

@ -478,7 +478,13 @@ fn drop_target<R>(
ui.painter().set(
background_id,
egui::epaint::RectShape::new(rect, style.rounding, fill, stroke, egui::StrokeKind::Inside),
egui::epaint::RectShape::new(
rect,
style.corner_radius,
fill,
stroke,
egui::StrokeKind::Inside,
),
);
egui::InnerResponse::new(ret, response)