Size

Struct Size 

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

The width component of the size.

§height: T

The height component of the size.

Implementations§

Source§

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

Source

pub fn new(width: T, height: T) -> Self

Create a new Size, a synonym for size

Source§

impl<T> Size<T>
where T: Clone + Debug + Default + PartialEq,

Source

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

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 type T and returns a value of type U.
§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<T> Size<T>
where T: Clone + Debug + Default + PartialEq + Half,

Source

pub fn center(&self) -> Point<T>

Compute the center point of the size.g

Source§

impl Size<Pixels>

Source

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>

Source

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 another Size to compare with self.
§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 });
Source

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 another Size to compare with self.
§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>

Source

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>

Source

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<T> Add for Size<T>
where T: Add<Output = T> + Clone + Debug + Default + PartialEq,

Source§

type Output = Size<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T> Along for Size<T>
where T: Clone + Debug + Default + PartialEq,

Source§

fn apply_along(&self, axis: Axis, f: impl FnOnce(T) -> T) -> Self

Returns the value of this size along the given axis.

Source§

type Unit = T

The unit associated with this type
Source§

fn along(&self, axis: Axis) -> T

Returns the unit along the given axis.
Source§

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

Source§

fn clone(&self) -> Size<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Size<T>
where T: Clone + Debug + Default + PartialEq,

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 Size<T>

Source§

fn default() -> Size<T>

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

impl<'de, T> Deserialize<'de> for Size<T>
where T: Deserialize<'de> + Clone + Debug + Default + PartialEq,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq + Display> Display for Size<T>

Source§

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

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

impl<T, __RhsT: Copy> Div<__RhsT> for Size<T>
where T: Div<__RhsT, Output = T> + Clone + Debug + Default + PartialEq,

Source§

type Output = Size<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: __RhsT) -> Size<T>

Performs the / operation. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq> From<Point<T>> for Size<T>

Source§

fn from(point: Point<T>) -> Self

Converts to this type from the input type.
Source§

impl From<Size<DevicePixels>> for Size

Source§

fn from(size: Size<DevicePixels>) -> Self

Converts to this type from the input type.
Source§

impl From<Size<Pixels>> for Size<AbsoluteLength>

Source§

fn from(size: Size<Pixels>) -> Self

Converts to this type from the input type.
Source§

impl From<Size<Pixels>> for Size<AvailableSpace>

Source§

fn from(size: Size<Pixels>) -> Self

Converts to this type from the input type.
Source§

impl From<Size<Pixels>> for Size<DefiniteLength>

Source§

fn from(size: Size<Pixels>) -> Self

Converts to this type from the input type.
Source§

impl<T, U> From<Size<T>> for Size<U>
where T: Into<U>, U: Clone + Debug + Default + PartialEq,

Source§

fn from(taffy_size: TaffySize<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, U> From<Size<T>> for Size<U>
where T: Into<U> + Clone + Debug + Default + PartialEq,

Source§

fn from(size: Size<T>) -> Self

Converts to this type from the input type.
Source§

impl From<Size2D<i32, UnknownUnit>> for Size<DevicePixels>

Source§

fn from(size: Size) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone + Debug + Default + PartialEq> From<SizeRefinement<T>> for Size<T>
where Option<T>: Clone,

Source§

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

Converts to this type from the input type.
Source§

impl From<Vector2F> for Size<f32>

Source§

fn from(vec: Vector2F) -> Self

Converts to this type from the input type.
Source§

impl From<Vector2I> for Size<DevicePixels>

Source§

fn from(value: Vector2I) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash + Clone + Debug + Default + PartialEq> Hash for Size<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> IsZero for Size<T>
where T: IsZero + Clone + Debug + Default + PartialEq,

Source§

fn is_zero(&self) -> bool

Determines if the value is zero. Read more
Source§

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

Source§

type Output = Size<Rhs>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<T, S> MulAssign<S> for Size<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 Size<T>

Source§

fn eq(&self, other: &Size<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

type Refinement = SizeRefinement<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> Serialize for Size<T>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> Sub for Size<T>
where T: Sub<Output = T> + Clone + Debug + Default + PartialEq,

Source§

type Output = Size<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

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

Source§

impl<T> Eq for Size<T>
where T: Eq + Clone + Debug + Default + PartialEq,

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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<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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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<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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
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<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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,