#[repr(C)]pub struct Corners<T: Clone + Debug + Default + PartialEq> {
pub top_left: T,
pub top_right: T,
pub bottom_right: T,
pub bottom_left: T,
}Expand description
Represents the corners of a box in a 2D space, such as border radius.
Each field represents the size of the corner on one side of the box: top_left, top_right, bottom_right, and bottom_left.
Fields§
§top_left: TThe value associated with the top left corner.
top_right: TThe value associated with the top right corner.
bottom_right: TThe value associated with the bottom right corner.
bottom_left: TThe value associated with the bottom left corner.
Implementations§
Source§impl<T> Corners<T>
impl<T> Corners<T>
Sourcepub fn all(value: T) -> Self
pub fn all(value: T) -> Self
Constructs Corners where all sides are set to the same specified value.
This function creates a Corners instance with the top_left, top_right, bottom_right, and bottom_left fields all initialized
to the same value provided as an argument. This is useful when you want to have uniform corners around a box,
such as a uniform border radius on a rectangle.
§Arguments
value- The value to set for all four corners.
§Returns
An Corners instance with all corners set to the given value.
§Examples
let uniform_corners = Corners::all(5.0);
assert_eq!(uniform_corners.top_left, 5.0);
assert_eq!(uniform_corners.top_right, 5.0);
assert_eq!(uniform_corners.bottom_right, 5.0);
assert_eq!(uniform_corners.bottom_left, 5.0);Sourcepub fn corner(&self, corner: Anchor) -> T
pub fn corner(&self, corner: Anchor) -> T
Returns the requested corner value, supporting all eight corner positions.
For the four basic corners (TopLeft, TopRight, BottomLeft, BottomRight), this returns the corresponding field value directly.
For the center positions (TopCenter, BottomCenter, LeftCenter, RightCenter), this calculates the average of the two adjacent corners.
§Returns
A value of type T representing the corner requested by the parameter.
§Examples
Basic corner positions:
let corners = Corners {
top_left: 10,
top_right: 20,
bottom_left: 30,
bottom_right: 40
};
assert_eq!(corners.corner(Anchor::TopLeft), 10);
assert_eq!(corners.corner(Anchor::BottomRight), 40);Center positions (calculated as average of adjacent corners):
let corners = Corners {
top_left: 10,
top_right: 20,
bottom_left: 30,
bottom_right: 40
};
assert_eq!(corners.corner(Anchor::TopCenter), 15);
assert_eq!(corners.corner(Anchor::BottomCenter), 35);
assert_eq!(corners.corner(Anchor::LeftCenter), 20);
assert_eq!(corners.corner(Anchor::RightCenter), 30);Source§impl Corners<AbsoluteLength>
impl Corners<AbsoluteLength>
Sourcepub fn to_pixels(self, rem_size: Pixels) -> Corners<Pixels>
pub fn to_pixels(self, rem_size: Pixels) -> Corners<Pixels>
Converts the AbsoluteLength to Pixels based on the provided rem size.
§Arguments
rem_size- The size of one REM unit in pixels, used for conversion if theAbsoluteLengthis in REMs.
§Returns
Returns a Corners<Pixels> instance with each corner’s length converted to pixels.
§Examples
let corners = Corners {
top_left: AbsoluteLength::Pixels(Pixels::from(15.0)),
top_right: AbsoluteLength::Rems(Rems(1.0)),
bottom_right: AbsoluteLength::Pixels(Pixels::from(30.0)),
bottom_left: AbsoluteLength::Rems(Rems(2.0)),
};
let rem_size = Pixels::from(16.0);
let corners_in_pixels = corners.to_pixels(rem_size);
assert_eq!(corners_in_pixels.top_left, Pixels::from(15.0));
assert_eq!(corners_in_pixels.top_right, Pixels::from(16.0)); // 1 rem converted to pixels
assert_eq!(corners_in_pixels.bottom_right, Pixels::from(30.0));
assert_eq!(corners_in_pixels.bottom_left, Pixels::from(32.0)); // 2 rems converted to pixelsSource§impl Corners<Pixels>
impl Corners<Pixels>
Sourcepub fn scale(&self, factor: f32) -> Corners<ScaledPixels>
pub fn scale(&self, factor: f32) -> Corners<ScaledPixels>
Scales the Corners<Pixels> by a given factor, returning Corners<ScaledPixels>.
This method is typically used for adjusting the corner sizes for different display densities or scaling factors.
§Arguments
factor- The scaling factor to apply to each corner.
§Returns
Returns a new Corners<ScaledPixels> where each corner is the result of scaling the original corner by the given factor.
§Examples
let corners = Corners {
top_left: Pixels::from(10.0),
top_right: Pixels::from(20.0),
bottom_right: Pixels::from(30.0),
bottom_left: Pixels::from(40.0),
};
let scaled_corners = corners.scale(2.0);
assert_eq!(scaled_corners.top_left, ScaledPixels::from(20.0));
assert_eq!(scaled_corners.top_right, ScaledPixels::from(40.0));
assert_eq!(scaled_corners.bottom_right, ScaledPixels::from(60.0));
assert_eq!(scaled_corners.bottom_left, ScaledPixels::from(80.0));Source§impl<T: Clone + Debug + Default + PartialEq> Corners<T>
impl<T: Clone + Debug + Default + PartialEq> Corners<T>
Sourcepub fn map<U>(&self, f: impl Fn(&T) -> U) -> Corners<U>
pub fn map<U>(&self, f: impl Fn(&T) -> U) -> Corners<U>
Applies a function to each field of the Corners, producing a new Corners<U>.
This method allows for converting a Corners<T> to a Corners<U> by specifying a closure
that defines how to convert between the two types. The closure is applied to each field
(top_left, top_right, bottom_right, bottom_left), resulting in new corners of the desired type.
§Arguments
f- A closure that takes a reference to a value of typeTand returns a value of typeU.
§Returns
Returns a new Corners<U> with each field mapped by the provided function.
§Examples
let corners = Corners {
top_left: Pixels::from(10.0),
top_right: Pixels::from(20.0),
bottom_right: Pixels::from(30.0),
bottom_left: Pixels::from(40.0),
};
let corners_in_rems = corners.map(|&px| Rems(f32::from(px) / 16.0));
assert_eq!(corners_in_rems, Corners {
top_left: Rems(0.625),
top_right: Rems(1.25),
bottom_right: Rems(1.875),
bottom_left: Rems(2.5),
});Trait Implementations§
Source§impl<T: Clone + Debug + Default + PartialEq> From<CornersRefinement<T>> for Corners<T>
impl<T: Clone + Debug + Default + PartialEq> From<CornersRefinement<T>> for Corners<T>
Source§fn from(value: CornersRefinement<T>) -> Self
fn from(value: CornersRefinement<T>) -> Self
Source§impl<T, S> MulAssign<S> for Corners<T>
impl<T, S> MulAssign<S> for Corners<T>
Source§fn mul_assign(&mut self, rhs: S)
fn mul_assign(&mut self, rhs: S)
*= operation. Read moreSource§impl<T: PartialEq + Clone + Debug + Default + PartialEq> PartialEq for Corners<T>
impl<T: PartialEq + Clone + Debug + Default + PartialEq> PartialEq for Corners<T>
Source§impl<T: Clone + Debug + Default + PartialEq> Refineable for Corners<T>
impl<T: Clone + Debug + Default + PartialEq> Refineable for Corners<T>
type Refinement = CornersRefinement<T>
Source§fn refine(&mut self, refinement: &Self::Refinement)
fn refine(&mut self, refinement: &Self::Refinement)
Source§fn refined(self, refinement: Self::Refinement) -> Self
fn refined(self, refinement: Self::Refinement) -> Self
self and calling
refine on it.Source§fn is_superset_of(&self, refinement: &Self::Refinement) -> bool
fn is_superset_of(&self, refinement: &Self::Refinement) -> bool
true if this instance would contain all values from the refinement. Read moreSource§fn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement
fn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement
impl<T> Copy for Corners<T>
impl<T: Eq + Clone + Debug + Default + PartialEq> Eq for Corners<T>
impl<T: Clone + Debug + Default + PartialEq> StructuralPartialEq for Corners<T>
Auto Trait Implementations§
impl<T> Freeze for Corners<T>where
T: Freeze,
impl<T> RefUnwindSafe for Corners<T>where
T: RefUnwindSafe,
impl<T> Send for Corners<T>where
T: Send,
impl<T> Sync for Corners<T>where
T: Sync,
impl<T> Unpin for Corners<T>where
T: Unpin,
impl<T> UnsafeUnpin for Corners<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Corners<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().