#[repr(C)]pub struct Edges<T: Clone + Debug + Default + PartialEq> {
pub top: T,
pub right: T,
pub bottom: T,
pub left: T,
}Expand description
The sizes of the four sides of a box, such as its padding or margin.
Each field holds the size of one side. The value is measured inward from that side: top
is the space along the top edge, and so on. Edges<Pixels> implements From<f32> and
From<Pixels> for the same value on all four sides.
§Examples
let edges = Edges {
top: 10.0,
right: 20.0,
bottom: 30.0,
left: 40.0,
};
assert_eq!(edges.top, 10.0);
assert_eq!(edges.right, 20.0);
assert_eq!(edges.bottom, 30.0);
assert_eq!(edges.left, 40.0);Fields§
§top: TThe size of the top side.
right: TThe size of the right side.
bottom: TThe size of the bottom side.
left: TThe size of the left side.
Implementations§
Source§impl<T: Clone + Debug + Default + PartialEq> Edges<T>
impl<T: Clone + Debug + Default + PartialEq> Edges<T>
Sourcepub fn all(value: T) -> Self
pub fn all(value: T) -> Self
Returns edges with value on all four sides.
§Examples
let uniform_edges = Edges::all(10.0);
assert_eq!(uniform_edges.top, 10.0);
assert_eq!(uniform_edges.right, 10.0);
assert_eq!(uniform_edges.bottom, 10.0);
assert_eq!(uniform_edges.left, 10.0);Sourcepub fn horizontal(value: T) -> Self
pub fn horizontal(value: T) -> Self
Returns edges with value on the left and right sides, and the default on the top and bottom.
§Examples
let edges = Edges::horizontal(10.0);
assert_eq!(edges.top, 0.0);
assert_eq!(edges.right, 10.0);
assert_eq!(edges.bottom, 0.0);
assert_eq!(edges.left, 10.0);Sourcepub fn vertical(value: T) -> Self
pub fn vertical(value: T) -> Self
Returns edges with value on the top and bottom sides, and the default on the left and right.
§Examples
let edges = Edges::vertical(10.0);
assert_eq!(edges.top, 10.0);
assert_eq!(edges.right, 0.0);
assert_eq!(edges.bottom, 10.0);
assert_eq!(edges.left, 0.0);Sourcepub fn map<U>(&self, f: impl Fn(&T) -> U) -> Edges<U>
pub fn map<U>(&self, f: impl Fn(&T) -> U) -> Edges<U>
Returns edges with f applied to each side.
§Examples
let edges = Edges { top: 10, right: 20, bottom: 30, left: 40 };
let edges_float = edges.map(|&value| value as f32 * 1.1);
assert_eq!(edges_float, Edges { top: 11.0, right: 22.0, bottom: 33.0, left: 44.0 });Sourcepub fn any<F: Fn(&T) -> bool>(&self, predicate: F) -> bool
pub fn any<F: Fn(&T) -> bool>(&self, predicate: F) -> bool
Returns true if predicate is true for at least one side.
§Examples
let edges = Edges {
top: 10,
right: 0,
bottom: 5,
left: 0,
};
assert!(edges.any(|value| *value == 0));
assert!(edges.any(|value| *value > 0));
assert!(!edges.any(|value| *value > 10));Source§impl Edges<Length>
impl Edges<Length>
Sourcepub fn auto() -> Self
pub fn auto() -> Self
Returns edges with Length::Auto on all four sides.
§Examples
let auto_edges = Edges::auto();
assert_eq!(auto_edges.top, Length::Auto);
assert_eq!(auto_edges.right, Length::Auto);
assert_eq!(auto_edges.bottom, Length::Auto);
assert_eq!(auto_edges.left, Length::Auto);Sourcepub fn zero() -> Self
pub fn zero() -> Self
Returns edges of zero pixels on all four sides.
§Examples
let no_edges = Edges::<Length>::zero();
assert_eq!(no_edges.top, Length::Definite(DefiniteLength::from(Pixels::ZERO)));
assert_eq!(no_edges.right, Length::Definite(DefiniteLength::from(Pixels::ZERO)));
assert_eq!(no_edges.bottom, Length::Definite(DefiniteLength::from(Pixels::ZERO)));
assert_eq!(no_edges.left, Length::Definite(DefiniteLength::from(Pixels::ZERO)));Source§impl Edges<DefiniteLength>
impl Edges<DefiniteLength>
Sourcepub fn zero() -> Self
pub fn zero() -> Self
Returns edges of zero on all four sides.
§Examples
let no_edges = Edges::<DefiniteLength>::zero();
assert_eq!(no_edges.top, DefiniteLength::from(px(0.)));
assert_eq!(no_edges.right, DefiniteLength::from(px(0.)));
assert_eq!(no_edges.bottom, DefiniteLength::from(px(0.)));
assert_eq!(no_edges.left, DefiniteLength::from(px(0.)));Sourcepub fn to_pixels(
self,
parent_size: Size<AbsoluteLength>,
rem_size: Pixels,
) -> Edges<Pixels>
pub fn to_pixels( self, parent_size: Size<AbsoluteLength>, rem_size: Pixels, ) -> Edges<Pixels>
Resolves each side to pixels.
top and bottom are fractions of parent_size.height, and left and right are fractions
of parent_size.width. Rems are multiplied by rem_size.
§Examples
let edges = Edges {
top: DefiniteLength::Absolute(AbsoluteLength::Pixels(px(10.0))),
right: relative(0.5).into(),
bottom: DefiniteLength::Absolute(AbsoluteLength::Rems(rems(2.0))),
left: relative(0.25).into(),
};
let parent_size = Size {
width: AbsoluteLength::Pixels(px(200.0)),
height: AbsoluteLength::Pixels(px(100.0)),
};
let rem_size = px(16.0);
let edges_in_pixels = edges.to_pixels(parent_size, rem_size);
assert_eq!(edges_in_pixels.top, px(10.0));
assert_eq!(edges_in_pixels.right, px(100.0));
assert_eq!(edges_in_pixels.bottom, px(32.0));
assert_eq!(edges_in_pixels.left, px(50.0));Source§impl Edges<AbsoluteLength>
impl Edges<AbsoluteLength>
Sourcepub fn zero() -> Self
pub fn zero() -> Self
Sets the edges of the Edges struct to zero, which means no size or thickness.
This is typically used when you want to specify that a box (like a padding or margin area) should have no edges, effectively making it non-existent or invisible in layout calculations.
§Returns
Returns an Edges<AbsoluteLength> with all edges set to zero length.
§Examples
let no_edges = Edges::<AbsoluteLength>::zero();
assert_eq!(no_edges.top, AbsoluteLength::Pixels(Pixels::ZERO));
assert_eq!(no_edges.right, AbsoluteLength::Pixels(Pixels::ZERO));
assert_eq!(no_edges.bottom, AbsoluteLength::Pixels(Pixels::ZERO));
assert_eq!(no_edges.left, AbsoluteLength::Pixels(Pixels::ZERO));Sourcepub fn to_pixels(self, rem_size: Pixels) -> Edges<Pixels>
pub fn to_pixels(self, rem_size: Pixels) -> Edges<Pixels>
Resolves each side to pixels. Rems are multiplied by rem_size.
§Examples
let edges = Edges {
top: AbsoluteLength::Pixels(px(10.0)),
right: AbsoluteLength::Rems(rems(1.0)),
bottom: AbsoluteLength::Pixels(px(20.0)),
left: AbsoluteLength::Rems(rems(2.0)),
};
let rem_size = px(16.0);
let edges_in_pixels = edges.to_pixels(rem_size);
assert_eq!(edges_in_pixels.top, px(10.0));
assert_eq!(edges_in_pixels.right, px(16.0));
assert_eq!(edges_in_pixels.bottom, px(20.0));
assert_eq!(edges_in_pixels.left, px(32.0));Source§impl Edges<Pixels>
impl Edges<Pixels>
Sourcepub fn scale(&self, factor: f32) -> Edges<ScaledPixels>
pub fn scale(&self, factor: f32) -> Edges<ScaledPixels>
Multiplies each side by factor, producing ScaledPixels.
§Examples
let edges = Edges {
top: Pixels::from(10.0),
right: Pixels::from(20.0),
bottom: Pixels::from(30.0),
left: Pixels::from(40.0),
};
let scaled_edges = edges.scale(2.0);
assert_eq!(scaled_edges.top, ScaledPixels::from(20.0));
assert_eq!(scaled_edges.right, ScaledPixels::from(40.0));
assert_eq!(scaled_edges.bottom, ScaledPixels::from(60.0));
assert_eq!(scaled_edges.left, ScaledPixels::from(80.0));Trait Implementations§
impl<T: Clone + Debug + Default + PartialEq + Copy> Copy for Edges<T>
impl<T: Eq + Clone + Debug + Default + PartialEq> Eq for Edges<T>
Source§impl<T: Clone + Debug + Default + PartialEq> From<EdgesRefinement<T>> for Edges<T>
impl<T: Clone + Debug + Default + PartialEq> From<EdgesRefinement<T>> for Edges<T>
Source§fn from(value: EdgesRefinement<T>) -> Self
fn from(value: EdgesRefinement<T>) -> Self
Source§impl<T, S> MulAssign<S> for Edges<T>
impl<T, S> MulAssign<S> for Edges<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 Edges<T>
impl<T: Clone + Debug + Default + PartialEq> Refineable for Edges<T>
type Refinement = EdgesRefinement<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 Edges<T>
Auto Trait Implementations§
impl<T> Freeze for Edges<T>where
T: Freeze,
impl<T> RefUnwindSafe for Edges<T>where
T: RefUnwindSafe,
impl<T> Send for Edges<T>where
T: Send,
impl<T> Sync for Edges<T>where
T: Sync,
impl<T> Unpin for Edges<T>where
T: Unpin,
impl<T> UnsafeUnpin for Edges<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Edges<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