Skip to main content

Size

Struct Size 

Source
pub struct Size { /* private fields */ }
Expand description

Holds a 2D floating-point size.

You can think of this as an Offset from the origin.

Implementations§

Source§

impl Size

Source

pub const ZERO: Size

An empty size, one with a zero width and a zero height.

Source

pub const INFINITE: Size

A size whose width and height are infinite.

See also:

  • is_infinite, which checks whether either dimension is infinite.
  • is_finite, which checks whether both dimensions are finite.
Source

pub const fn new(width: f64, height: f64) -> Size

Creates a Size with the given width and height.

Source

pub const fn square(dimension: f64) -> Size

Creates a square Size whose width and height are the given dimension.

See also:

  • from_radius, which is more convenient when the available size is the radius of a circle.
Source

pub const fn from_width(width: f64) -> Size

Creates a Size with the given width and an infinite height.

Source

pub const fn from_height(height: f64) -> Size

Creates a Size with the given height and an infinite width.

Source

pub const fn from_radius(radius: f64) -> Size

Creates a square Size whose width and height are twice the given dimension.

This is a square that contains a circle with the given radius.

See also:

  • square, which creates a square with the given dimension.
Source

pub const fn width(&self) -> f64

The horizontal extent of this size.

Source

pub const fn height(&self) -> f64

The vertical extent of this size.

Source

pub fn is_infinite(&self) -> bool

Returns true if either component is f64::INFINITY, and false if both are finite (or negative infinity, or NaN).

This is different than comparing for equality with an instance that has both components set to f64::INFINITY.

See also:

  • is_finite, which is true if both components are finite (and not NaN).
Source

pub fn is_finite(&self) -> bool

Whether both components are finite (neither infinite nor NaN).

See also:

  • is_infinite, which returns true if either component is equal to positive infinity.
Source

pub fn lt(&self, other: &Size) -> bool

Less-than operator. Compares an Offset or Size to another Offset or Size, and returns true if both the horizontal and vertical values of the left-hand-side operand are smaller than the horizontal and vertical values of the right-hand-side operand respectively. Returns false otherwise.

This is a partial ordering. It is possible for two values to be neither less, nor greater than, nor equal to, another.

Source

pub fn le(&self, other: &Size) -> bool

Less-than-or-equal-to operator. Compares an Offset or Size to another Offset or Size, and returns true if both the horizontal and vertical values of the left-hand-side operand are smaller than or equal to the horizontal and vertical values of the right-hand-side operand respectively. Returns false otherwise.

This is a partial ordering. It is possible for two values to be neither less, nor greater than, nor equal to, another.

Source

pub fn gt(&self, other: &Size) -> bool

Greater-than operator. Compares an Offset or Size to another Offset or Size, and returns true if both the horizontal and vertical values of the left-hand-side operand are bigger than the horizontal and vertical values of the right-hand-side operand respectively. Returns false otherwise.

This is a partial ordering. It is possible for two values to be neither less, nor greater than, nor equal to, another.

Source

pub fn ge(&self, other: &Size) -> bool

Greater-than-or-equal-to operator. Compares an Offset or Size to another Offset or Size, and returns true if both the horizontal and vertical values of the left-hand-side operand are bigger than or equal to the horizontal and vertical values of the right-hand-side operand respectively. Returns false otherwise.

This is a partial ordering. It is possible for two values to be neither less, nor greater than, nor equal to, another.

Source

pub fn aspect_ratio(&self) -> f64

The aspect ratio of this size.

This returns the width divided by the height.

If the width is zero, the result will be zero. If the height is zero (and the width is not), the result will be f64::INFINITY or f64::NEG_INFINITY as determined by the sign of width.

See also:

  • AspectRatio, a widget for giving a child widget a specific aspect ratio.
  • FittedBox, a widget that (in most modes) attempts to maintain a child widget’s aspect ratio while changing its size.
Source

pub fn is_empty(&self) -> bool

Whether this size encloses a zero area.

Negative areas are considered empty.

Source

pub fn truncating_div(&self, operand: f64) -> Size

Integer (truncating) division operator.

Returns a Size whose dimensions are the dimensions of this size divided by the scalar operand, rounded towards zero.

Source

pub fn shortest_side(&self) -> f64

The lesser of the magnitudes of the width and the height.

Source

pub fn longest_side(&self) -> f64

The greater of the magnitudes of the width and the height.

Source

pub fn top_left(&self, origin: Offset) -> Offset

The offset to the intersection of the top and left edges of the rectangle described by the given Offset (which is interpreted as the top-left corner) and this Size.

See also Rect::top_left.

Source

pub fn top_center(&self, origin: Offset) -> Offset

The offset to the center of the top edge of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect::top_center.

Source

pub fn top_right(&self, origin: Offset) -> Offset

The offset to the intersection of the top and right edges of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect::top_right.

Source

pub fn center_left(&self, origin: Offset) -> Offset

The offset to the center of the left edge of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect::center_left.

Source

pub fn center(&self, origin: Offset) -> Offset

The offset to the point halfway between the left and right and the top and bottom edges of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect::center.

Source

pub fn center_right(&self, origin: Offset) -> Offset

The offset to the center of the right edge of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect::center_right.

Source

pub fn bottom_left(&self, origin: Offset) -> Offset

The offset to the intersection of the bottom and left edges of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect::bottom_left.

Source

pub fn bottom_center(&self, origin: Offset) -> Offset

The offset to the center of the bottom edge of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect::bottom_center.

Source

pub fn bottom_right(&self, origin: Offset) -> Offset

The offset to the intersection of the bottom and right edges of the rectangle described by the given offset (which is interpreted as the top-left corner) and this size.

See also Rect::bottom_right.

Source

pub fn contains(&self, offset: Offset) -> bool

Whether the point specified by the given offset (which is assumed to be relative to the top left of the size) lies between the left and right and the top and bottom edges of a rectangle of this size.

Rectangles include their top and left edges but exclude their bottom and right edges.

Source

pub fn flipped(&self) -> Size

A Size with the width and height swapped.

Source

pub fn lerp(a: Option<Size>, b: Option<Size>, t: f64) -> Option<Size>

Linearly interpolate between two sizes.

If either size is null, this function interpolates from Size::ZERO.

The t argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning a (or something equivalent to a), 1.0 meaning that the interpolation has finished, returning b (or something equivalent to b), and values in between meaning that the interpolation is at the relevant point on the timeline between a and b. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid (and can easily be generated by curves such as Curves.elasticInOut).

Values for t are usually obtained from an Animation<double>, such as an AnimationController.

Trait Implementations§

Source§

impl Add<Offset> for Size

Binary addition operator for adding an Offset to a Size.

Returns a Size whose width is the sum of the width of the left-hand-side operand, a Size, and the Offset::dx dimension of the right-hand-side operand, an Offset, and whose height is the sum of the height of the left-hand-side operand and the Offset::dy dimension of the right-hand-side operand.

Source§

type Output = Size

The resulting type after applying the + operator.
Source§

fn add(self, other: Offset) -> Size

Performs the + operation. Read more
Source§

impl BitAnd<Size> for Offset

Rectangle constructor operator.

Combines an Offset and a Size to form a Rect whose top-left coordinate is the point given by adding this offset, the left-hand-side operand, to the origin, and whose size is the right-hand-side operand.

let my_rect = Offset::ZERO & Size::new(100.0, 100.0);
// same as: Rect::from_ltwh(0.0, 0.0, 100.0, 100.0)
Source§

type Output = Rect

The resulting type after applying the & operator.
Source§

fn bitand(self, other: Size) -> Rect

Performs the & operation. Read more
Source§

impl Clone for Size

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 Copy for Size

Source§

impl Debug for Size

Source§

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

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

impl Div<f64> for Size

Division operator.

Returns a Size whose dimensions are the dimensions of the left-hand-side operand (a Size) divided by the scalar right-hand-side operand (an f64).

Source§

type Output = Size

The resulting type after applying the / operator.
Source§

fn div(self, operand: f64) -> Size

Performs the / operation. Read more
Source§

impl From<Size> for Size

Source§

fn from(size: Size) -> Size

Converts to this type from the input type.
Source§

impl Mul<f64> for Size

Multiplication operator.

Returns a Size whose dimensions are the dimensions of the left-hand-side operand (a Size) multiplied by the scalar right-hand-side operand (an f64).

Source§

type Output = Size

The resulting type after applying the * operator.
Source§

fn mul(self, operand: f64) -> Size

Performs the * operation. Read more
Source§

impl PartialEq for Size

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 Rem<f64> for Size

Modulo (remainder) operator.

Returns a Size whose dimensions are the remainder of dividing the left-hand-side operand (a Size) by the scalar right-hand-side operand (an f64).

Source§

type Output = Size

The resulting type after applying the % operator.
Source§

fn rem(self, operand: f64) -> Size

Performs the % operation. Read more
Source§

impl StructuralPartialEq for Size

Source§

impl Sub for Size

Binary subtraction operator for Size.

Subtracting a Size from a Size returns the Offset that describes how much bigger the left-hand-side operand is than the right-hand-side operand. Adding that resulting Offset to the Size that was the right-hand-side operand would return a Size equal to the Size that was the left-hand-side operand. (i.e. if size_a - size_b -> offset_a, then offset_a + size_b -> size_a)

Source§

type Output = Offset

The resulting type after applying the - operator.
Source§

fn sub(self, other: Size) -> Offset

Performs the - operation. Read more
Source§

impl Sub<Offset> for Size

Subtracting an Offset from a Size returns the Size that is smaller than the Size operand by the difference given by the Offset operand. In other words, the returned Size has a width consisting of the width of the left-hand-side operand minus the Offset::dx dimension of the right-hand-side operand, and a height consisting of the height of the left-hand-side operand minus the Offset::dy dimension of the right-hand-side operand.

Source§

type Output = Size

The resulting type after applying the - operator.
Source§

fn sub(self, other: Offset) -> Size

Performs the - operation. Read more

Auto Trait Implementations§

§

impl Freeze for Size

§

impl RefUnwindSafe for Size

§

impl Send for Size

§

impl Sync for Size

§

impl Unpin for Size

§

impl UnsafeUnpin for Size

§

impl UnwindSafe for Size

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<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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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, 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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,