Skip to content

Commit 23ed493

Browse files
authored
⚠️ 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`
1 parent 3c07e01 commit 23ed493

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+378
-330
lines changed

crates/egui/src/containers/collapsing_header.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ impl CollapsingHeader {
573573
if ui.visuals().collapsing_header_frame || show_background {
574574
ui.painter().add(epaint::RectShape::new(
575575
header_response.rect.expand(visuals.expansion),
576-
visuals.rounding,
576+
visuals.corner_radius,
577577
visuals.weak_bg_fill,
578578
visuals.bg_stroke,
579579
StrokeKind::Inside,
@@ -586,7 +586,7 @@ impl CollapsingHeader {
586586

587587
ui.painter().rect(
588588
rect,
589-
visuals.rounding,
589+
visuals.corner_radius,
590590
visuals.bg_fill,
591591
visuals.bg_stroke,
592592
StrokeKind::Inside,

crates/egui/src/containers/combo_box.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ fn button_frame(
471471
where_to_put_background,
472472
epaint::RectShape::new(
473473
outer_rect.expand(visuals.expansion),
474-
visuals.rounding,
474+
visuals.corner_radius,
475475
visuals.weak_bg_fill,
476476
visuals.bg_stroke,
477477
epaint::StrokeKind::Inside,

crates/egui/src/containers/frame.rs

+23-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
epaint, layers::ShapeIdx, InnerResponse, Response, Sense, Style, Ui, UiBuilder, UiKind,
55
UiStackInfo,
66
};
7-
use epaint::{Color32, Margin, Marginf, Rect, Rounding, Shadow, Shape, Stroke};
7+
use epaint::{Color32, CornerRadius, Margin, Marginf, Rect, Shadow, Shape, Stroke};
88

99
/// A frame around some content, including margin, colors, etc.
1010
///
@@ -119,7 +119,7 @@ pub struct Frame {
119119
/// (or, if there is no stroke, the outer corner of [`Self::fill`]).
120120
///
121121
/// In other words, this is the corner radius of the _widget rect_.
122-
pub rounding: Rounding,
122+
pub corner_radius: CornerRadius,
123123

124124
/// Margin outside the painted frame.
125125
///
@@ -161,7 +161,7 @@ impl Frame {
161161
inner_margin: Margin::ZERO,
162162
stroke: Stroke::NONE,
163163
fill: Color32::TRANSPARENT,
164-
rounding: Rounding::ZERO,
164+
corner_radius: CornerRadius::ZERO,
165165
outer_margin: Margin::ZERO,
166166
shadow: Shadow::NONE,
167167
};
@@ -182,7 +182,7 @@ impl Frame {
182182
pub fn group(style: &Style) -> Self {
183183
Self::new()
184184
.inner_margin(6)
185-
.rounding(style.visuals.widgets.noninteractive.rounding)
185+
.corner_radius(style.visuals.widgets.noninteractive.corner_radius)
186186
.stroke(style.visuals.widgets.noninteractive.bg_stroke)
187187
}
188188

@@ -199,7 +199,7 @@ impl Frame {
199199
pub fn window(style: &Style) -> Self {
200200
Self::new()
201201
.inner_margin(style.spacing.window_margin)
202-
.rounding(style.visuals.window_rounding)
202+
.corner_radius(style.visuals.window_corner_radius)
203203
.shadow(style.visuals.window_shadow)
204204
.fill(style.visuals.window_fill())
205205
.stroke(style.visuals.window_stroke())
@@ -208,7 +208,7 @@ impl Frame {
208208
pub fn menu(style: &Style) -> Self {
209209
Self::new()
210210
.inner_margin(style.spacing.menu_margin)
211-
.rounding(style.visuals.menu_rounding)
211+
.corner_radius(style.visuals.menu_corner_radius)
212212
.shadow(style.visuals.popup_shadow)
213213
.fill(style.visuals.window_fill())
214214
.stroke(style.visuals.window_stroke())
@@ -217,7 +217,7 @@ impl Frame {
217217
pub fn popup(style: &Style) -> Self {
218218
Self::new()
219219
.inner_margin(style.spacing.menu_margin)
220-
.rounding(style.visuals.menu_rounding)
220+
.corner_radius(style.visuals.menu_corner_radius)
221221
.shadow(style.visuals.popup_shadow)
222222
.fill(style.visuals.window_fill())
223223
.stroke(style.visuals.window_stroke())
@@ -230,7 +230,7 @@ impl Frame {
230230
pub fn canvas(style: &Style) -> Self {
231231
Self::new()
232232
.inner_margin(2)
233-
.rounding(style.visuals.widgets.noninteractive.rounding)
233+
.corner_radius(style.visuals.widgets.noninteractive.corner_radius)
234234
.fill(style.visuals.extreme_bg_color)
235235
.stroke(style.visuals.window_stroke())
236236
}
@@ -277,11 +277,21 @@ impl Frame {
277277
///
278278
/// In other words, this is the corner radius of the _widget rect_.
279279
#[inline]
280-
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
281-
self.rounding = rounding.into();
280+
pub fn corner_radius(mut self, corner_radius: impl Into<CornerRadius>) -> Self {
281+
self.corner_radius = corner_radius.into();
282282
self
283283
}
284284

285+
/// The rounding of the _outer_ corner of the [`Self::stroke`]
286+
/// (or, if there is no stroke, the outer corner of [`Self::fill`]).
287+
///
288+
/// In other words, this is the corner radius of the _widget rect_.
289+
#[inline]
290+
#[deprecated = "Renamed to `corner_radius`"]
291+
pub fn rounding(self, corner_radius: impl Into<CornerRadius>) -> Self {
292+
self.corner_radius(corner_radius)
293+
}
294+
285295
/// Margin outside the painted frame.
286296
///
287297
/// Similar to what is called `margin` in CSS.
@@ -424,7 +434,7 @@ impl Frame {
424434
inner_margin: _,
425435
fill,
426436
stroke,
427-
rounding,
437+
corner_radius,
428438
outer_margin: _,
429439
shadow,
430440
} = *self;
@@ -433,7 +443,7 @@ impl Frame {
433443

434444
let frame_shape = Shape::Rect(epaint::RectShape::new(
435445
widget_rect,
436-
rounding,
446+
corner_radius,
437447
fill,
438448
stroke,
439449
epaint::StrokeKind::Inside,
@@ -442,7 +452,7 @@ impl Frame {
442452
if shadow == Default::default() {
443453
frame_shape
444454
} else {
445-
let shadow = shadow.as_shape(widget_rect, rounding);
455+
let shadow = shadow.as_shape(widget_rect, corner_radius);
446456
Shape::Vec(vec![Shape::from(shadow), frame_shape])
447457
}
448458
}

crates/egui/src/containers/scroll_area.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ impl Prepared {
12401240
// Background:
12411241
ui.painter().add(epaint::Shape::rect_filled(
12421242
outer_scroll_bar_rect,
1243-
visuals.rounding,
1243+
visuals.corner_radius,
12441244
ui.visuals()
12451245
.extreme_bg_color
12461246
.gamma_multiply(background_opacity),
@@ -1249,7 +1249,7 @@ impl Prepared {
12491249
// Handle:
12501250
ui.painter().add(epaint::Shape::rect_filled(
12511251
handle_rect,
1252-
visuals.rounding,
1252+
visuals.corner_radius,
12531253
handle_color.gamma_multiply(handle_opacity),
12541254
));
12551255
}

crates/egui/src/containers/window.rs

+30-50
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::sync::Arc;
44

55
use emath::GuiRounding as _;
6-
use epaint::{RectShape, Roundingf};
6+
use epaint::{CornerRadiusF32, RectShape};
77

88
use crate::collapsing_header::CollapsingState;
99
use crate::*;
@@ -485,8 +485,8 @@ impl Window<'_> {
485485
.at_least(style.spacing.interact_size.y);
486486
let title_bar_inner_height = title_bar_inner_height + window_frame.inner_margin.sum().y;
487487
let half_height = (title_bar_inner_height / 2.0).round() as _;
488-
window_frame.rounding.ne = window_frame.rounding.ne.clamp(0, half_height);
489-
window_frame.rounding.nw = window_frame.rounding.nw.clamp(0, half_height);
488+
window_frame.corner_radius.ne = window_frame.corner_radius.ne.clamp(0, half_height);
489+
window_frame.corner_radius.nw = window_frame.corner_radius.nw.clamp(0, half_height);
490490

491491
let title_content_spacing = if is_collapsed {
492492
0.0
@@ -612,7 +612,7 @@ impl Window<'_> {
612612

613613
if on_top && area_content_ui.visuals().window_highlight_topmost {
614614
let mut round =
615-
window_frame.rounding - window_frame.stroke.width.round() as u8;
615+
window_frame.corner_radius - window_frame.stroke.width.round() as u8;
616616

617617
if !is_collapsed {
618618
round.se = 0;
@@ -667,28 +667,28 @@ fn paint_resize_corner(
667667
window_frame: &Frame,
668668
i: ResizeInteraction,
669669
) {
670-
let rounding = window_frame.rounding;
670+
let cr = window_frame.corner_radius;
671671

672672
let (corner, radius, corner_response) = if possible.resize_right && possible.resize_bottom {
673-
(Align2::RIGHT_BOTTOM, rounding.se, i.right & i.bottom)
673+
(Align2::RIGHT_BOTTOM, cr.se, i.right & i.bottom)
674674
} else if possible.resize_left && possible.resize_bottom {
675-
(Align2::LEFT_BOTTOM, rounding.sw, i.left & i.bottom)
675+
(Align2::LEFT_BOTTOM, cr.sw, i.left & i.bottom)
676676
} else if possible.resize_left && possible.resize_top {
677-
(Align2::LEFT_TOP, rounding.nw, i.left & i.top)
677+
(Align2::LEFT_TOP, cr.nw, i.left & i.top)
678678
} else if possible.resize_right && possible.resize_top {
679-
(Align2::RIGHT_TOP, rounding.ne, i.right & i.top)
679+
(Align2::RIGHT_TOP, cr.ne, i.right & i.top)
680680
} else {
681681
// We're not in two directions, but it is still nice to tell the user
682682
// we're resizable by painting the resize corner in the expected place
683683
// (i.e. for windows only resizable in one direction):
684684
if possible.resize_right || possible.resize_bottom {
685-
(Align2::RIGHT_BOTTOM, rounding.se, i.right & i.bottom)
685+
(Align2::RIGHT_BOTTOM, cr.se, i.right & i.bottom)
686686
} else if possible.resize_left || possible.resize_bottom {
687-
(Align2::LEFT_BOTTOM, rounding.sw, i.left & i.bottom)
687+
(Align2::LEFT_BOTTOM, cr.sw, i.left & i.bottom)
688688
} else if possible.resize_left || possible.resize_top {
689-
(Align2::LEFT_TOP, rounding.nw, i.left & i.top)
689+
(Align2::LEFT_TOP, cr.nw, i.left & i.top)
690690
} else if possible.resize_right || possible.resize_top {
691-
(Align2::RIGHT_TOP, rounding.ne, i.right & i.top)
691+
(Align2::RIGHT_TOP, cr.ne, i.right & i.top)
692692
} else {
693693
return;
694694
}
@@ -1054,7 +1054,7 @@ fn paint_frame_interaction(ui: &Ui, rect: Rect, interaction: ResizeInteraction)
10541054
bottom = interaction.bottom.hover;
10551055
}
10561056

1057-
let rounding = Roundingf::from(ui.visuals().window_rounding);
1057+
let cr = CornerRadiusF32::from(ui.visuals().window_corner_radius);
10581058

10591059
// Put the rect in the center of the fixed window stroke:
10601060
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)
10721072
let mut points = Vec::new();
10731073

10741074
if right && !bottom && !top {
1075-
points.push(pos2(max.x, min.y + rounding.ne));
1076-
points.push(pos2(max.x, max.y - rounding.se));
1075+
points.push(pos2(max.x, min.y + cr.ne));
1076+
points.push(pos2(max.x, max.y - cr.se));
10771077
}
10781078
if right && bottom {
1079-
points.push(pos2(max.x, min.y + rounding.ne));
1080-
points.push(pos2(max.x, max.y - rounding.se));
1081-
add_circle_quadrant(
1082-
&mut points,
1083-
pos2(max.x - rounding.se, max.y - rounding.se),
1084-
rounding.se,
1085-
0.0,
1086-
);
1079+
points.push(pos2(max.x, min.y + cr.ne));
1080+
points.push(pos2(max.x, max.y - cr.se));
1081+
add_circle_quadrant(&mut points, pos2(max.x - cr.se, max.y - cr.se), cr.se, 0.0);
10871082
}
10881083
if bottom {
1089-
points.push(pos2(max.x - rounding.se, max.y));
1090-
points.push(pos2(min.x + rounding.sw, max.y));
1084+
points.push(pos2(max.x - cr.se, max.y));
1085+
points.push(pos2(min.x + cr.sw, max.y));
10911086
}
10921087
if left && bottom {
1093-
add_circle_quadrant(
1094-
&mut points,
1095-
pos2(min.x + rounding.sw, max.y - rounding.sw),
1096-
rounding.sw,
1097-
1.0,
1098-
);
1088+
add_circle_quadrant(&mut points, pos2(min.x + cr.sw, max.y - cr.sw), cr.sw, 1.0);
10991089
}
11001090
if left {
1101-
points.push(pos2(min.x, max.y - rounding.sw));
1102-
points.push(pos2(min.x, min.y + rounding.nw));
1091+
points.push(pos2(min.x, max.y - cr.sw));
1092+
points.push(pos2(min.x, min.y + cr.nw));
11031093
}
11041094
if left && top {
1105-
add_circle_quadrant(
1106-
&mut points,
1107-
pos2(min.x + rounding.nw, min.y + rounding.nw),
1108-
rounding.nw,
1109-
2.0,
1110-
);
1095+
add_circle_quadrant(&mut points, pos2(min.x + cr.nw, min.y + cr.nw), cr.nw, 2.0);
11111096
}
11121097
if top {
1113-
points.push(pos2(min.x + rounding.nw, min.y));
1114-
points.push(pos2(max.x - rounding.ne, min.y));
1098+
points.push(pos2(min.x + cr.nw, min.y));
1099+
points.push(pos2(max.x - cr.ne, min.y));
11151100
}
11161101
if right && top {
1117-
add_circle_quadrant(
1118-
&mut points,
1119-
pos2(max.x - rounding.ne, min.y + rounding.ne),
1120-
rounding.ne,
1121-
3.0,
1122-
);
1123-
points.push(pos2(max.x, min.y + rounding.ne));
1124-
points.push(pos2(max.x, max.y - rounding.se));
1102+
add_circle_quadrant(&mut points, pos2(max.x - cr.ne, min.y + cr.ne), cr.ne, 3.0);
1103+
points.push(pos2(max.x, min.y + cr.ne));
1104+
points.push(pos2(max.x, max.y - cr.se));
11251105
}
11261106

11271107
ui.painter().add(Shape::line(points, stroke));

crates/egui/src/lib.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ pub use epaint::{
464464
mutex,
465465
text::{FontData, FontDefinitions, FontFamily, FontId, FontTweak},
466466
textures::{TextureFilter, TextureOptions, TextureWrapMode, TexturesDelta},
467-
ClippedPrimitive, ColorImage, FontImage, ImageData, Margin, Mesh, PaintCallback,
468-
PaintCallbackInfo, Rounding, Shadow, Shape, Stroke, StrokeKind, TextureHandle, TextureId,
467+
ClippedPrimitive, ColorImage, CornerRadius, FontImage, ImageData, Margin, Mesh, PaintCallback,
468+
PaintCallbackInfo, Shadow, Shape, Stroke, StrokeKind, TextureHandle, TextureId,
469469
};
470470

471471
pub mod text {
@@ -510,6 +510,9 @@ pub use self::{
510510
widgets::*,
511511
};
512512

513+
#[deprecated = "Renamed to CornerRadius"]
514+
pub type Rounding = CornerRadius;
515+
513516
// ----------------------------------------------------------------------------
514517

515518
/// 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) {
538541
/// ui.add(
539542
/// egui::Image::new(egui::include_image!("../assets/ferris.png"))
540543
/// .max_width(200.0)
541-
/// .rounding(10.0),
544+
/// .corner_radius(10),
542545
/// );
543546
///
544547
/// let image_source: egui::ImageSource = egui::include_image!("../assets/ferris.png");

crates/egui/src/menu.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl SubMenuButton {
580580
if ui.visuals().button_frame {
581581
ui.painter().rect_filled(
582582
rect.expand(visuals.expansion),
583-
visuals.rounding,
583+
visuals.corner_radius,
584584
visuals.weak_bg_fill,
585585
);
586586
}

0 commit comments

Comments
 (0)