#[repr(C)]pub struct Edges<T: Clone + Debug + Default + PartialEq> {
pub top: T,
pub right: T,
pub bottom: T,
pub left: T,
}Expand description
Represents the edges of a box in a 2D space, such as padding or margin.
Each field represents the size of the edge on one side of the box: top, right, bottom, and left.
§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 edge.
right: TThe size of the right edge.
bottom: TThe size of the bottom edge.
left: TThe size of the left edge.
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
Constructs Edges where all sides are set to the same specified value.
This function creates an Edges instance with the top, right, bottom, and left fields all initialized
to the same value provided as an argument. This is useful when you want to have uniform edges around a box,
such as padding or margin with the same size on all sides.
§Arguments
value- The value to set for all four sides of the edges.
§Returns
An Edges instance with all sides set to the given value.
§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 map<U>(&self, f: impl Fn(&T) -> U) -> Edges<U>
pub fn map<U>(&self, f: impl Fn(&T) -> U) -> Edges<U>
Applies a function to each field of the Edges, producing a new Edges<U>.
This method allows for converting an Edges<T> to an Edges<U> by specifying a closure
that defines how to convert between the two types. The closure is applied to each field
(top, right, bottom, left), resulting in new edges 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 Edges<U> with each field mapped by the provided function.
§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
Checks if any of the edges satisfy a given predicate.
This method applies a predicate function to each field of the Edges and returns true if any field satisfies the predicate.
§Arguments
predicate- A closure that takes a reference to a value of typeTand returns abool.
§Returns
Returns true if the predicate returns true for any of the edge values, false otherwise.
§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
Sets the edges of the Edges struct to auto, which is a special value that allows the layout engine to automatically determine the size of the edges.
This is typically used in layout contexts where the exact size of the edges is not important, or when the size should be calculated based on the content or container.
§Returns
Returns an Edges<Length> with all edges set to Length::Auto.
§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
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<Length> with all edges set to zero length.
§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
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<DefiniteLength> with all edges set to zero length.
§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>
Converts the DefiniteLength to Pixels based on the parent size and the REM size.
This method allows for a DefiniteLength value to be converted into pixels, taking into account
the size of the parent element (for percentage-based lengths) and the size of a rem unit (for rem-based lengths).
§Arguments
parent_size-Size<AbsoluteLength>representing the size of the parent element.rem_size-Pixelsrepresenting the size of one REM unit.
§Returns
Returns an Edges<Pixels> representing the edges with lengths converted to pixels.
§Examples
let edges = Edges {
top: DefiniteLength::Absolute(AbsoluteLength::Pixels(px(10.0))),
right: DefiniteLength::Fraction(0.5),
bottom: DefiniteLength::Absolute(AbsoluteLength::Rems(rems(2.0))),
left: DefiniteLength::Fraction(0.25),
};
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)); // Absolute length in pixels
assert_eq!(edges_in_pixels.right, px(100.0)); // 50% of parent width
assert_eq!(edges_in_pixels.bottom, px(32.0)); // 2 rems
assert_eq!(edges_in_pixels.left, px(50.0)); // 25% of parent widthSource§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>
Converts the AbsoluteLength to Pixels based on the rem_size.
If the AbsoluteLength is already in pixels, it simply returns the corresponding Pixels value.
If the AbsoluteLength is in rems, it multiplies the number of rems by the rem_size to convert it to pixels.
§Arguments
rem_size- The size of one rem unit in pixels.
§Returns
Returns an Edges<Pixels> representing the edges with lengths converted to pixels.
§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)); // Already in pixels
assert_eq!(edges_in_pixels.right, px(16.0)); // 1 rem converted to pixels
assert_eq!(edges_in_pixels.bottom, px(20.0)); // Already in pixels
assert_eq!(edges_in_pixels.left, px(32.0)); // 2 rems converted to pixelsSource§impl Edges<Pixels>
impl Edges<Pixels>
Sourcepub fn scale(&self, factor: f32) -> Edges<ScaledPixels>
pub fn scale(&self, factor: f32) -> Edges<ScaledPixels>
Scales the Edges<Pixels> by a given factor, returning Edges<ScaledPixels>.
This method is typically used for adjusting the edge sizes for different display densities or scaling factors.
§Arguments
factor- The scaling factor to apply to each edge.
§Returns
Returns a new Edges<ScaledPixels> where each edge is the result of scaling the original edge by the given factor.
§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§
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: Clone + Debug + Default + PartialEq + Copy> Copy for Edges<T>
impl<T: Eq + Clone + Debug + Default + PartialEq> Eq for Edges<T>
impl<T: 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> UnwindSafe for Edges<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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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<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§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().