⚠️ 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:
parent
3c07e01d08
commit
23ed49334e
|
|
@ -573,7 +573,7 @@ impl CollapsingHeader {
|
||||||
if ui.visuals().collapsing_header_frame || show_background {
|
if ui.visuals().collapsing_header_frame || show_background {
|
||||||
ui.painter().add(epaint::RectShape::new(
|
ui.painter().add(epaint::RectShape::new(
|
||||||
header_response.rect.expand(visuals.expansion),
|
header_response.rect.expand(visuals.expansion),
|
||||||
visuals.rounding,
|
visuals.corner_radius,
|
||||||
visuals.weak_bg_fill,
|
visuals.weak_bg_fill,
|
||||||
visuals.bg_stroke,
|
visuals.bg_stroke,
|
||||||
StrokeKind::Inside,
|
StrokeKind::Inside,
|
||||||
|
|
@ -586,7 +586,7 @@ impl CollapsingHeader {
|
||||||
|
|
||||||
ui.painter().rect(
|
ui.painter().rect(
|
||||||
rect,
|
rect,
|
||||||
visuals.rounding,
|
visuals.corner_radius,
|
||||||
visuals.bg_fill,
|
visuals.bg_fill,
|
||||||
visuals.bg_stroke,
|
visuals.bg_stroke,
|
||||||
StrokeKind::Inside,
|
StrokeKind::Inside,
|
||||||
|
|
|
||||||
|
|
@ -471,7 +471,7 @@ fn button_frame(
|
||||||
where_to_put_background,
|
where_to_put_background,
|
||||||
epaint::RectShape::new(
|
epaint::RectShape::new(
|
||||||
outer_rect.expand(visuals.expansion),
|
outer_rect.expand(visuals.expansion),
|
||||||
visuals.rounding,
|
visuals.corner_radius,
|
||||||
visuals.weak_bg_fill,
|
visuals.weak_bg_fill,
|
||||||
visuals.bg_stroke,
|
visuals.bg_stroke,
|
||||||
epaint::StrokeKind::Inside,
|
epaint::StrokeKind::Inside,
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
epaint, layers::ShapeIdx, InnerResponse, Response, Sense, Style, Ui, UiBuilder, UiKind,
|
epaint, layers::ShapeIdx, InnerResponse, Response, Sense, Style, Ui, UiBuilder, UiKind,
|
||||||
UiStackInfo,
|
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.
|
/// 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`]).
|
/// (or, if there is no stroke, the outer corner of [`Self::fill`]).
|
||||||
///
|
///
|
||||||
/// In other words, this is the corner radius of the _widget rect_.
|
/// In other words, this is the corner radius of the _widget rect_.
|
||||||
pub rounding: Rounding,
|
pub corner_radius: CornerRadius,
|
||||||
|
|
||||||
/// Margin outside the painted frame.
|
/// Margin outside the painted frame.
|
||||||
///
|
///
|
||||||
|
|
@ -161,7 +161,7 @@ impl Frame {
|
||||||
inner_margin: Margin::ZERO,
|
inner_margin: Margin::ZERO,
|
||||||
stroke: Stroke::NONE,
|
stroke: Stroke::NONE,
|
||||||
fill: Color32::TRANSPARENT,
|
fill: Color32::TRANSPARENT,
|
||||||
rounding: Rounding::ZERO,
|
corner_radius: CornerRadius::ZERO,
|
||||||
outer_margin: Margin::ZERO,
|
outer_margin: Margin::ZERO,
|
||||||
shadow: Shadow::NONE,
|
shadow: Shadow::NONE,
|
||||||
};
|
};
|
||||||
|
|
@ -182,7 +182,7 @@ impl Frame {
|
||||||
pub fn group(style: &Style) -> Self {
|
pub fn group(style: &Style) -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
.inner_margin(6)
|
.inner_margin(6)
|
||||||
.rounding(style.visuals.widgets.noninteractive.rounding)
|
.corner_radius(style.visuals.widgets.noninteractive.corner_radius)
|
||||||
.stroke(style.visuals.widgets.noninteractive.bg_stroke)
|
.stroke(style.visuals.widgets.noninteractive.bg_stroke)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,7 +199,7 @@ impl Frame {
|
||||||
pub fn window(style: &Style) -> Self {
|
pub fn window(style: &Style) -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
.inner_margin(style.spacing.window_margin)
|
.inner_margin(style.spacing.window_margin)
|
||||||
.rounding(style.visuals.window_rounding)
|
.corner_radius(style.visuals.window_corner_radius)
|
||||||
.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())
|
||||||
|
|
@ -208,7 +208,7 @@ impl Frame {
|
||||||
pub fn menu(style: &Style) -> Self {
|
pub fn menu(style: &Style) -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
.inner_margin(style.spacing.menu_margin)
|
.inner_margin(style.spacing.menu_margin)
|
||||||
.rounding(style.visuals.menu_rounding)
|
.corner_radius(style.visuals.menu_corner_radius)
|
||||||
.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())
|
||||||
|
|
@ -217,7 +217,7 @@ impl Frame {
|
||||||
pub fn popup(style: &Style) -> Self {
|
pub fn popup(style: &Style) -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
.inner_margin(style.spacing.menu_margin)
|
.inner_margin(style.spacing.menu_margin)
|
||||||
.rounding(style.visuals.menu_rounding)
|
.corner_radius(style.visuals.menu_corner_radius)
|
||||||
.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())
|
||||||
|
|
@ -230,7 +230,7 @@ impl Frame {
|
||||||
pub fn canvas(style: &Style) -> Self {
|
pub fn canvas(style: &Style) -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
.inner_margin(2)
|
.inner_margin(2)
|
||||||
.rounding(style.visuals.widgets.noninteractive.rounding)
|
.corner_radius(style.visuals.widgets.noninteractive.corner_radius)
|
||||||
.fill(style.visuals.extreme_bg_color)
|
.fill(style.visuals.extreme_bg_color)
|
||||||
.stroke(style.visuals.window_stroke())
|
.stroke(style.visuals.window_stroke())
|
||||||
}
|
}
|
||||||
|
|
@ -277,11 +277,21 @@ impl Frame {
|
||||||
///
|
///
|
||||||
/// In other words, this is the corner radius of the _widget rect_.
|
/// In other words, this is the corner radius of the _widget rect_.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
|
pub fn corner_radius(mut self, corner_radius: impl Into<CornerRadius>) -> Self {
|
||||||
self.rounding = rounding.into();
|
self.corner_radius = corner_radius.into();
|
||||||
self
|
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.
|
/// Margin outside the painted frame.
|
||||||
///
|
///
|
||||||
/// Similar to what is called `margin` in CSS.
|
/// Similar to what is called `margin` in CSS.
|
||||||
|
|
@ -424,7 +434,7 @@ impl Frame {
|
||||||
inner_margin: _,
|
inner_margin: _,
|
||||||
fill,
|
fill,
|
||||||
stroke,
|
stroke,
|
||||||
rounding,
|
corner_radius,
|
||||||
outer_margin: _,
|
outer_margin: _,
|
||||||
shadow,
|
shadow,
|
||||||
} = *self;
|
} = *self;
|
||||||
|
|
@ -433,7 +443,7 @@ impl Frame {
|
||||||
|
|
||||||
let frame_shape = Shape::Rect(epaint::RectShape::new(
|
let frame_shape = Shape::Rect(epaint::RectShape::new(
|
||||||
widget_rect,
|
widget_rect,
|
||||||
rounding,
|
corner_radius,
|
||||||
fill,
|
fill,
|
||||||
stroke,
|
stroke,
|
||||||
epaint::StrokeKind::Inside,
|
epaint::StrokeKind::Inside,
|
||||||
|
|
@ -442,7 +452,7 @@ impl Frame {
|
||||||
if shadow == Default::default() {
|
if shadow == Default::default() {
|
||||||
frame_shape
|
frame_shape
|
||||||
} else {
|
} 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])
|
Shape::Vec(vec![Shape::from(shadow), frame_shape])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1240,7 +1240,7 @@ impl Prepared {
|
||||||
// Background:
|
// Background:
|
||||||
ui.painter().add(epaint::Shape::rect_filled(
|
ui.painter().add(epaint::Shape::rect_filled(
|
||||||
outer_scroll_bar_rect,
|
outer_scroll_bar_rect,
|
||||||
visuals.rounding,
|
visuals.corner_radius,
|
||||||
ui.visuals()
|
ui.visuals()
|
||||||
.extreme_bg_color
|
.extreme_bg_color
|
||||||
.gamma_multiply(background_opacity),
|
.gamma_multiply(background_opacity),
|
||||||
|
|
@ -1249,7 +1249,7 @@ impl Prepared {
|
||||||
// Handle:
|
// Handle:
|
||||||
ui.painter().add(epaint::Shape::rect_filled(
|
ui.painter().add(epaint::Shape::rect_filled(
|
||||||
handle_rect,
|
handle_rect,
|
||||||
visuals.rounding,
|
visuals.corner_radius,
|
||||||
handle_color.gamma_multiply(handle_opacity),
|
handle_color.gamma_multiply(handle_opacity),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use emath::GuiRounding as _;
|
use emath::GuiRounding as _;
|
||||||
use epaint::{RectShape, Roundingf};
|
use epaint::{CornerRadiusF32, RectShape};
|
||||||
|
|
||||||
use crate::collapsing_header::CollapsingState;
|
use crate::collapsing_header::CollapsingState;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
@ -485,8 +485,8 @@ impl Window<'_> {
|
||||||
.at_least(style.spacing.interact_size.y);
|
.at_least(style.spacing.interact_size.y);
|
||||||
let title_bar_inner_height = title_bar_inner_height + window_frame.inner_margin.sum().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 _;
|
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.corner_radius.ne = window_frame.corner_radius.ne.clamp(0, half_height);
|
||||||
window_frame.rounding.nw = window_frame.rounding.nw.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 {
|
let title_content_spacing = if is_collapsed {
|
||||||
0.0
|
0.0
|
||||||
|
|
@ -612,7 +612,7 @@ impl Window<'_> {
|
||||||
|
|
||||||
if on_top && area_content_ui.visuals().window_highlight_topmost {
|
if on_top && area_content_ui.visuals().window_highlight_topmost {
|
||||||
let mut round =
|
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 {
|
if !is_collapsed {
|
||||||
round.se = 0;
|
round.se = 0;
|
||||||
|
|
@ -667,28 +667,28 @@ fn paint_resize_corner(
|
||||||
window_frame: &Frame,
|
window_frame: &Frame,
|
||||||
i: ResizeInteraction,
|
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 {
|
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 {
|
} 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 {
|
} 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 {
|
} 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 {
|
} else {
|
||||||
// We're not in two directions, but it is still nice to tell the user
|
// 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
|
// we're resizable by painting the resize corner in the expected place
|
||||||
// (i.e. for windows only resizable in one direction):
|
// (i.e. for windows only resizable in one direction):
|
||||||
if possible.resize_right || possible.resize_bottom {
|
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 {
|
} 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 {
|
} 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 {
|
} 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 {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1054,7 +1054,7 @@ fn paint_frame_interaction(ui: &Ui, rect: Rect, interaction: ResizeInteraction)
|
||||||
bottom = interaction.bottom.hover;
|
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:
|
// Put the rect in the center of the fixed window stroke:
|
||||||
let rect = rect.shrink(interaction.window_frame.stroke.width / 2.0);
|
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();
|
let mut points = Vec::new();
|
||||||
|
|
||||||
if right && !bottom && !top {
|
if right && !bottom && !top {
|
||||||
points.push(pos2(max.x, min.y + rounding.ne));
|
points.push(pos2(max.x, min.y + cr.ne));
|
||||||
points.push(pos2(max.x, max.y - rounding.se));
|
points.push(pos2(max.x, max.y - cr.se));
|
||||||
}
|
}
|
||||||
if right && bottom {
|
if right && bottom {
|
||||||
points.push(pos2(max.x, min.y + rounding.ne));
|
points.push(pos2(max.x, min.y + cr.ne));
|
||||||
points.push(pos2(max.x, max.y - rounding.se));
|
points.push(pos2(max.x, max.y - cr.se));
|
||||||
add_circle_quadrant(
|
add_circle_quadrant(&mut points, pos2(max.x - cr.se, max.y - cr.se), cr.se, 0.0);
|
||||||
&mut points,
|
|
||||||
pos2(max.x - rounding.se, max.y - rounding.se),
|
|
||||||
rounding.se,
|
|
||||||
0.0,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if bottom {
|
if bottom {
|
||||||
points.push(pos2(max.x - rounding.se, max.y));
|
points.push(pos2(max.x - cr.se, max.y));
|
||||||
points.push(pos2(min.x + rounding.sw, max.y));
|
points.push(pos2(min.x + cr.sw, max.y));
|
||||||
}
|
}
|
||||||
if left && bottom {
|
if left && bottom {
|
||||||
add_circle_quadrant(
|
add_circle_quadrant(&mut points, pos2(min.x + cr.sw, max.y - cr.sw), cr.sw, 1.0);
|
||||||
&mut points,
|
|
||||||
pos2(min.x + rounding.sw, max.y - rounding.sw),
|
|
||||||
rounding.sw,
|
|
||||||
1.0,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if left {
|
if left {
|
||||||
points.push(pos2(min.x, max.y - rounding.sw));
|
points.push(pos2(min.x, max.y - cr.sw));
|
||||||
points.push(pos2(min.x, min.y + rounding.nw));
|
points.push(pos2(min.x, min.y + cr.nw));
|
||||||
}
|
}
|
||||||
if left && top {
|
if left && top {
|
||||||
add_circle_quadrant(
|
add_circle_quadrant(&mut points, pos2(min.x + cr.nw, min.y + cr.nw), cr.nw, 2.0);
|
||||||
&mut points,
|
|
||||||
pos2(min.x + rounding.nw, min.y + rounding.nw),
|
|
||||||
rounding.nw,
|
|
||||||
2.0,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if top {
|
if top {
|
||||||
points.push(pos2(min.x + rounding.nw, min.y));
|
points.push(pos2(min.x + cr.nw, min.y));
|
||||||
points.push(pos2(max.x - rounding.ne, min.y));
|
points.push(pos2(max.x - cr.ne, min.y));
|
||||||
}
|
}
|
||||||
if right && top {
|
if right && top {
|
||||||
add_circle_quadrant(
|
add_circle_quadrant(&mut points, pos2(max.x - cr.ne, min.y + cr.ne), cr.ne, 3.0);
|
||||||
&mut points,
|
points.push(pos2(max.x, min.y + cr.ne));
|
||||||
pos2(max.x - rounding.ne, min.y + rounding.ne),
|
points.push(pos2(max.x, max.y - cr.se));
|
||||||
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, stroke));
|
ui.painter().add(Shape::line(points, stroke));
|
||||||
|
|
|
||||||
|
|
@ -464,8 +464,8 @@ pub use epaint::{
|
||||||
mutex,
|
mutex,
|
||||||
text::{FontData, FontDefinitions, FontFamily, FontId, FontTweak},
|
text::{FontData, FontDefinitions, FontFamily, FontId, FontTweak},
|
||||||
textures::{TextureFilter, TextureOptions, TextureWrapMode, TexturesDelta},
|
textures::{TextureFilter, TextureOptions, TextureWrapMode, TexturesDelta},
|
||||||
ClippedPrimitive, ColorImage, FontImage, ImageData, Margin, Mesh, PaintCallback,
|
ClippedPrimitive, ColorImage, CornerRadius, FontImage, ImageData, Margin, Mesh, PaintCallback,
|
||||||
PaintCallbackInfo, Rounding, Shadow, Shape, Stroke, StrokeKind, TextureHandle, TextureId,
|
PaintCallbackInfo, Shadow, Shape, Stroke, StrokeKind, TextureHandle, TextureId,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod text {
|
pub mod text {
|
||||||
|
|
@ -510,6 +510,9 @@ pub use self::{
|
||||||
widgets::*,
|
widgets::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[deprecated = "Renamed to CornerRadius"]
|
||||||
|
pub type Rounding = CornerRadius;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
/// Helper function that adds a label when compiling with debug assertions enabled.
|
/// 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(
|
/// ui.add(
|
||||||
/// egui::Image::new(egui::include_image!("../assets/ferris.png"))
|
/// egui::Image::new(egui::include_image!("../assets/ferris.png"))
|
||||||
/// .max_width(200.0)
|
/// .max_width(200.0)
|
||||||
/// .rounding(10.0),
|
/// .corner_radius(10),
|
||||||
/// );
|
/// );
|
||||||
///
|
///
|
||||||
/// let image_source: egui::ImageSource = egui::include_image!("../assets/ferris.png");
|
/// let image_source: egui::ImageSource = egui::include_image!("../assets/ferris.png");
|
||||||
|
|
|
||||||
|
|
@ -580,7 +580,7 @@ impl SubMenuButton {
|
||||||
if ui.visuals().button_frame {
|
if ui.visuals().button_frame {
|
||||||
ui.painter().rect_filled(
|
ui.painter().rect_filled(
|
||||||
rect.expand(visuals.expansion),
|
rect.expand(visuals.expansion),
|
||||||
visuals.rounding,
|
visuals.corner_radius,
|
||||||
visuals.weak_bg_fill,
|
visuals.weak_bg_fill,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||||
use emath::GuiRounding as _;
|
use emath::GuiRounding as _;
|
||||||
use epaint::{
|
use epaint::{
|
||||||
text::{Fonts, Galley, LayoutJob},
|
text::{Fonts, Galley, LayoutJob},
|
||||||
CircleShape, ClippedShape, PathStroke, RectShape, Rounding, Shape, Stroke, StrokeKind,
|
CircleShape, ClippedShape, CornerRadius, PathStroke, RectShape, Shape, Stroke, StrokeKind,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -412,14 +412,14 @@ impl Painter {
|
||||||
pub fn rect(
|
pub fn rect(
|
||||||
&self,
|
&self,
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
rounding: impl Into<Rounding>,
|
corner_radius: impl Into<CornerRadius>,
|
||||||
fill_color: impl Into<Color32>,
|
fill_color: impl Into<Color32>,
|
||||||
stroke: impl Into<Stroke>,
|
stroke: impl Into<Stroke>,
|
||||||
stroke_kind: StrokeKind,
|
stroke_kind: StrokeKind,
|
||||||
) -> ShapeIdx {
|
) -> ShapeIdx {
|
||||||
self.add(RectShape::new(
|
self.add(RectShape::new(
|
||||||
rect,
|
rect,
|
||||||
rounding,
|
corner_radius,
|
||||||
fill_color,
|
fill_color,
|
||||||
stroke,
|
stroke,
|
||||||
stroke_kind,
|
stroke_kind,
|
||||||
|
|
@ -429,21 +429,21 @@ impl Painter {
|
||||||
pub fn rect_filled(
|
pub fn rect_filled(
|
||||||
&self,
|
&self,
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
rounding: impl Into<Rounding>,
|
corner_radius: impl Into<CornerRadius>,
|
||||||
fill_color: impl Into<Color32>,
|
fill_color: impl Into<Color32>,
|
||||||
) -> ShapeIdx {
|
) -> ShapeIdx {
|
||||||
self.add(RectShape::filled(rect, rounding, fill_color))
|
self.add(RectShape::filled(rect, corner_radius, fill_color))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The stroke extends _outside_ the [`Rect`].
|
/// The stroke extends _outside_ the [`Rect`].
|
||||||
pub fn rect_stroke(
|
pub fn rect_stroke(
|
||||||
&self,
|
&self,
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
rounding: impl Into<Rounding>,
|
corner_radius: impl Into<CornerRadius>,
|
||||||
stroke: impl Into<Stroke>,
|
stroke: impl Into<Stroke>,
|
||||||
stroke_kind: StrokeKind,
|
stroke_kind: StrokeKind,
|
||||||
) -> ShapeIdx {
|
) -> 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()`.
|
/// 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| {
|
/// # egui::__run_test_ui(|ui| {
|
||||||
/// # let rect = egui::Rect::from_min_size(Default::default(), egui::Vec2::splat(100.0));
|
/// # let rect = egui::Rect::from_min_size(Default::default(), egui::Vec2::splat(100.0));
|
||||||
/// egui::Image::new(egui::include_image!("../assets/ferris.png"))
|
/// egui::Image::new(egui::include_image!("../assets/ferris.png"))
|
||||||
/// .rounding(5.0)
|
/// .corner_radius(5)
|
||||||
/// .tint(egui::Color32::LIGHT_BLUE)
|
/// .tint(egui::Color32::LIGHT_BLUE)
|
||||||
/// .paint_at(ui, rect);
|
/// .paint_at(ui, rect);
|
||||||
/// # });
|
/// # });
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
use std::{collections::BTreeMap, ops::RangeInclusive, sync::Arc};
|
use std::{collections::BTreeMap, ops::RangeInclusive, sync::Arc};
|
||||||
|
|
||||||
use emath::Align;
|
use emath::Align;
|
||||||
use epaint::{text::FontTweak, Rounding, Shadow, Stroke};
|
use epaint::{text::FontTweak, CornerRadius, Shadow, Stroke};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ecolor::Color32,
|
ecolor::Color32,
|
||||||
|
|
@ -915,7 +915,7 @@ pub struct Visuals {
|
||||||
/// A good color for error text (e.g. red).
|
/// A good color for error text (e.g. red).
|
||||||
pub error_fg_color: Color32,
|
pub error_fg_color: Color32,
|
||||||
|
|
||||||
pub window_rounding: Rounding,
|
pub window_corner_radius: CornerRadius,
|
||||||
pub window_shadow: Shadow,
|
pub window_shadow: Shadow,
|
||||||
pub window_fill: Color32,
|
pub window_fill: Color32,
|
||||||
pub window_stroke: Stroke,
|
pub window_stroke: Stroke,
|
||||||
|
|
@ -923,7 +923,7 @@ pub struct Visuals {
|
||||||
/// Highlight the topmost window.
|
/// Highlight the topmost window.
|
||||||
pub window_highlight_topmost: bool,
|
pub window_highlight_topmost: bool,
|
||||||
|
|
||||||
pub menu_rounding: Rounding,
|
pub menu_corner_radius: CornerRadius,
|
||||||
|
|
||||||
/// Panel background color
|
/// Panel background color
|
||||||
pub panel_fill: Color32,
|
pub panel_fill: Color32,
|
||||||
|
|
@ -1107,7 +1107,7 @@ pub struct WidgetVisuals {
|
||||||
pub bg_stroke: Stroke,
|
pub bg_stroke: Stroke,
|
||||||
|
|
||||||
/// Button frames etc.
|
/// 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, …).
|
/// 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,
|
||||||
|
|
@ -1121,6 +1121,11 @@ impl WidgetVisuals {
|
||||||
pub fn text_color(&self) -> Color32 {
|
pub fn text_color(&self) -> Color32 {
|
||||||
self.fg_stroke.color
|
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
|
/// 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
|
warn_fg_color: Color32::from_rgb(255, 143, 0), // orange
|
||||||
error_fg_color: Color32::from_rgb(255, 0, 0), // red
|
error_fg_color: Color32::from_rgb(255, 0, 0), // red
|
||||||
|
|
||||||
window_rounding: Rounding::same(6),
|
window_corner_radius: CornerRadius::same(6),
|
||||||
window_shadow: Shadow {
|
window_shadow: Shadow {
|
||||||
offset: [10, 20],
|
offset: [10, 20],
|
||||||
blur: 15,
|
blur: 15,
|
||||||
|
|
@ -1302,7 +1307,7 @@ impl Visuals {
|
||||||
window_stroke: Stroke::new(1.0, Color32::from_gray(60)),
|
window_stroke: Stroke::new(1.0, Color32::from_gray(60)),
|
||||||
window_highlight_topmost: true,
|
window_highlight_topmost: true,
|
||||||
|
|
||||||
menu_rounding: Rounding::same(6),
|
menu_corner_radius: CornerRadius::same(6),
|
||||||
|
|
||||||
panel_fill: Color32::from_gray(27),
|
panel_fill: Color32::from_gray(27),
|
||||||
|
|
||||||
|
|
@ -1412,7 +1417,7 @@ impl Widgets {
|
||||||
bg_fill: Color32::from_gray(27),
|
bg_fill: Color32::from_gray(27),
|
||||||
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // separators, indentation lines
|
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
|
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,
|
expansion: 0.0,
|
||||||
},
|
},
|
||||||
inactive: WidgetVisuals {
|
inactive: WidgetVisuals {
|
||||||
|
|
@ -1420,7 +1425,7 @@ impl Widgets {
|
||||||
bg_fill: Color32::from_gray(60), // checkbox background
|
bg_fill: Color32::from_gray(60), // checkbox 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
|
||||||
rounding: Rounding::same(2),
|
corner_radius: CornerRadius::same(2),
|
||||||
expansion: 0.0,
|
expansion: 0.0,
|
||||||
},
|
},
|
||||||
hovered: WidgetVisuals {
|
hovered: WidgetVisuals {
|
||||||
|
|
@ -1428,7 +1433,7 @@ impl Widgets {
|
||||||
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)),
|
||||||
rounding: Rounding::same(3),
|
corner_radius: CornerRadius::same(3),
|
||||||
expansion: 1.0,
|
expansion: 1.0,
|
||||||
},
|
},
|
||||||
active: WidgetVisuals {
|
active: WidgetVisuals {
|
||||||
|
|
@ -1436,7 +1441,7 @@ impl Widgets {
|
||||||
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),
|
||||||
rounding: Rounding::same(2),
|
corner_radius: CornerRadius::same(2),
|
||||||
expansion: 1.0,
|
expansion: 1.0,
|
||||||
},
|
},
|
||||||
open: WidgetVisuals {
|
open: WidgetVisuals {
|
||||||
|
|
@ -1444,7 +1449,7 @@ impl Widgets {
|
||||||
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)),
|
||||||
rounding: Rounding::same(2),
|
corner_radius: CornerRadius::same(2),
|
||||||
expansion: 0.0,
|
expansion: 0.0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -1457,7 +1462,7 @@ impl Widgets {
|
||||||
bg_fill: Color32::from_gray(248),
|
bg_fill: Color32::from_gray(248),
|
||||||
bg_stroke: Stroke::new(1.0, Color32::from_gray(190)), // separators, indentation lines
|
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
|
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,
|
expansion: 0.0,
|
||||||
},
|
},
|
||||||
inactive: WidgetVisuals {
|
inactive: WidgetVisuals {
|
||||||
|
|
@ -1465,7 +1470,7 @@ impl Widgets {
|
||||||
bg_fill: Color32::from_gray(230), // checkbox background
|
bg_fill: Color32::from_gray(230), // checkbox background
|
||||||
bg_stroke: Default::default(),
|
bg_stroke: Default::default(),
|
||||||
fg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // button text
|
fg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // button text
|
||||||
rounding: Rounding::same(2),
|
corner_radius: CornerRadius::same(2),
|
||||||
expansion: 0.0,
|
expansion: 0.0,
|
||||||
},
|
},
|
||||||
hovered: WidgetVisuals {
|
hovered: WidgetVisuals {
|
||||||
|
|
@ -1473,7 +1478,7 @@ impl Widgets {
|
||||||
bg_fill: Color32::from_gray(220),
|
bg_fill: Color32::from_gray(220),
|
||||||
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),
|
||||||
rounding: Rounding::same(3),
|
corner_radius: CornerRadius::same(3),
|
||||||
expansion: 1.0,
|
expansion: 1.0,
|
||||||
},
|
},
|
||||||
active: WidgetVisuals {
|
active: WidgetVisuals {
|
||||||
|
|
@ -1481,7 +1486,7 @@ impl Widgets {
|
||||||
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),
|
||||||
rounding: Rounding::same(2),
|
corner_radius: CornerRadius::same(2),
|
||||||
expansion: 1.0,
|
expansion: 1.0,
|
||||||
},
|
},
|
||||||
open: WidgetVisuals {
|
open: WidgetVisuals {
|
||||||
|
|
@ -1489,7 +1494,7 @@ impl Widgets {
|
||||||
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),
|
||||||
rounding: Rounding::same(2),
|
corner_radius: CornerRadius::same(2),
|
||||||
expansion: 0.0,
|
expansion: 0.0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -1924,7 +1929,7 @@ impl WidgetVisuals {
|
||||||
weak_bg_fill,
|
weak_bg_fill,
|
||||||
bg_fill: mandatory_bg_fill,
|
bg_fill: mandatory_bg_fill,
|
||||||
bg_stroke,
|
bg_stroke,
|
||||||
rounding,
|
corner_radius,
|
||||||
fg_stroke,
|
fg_stroke,
|
||||||
expansion,
|
expansion,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
@ -1948,8 +1953,8 @@ impl WidgetVisuals {
|
||||||
ui.add(bg_stroke);
|
ui.add(bg_stroke);
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Rounding");
|
ui.label("Corner radius");
|
||||||
ui.add(rounding);
|
ui.add(corner_radius);
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Foreground stroke (text)");
|
ui.label("Foreground stroke (text)");
|
||||||
|
|
@ -1978,13 +1983,13 @@ impl Visuals {
|
||||||
warn_fg_color,
|
warn_fg_color,
|
||||||
error_fg_color,
|
error_fg_color,
|
||||||
|
|
||||||
window_rounding,
|
window_corner_radius,
|
||||||
window_shadow,
|
window_shadow,
|
||||||
window_fill,
|
window_fill,
|
||||||
window_stroke,
|
window_stroke,
|
||||||
window_highlight_topmost,
|
window_highlight_topmost,
|
||||||
|
|
||||||
menu_rounding,
|
menu_corner_radius,
|
||||||
|
|
||||||
panel_fill,
|
panel_fill,
|
||||||
|
|
||||||
|
|
@ -2066,8 +2071,8 @@ impl Visuals {
|
||||||
ui.add(window_stroke);
|
ui.add(window_stroke);
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Rounding");
|
ui.label("Corner radius");
|
||||||
ui.add(window_rounding);
|
ui.add(window_corner_radius);
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Shadow");
|
ui.label("Shadow");
|
||||||
|
|
@ -2084,8 +2089,8 @@ impl Visuals {
|
||||||
.spacing([12.0, 8.0])
|
.spacing([12.0, 8.0])
|
||||||
.striped(true)
|
.striped(true)
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
ui.label("Rounding");
|
ui.label("Corner radius");
|
||||||
ui.add(menu_rounding);
|
ui.add(menu_corner_radius);
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Shadow");
|
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 {
|
fn ui(self, ui: &mut Ui) -> Response {
|
||||||
let mut same = self.is_same();
|
let mut same = self.is_same();
|
||||||
|
|
||||||
|
|
@ -2398,37 +2403,39 @@ impl Widget for &mut Rounding {
|
||||||
|
|
||||||
let mut cr = self.nw;
|
let mut cr = self.nw;
|
||||||
ui.add(DragValue::new(&mut cr).range(0.0..=f32::INFINITY));
|
ui.add(DragValue::new(&mut cr).range(0.0..=f32::INFINITY));
|
||||||
*self = Rounding::same(cr);
|
*self = CornerRadius::same(cr);
|
||||||
})
|
})
|
||||||
.response
|
.response
|
||||||
} else {
|
} else {
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.checkbox(&mut same, "same");
|
ui.checkbox(&mut same, "same");
|
||||||
|
|
||||||
crate::Grid::new("rounding").num_columns(2).show(ui, |ui| {
|
crate::Grid::new("Corner radius")
|
||||||
ui.label("NW");
|
.num_columns(2)
|
||||||
ui.add(DragValue::new(&mut self.nw).range(0.0..=f32::INFINITY));
|
.show(ui, |ui| {
|
||||||
ui.end_row();
|
ui.label("NW");
|
||||||
|
ui.add(DragValue::new(&mut self.nw).range(0.0..=f32::INFINITY));
|
||||||
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("NE");
|
ui.label("NE");
|
||||||
ui.add(DragValue::new(&mut self.ne).range(0.0..=f32::INFINITY));
|
ui.add(DragValue::new(&mut self.ne).range(0.0..=f32::INFINITY));
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("SW");
|
ui.label("SW");
|
||||||
ui.add(DragValue::new(&mut self.sw).range(0.0..=f32::INFINITY));
|
ui.add(DragValue::new(&mut self.sw).range(0.0..=f32::INFINITY));
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("SE");
|
ui.label("SE");
|
||||||
ui.add(DragValue::new(&mut self.se).range(0.0..=f32::INFINITY));
|
ui.add(DragValue::new(&mut self.se).range(0.0..=f32::INFINITY));
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.response
|
.response
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply the checkbox:
|
// Apply the checkbox:
|
||||||
if same {
|
if same {
|
||||||
*self = Rounding::from(self.average());
|
*self = CornerRadius::from(self.average());
|
||||||
} else {
|
} else {
|
||||||
// Make sure we aren't same:
|
// Make sure we aren't same:
|
||||||
if self.is_same() {
|
if self.is_same() {
|
||||||
|
|
@ -2513,7 +2520,7 @@ impl Widget for &mut crate::Frame {
|
||||||
let crate::Frame {
|
let crate::Frame {
|
||||||
inner_margin,
|
inner_margin,
|
||||||
outer_margin,
|
outer_margin,
|
||||||
rounding,
|
corner_radius,
|
||||||
shadow,
|
shadow,
|
||||||
fill,
|
fill,
|
||||||
stroke,
|
stroke,
|
||||||
|
|
@ -2533,8 +2540,8 @@ impl Widget for &mut crate::Frame {
|
||||||
ui.push_id("outer", |ui| ui.add(outer_margin));
|
ui.push_id("outer", |ui| ui.add(outer_margin));
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Rounding");
|
ui.label("Corner radius");
|
||||||
ui.add(rounding);
|
ui.add(corner_radius);
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Shadow");
|
ui.label("Shadow");
|
||||||
|
|
|
||||||
|
|
@ -2127,7 +2127,7 @@ impl Ui {
|
||||||
/// ui.add(
|
/// ui.add(
|
||||||
/// egui::Image::new(egui::include_image!("../assets/ferris.png"))
|
/// egui::Image::new(egui::include_image!("../assets/ferris.png"))
|
||||||
/// .max_width(200.0)
|
/// .max_width(200.0)
|
||||||
/// .rounding(10.0),
|
/// .corner_radius(10),
|
||||||
/// );
|
/// );
|
||||||
/// # });
|
/// # });
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
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,
|
TextWrapMode, Ui, Vec2, Widget, WidgetInfo, WidgetText, WidgetType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ pub struct Button<'a> {
|
||||||
small: bool,
|
small: bool,
|
||||||
frame: Option<bool>,
|
frame: Option<bool>,
|
||||||
min_size: Vec2,
|
min_size: Vec2,
|
||||||
rounding: Option<Rounding>,
|
corner_radius: Option<CornerRadius>,
|
||||||
selected: bool,
|
selected: bool,
|
||||||
image_tint_follows_text_color: bool,
|
image_tint_follows_text_color: bool,
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +69,7 @@ impl<'a> Button<'a> {
|
||||||
small: false,
|
small: false,
|
||||||
frame: None,
|
frame: None,
|
||||||
min_size: Vec2::ZERO,
|
min_size: Vec2::ZERO,
|
||||||
rounding: None,
|
corner_radius: None,
|
||||||
selected: false,
|
selected: false,
|
||||||
image_tint_follows_text_color: false,
|
image_tint_follows_text_color: false,
|
||||||
}
|
}
|
||||||
|
|
@ -153,11 +153,17 @@ impl<'a> Button<'a> {
|
||||||
|
|
||||||
/// Set the rounding of the button.
|
/// Set the rounding of the button.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
|
pub fn corner_radius(mut self, corner_radius: impl Into<CornerRadius>) -> Self {
|
||||||
self.rounding = Some(rounding.into());
|
self.corner_radius = Some(corner_radius.into());
|
||||||
self
|
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.
|
/// 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.
|
/// 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,
|
small,
|
||||||
frame,
|
frame,
|
||||||
min_size,
|
min_size,
|
||||||
rounding,
|
corner_radius,
|
||||||
selected,
|
selected,
|
||||||
image_tint_follows_text_color,
|
image_tint_follows_text_color,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
@ -292,11 +298,11 @@ impl Widget for Button<'_> {
|
||||||
if ui.is_rect_visible(rect) {
|
if ui.is_rect_visible(rect) {
|
||||||
let visuals = ui.style().interact(&response);
|
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;
|
let selection = ui.visuals().selection;
|
||||||
(
|
(
|
||||||
Vec2::ZERO,
|
Vec2::ZERO,
|
||||||
Rounding::ZERO,
|
CornerRadius::ZERO,
|
||||||
selection.bg_fill,
|
selection.bg_fill,
|
||||||
selection.stroke,
|
selection.stroke,
|
||||||
)
|
)
|
||||||
|
|
@ -304,19 +310,19 @@ impl Widget for Button<'_> {
|
||||||
let expansion = Vec2::splat(visuals.expansion);
|
let expansion = Vec2::splat(visuals.expansion);
|
||||||
(
|
(
|
||||||
expansion,
|
expansion,
|
||||||
visuals.rounding,
|
visuals.corner_radius,
|
||||||
visuals.weak_bg_fill,
|
visuals.weak_bg_fill,
|
||||||
visuals.bg_stroke,
|
visuals.bg_stroke,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Default::default()
|
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_fill = fill.unwrap_or(frame_fill);
|
||||||
let frame_stroke = stroke.unwrap_or(frame_stroke);
|
let frame_stroke = stroke.unwrap_or(frame_stroke);
|
||||||
ui.painter().rect(
|
ui.painter().rect(
|
||||||
rect.expand2(frame_expansion),
|
rect.expand2(frame_expansion),
|
||||||
frame_rounding,
|
frame_cr,
|
||||||
frame_fill,
|
frame_fill,
|
||||||
frame_stroke,
|
frame_stroke,
|
||||||
epaint::StrokeKind::Inside,
|
epaint::StrokeKind::Inside,
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ impl Widget for Checkbox<'_> {
|
||||||
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::new(
|
ui.painter().add(epaint::RectShape::new(
|
||||||
big_icon_rect.expand(visuals.expansion),
|
big_icon_rect.expand(visuals.expansion),
|
||||||
visuals.rounding,
|
visuals.corner_radius,
|
||||||
visuals.bg_fill,
|
visuals.bg_fill,
|
||||||
visuals.bg_stroke,
|
visuals.bg_stroke,
|
||||||
epaint::StrokeKind::Inside,
|
epaint::StrokeKind::Inside,
|
||||||
|
|
|
||||||
|
|
@ -100,10 +100,10 @@ fn color_button(ui: &mut Ui, color: Color32, open: bool) -> Response {
|
||||||
let stroke_width = 1.0;
|
let stroke_width = 1.0;
|
||||||
show_color_at(ui.painter(), color, rect.shrink(stroke_width));
|
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(
|
ui.painter().rect_stroke(
|
||||||
rect,
|
rect,
|
||||||
rounding,
|
corner_radius,
|
||||||
(stroke_width, visuals.bg_fill), // Using fill for stroke is intentional, because default style has no border
|
(stroke_width, visuals.bg_fill), // Using fill for stroke is intentional, because default style has no border
|
||||||
StrokeKind::Inside,
|
StrokeKind::Inside,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use epaint::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
load::{Bytes, SizeHint, SizedTexture, TextureLoadResult, TexturePoll},
|
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,
|
TextStyle, TextureOptions, Ui, Vec2, Widget, WidgetInfo, WidgetType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ use crate::{
|
||||||
/// # egui::__run_test_ui(|ui| {
|
/// # egui::__run_test_ui(|ui| {
|
||||||
/// ui.add(
|
/// ui.add(
|
||||||
/// egui::Image::new(egui::include_image!("../../assets/ferris.png"))
|
/// 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| {
|
/// # egui::__run_test_ui(|ui| {
|
||||||
/// # let rect = egui::Rect::from_min_size(Default::default(), egui::Vec2::splat(100.0));
|
/// # let rect = egui::Rect::from_min_size(Default::default(), egui::Vec2::splat(100.0));
|
||||||
/// egui::Image::new(egui::include_image!("../../assets/ferris.png"))
|
/// egui::Image::new(egui::include_image!("../../assets/ferris.png"))
|
||||||
/// .rounding(5.0)
|
/// .corner_radius(5)
|
||||||
/// .tint(egui::Color32::LIGHT_BLUE)
|
/// .tint(egui::Color32::LIGHT_BLUE)
|
||||||
/// .paint_at(ui, rect);
|
/// .paint_at(ui, rect);
|
||||||
/// # });
|
/// # });
|
||||||
|
|
@ -233,25 +233,37 @@ impl<'a> Image<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rotate(mut self, angle: f32, origin: Vec2) -> Self {
|
pub fn rotate(mut self, angle: f32, origin: Vec2) -> Self {
|
||||||
self.image_options.rotation = Some((Rot2::from_angle(angle), origin));
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Round the corners of the image.
|
/// 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,
|
/// Due to limitations in the current implementation,
|
||||||
/// this will turn off any rotation of the image.
|
/// this will turn off any rotation of the image.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
|
pub fn corner_radius(mut self, corner_radius: impl Into<CornerRadius>) -> Self {
|
||||||
self.image_options.rounding = rounding.into();
|
self.image_options.corner_radius = corner_radius.into();
|
||||||
if self.image_options.rounding != Rounding::ZERO {
|
if self.image_options.corner_radius != CornerRadius::ZERO {
|
||||||
self.image_options.rotation = None; // incompatible with rounding
|
self.image_options.rotation = None; // incompatible with rounding
|
||||||
}
|
}
|
||||||
self
|
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.
|
/// Show a spinner when the image is loading.
|
||||||
///
|
///
|
||||||
/// By default this uses the value of [`crate::Visuals::image_loading_spinners`].
|
/// 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| {
|
/// # egui::__run_test_ui(|ui| {
|
||||||
/// # let rect = egui::Rect::from_min_size(Default::default(), egui::Vec2::splat(100.0));
|
/// # let rect = egui::Rect::from_min_size(Default::default(), egui::Vec2::splat(100.0));
|
||||||
/// egui::Image::new(egui::include_image!("../../assets/ferris.png"))
|
/// egui::Image::new(egui::include_image!("../../assets/ferris.png"))
|
||||||
/// .rounding(5.0)
|
/// .corner_radius(5)
|
||||||
/// .tint(egui::Color32::LIGHT_BLUE)
|
/// .tint(egui::Color32::LIGHT_BLUE)
|
||||||
/// .paint_at(ui, rect);
|
/// .paint_at(ui, rect);
|
||||||
/// # });
|
/// # });
|
||||||
|
|
@ -778,11 +790,11 @@ pub struct ImageOptions {
|
||||||
|
|
||||||
/// Round the corners of the image.
|
/// 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,
|
/// Due to limitations in the current implementation,
|
||||||
/// this will turn off any rotation of the image.
|
/// this will turn off any rotation of the image.
|
||||||
pub rounding: Rounding,
|
pub corner_radius: CornerRadius,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ImageOptions {
|
impl Default for ImageOptions {
|
||||||
|
|
@ -792,7 +804,7 @@ impl Default for ImageOptions {
|
||||||
bg_fill: Default::default(),
|
bg_fill: Default::default(),
|
||||||
tint: Color32::WHITE,
|
tint: Color32::WHITE,
|
||||||
rotation: None,
|
rotation: None,
|
||||||
rounding: Rounding::ZERO,
|
corner_radius: CornerRadius::ZERO,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -804,7 +816,11 @@ pub fn paint_texture_at(
|
||||||
texture: &SizedTexture,
|
texture: &SizedTexture,
|
||||||
) {
|
) {
|
||||||
if options.bg_fill != Default::default() {
|
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 {
|
match options.rotation {
|
||||||
|
|
@ -812,7 +828,7 @@ pub fn paint_texture_at(
|
||||||
// TODO(emilk): implement this using `PathShape` (add texture support to it).
|
// TODO(emilk): implement this using `PathShape` (add texture support to it).
|
||||||
// This will also give us anti-aliasing of rotated images.
|
// This will also give us anti-aliasing of rotated images.
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
options.rounding == Rounding::ZERO,
|
options.corner_radius == CornerRadius::ZERO,
|
||||||
"Image had both rounding and rotation. Please pick only one"
|
"Image had both rounding and rotation. Please pick only one"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -823,7 +839,7 @@ pub fn paint_texture_at(
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
painter.add(
|
painter.add(
|
||||||
RectShape::filled(rect, options.rounding, options.tint)
|
RectShape::filled(rect, options.corner_radius, options.tint)
|
||||||
.with_texture(texture.id, options.uv),
|
.with_texture(texture.id, options.uv),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
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,
|
WidgetType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -62,13 +62,24 @@ impl<'a> ImageButton<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set rounding for the `ImageButton`.
|
/// Set rounding for the `ImageButton`.
|
||||||
|
///
|
||||||
/// If the underlying image already has rounding, this
|
/// If the underlying image already has rounding, this
|
||||||
/// will override that value.
|
/// will override that value.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
|
pub fn corner_radius(mut self, corner_radius: impl Into<CornerRadius>) -> Self {
|
||||||
self.image = self.image.rounding(rounding.into());
|
self.image = self.image.corner_radius(corner_radius.into());
|
||||||
self
|
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<'_> {
|
impl Widget for ImageButton<'_> {
|
||||||
|
|
@ -100,7 +111,7 @@ impl Widget for ImageButton<'_> {
|
||||||
let selection = ui.visuals().selection;
|
let selection = ui.visuals().selection;
|
||||||
(
|
(
|
||||||
Vec2::ZERO,
|
Vec2::ZERO,
|
||||||
self.image.image_options().rounding,
|
self.image.image_options().corner_radius,
|
||||||
selection.bg_fill,
|
selection.bg_fill,
|
||||||
selection.stroke,
|
selection.stroke,
|
||||||
)
|
)
|
||||||
|
|
@ -109,7 +120,7 @@ impl Widget for ImageButton<'_> {
|
||||||
let expansion = Vec2::splat(visuals.expansion);
|
let expansion = Vec2::splat(visuals.expansion);
|
||||||
(
|
(
|
||||||
expansion,
|
expansion,
|
||||||
self.image.image_options().rounding,
|
self.image.image_options().corner_radius,
|
||||||
visuals.weak_bg_fill,
|
visuals.weak_bg_fill,
|
||||||
visuals.bg_stroke,
|
visuals.bg_stroke,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
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,
|
TextStyle, TextWrapMode, Ui, Vec2, Widget, WidgetInfo, WidgetText, WidgetType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ pub struct ProgressBar {
|
||||||
text: Option<ProgressBarText>,
|
text: Option<ProgressBarText>,
|
||||||
fill: Option<Color32>,
|
fill: Option<Color32>,
|
||||||
animate: bool,
|
animate: bool,
|
||||||
rounding: Option<Rounding>,
|
corner_radius: Option<CornerRadius>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProgressBar {
|
impl ProgressBar {
|
||||||
|
|
@ -32,7 +32,7 @@ impl ProgressBar {
|
||||||
text: None,
|
text: None,
|
||||||
fill: None,
|
fill: None,
|
||||||
animate: false,
|
animate: false,
|
||||||
rounding: None,
|
corner_radius: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ impl ProgressBar {
|
||||||
/// Note that this will cause the UI to be redrawn.
|
/// Note that this will cause the UI to be redrawn.
|
||||||
/// Defaults to `false`.
|
/// 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
|
/// rendered, since it requires a perfect circle to render correctly. However, the UI is still
|
||||||
/// redrawn.
|
/// redrawn.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
@ -86,14 +86,20 @@ impl ProgressBar {
|
||||||
|
|
||||||
/// Set the rounding of the progress bar.
|
/// 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
|
/// rendered, since it requires a perfect circle to render correctly. However, the UI is still
|
||||||
/// redrawn.
|
/// redrawn.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rounding(mut self, rounding: impl Into<Rounding>) -> Self {
|
pub fn corner_radius(mut self, corner_radius: impl Into<CornerRadius>) -> Self {
|
||||||
self.rounding = Some(rounding.into());
|
self.corner_radius = Some(corner_radius.into());
|
||||||
self
|
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 {
|
impl Widget for ProgressBar {
|
||||||
|
|
@ -105,7 +111,7 @@ impl Widget for ProgressBar {
|
||||||
text,
|
text,
|
||||||
fill,
|
fill,
|
||||||
animate,
|
animate,
|
||||||
rounding,
|
corner_radius,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let animate = animate && progress < 1.0;
|
let animate = animate && progress < 1.0;
|
||||||
|
|
@ -133,13 +139,13 @@ impl Widget for ProgressBar {
|
||||||
}
|
}
|
||||||
|
|
||||||
let visuals = ui.style().visuals.clone();
|
let visuals = ui.style().visuals.clone();
|
||||||
let is_custom_rounding = rounding.is_some();
|
let has_custom_cr = corner_radius.is_some();
|
||||||
let corner_radius = outer_rect.height() / 2.0;
|
let half_height = outer_rect.height() / 2.0;
|
||||||
let rounding = rounding.unwrap_or_else(|| corner_radius.into());
|
let corner_radius = corner_radius.unwrap_or_else(|| half_height.into());
|
||||||
ui.painter()
|
ui.painter()
|
||||||
.rect_filled(outer_rect, rounding, visuals.extreme_bg_color);
|
.rect_filled(outer_rect, corner_radius, visuals.extreme_bg_color);
|
||||||
let min_width =
|
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 filled_width = (outer_rect.width() * progress).at_least(min_width);
|
||||||
let inner_rect =
|
let inner_rect =
|
||||||
Rect::from_min_size(outer_rect.min, vec2(filled_width, outer_rect.height()));
|
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(
|
ui.painter().rect_filled(
|
||||||
inner_rect,
|
inner_rect,
|
||||||
rounding,
|
corner_radius,
|
||||||
Color32::from(
|
Color32::from(
|
||||||
Rgba::from(fill.unwrap_or(visuals.selection.bg_fill)) * color_factor as f32,
|
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 n_points = 20;
|
||||||
let time = ui.input(|i| i.time);
|
let time = ui.input(|i| i.time);
|
||||||
let start_angle = time * std::f64::consts::TAU;
|
let start_angle = time * std::f64::consts::TAU;
|
||||||
let end_angle = start_angle + 240f64.to_radians() * time.sin();
|
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)
|
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(-half_height, 0.0)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
ui.painter()
|
ui.painter()
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ impl Widget for SelectableLabel {
|
||||||
|
|
||||||
ui.painter().rect(
|
ui.painter().rect(
|
||||||
rect,
|
rect,
|
||||||
visuals.rounding,
|
visuals.corner_radius,
|
||||||
visuals.weak_bg_fill,
|
visuals.weak_bg_fill,
|
||||||
visuals.bg_stroke,
|
visuals.bg_stroke,
|
||||||
epaint::StrokeKind::Inside,
|
epaint::StrokeKind::Inside,
|
||||||
|
|
|
||||||
|
|
@ -760,10 +760,10 @@ impl Slider<'_> {
|
||||||
|
|
||||||
let rail_radius = (spacing.slider_rail_height / 2.0).at_least(0.0);
|
let rail_radius = (spacing.slider_rail_height / 2.0).at_least(0.0);
|
||||||
let rail_rect = self.rail_rect(rect, rail_radius);
|
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()
|
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 position_1d = self.position_from_value(value, position_range);
|
||||||
let center = self.marker_center(position_1d, &rail_rect);
|
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.
|
// The trailing rect has to be drawn differently depending on the orientation.
|
||||||
match self.orientation {
|
match self.orientation {
|
||||||
SliderOrientation::Horizontal => {
|
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 => {
|
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(
|
ui.painter().rect_filled(
|
||||||
trailing_rail_rect,
|
trailing_rail_rect,
|
||||||
rounding,
|
corner_radius,
|
||||||
ui.visuals().selection.bg_fill,
|
ui.visuals().selection.bg_fill,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -817,7 +817,7 @@ impl Slider<'_> {
|
||||||
let rect = Rect::from_center_size(center, 2.0 * v);
|
let rect = Rect::from_center_size(center, 2.0 * v);
|
||||||
ui.painter().rect(
|
ui.painter().rect(
|
||||||
rect,
|
rect,
|
||||||
visuals.rounding,
|
visuals.corner_radius,
|
||||||
visuals.bg_fill,
|
visuals.bg_fill,
|
||||||
visuals.fg_stroke,
|
visuals.fg_stroke,
|
||||||
epaint::StrokeKind::Inside,
|
epaint::StrokeKind::Inside,
|
||||||
|
|
|
||||||
|
|
@ -442,7 +442,7 @@ impl TextEdit<'_> {
|
||||||
if output.response.has_focus() {
|
if output.response.has_focus() {
|
||||||
epaint::RectShape::new(
|
epaint::RectShape::new(
|
||||||
frame_rect,
|
frame_rect,
|
||||||
visuals.rounding,
|
visuals.corner_radius,
|
||||||
background_color,
|
background_color,
|
||||||
ui.visuals().selection.stroke,
|
ui.visuals().selection.stroke,
|
||||||
StrokeKind::Inside,
|
StrokeKind::Inside,
|
||||||
|
|
@ -450,7 +450,7 @@ impl TextEdit<'_> {
|
||||||
} else {
|
} else {
|
||||||
epaint::RectShape::new(
|
epaint::RectShape::new(
|
||||||
frame_rect,
|
frame_rect,
|
||||||
visuals.rounding,
|
visuals.corner_radius,
|
||||||
background_color,
|
background_color,
|
||||||
visuals.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop".
|
visuals.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop".
|
||||||
StrokeKind::Inside,
|
StrokeKind::Inside,
|
||||||
|
|
@ -460,7 +460,7 @@ impl TextEdit<'_> {
|
||||||
let visuals = &ui.style().visuals.widgets.inactive;
|
let visuals = &ui.style().visuals.widgets.inactive;
|
||||||
epaint::RectShape::stroke(
|
epaint::RectShape::stroke(
|
||||||
frame_rect,
|
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".
|
visuals.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop".
|
||||||
StrokeKind::Inside,
|
StrokeKind::Inside,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,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::new(
|
shapes.push(Shape::Rect(epaint::RectShape::new(
|
||||||
rect,
|
rect,
|
||||||
style.rounding,
|
style.corner_radius,
|
||||||
ui.visuals().extreme_bg_color,
|
ui.visuals().extreme_bg_color,
|
||||||
ui.style().noninteractive().bg_stroke,
|
ui.style().noninteractive().bg_stroke,
|
||||||
egui::StrokeKind::Inside,
|
egui::StrokeKind::Inside,
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ impl eframe::App for FractalClockApp {
|
||||||
.frame(
|
.frame(
|
||||||
egui::Frame::dark_canvas(&ctx.style())
|
egui::Frame::dark_canvas(&ctx.style())
|
||||||
.stroke(egui::Stroke::NONE)
|
.stroke(egui::Stroke::NONE)
|
||||||
.rounding(0),
|
.corner_radius(0),
|
||||||
)
|
)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
self.fractal_clock
|
self.fractal_clock
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ impl Default for FrameDemo {
|
||||||
frame: egui::Frame::new()
|
frame: egui::Frame::new()
|
||||||
.inner_margin(12)
|
.inner_margin(12)
|
||||||
.outer_margin(24)
|
.outer_margin(24)
|
||||||
.rounding(14)
|
.corner_radius(14)
|
||||||
.shadow(egui::Shadow {
|
.shadow(egui::Shadow {
|
||||||
offset: [8, 12],
|
offset: [8, 12],
|
||||||
blur: 16,
|
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:
|
// We want to paint a background around the outer margin of the demonstration frame, so we use another frame around it:
|
||||||
egui::Frame::default()
|
egui::Frame::default()
|
||||||
.stroke(ui.visuals().widgets.noninteractive.bg_stroke)
|
.stroke(ui.visuals().widgets.noninteractive.bg_stroke)
|
||||||
.rounding(ui.visuals().widgets.noninteractive.rounding)
|
.corner_radius(ui.visuals().widgets.noninteractive.corner_radius)
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
self.frame.show(ui, |ui| {
|
self.frame.show(ui, |ui| {
|
||||||
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
|
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);
|
||||||
|
|
|
||||||
|
|
@ -358,7 +358,7 @@ impl ColorWidgets {
|
||||||
#[cfg_attr(feature = "serde", serde(default))]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
struct BoxPainting {
|
struct BoxPainting {
|
||||||
size: Vec2,
|
size: Vec2,
|
||||||
rounding: f32,
|
corner_radius: f32,
|
||||||
stroke_width: f32,
|
stroke_width: f32,
|
||||||
num_boxes: usize,
|
num_boxes: usize,
|
||||||
}
|
}
|
||||||
|
|
@ -367,7 +367,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),
|
||||||
rounding: 5.0,
|
corner_radius: 5.0,
|
||||||
stroke_width: 2.0,
|
stroke_width: 2.0,
|
||||||
num_boxes: 1,
|
num_boxes: 1,
|
||||||
}
|
}
|
||||||
|
|
@ -378,7 +378,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.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.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"));
|
||||||
|
|
||||||
|
|
@ -387,7 +387,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.rounding,
|
self.corner_radius,
|
||||||
ui.visuals().text_color().gamma_multiply(0.5),
|
ui.visuals().text_color().gamma_multiply(0.5),
|
||||||
Stroke::new(self.stroke_width, Color32::WHITE),
|
Stroke::new(self.stroke_width, Color32::WHITE),
|
||||||
egui::StrokeKind::Inside,
|
egui::StrokeKind::Inside,
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,7 @@ fn rect_shape_ui(ui: &mut egui::Ui, shape: &mut RectShape) {
|
||||||
|
|
||||||
let RectShape {
|
let RectShape {
|
||||||
rect,
|
rect,
|
||||||
rounding,
|
corner_radius,
|
||||||
fill,
|
fill,
|
||||||
stroke,
|
stroke,
|
||||||
stroke_kind,
|
stroke_kind,
|
||||||
|
|
@ -304,8 +304,8 @@ fn rect_shape_ui(ui: &mut egui::Ui, shape: &mut RectShape) {
|
||||||
});
|
});
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Rounding");
|
ui.label("Corner radius");
|
||||||
ui.add(rounding);
|
ui.add(corner_radius);
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Fill");
|
ui.label("Fill");
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:f90f94a842a1d0f1386c3cdd28e60e6ad6efe968f510a11bde418b5bc70a81d2
|
oid sha256:244d539111e994a4ed2aa95a2b4d0ff12b948e21843c8a1dddcf54cbb388f1aa
|
||||||
size 23897
|
size 24280
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:c39868f184364555ae90fbfc035aa668f61189be7aeee6bec4e45a8de438ad8e
|
oid sha256:daa5ec4ddd2f983c4b9f2b0a73c973f58abcb186fbd0d68a9fd0ce7173e5d4e7
|
||||||
size 87661
|
size 88031
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:dd029fdc49e6d4078337472c39b9d58bf69073c1b7750c6dd1b7ccd450d52395
|
oid sha256:c09af9c7f4297e2d5b2305366ed57b3203807ca2426314acdf836e25f154d8eb
|
||||||
size 119869
|
size 120244
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:e698ba12efd129099877248f9630ba983d683e1b495b2523ed3569989341e905
|
oid sha256:f621bcf7c8fd18156bef2428ab3b9994e6a4d475ae589eb734d50f9a4f3383bd
|
||||||
size 51735
|
size 52101
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:18b81b5cd88372b65b1ecc62e9a5e894960279310b05a1bd5c8df5bffa244ad0
|
oid sha256:f1476e105a3e9c1ff7b2f4a82481462795e4708e3fcf6d495a042faae537184e
|
||||||
size 54922
|
size 55298
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:bf5df173431d330e4b6045a72227c2bb7613ec98c63f013ea899a3a57cd6617a
|
oid sha256:695a731d9e302db2c5b7f4a0ef44794cf55eb0be093c070b8ffaeb28121569bc
|
||||||
size 55522
|
size 55888
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:987c162842a08271e833c41a55573d9f30cf045bf7ca3cb03e81d0cc13d5a16e
|
oid sha256:854c12c69b31c0c82a9596d167772e00d7a051600e4151535e2cec04491e57a6
|
||||||
size 36763
|
size 37139
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:8c5c3055cd190823a4204aa6f23362a88bc5ab5ed5453d9be1b6077dded6cd54
|
oid sha256:1aacb27847c2e942d56d60e4b72797d93f7265a6effe4e47437e1314e6477e6f
|
||||||
size 36809
|
size 37184
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ impl<'l> StripLayout<'l> {
|
||||||
if flags.striped {
|
if flags.striped {
|
||||||
self.ui.painter().rect_filled(
|
self.ui.painter().rect_filled(
|
||||||
gapless_rect,
|
gapless_rect,
|
||||||
egui::Rounding::ZERO,
|
egui::CornerRadius::ZERO,
|
||||||
self.ui.visuals().faint_bg_color,
|
self.ui.visuals().faint_bg_color,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +136,7 @@ impl<'l> StripLayout<'l> {
|
||||||
if flags.selected {
|
if flags.selected {
|
||||||
self.ui.painter().rect_filled(
|
self.ui.painter().rect_filled(
|
||||||
gapless_rect,
|
gapless_rect,
|
||||||
egui::Rounding::ZERO,
|
egui::CornerRadius::ZERO,
|
||||||
self.ui.visuals().selection.bg_fill,
|
self.ui.visuals().selection.bg_fill,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +144,7 @@ impl<'l> StripLayout<'l> {
|
||||||
if flags.hovered && !flags.selected && self.sense.interactive() {
|
if flags.hovered && !flags.selected && self.sense.interactive() {
|
||||||
self.ui.painter().rect_filled(
|
self.ui.painter().rect_filled(
|
||||||
gapless_rect,
|
gapless_rect,
|
||||||
egui::Rounding::ZERO,
|
egui::CornerRadius::ZERO,
|
||||||
self.ui.visuals().widgets.hovered.bg_fill,
|
self.ui.visuals().widgets.hovered.bg_fill,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@
|
||||||
/// The rounding uses `u8` to save space,
|
/// The rounding uses `u8` to save space,
|
||||||
/// so the amount of rounding is limited to integers in the range `[0, 255]`.
|
/// 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)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[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.
|
/// Radius of the rounding of the North-West (left top) corner.
|
||||||
pub nw: u8,
|
pub nw: u8,
|
||||||
|
|
||||||
|
|
@ -24,28 +24,28 @@ pub struct Rounding {
|
||||||
pub se: u8,
|
pub se: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Rounding {
|
impl Default for CornerRadius {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::ZERO
|
Self::ZERO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u8> for Rounding {
|
impl From<u8> for CornerRadius {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(radius: u8) -> Self {
|
fn from(radius: u8) -> Self {
|
||||||
Self::same(radius)
|
Self::same(radius)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<f32> for Rounding {
|
impl From<f32> for CornerRadius {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(radius: f32) -> Self {
|
fn from(radius: f32) -> Self {
|
||||||
Self::same(radius.round() as u8)
|
Self::same(radius.round() as u8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rounding {
|
impl CornerRadius {
|
||||||
/// No rounding on any corner.
|
/// No rounding on any corner.
|
||||||
pub const ZERO: Self = Self {
|
pub const ZERO: Self = Self {
|
||||||
nw: 0,
|
nw: 0,
|
||||||
|
|
@ -99,7 +99,7 @@ impl Rounding {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Add for Rounding {
|
impl std::ops::Add for CornerRadius {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add(self, rhs: Self) -> Self {
|
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;
|
type Output = Self;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add(self, rhs: u8) -> Self {
|
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]
|
#[inline]
|
||||||
fn add_assign(&mut self, rhs: Self) {
|
fn add_assign(&mut self, rhs: Self) {
|
||||||
*self = 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]
|
#[inline]
|
||||||
fn add_assign(&mut self, rhs: u8) {
|
fn add_assign(&mut self, rhs: u8) {
|
||||||
*self = Self {
|
*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;
|
type Output = Self;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(self, rhs: Self) -> Self {
|
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;
|
type Output = Self;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(self, rhs: u8) -> Self {
|
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]
|
#[inline]
|
||||||
fn sub_assign(&mut self, rhs: Self) {
|
fn sub_assign(&mut self, rhs: Self) {
|
||||||
*self = 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]
|
#[inline]
|
||||||
fn sub_assign(&mut self, rhs: u8) {
|
fn sub_assign(&mut self, rhs: u8) {
|
||||||
*self = Self {
|
*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;
|
type Output = Self;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn div(self, rhs: f32) -> Self {
|
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]
|
#[inline]
|
||||||
fn div_assign(&mut self, rhs: f32) {
|
fn div_assign(&mut self, rhs: f32) {
|
||||||
*self = Self {
|
*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;
|
type Output = Self;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn mul(self, rhs: f32) -> Self {
|
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]
|
#[inline]
|
||||||
fn mul_assign(&mut self, rhs: f32) {
|
fn mul_assign(&mut self, rhs: f32) {
|
||||||
*self = Self {
|
*self = Self {
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use crate::Rounding;
|
use crate::CornerRadius;
|
||||||
|
|
||||||
/// How rounded the corners of things should be, in `f32`.
|
/// 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)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[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.
|
/// Radius of the rounding of the North-West (left top) corner.
|
||||||
pub nw: f32,
|
pub nw: f32,
|
||||||
|
|
||||||
|
|
@ -19,38 +19,38 @@ pub struct Roundingf {
|
||||||
pub se: f32,
|
pub se: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Rounding> for Roundingf {
|
impl From<CornerRadius> for CornerRadiusF32 {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(rounding: Rounding) -> Self {
|
fn from(cr: CornerRadius) -> Self {
|
||||||
Self {
|
Self {
|
||||||
nw: rounding.nw as f32,
|
nw: cr.nw as f32,
|
||||||
ne: rounding.ne as f32,
|
ne: cr.ne as f32,
|
||||||
sw: rounding.sw as f32,
|
sw: cr.sw as f32,
|
||||||
se: rounding.se as f32,
|
se: cr.se as f32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Roundingf> for Rounding {
|
impl From<CornerRadiusF32> for CornerRadius {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(rounding: Roundingf) -> Self {
|
fn from(cr: CornerRadiusF32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
nw: rounding.nw.round() as u8,
|
nw: cr.nw.round() as u8,
|
||||||
ne: rounding.ne.round() as u8,
|
ne: cr.ne.round() as u8,
|
||||||
sw: rounding.sw.round() as u8,
|
sw: cr.sw.round() as u8,
|
||||||
se: rounding.se.round() as u8,
|
se: cr.se.round() as u8,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Roundingf {
|
impl Default for CornerRadiusF32 {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::ZERO
|
Self::ZERO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<f32> for Roundingf {
|
impl From<f32> for CornerRadiusF32 {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(radius: f32) -> Self {
|
fn from(radius: f32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -62,7 +62,7 @@ impl From<f32> for Roundingf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Roundingf {
|
impl CornerRadiusF32 {
|
||||||
/// No rounding on any corner.
|
/// No rounding on any corner.
|
||||||
pub const ZERO: Self = Self {
|
pub const ZERO: Self = Self {
|
||||||
nw: 0.0,
|
nw: 0.0,
|
||||||
|
|
@ -111,7 +111,7 @@ impl Roundingf {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Add for Roundingf {
|
impl std::ops::Add for CornerRadiusF32 {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add(self, rhs: Self) -> Self {
|
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]
|
#[inline]
|
||||||
fn add_assign(&mut self, rhs: Self) {
|
fn add_assign(&mut self, rhs: Self) {
|
||||||
*self = 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]
|
#[inline]
|
||||||
fn add_assign(&mut self, rhs: f32) {
|
fn add_assign(&mut self, rhs: f32) {
|
||||||
*self = Self {
|
*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;
|
type Output = Self;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn sub(self, rhs: Self) -> Self {
|
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]
|
#[inline]
|
||||||
fn sub_assign(&mut self, rhs: Self) {
|
fn sub_assign(&mut self, rhs: Self) {
|
||||||
*self = 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]
|
#[inline]
|
||||||
fn sub_assign(&mut self, rhs: f32) {
|
fn sub_assign(&mut self, rhs: f32) {
|
||||||
*self = Self {
|
*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;
|
type Output = Self;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn div(self, rhs: f32) -> Self {
|
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]
|
#[inline]
|
||||||
fn div_assign(&mut self, rhs: f32) {
|
fn div_assign(&mut self, rhs: f32) {
|
||||||
*self = Self {
|
*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;
|
type Output = Self;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn mul(self, rhs: f32) -> Self {
|
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]
|
#[inline]
|
||||||
fn mul_assign(&mut self, rhs: f32) {
|
fn mul_assign(&mut self, rhs: f32) {
|
||||||
*self = Self {
|
*self = Self {
|
||||||
|
|
@ -25,13 +25,13 @@
|
||||||
|
|
||||||
mod brush;
|
mod brush;
|
||||||
pub mod color;
|
pub mod color;
|
||||||
|
mod corner_radius;
|
||||||
|
mod corner_radius_f32;
|
||||||
pub mod image;
|
pub mod image;
|
||||||
mod margin;
|
mod margin;
|
||||||
mod marginf;
|
mod marginf;
|
||||||
mod mesh;
|
mod mesh;
|
||||||
pub mod mutex;
|
pub mod mutex;
|
||||||
mod rounding;
|
|
||||||
mod roundingf;
|
|
||||||
mod shadow;
|
mod shadow;
|
||||||
pub mod shape_transform;
|
pub mod shape_transform;
|
||||||
mod shapes;
|
mod shapes;
|
||||||
|
|
@ -48,12 +48,12 @@ mod viewport;
|
||||||
pub use self::{
|
pub use self::{
|
||||||
brush::Brush,
|
brush::Brush,
|
||||||
color::ColorMode,
|
color::ColorMode,
|
||||||
|
corner_radius::CornerRadius,
|
||||||
|
corner_radius_f32::CornerRadiusF32,
|
||||||
image::{ColorImage, FontImage, ImageData, ImageDelta},
|
image::{ColorImage, FontImage, ImageData, ImageDelta},
|
||||||
margin::Margin,
|
margin::Margin,
|
||||||
marginf::Marginf,
|
marginf::Marginf,
|
||||||
mesh::{Mesh, Mesh16, Vertex},
|
mesh::{Mesh, Mesh16, Vertex},
|
||||||
rounding::Rounding,
|
|
||||||
roundingf::Roundingf,
|
|
||||||
shadow::Shadow,
|
shadow::Shadow,
|
||||||
shapes::{
|
shapes::{
|
||||||
CircleShape, CubicBezierShape, EllipseShape, PaintCallback, PaintCallbackInfo, PathShape,
|
CircleShape, CubicBezierShape, EllipseShape, PaintCallback, PaintCallbackInfo, PathShape,
|
||||||
|
|
@ -69,6 +69,9 @@ pub use self::{
|
||||||
viewport::ViewportInPixels,
|
viewport::ViewportInPixels,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[deprecated = "Renamed to CornerRadius"]
|
||||||
|
pub type Rounding = CornerRadius;
|
||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
pub use tessellator::tessellate_shapes;
|
pub use tessellator::tessellate_shapes;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
/// The color and fuzziness of a fuzzy shape.
|
||||||
///
|
///
|
||||||
|
|
@ -44,7 +44,7 @@ impl Shadow {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The argument is the rectangle of the shadow caster.
|
/// 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
|
// tessellator.clip_rect = clip_rect; // TODO(emilk): culling
|
||||||
|
|
||||||
let Self {
|
let Self {
|
||||||
|
|
@ -58,9 +58,9 @@ impl Shadow {
|
||||||
let rect = rect
|
let rect = rect
|
||||||
.translate(Vec2::new(offset_x as _, offset_y as _))
|
.translate(Vec2::new(offset_x as _, offset_y as _))
|
||||||
.expand(spread 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?
|
/// How much larger than the parent rect are we in each direction?
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ pub fn adjust_colors(
|
||||||
})
|
})
|
||||||
| Shape::Rect(RectShape {
|
| Shape::Rect(RectShape {
|
||||||
rect: _,
|
rect: _,
|
||||||
rounding: _,
|
corner_radius: _,
|
||||||
fill,
|
fill,
|
||||||
stroke,
|
stroke,
|
||||||
stroke_kind: _,
|
stroke_kind: _,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ pub struct RectShape {
|
||||||
|
|
||||||
/// How rounded the corners of the rectangle are.
|
/// 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.
|
/// This is the corner radii of the rectangle.
|
||||||
/// If there is a stroke, then the stroke will have an inner and outer corner radius,
|
/// 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,
|
/// For [`StrokeKind::Inside`], the outside of the stroke coincides with the rectangle,
|
||||||
/// so the rounding will in this case specify the outer corner radius.
|
/// so the rounding will in this case specify the outer corner radius.
|
||||||
pub rounding: Rounding,
|
pub corner_radius: CornerRadius,
|
||||||
|
|
||||||
/// How to fill the rectangle.
|
/// How to fill the rectangle.
|
||||||
pub fill: Color32,
|
pub fill: Color32,
|
||||||
|
|
@ -73,14 +73,14 @@ impl RectShape {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
rounding: impl Into<Rounding>,
|
corner_radius: impl Into<CornerRadius>,
|
||||||
fill_color: impl Into<Color32>,
|
fill_color: impl Into<Color32>,
|
||||||
stroke: impl Into<Stroke>,
|
stroke: impl Into<Stroke>,
|
||||||
stroke_kind: StrokeKind,
|
stroke_kind: StrokeKind,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
rect,
|
rect,
|
||||||
rounding: rounding.into(),
|
corner_radius: corner_radius.into(),
|
||||||
fill: fill_color.into(),
|
fill: fill_color.into(),
|
||||||
stroke: stroke.into(),
|
stroke: stroke.into(),
|
||||||
stroke_kind,
|
stroke_kind,
|
||||||
|
|
@ -93,12 +93,12 @@ impl RectShape {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn filled(
|
pub fn filled(
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
rounding: impl Into<Rounding>,
|
corner_radius: impl Into<CornerRadius>,
|
||||||
fill_color: impl Into<Color32>,
|
fill_color: impl Into<Color32>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new(
|
Self::new(
|
||||||
rect,
|
rect,
|
||||||
rounding,
|
corner_radius,
|
||||||
fill_color,
|
fill_color,
|
||||||
Stroke::NONE,
|
Stroke::NONE,
|
||||||
StrokeKind::Outside, // doesn't matter
|
StrokeKind::Outside, // doesn't matter
|
||||||
|
|
@ -108,12 +108,12 @@ impl RectShape {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn stroke(
|
pub fn stroke(
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
rounding: impl Into<Rounding>,
|
corner_radius: impl Into<CornerRadius>,
|
||||||
stroke: impl Into<Stroke>,
|
stroke: impl Into<Stroke>,
|
||||||
stroke_kind: StrokeKind,
|
stroke_kind: StrokeKind,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let fill = Color32::TRANSPARENT;
|
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.
|
/// Set if the stroke is on the inside, outside, or centered on the rectangle.
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use emath::{pos2, Align2, Pos2, Rangef, Rect, TSTransform, Vec2};
|
||||||
use crate::{
|
use crate::{
|
||||||
stroke::PathStroke,
|
stroke::PathStroke,
|
||||||
text::{FontId, Fonts, Galley},
|
text::{FontId, Fonts, Galley},
|
||||||
Color32, Mesh, Rounding, Stroke, StrokeKind, TextureId,
|
Color32, CornerRadius, Mesh, Stroke, StrokeKind, TextureId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
|
@ -279,21 +279,21 @@ impl Shape {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rect_filled(
|
pub fn rect_filled(
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
rounding: impl Into<Rounding>,
|
corner_radius: impl Into<CornerRadius>,
|
||||||
fill_color: impl Into<Color32>,
|
fill_color: impl Into<Color32>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::Rect(RectShape::filled(rect, rounding, fill_color))
|
Self::Rect(RectShape::filled(rect, corner_radius, fill_color))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// See also [`Self::rect_filled`].
|
/// See also [`Self::rect_filled`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn rect_stroke(
|
pub fn rect_stroke(
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
rounding: impl Into<Rounding>,
|
corner_radius: impl Into<CornerRadius>,
|
||||||
stroke: impl Into<Stroke>,
|
stroke: impl Into<Stroke>,
|
||||||
stroke_kind: StrokeKind,
|
stroke_kind: StrokeKind,
|
||||||
) -> Self {
|
) -> 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)]
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
|
|
@ -451,7 +451,7 @@ impl Shape {
|
||||||
}
|
}
|
||||||
Self::Rect(rect_shape) => {
|
Self::Rect(rect_shape) => {
|
||||||
rect_shape.rect = transform * rect_shape.rect;
|
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.stroke.width *= transform.scaling;
|
||||||
rect_shape.blur_width *= transform.scaling;
|
rect_shape.blur_width *= transform.scaling;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ use emath::{pos2, remap, vec2, GuiRounding as _, NumExt, Pos2, Rect, Rot2, Vec2}
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
color::ColorMode, emath, stroke::PathStroke, texture_atlas::PreparedDisc, CircleShape,
|
color::ColorMode, emath, stroke::PathStroke, texture_atlas::PreparedDisc, CircleShape,
|
||||||
ClippedPrimitive, ClippedShape, Color32, CubicBezierShape, EllipseShape, Mesh, PathShape,
|
ClippedPrimitive, ClippedShape, Color32, CornerRadiusF32, CubicBezierShape, EllipseShape, Mesh,
|
||||||
Primitive, QuadraticBezierShape, RectShape, Roundingf, Shape, Stroke, StrokeKind, TextShape,
|
PathShape, Primitive, QuadraticBezierShape, RectShape, Shape, Stroke, StrokeKind, TextShape,
|
||||||
TextureId, Vertex, WHITE_UV,
|
TextureId, Vertex, WHITE_UV,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -534,19 +534,19 @@ impl Path {
|
||||||
|
|
||||||
pub mod path {
|
pub mod path {
|
||||||
//! Helpers for constructing paths
|
//! Helpers for constructing paths
|
||||||
use crate::Roundingf;
|
use crate::CornerRadiusF32;
|
||||||
use emath::{pos2, Pos2, Rect};
|
use emath::{pos2, Pos2, Rect};
|
||||||
|
|
||||||
/// overwrites existing points
|
/// 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();
|
path.clear();
|
||||||
|
|
||||||
let min = rect.min;
|
let min = rect.min;
|
||||||
let max = rect.max;
|
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.reserve(4);
|
||||||
path.push(pos2(min.x, min.y)); // left top
|
path.push(pos2(min.x, min.y)); // left top
|
||||||
path.push(pos2(max.x, min.y)); // right 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.
|
// Duplicated vertices can happen when one side is all rounding, with no straight edge between.
|
||||||
let eps = f32::EPSILON * rect.size().max_elem();
|
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
|
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
|
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
|
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
|
path.pop(); // avoid duplicated vertex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -633,11 +633,11 @@ 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_rounding(rounding: Roundingf, rect: Rect) -> Roundingf {
|
fn clamp_corner_radius(cr: CornerRadiusF32, rect: Rect) -> CornerRadiusF32 {
|
||||||
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.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 brush = rect_shape.brush.as_ref();
|
||||||
let RectShape {
|
let RectShape {
|
||||||
mut rect,
|
mut rect,
|
||||||
rounding,
|
corner_radius,
|
||||||
mut fill,
|
mut fill,
|
||||||
mut stroke,
|
mut stroke,
|
||||||
mut stroke_kind,
|
mut stroke_kind,
|
||||||
|
|
@ -1738,7 +1738,7 @@ impl Tessellator {
|
||||||
brush: _, // brush is extracted on its own, because it is not Copy
|
brush: _, // brush is extracted on its own, because it is not Copy
|
||||||
} = *rect_shape;
|
} = *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 round_to_pixels = round_to_pixels.unwrap_or(self.options.round_rects_to_pixels);
|
||||||
let pixel_size = 1.0 / self.pixels_per_point;
|
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_most(rect.size().min_elem() - eps - 2.0 * stroke.width)
|
||||||
.at_least(0.0);
|
.at_least(0.0);
|
||||||
|
|
||||||
rounding += 0.5 * blur_width;
|
corner_radius += 0.5 * blur_width;
|
||||||
|
|
||||||
self.feathering = self.feathering.max(blur_width);
|
self.feathering = self.feathering.max(blur_width);
|
||||||
}
|
}
|
||||||
|
|
@ -1858,54 +1858,54 @@ impl Tessellator {
|
||||||
// We do this because `path::rounded_rectangle` uses the
|
// We do this because `path::rounded_rectangle` uses the
|
||||||
// corner radius to pick the fidelity/resolution of the corner.
|
// corner radius to pick the fidelity/resolution of the corner.
|
||||||
|
|
||||||
let original_rounding = rounding;
|
let original_cr = corner_radius;
|
||||||
|
|
||||||
match stroke_kind {
|
match stroke_kind {
|
||||||
StrokeKind::Inside => {}
|
StrokeKind::Inside => {}
|
||||||
StrokeKind::Middle => {
|
StrokeKind::Middle => {
|
||||||
rect = rect.expand(stroke.width / 2.0);
|
rect = rect.expand(stroke.width / 2.0);
|
||||||
rounding += stroke.width / 2.0;
|
corner_radius += stroke.width / 2.0;
|
||||||
}
|
}
|
||||||
StrokeKind::Outside => {
|
StrokeKind::Outside => {
|
||||||
rect = rect.expand(stroke.width);
|
rect = rect.expand(stroke.width);
|
||||||
rounding += stroke.width;
|
corner_radius += stroke.width;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stroke_kind = StrokeKind::Inside;
|
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.
|
// because the small bend will be extruded inwards and cross itself.
|
||||||
// There are two ways to solve this (wile maintaining constant stroke width):
|
// There are two ways to solve this (wile maintaining constant stroke width):
|
||||||
// either we increase the rounding, or we set it to zero.
|
// either we increase the corner_radius, or we set it to zero.
|
||||||
// We choose the former: if the user asks for _any_ rounding, they should get it.
|
// 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_inside_cr = 0.1; // Large enough to avoid numerical issues
|
||||||
let min_outside_rounding = stroke.width + min_inside_rounding;
|
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 {
|
if 0.0 < original_cr.nw {
|
||||||
rounding.nw += extra_rounding_tweak;
|
corner_radius.nw += extra_cr_tweak;
|
||||||
rounding.nw = rounding.nw.at_least(min_outside_rounding);
|
corner_radius.nw = corner_radius.nw.at_least(min_outside_cr);
|
||||||
}
|
}
|
||||||
if 0.0 < original_rounding.ne {
|
if 0.0 < original_cr.ne {
|
||||||
rounding.ne += extra_rounding_tweak;
|
corner_radius.ne += extra_cr_tweak;
|
||||||
rounding.ne = rounding.ne.at_least(min_outside_rounding);
|
corner_radius.ne = corner_radius.ne.at_least(min_outside_cr);
|
||||||
}
|
}
|
||||||
if 0.0 < original_rounding.sw {
|
if 0.0 < original_cr.sw {
|
||||||
rounding.sw += extra_rounding_tweak;
|
corner_radius.sw += extra_cr_tweak;
|
||||||
rounding.sw = rounding.sw.at_least(min_outside_rounding);
|
corner_radius.sw = corner_radius.sw.at_least(min_outside_cr);
|
||||||
}
|
}
|
||||||
if 0.0 < original_rounding.se {
|
if 0.0 < original_cr.se {
|
||||||
rounding.se += extra_rounding_tweak;
|
corner_radius.se += extra_cr_tweak;
|
||||||
rounding.se = rounding.se.at_least(min_outside_rounding);
|
corner_radius.se = corner_radius.se.at_least(min_outside_cr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = &mut self.scratchpad_path;
|
let path = &mut self.scratchpad_path;
|
||||||
path.clear();
|
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);
|
path.add_line_loop(&self.scratchpad_points);
|
||||||
|
|
||||||
let path_stroke = PathStroke::from(stroke).with_kind(stroke_kind);
|
let path_stroke = PathStroke::from(stroke).with_kind(stroke_kind);
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ fn custom_window_frame(ctx: &egui::Context, title: &str, add_contents: impl FnOn
|
||||||
|
|
||||||
let panel_frame = egui::Frame::new()
|
let panel_frame = egui::Frame::new()
|
||||||
.fill(ctx.style().visuals.window_fill())
|
.fill(ctx.style().visuals.window_fill())
|
||||||
.rounding(10)
|
.corner_radius(10)
|
||||||
.stroke(ctx.style().visuals.widgets.noninteractive.fg_stroke)
|
.stroke(ctx.style().visuals.widgets.noninteractive.fg_stroke)
|
||||||
.outer_margin(1); // so the stroke is within the bounds
|
.outer_margin(1); // so the stroke is within the bounds
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ impl eframe::App for MyApp {
|
||||||
.on_hover_text_at_pointer("Svg");
|
.on_hover_text_at_pointer("Svg");
|
||||||
|
|
||||||
let url = "https://picsum.photos/seed/1.759706314/1024";
|
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);
|
.on_hover_text_at_pointer(url);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -478,7 +478,13 @@ fn drop_target<R>(
|
||||||
|
|
||||||
ui.painter().set(
|
ui.painter().set(
|
||||||
background_id,
|
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)
|
egui::InnerResponse::new(ret, response)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue