#[repr(C)]pub struct Size<T: Clone + Debug + Default + PartialEq> {
pub width: T,
pub height: T,
}Expand description
A structure representing a two-dimensional size with width and height in a given unit.
This struct is generic over the type T, which can be any type that implements Clone, Default, and Debug.
It is commonly used to specify dimensions for elements in a UI, such as a window or element.
Fields§
§width: TThe width component of the size.
height: TThe height component of the size.
Implementations§
Source§impl<T> Size<T>
impl<T> Size<T>
Sourcepub fn map<U>(&self, f: impl Fn(T) -> U) -> Size<U>
pub fn map<U>(&self, f: impl Fn(T) -> U) -> Size<U>
Applies a function to the width and height of the size, producing a new Size<U>.
This method allows for converting a Size<T> to a Size<U> by specifying a closure
that defines how to convert between the two types. The closure is applied to both the width
and height, resulting in a new size of the desired type.
§Arguments
f- A closure that takes a value of typeTand returns a value of typeU.
§Examples
let my_size = Size { width: 10, height: 20 };
let my_new_size = my_size.map(|dimension| dimension as f32 * 1.5);
assert_eq!(my_new_size, Size { width: 15.0, height: 30.0 });Source§impl Size<Pixels>
impl Size<Pixels>
Sourcepub fn scale(&self, factor: f32) -> Size<ScaledPixels>
pub fn scale(&self, factor: f32) -> Size<ScaledPixels>
Scales the size by a given factor.
This method multiplies both the width and height by the provided scaling factor,
resulting in a new Size<ScaledPixels> that is proportionally larger or smaller
depending on the factor.
§Arguments
factor- The scaling factor to apply to the width and height.
§Examples
let size = Size { width: Pixels::from(100.0), height: Pixels::from(50.0) };
let scaled_size = size.scale(2.0);
assert_eq!(scaled_size, Size { width: ScaledPixels::from(200.0), height: ScaledPixels::from(100.0) });Source§impl<T> Size<T>
impl<T> Size<T>
Sourcepub fn max(&self, other: &Self) -> Self
pub fn max(&self, other: &Self) -> Self
Returns a new Size with the maximum width and height from self and other.
§Arguments
other- A reference to anotherSizeto compare withself.
§Examples
let size1 = Size { width: 30, height: 40 };
let size2 = Size { width: 50, height: 20 };
let max_size = size1.max(&size2);
assert_eq!(max_size, Size { width: 50, height: 40 });Sourcepub fn min(&self, other: &Self) -> Self
pub fn min(&self, other: &Self) -> Self
Returns a new Size with the minimum width and height from self and other.
§Arguments
other- A reference to anotherSizeto compare withself.
§Examples
let size1 = Size { width: 30, height: 40 };
let size2 = Size { width: 50, height: 20 };
let min_size = size1.min(&size2);
assert_eq!(min_size, Size { width: 30, height: 20 });Source§impl Size<Length>
impl Size<Length>
Sourcepub fn full() -> Self
pub fn full() -> Self
Returns a Size with both width and height set to fill the available space.
This function creates a Size instance where both the width and height are set to Length::Definite(DefiniteLength::Fraction(1.0)),
which represents 100% of the available space in both dimensions.
§Returns
A Size<Length> that will fill the available space when used in a layout.
Source§impl Size<Length>
impl Size<Length>
Sourcepub fn auto() -> Self
pub fn auto() -> Self
Returns a Size with both width and height set to auto, which allows the layout engine to determine the size.
This function creates a Size instance where both the width and height are set to Length::Auto,
indicating that their size should be computed based on the layout context, such as the content size or
available space.
§Returns
A Size<Length> with width and height set to Length::Auto.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Size<T>
impl<'de, T> Deserialize<'de> for Size<T>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<Size<DevicePixels>> for Size
impl From<Size<DevicePixels>> for Size
Source§fn from(size: Size<DevicePixels>) -> Self
fn from(size: Size<DevicePixels>) -> Self
Source§impl From<Size2D<i32, UnknownUnit>> for Size<DevicePixels>
impl From<Size2D<i32, UnknownUnit>> for Size<DevicePixels>
Source§impl<T: Clone + Debug + Default + PartialEq> From<SizeRefinement<T>> for Size<T>
impl<T: Clone + Debug + Default + PartialEq> From<SizeRefinement<T>> for Size<T>
Source§fn from(value: SizeRefinement<T>) -> Self
fn from(value: SizeRefinement<T>) -> Self
Source§impl<T, S> MulAssign<S> for Size<T>
impl<T, S> MulAssign<S> for Size<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 Size<T>
impl<T: Clone + Debug + Default + PartialEq> Refineable for Size<T>
type Refinement = SizeRefinement<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 + Clone + Debug + Default + PartialEq> Copy for Size<T>
impl<T> Eq for Size<T>
impl<T: Clone + Debug + Default + PartialEq> StructuralPartialEq for Size<T>
Auto Trait Implementations§
impl<T> Freeze for Size<T>where
T: Freeze,
impl<T> RefUnwindSafe for Size<T>where
T: RefUnwindSafe,
impl<T> Send for Size<T>where
T: Send,
impl<T> Sync for Size<T>where
T: Sync,
impl<T> Unpin for Size<T>where
T: Unpin,
impl<T> UnwindSafe for Size<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().