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
## Preparation
* [ ] make sure there are no important unmerged PRs
* [ ] run `scripts/generate_example_screenshots.sh` if needed
* [ ] write a short release note that fits in a 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,
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.
///
@ -337,10 +337,10 @@ impl Frame {
///
/// [`Self::inner_margin`] + [`Self.stroke`]`.width` + [`Self::outer_margin`].
#[inline]
pub fn total_margin(&self) -> Marginf {
Marginf::from(self.inner_margin)
+ Marginf::from(self.stroke.width)
+ Marginf::from(self.outer_margin)
pub fn total_margin(&self) -> MarginF32 {
MarginF32::from(self.inner_margin)
+ MarginF32::from(self.stroke.width)
+ MarginF32::from(self.outer_margin)
}
/// Calculate the `fill_rect` from the `content_rect`.
@ -354,14 +354,14 @@ impl Frame {
///
/// This is the visible and interactive rectangle.
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`.
///
/// 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 {
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();
content_rect
+ self.frame.inner_margin
+ Marginf::from(self.frame.stroke.width)
+ MarginF32::from(self.frame.stroke.width)
+ self.frame.outer_margin
}

View File

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

View File

@ -9,7 +9,7 @@ use emath::{vec2, Rect, Vec2};
/// Use with care.
///
/// 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)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Margin {

View File

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