From 2513213e8953fbaccb9ece1cabd3697cbca8aa2c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 12 Jul 2024 19:35:01 +0200 Subject: Add directional `border::Radius` helpers --- core/src/border.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++++ core/src/border_radius.rs | 22 ---------------- 2 files changed, 64 insertions(+), 22 deletions(-) delete mode 100644 core/src/border_radius.rs diff --git a/core/src/border.rs b/core/src/border.rs index 05e74ac6..da0aaa28 100644 --- a/core/src/border.rs +++ b/core/src/border.rs @@ -114,6 +114,26 @@ pub fn bottom_left(value: impl Into) -> Radius { Radius::default().bottom_left(value) } +/// Creates a new [`Radius`] with the given value as top left and top right. +pub fn top(value: impl Into) -> Radius { + Radius::default().top(value) +} + +/// Creates a new [`Radius`] with the given value as bottom left and bottom right. +pub fn bottom(value: impl Into) -> Radius { + Radius::default().bottom(value) +} + +/// Creates a new [`Radius`] with the given value as top left and bottom left. +pub fn left(value: impl Into) -> Radius { + Radius::default().left(value) +} + +/// Creates a new [`Radius`] with the given value as top right and bottom right. +pub fn right(value: impl Into) -> Radius { + Radius::default().right(value) +} + impl Radius { /// Creates a new [`Radius`] with the same value for each corner. pub fn new(value: impl Into) -> Self { @@ -158,6 +178,50 @@ impl Radius { ..self } } + + /// Sets the top left and top right values of the [`Radius`]. + pub fn top(self, value: impl Into) -> Self { + let value = value.into().0; + + Self { + top_left: value, + top_right: value, + ..self + } + } + + /// Sets the bottom left and bottom right values of the [`Radius`]. + pub fn bottom(self, value: impl Into) -> Self { + let value = value.into().0; + + Self { + bottom_left: value, + bottom_right: value, + ..self + } + } + + /// Sets the top left and bottom left values of the [`Radius`]. + pub fn left(self, value: impl Into) -> Self { + let value = value.into().0; + + Self { + top_left: value, + bottom_left: value, + ..self + } + } + + /// Sets the top right and bottom right values of the [`Radius`]. + pub fn right(self, value: impl Into) -> Self { + let value = value.into().0; + + Self { + top_right: value, + bottom_right: value, + ..self + } + } } impl From for Radius { diff --git a/core/src/border_radius.rs b/core/src/border_radius.rs deleted file mode 100644 index a444dd74..00000000 --- a/core/src/border_radius.rs +++ /dev/null @@ -1,22 +0,0 @@ -/// The border radii for the corners of a graphics primitive in the order: -/// top-left, top-right, bottom-right, bottom-left. -#[derive(Debug, Clone, Copy, PartialEq, Default)] -pub struct BorderRadius([f32; 4]); - -impl From for BorderRadius { - fn from(w: f32) -> Self { - Self([w; 4]) - } -} - -impl From<[f32; 4]> for BorderRadius { - fn from(radi: [f32; 4]) -> Self { - Self(radi) - } -} - -impl From for [f32; 4] { - fn from(radi: BorderRadius) -> Self { - radi.0 - } -} -- cgit