summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-07-12 19:35:01 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-07-12 19:35:01 +0200
commit2513213e8953fbaccb9ece1cabd3697cbca8aa2c (patch)
tree59757c276e7eee71121914308e288066adf31cf9 /core/src
parentab392cee947a7207bdd021d5f04945b9d5a16b4b (diff)
downloadiced-2513213e8953fbaccb9ece1cabd3697cbca8aa2c.tar.gz
iced-2513213e8953fbaccb9ece1cabd3697cbca8aa2c.tar.bz2
iced-2513213e8953fbaccb9ece1cabd3697cbca8aa2c.zip
Add directional `border::Radius` helpers
Diffstat (limited to 'core/src')
-rw-r--r--core/src/border.rs64
-rw-r--r--core/src/border_radius.rs22
2 files changed, 64 insertions, 22 deletions
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<Pixels>) -> 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<Pixels>) -> 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<Pixels>) -> 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<Pixels>) -> 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<Pixels>) -> Radius {
+ Radius::default().right(value)
+}
+
impl Radius {
/// Creates a new [`Radius`] with the same value for each corner.
pub fn new(value: impl Into<Pixels>) -> 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<Pixels>) -> 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<Pixels>) -> 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<Pixels>) -> 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<Pixels>) -> Self {
+ let value = value.into().0;
+
+ Self {
+ top_right: value,
+ bottom_right: value,
+ ..self
+ }
+ }
}
impl From<f32> 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<f32> 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<BorderRadius> for [f32; 4] {
- fn from(radi: BorderRadius) -> Self {
- radi.0
- }
-}