Skip to content

Commit

Permalink
Rename Marginf to MarginF32 for consistency with CornerRadiusF32 (
Browse files Browse the repository at this point in the history
#5677)

* [x] I have followed the instructions in the PR template
  • Loading branch information
lucasmerlin authored Feb 11, 2025
1 parent 1c6e7b1 commit 510b3cd
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 52 deletions.
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions crates/egui/src/containers/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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`.
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions crates/epaint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion crates/epaint/src/margin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
79 changes: 41 additions & 38 deletions crates/epaint/src/marginf.rs → crates/epaint/src/margin_f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 _,
Expand All @@ -41,7 +44,7 @@ impl From<Marginf> for Margin {
}
}

impl Marginf {
impl MarginF32 {
pub const ZERO: Self = Self {
left: 0.0,
right: 0.0,
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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;
Expand All @@ -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]
Expand All @@ -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;
Expand All @@ -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]
Expand All @@ -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;
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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;
Expand All @@ -256,44 +259,44 @@ 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(),
)
}
}

/// `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(),
)
}
}

/// `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;
}
}
6 changes: 3 additions & 3 deletions crates/epaint/src/shadow.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 510b3cd

Please sign in to comment.