Rename `Marginf` to `MarginF32` for consistency with `CornerRadiusF32` (#5677)

* [x] I have followed the instructions in the PR template
This commit is contained in:
lucasmerlin 2025-02-11 11:23:59 +01:00 committed by GitHub
parent 1c6e7b1bd0
commit 510b3cdf48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 56 additions and 52 deletions

View File

@ -45,6 +45,7 @@ We don't update the MSRV in a patch release, unless we really, really need to.
* [ ] check that CI is green * [ ] check that CI is green
## Preparation ## Preparation
* [ ] make sure there are no important unmerged PRs
* [ ] run `scripts/generate_example_screenshots.sh` if needed * [ ] run `scripts/generate_example_screenshots.sh` if needed
* [ ] write a short release note that fits in a bluesky post * [ ] write a short release note that fits in a bluesky post
* [ ] record gif for `CHANGELOG.md` release note (and later bluesky post) * [ ] record gif for `CHANGELOG.md` release note (and later bluesky post)

View File

@ -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, CornerRadius, Margin, Marginf, Rect, Shadow, Shape, Stroke}; use epaint::{Color32, CornerRadius, Margin, MarginF32, Rect, Shadow, Shape, Stroke};
/// A frame around some content, including margin, colors, etc. /// A frame around some content, including margin, colors, etc.
/// ///
@ -337,10 +337,10 @@ impl Frame {
/// ///
/// [`Self::inner_margin`] + [`Self.stroke`]`.width` + [`Self::outer_margin`]. /// [`Self::inner_margin`] + [`Self.stroke`]`.width` + [`Self::outer_margin`].
#[inline] #[inline]
pub fn total_margin(&self) -> Marginf { pub fn total_margin(&self) -> MarginF32 {
Marginf::from(self.inner_margin) MarginF32::from(self.inner_margin)
+ Marginf::from(self.stroke.width) + MarginF32::from(self.stroke.width)
+ Marginf::from(self.outer_margin) + MarginF32::from(self.outer_margin)
} }
/// Calculate the `fill_rect` from the `content_rect`. /// Calculate the `fill_rect` from the `content_rect`.
@ -354,14 +354,14 @@ impl Frame {
/// ///
/// This is the visible and interactive rectangle. /// This is the visible and interactive rectangle.
pub fn widget_rect(&self, content_rect: Rect) -> Rect { pub fn widget_rect(&self, content_rect: Rect) -> Rect {
content_rect + self.inner_margin + Marginf::from(self.stroke.width) content_rect + self.inner_margin + MarginF32::from(self.stroke.width)
} }
/// Calculate the `outer_rect` from the `content_rect`. /// Calculate the `outer_rect` from the `content_rect`.
/// ///
/// This is what is allocated in the outer [`Ui`], and is what is returned by [`Response::rect`]. /// This is what is allocated in the outer [`Ui`], and is what is returned by [`Response::rect`].
pub fn outer_rect(&self, content_rect: Rect) -> Rect { pub fn outer_rect(&self, content_rect: Rect) -> Rect {
content_rect + self.inner_margin + Marginf::from(self.stroke.width) + self.outer_margin content_rect + self.inner_margin + MarginF32::from(self.stroke.width) + self.outer_margin
} }
} }
@ -463,7 +463,7 @@ impl Prepared {
let content_rect = self.content_ui.min_rect(); let content_rect = self.content_ui.min_rect();
content_rect content_rect
+ self.frame.inner_margin + self.frame.inner_margin
+ Marginf::from(self.frame.stroke.width) + MarginF32::from(self.frame.stroke.width)
+ self.frame.outer_margin + self.frame.outer_margin
} }

View File

@ -29,7 +29,7 @@ mod corner_radius;
mod corner_radius_f32; mod corner_radius_f32;
pub mod image; pub mod image;
mod margin; mod margin;
mod marginf; mod margin_f32;
mod mesh; mod mesh;
pub mod mutex; pub mod mutex;
mod shadow; mod shadow;
@ -52,7 +52,7 @@ pub use self::{
corner_radius_f32::CornerRadiusF32, corner_radius_f32::CornerRadiusF32,
image::{ColorImage, FontImage, ImageData, ImageDelta}, image::{ColorImage, FontImage, ImageData, ImageDelta},
margin::Margin, margin::Margin,
marginf::Marginf, margin_f32::*,
mesh::{Mesh, Mesh16, Vertex}, mesh::{Mesh, Mesh16, Vertex},
shadow::Shadow, shadow::Shadow,
shapes::{ shapes::{

View File

@ -9,7 +9,7 @@ use emath::{vec2, Rect, Vec2};
/// Use with care. /// Use with care.
/// ///
/// All values are stored as [`i8`] to keep the size of [`Margin`] small. /// All values are stored as [`i8`] to keep the size of [`Margin`] small.
/// If you want floats, use [`crate::Marginf`] instead. /// If you want floats, use [`crate::MarginF32`] instead.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Margin { pub struct Margin {

View File

@ -10,14 +10,17 @@ use crate::Margin;
/// For storage, use [`crate::Margin`] instead. /// For storage, use [`crate::Margin`] instead.
#[derive(Clone, Copy, Debug, Default, PartialEq)] #[derive(Clone, Copy, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Marginf { pub struct MarginF32 {
pub left: f32, pub left: f32,
pub right: f32, pub right: f32,
pub top: f32, pub top: f32,
pub bottom: f32, pub bottom: f32,
} }
impl From<Margin> for Marginf { #[deprecated = "Renamed to MarginF32"]
pub type Marginf = MarginF32;
impl From<Margin> for MarginF32 {
#[inline] #[inline]
fn from(margin: Margin) -> Self { fn from(margin: Margin) -> Self {
Self { Self {
@ -29,9 +32,9 @@ impl From<Margin> for Marginf {
} }
} }
impl From<Marginf> for Margin { impl From<MarginF32> for Margin {
#[inline] #[inline]
fn from(marginf: Marginf) -> Self { fn from(marginf: MarginF32) -> Self {
Self { Self {
left: marginf.left as _, left: marginf.left as _,
right: marginf.right as _, right: marginf.right as _,
@ -41,7 +44,7 @@ impl From<Marginf> for Margin {
} }
} }
impl Marginf { impl MarginF32 {
pub const ZERO: Self = Self { pub const ZERO: Self = Self {
left: 0.0, left: 0.0,
right: 0.0, right: 0.0,
@ -108,22 +111,22 @@ impl Marginf {
} }
} }
impl From<f32> for Marginf { impl From<f32> for MarginF32 {
#[inline] #[inline]
fn from(v: f32) -> Self { fn from(v: f32) -> Self {
Self::same(v) Self::same(v)
} }
} }
impl From<Vec2> for Marginf { impl From<Vec2> for MarginF32 {
#[inline] #[inline]
fn from(v: Vec2) -> Self { fn from(v: Vec2) -> Self {
Self::symmetric(v.x, v.y) Self::symmetric(v.x, v.y)
} }
} }
/// `Marginf + Marginf` /// `MarginF32 + MarginF32`
impl std::ops::Add for Marginf { impl std::ops::Add for MarginF32 {
type Output = Self; type Output = Self;
#[inline] #[inline]
@ -137,8 +140,8 @@ impl std::ops::Add for Marginf {
} }
} }
/// `Marginf + f32` /// `MarginF32 + f32`
impl std::ops::Add<f32> for Marginf { impl std::ops::Add<f32> for MarginF32 {
type Output = Self; type Output = Self;
#[inline] #[inline]
@ -153,7 +156,7 @@ impl std::ops::Add<f32> for Marginf {
} }
/// `Margind += f32` /// `Margind += f32`
impl std::ops::AddAssign<f32> for Marginf { impl std::ops::AddAssign<f32> for MarginF32 {
#[inline] #[inline]
fn add_assign(&mut self, v: f32) { fn add_assign(&mut self, v: f32) {
self.left += v; self.left += v;
@ -163,8 +166,8 @@ impl std::ops::AddAssign<f32> for Marginf {
} }
} }
/// `Marginf * f32` /// `MarginF32 * f32`
impl std::ops::Mul<f32> for Marginf { impl std::ops::Mul<f32> for MarginF32 {
type Output = Self; type Output = Self;
#[inline] #[inline]
@ -178,8 +181,8 @@ impl std::ops::Mul<f32> for Marginf {
} }
} }
/// `Marginf *= f32` /// `MarginF32 *= f32`
impl std::ops::MulAssign<f32> for Marginf { impl std::ops::MulAssign<f32> for MarginF32 {
#[inline] #[inline]
fn mul_assign(&mut self, v: f32) { fn mul_assign(&mut self, v: f32) {
self.left *= v; self.left *= v;
@ -189,8 +192,8 @@ impl std::ops::MulAssign<f32> for Marginf {
} }
} }
/// `Marginf / f32` /// `MarginF32 / f32`
impl std::ops::Div<f32> for Marginf { impl std::ops::Div<f32> for MarginF32 {
type Output = Self; type Output = Self;
#[inline] #[inline]
@ -204,8 +207,8 @@ impl std::ops::Div<f32> for Marginf {
} }
} }
/// `Marginf /= f32` /// `MarginF32 /= f32`
impl std::ops::DivAssign<f32> for Marginf { impl std::ops::DivAssign<f32> for MarginF32 {
#[inline] #[inline]
fn div_assign(&mut self, v: f32) { fn div_assign(&mut self, v: f32) {
self.left /= v; self.left /= v;
@ -215,8 +218,8 @@ impl std::ops::DivAssign<f32> for Marginf {
} }
} }
/// `Marginf - Marginf` /// `MarginF32 - MarginF32`
impl std::ops::Sub for Marginf { impl std::ops::Sub for MarginF32 {
type Output = Self; type Output = Self;
#[inline] #[inline]
@ -230,8 +233,8 @@ impl std::ops::Sub for Marginf {
} }
} }
/// `Marginf - f32` /// `MarginF32 - f32`
impl std::ops::Sub<f32> for Marginf { impl std::ops::Sub<f32> for MarginF32 {
type Output = Self; type Output = Self;
#[inline] #[inline]
@ -245,8 +248,8 @@ impl std::ops::Sub<f32> for Marginf {
} }
} }
/// `Marginf -= f32` /// `MarginF32 -= f32`
impl std::ops::SubAssign<f32> for Marginf { impl std::ops::SubAssign<f32> for MarginF32 {
#[inline] #[inline]
fn sub_assign(&mut self, v: f32) { fn sub_assign(&mut self, v: f32) {
self.left -= v; self.left -= v;
@ -256,12 +259,12 @@ impl std::ops::SubAssign<f32> for Marginf {
} }
} }
/// `Rect + Marginf` /// `Rect + MarginF32`
impl std::ops::Add<Marginf> for Rect { impl std::ops::Add<MarginF32> for Rect {
type Output = Self; type Output = Self;
#[inline] #[inline]
fn add(self, margin: Marginf) -> Self { fn add(self, margin: MarginF32) -> Self {
Self::from_min_max( Self::from_min_max(
self.min - margin.left_top(), self.min - margin.left_top(),
self.max + margin.right_bottom(), self.max + margin.right_bottom(),
@ -269,20 +272,20 @@ impl std::ops::Add<Marginf> for Rect {
} }
} }
/// `Rect += Marginf` /// `Rect += MarginF32`
impl std::ops::AddAssign<Marginf> for Rect { impl std::ops::AddAssign<MarginF32> for Rect {
#[inline] #[inline]
fn add_assign(&mut self, margin: Marginf) { fn add_assign(&mut self, margin: MarginF32) {
*self = *self + margin; *self = *self + margin;
} }
} }
/// `Rect - Marginf` /// `Rect - MarginF32`
impl std::ops::Sub<Marginf> for Rect { impl std::ops::Sub<MarginF32> for Rect {
type Output = Self; type Output = Self;
#[inline] #[inline]
fn sub(self, margin: Marginf) -> Self { fn sub(self, margin: MarginF32) -> Self {
Self::from_min_max( Self::from_min_max(
self.min + margin.left_top(), self.min + margin.left_top(),
self.max - margin.right_bottom(), self.max - margin.right_bottom(),
@ -290,10 +293,10 @@ impl std::ops::Sub<Marginf> for Rect {
} }
} }
/// `Rect -= Marginf` /// `Rect -= MarginF32`
impl std::ops::SubAssign<Marginf> for Rect { impl std::ops::SubAssign<MarginF32> for Rect {
#[inline] #[inline]
fn sub_assign(&mut self, margin: Marginf) { fn sub_assign(&mut self, margin: MarginF32) {
*self = *self - margin; *self = *self - margin;
} }
} }

View File

@ -1,4 +1,4 @@
use crate::{Color32, CornerRadius, Marginf, Rect, RectShape, Vec2}; use crate::{Color32, CornerRadius, MarginF32, Rect, RectShape, Vec2};
/// The color and fuzziness of a fuzzy shape. /// The color and fuzziness of a fuzzy shape.
/// ///
@ -64,7 +64,7 @@ impl Shadow {
} }
/// How much larger than the parent rect are we in each direction? /// How much larger than the parent rect are we in each direction?
pub fn margin(&self) -> Marginf { pub fn margin(&self) -> MarginF32 {
let Self { let Self {
offset, offset,
blur, blur,
@ -74,7 +74,7 @@ impl Shadow {
let spread = spread as f32; let spread = spread as f32;
let blur = blur as f32; let blur = blur as f32;
let [offset_x, offset_y] = offset; let [offset_x, offset_y] = offset;
Marginf { MarginF32 {
left: spread + 0.5 * blur - offset_x as f32, left: spread + 0.5 * blur - offset_x as f32,
right: spread + 0.5 * blur + offset_x as f32, right: spread + 0.5 * blur + offset_x as f32,
top: spread + 0.5 * blur - offset_y as f32, top: spread + 0.5 * blur - offset_y as f32,