#[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
The values at the four corners of a box, such as a border radius.
Use Corners<Pixels> for radii. Corners<Pixels> implements From<f32> and From<Pixels>
for the same value at every corner.
§Examples
let radii = Corners::all(px(8.));
assert_eq!(radii.top_left, Pixels::from(8.));
assert_eq!(radii.bottom_right, Pixels::from(8.));Fields§
§top_left: TThe value at the top left corner.
top_right: TThe value at the top right corner.
bottom_right: TThe value at the bottom right corner.
bottom_left: TThe value at 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
Returns corners with value at every corner.
§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 value at corner.
The four corner anchors return their field. An edge midpoint returns the average of the two
corners on that edge, computed with Half. For example, Anchor::TopCenter averages
top_left and top_right.
§Examples
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);Edge midpoints, calculated as the average of the 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>
Resolves each corner to pixels. Rems are multiplied by rem_size.
§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));
assert_eq!(corners_in_pixels.bottom_right, Pixels::from(30.0));
assert_eq!(corners_in_pixels.bottom_left, Pixels::from(32.0));Source§impl Corners<Pixels>
impl Corners<Pixels>
Sourcepub fn scale(&self, factor: f32) -> Corners<ScaledPixels>
pub fn scale(&self, factor: f32) -> Corners<ScaledPixels>
Multiplies each corner by factor, producing ScaledPixels.
§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: Div<f32, Output = T> + Ord + Clone + Debug + Default + PartialEq> Corners<T>
impl<T: Div<f32, Output = T> + Ord + Clone + Debug + Default + PartialEq> Corners<T>
Sourcepub fn clamp_radii_for_quad_size(self, size: Size<T>) -> Corners<T>
pub fn clamp_radii_for_quad_size(self, size: Size<T>) -> Corners<T>
Limits each corner radius to half of the shorter side of size.
Radii larger than that would overlap, so each one is replaced by the limit. Radii below the limit are unchanged.
§Examples
let radii = Corners::all(px(30.)).clamp_radii_for_quad_size(size(px(40.), px(100.)));
assert_eq!(radii, Corners::all(px(20.)));
let small = Corners::all(px(5.)).clamp_radii_for_quad_size(size(px(40.), px(100.)));
assert_eq!(small, Corners::all(px(5.)));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>
Returns corners with f applied to each corner.
§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§
impl<T> Copy for Corners<T>
impl<T: Eq + Clone + Debug + Default + PartialEq> Eq for Corners<T>
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: 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: PartialEq + 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<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
replaced by palette::chromatic_adaptation::AdaptIntoUnclamped
Source§impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
impl<T, C> AdaptIntoUnclamped<T> for Cwhere
T: AdaptFromUnclamped<C>,
Source§type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
type Scalar = <T as AdaptFromUnclamped<C>>::Scalar
Source§fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
fn adapt_into_unclamped_with<M>(self) -> Twhere
M: LmsToXyz<<C as AdaptIntoUnclamped<T>>::Scalar> + XyzToLms<<C as AdaptIntoUnclamped<T>>::Scalar>,
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T, C> ComponentsInto<C> for T
impl<T, C> ComponentsInto<C> for T
Source§fn components_into(self) -> C
fn components_into(self) -> C
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> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.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, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
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> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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().Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more