Add directional border::Radius helpers
This commit is contained in:
parent
ab392cee94
commit
2513213e89
2 changed files with 64 additions and 22 deletions
|
|
@ -114,6 +114,26 @@ pub fn bottom_left(value: impl Into<Pixels>) -> Radius {
|
||||||
Radius::default().bottom_left(value)
|
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 {
|
impl Radius {
|
||||||
/// Creates a new [`Radius`] with the same value for each corner.
|
/// Creates a new [`Radius`] with the same value for each corner.
|
||||||
pub fn new(value: impl Into<Pixels>) -> Self {
|
pub fn new(value: impl Into<Pixels>) -> Self {
|
||||||
|
|
@ -158,6 +178,50 @@ impl Radius {
|
||||||
..self
|
..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 {
|
impl From<f32> for Radius {
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue