Skip to main content

Edges

Struct Edges 

Source
#[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: T

The size of the top side.

§right: T

The size of the right side.

§bottom: T

The size of the bottom side.

§left: T

The size of the left side.

Implementations§

Source§

impl<T: Clone + Debug + Default + PartialEq> Edges<T>

Source

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);
Source

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);
Source

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);
Source

pub fn map<U>(&self, f: impl Fn(&T) -> U) -> Edges<U>
where U: Clone + Debug + Default + PartialEq,

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 });
Source

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>

Source

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);
Source

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>

Source

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.)));
Source

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>

Source

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));
Source

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>

Source

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));
Source

pub fn max(&self) -> Pixels

Returns the largest of the four sides.

§Examples
let edges = Edges { top: px(4.), right: px(9.), bottom: px(2.), left: px(1.) };
assert_eq!(edges.max(), px(9.));

Trait Implementations§

Source§

impl<T: Clone + Clone + Debug + Default + PartialEq> Clone for Edges<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq + Copy> Copy for Edges<T>

Source§

impl<T: Debug + Clone + Debug + Default + PartialEq> Debug for Edges<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default + Clone + Debug + Default + PartialEq> Default for Edges<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Eq + Clone + Debug + Default + PartialEq> Eq for Edges<T>

Source§

impl<T: Clone + Debug + Default + PartialEq> From<EdgesRefinement<T>> for Edges<T>
where Option<T>: Clone,

Source§

fn from(value: EdgesRefinement<T>) -> Self

Converts to this type from the input type.
Source§

impl From<Pixels> for Edges<Pixels>

Source§

fn from(val: Pixels) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Edges<Pixels>

Source§

fn from(val: f32) -> Self

Converts to this type from the input type.
Source§

impl<T: Lerp + Clone + Debug + Default + PartialEq> Lerp for Edges<T>

Source§

fn lerp(&self, to: &Self, delta: f32) -> Self

Returns the value delta of the way from self to to.
Source§

impl<T> Mul for Edges<T>
where T: Mul<Output = T> + Clone + Debug + Default + PartialEq,

Source§

type Output = Edges<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<T, S> MulAssign<S> for Edges<T>
where T: Mul<S, Output = T> + Clone + Debug + Default + PartialEq, S: Clone,

Source§

fn mul_assign(&mut self, rhs: S)

Performs the *= operation. Read more
Source§

impl<T: PartialEq + Clone + Debug + Default + PartialEq> PartialEq for Edges<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for Edges<T>
where Option<T>: Clone,

Source§

type Refinement = EdgesRefinement<T>

Source§

fn refine(&mut self, refinement: &Self::Refinement)

Applies the given refinement to this instance, modifying it in place. Read more
Source§

fn refined(self, refinement: Self::Refinement) -> Self

Returns a new instance with the refinement applied, equivalent to cloning self and calling refine on it.
Source§

fn is_superset_of(&self, refinement: &Self::Refinement) -> bool

Returns true if this instance would contain all values from the refinement. Read more
Source§

fn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement

Returns a refinement that represents the difference between this instance and the given refinement. Read more
Source§

fn from_cascade(cascade: &Cascade<Self>) -> Self
where Self: Sized + Default,

Creates an instance from a cascade by merging all refinements atop the default value.
Source§

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 S
where 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) -> D
where M: TransformMatrix<T>,

👎Deprecated since 0.7.7:

replaced by palette::chromatic_adaptation::AdaptIntoUnclamped

Convert the source color to the destination color using the specified method.
Source§

fn adapt_into(self) -> D

👎Deprecated since 0.7.7:

replaced by palette::chromatic_adaptation::AdaptIntoUnclamped

Convert the source color to the destination color using the bradford method by default.
Source§

impl<T, C> AdaptIntoUnclamped<T> for C
where T: AdaptFromUnclamped<C>,

Source§

type Scalar = <T as AdaptFromUnclamped<C>>::Scalar

The number type that’s used as the color’s components.
Source§

fn adapt_into_unclamped_with<M>(self) -> T

Adapt a color of type Self into a color of type T, using the custom matrix M. Read more
Source§

fn adapt_into_unclamped(self) -> T
where Bradford: LmsToXyz<Self::Scalar> + XyzToLms<Self::Scalar>,

Adapt a color of type Self into a color of type T, using the Bradford matrix. Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

Source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
Source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

Source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

Source§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

Source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
Source§

impl<T, C> ComponentsInto<C> for T

Source§

fn components_into(self) -> C

Cast this collection of color components into a collection of colors. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromAngle<T> for T

Source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
Source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

Source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> IntoAngle<U> for T
where U: FromAngle<T>,

Source§

fn into_angle(self) -> U

Performs a conversion into T.
Source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

Source§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoStimulus<T> for T

Source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

Source§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
Source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

Source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
Source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

Source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more