#[repr(C)]pub struct Size<T>{
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: &Size<T>) -> Size<T>
pub fn max(&self, other: &Size<T>) -> Size<T>
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: &Size<T>) -> Size<T>
pub fn min(&self, other: &Size<T>) -> Size<T>
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() -> Size<Length>
pub fn full() -> Size<Length>
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() -> Size<Length>
pub fn auto() -> Size<Length>
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.
Source§impl Size<DevicePixels>
impl Size<DevicePixels>
Source§impl Size<Pixels>
impl Size<Pixels>
Sourcepub fn to_device_pixels(self, scale_factor: f32) -> Size<DevicePixels>
pub fn to_device_pixels(self, scale_factor: f32) -> Size<DevicePixels>
Converts the size from logical to physical pixels.
Trait Implementations§
impl<T> Copy for Size<T>
Source§impl<'de, T> Deserialize<'de> for Size<T>
impl<'de, T> Deserialize<'de> for Size<T>
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Size<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Size<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl<T> Eq for Size<T>
Source§impl<T> From<SizeRefinement<T>> for Size<T>
impl<T> From<SizeRefinement<T>> for Size<T>
Source§fn from(value: SizeRefinement<T>) -> Size<T>
fn from(value: SizeRefinement<T>) -> Size<T>
Source§impl Interpolate for Size<Pixels>
impl Interpolate for Size<Pixels>
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> Refineable for Size<T>
impl<T> Refineable for Size<T>
type Refinement = SizeRefinement<T>
Source§fn refine(&mut self, refinement: &<Size<T> as Refineable>::Refinement)
fn refine(&mut self, refinement: &<Size<T> as Refineable>::Refinement)
Source§fn refined(self, refinement: <Size<T> as Refineable>::Refinement) -> Size<T>
fn refined(self, refinement: <Size<T> as Refineable>::Refinement) -> Size<T>
self and calling
refine on it.Source§fn is_superset_of(
&self,
refinement: &<Size<T> as Refineable>::Refinement,
) -> bool
fn is_superset_of( &self, refinement: &<Size<T> as Refineable>::Refinement, ) -> bool
true if this instance would contain all values from the refinement. Read moreSource§fn subtract(
&self,
refinement: &<Size<T> as Refineable>::Refinement,
) -> <Size<T> as Refineable>::Refinement
fn subtract( &self, refinement: &<Size<T> as Refineable>::Refinement, ) -> <Size<T> as Refineable>::Refinement
Source§impl<T> Serialize for Size<T>
impl<T> Serialize for Size<T>
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl<T> 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> UnsafeUnpin for Size<T>where
T: UnsafeUnpin,
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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().