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
impl Size
Sourcepub const INFINITE: Size
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.
Sourcepub const fn square(dimension: f64) -> Size
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.
Sourcepub const fn from_width(width: f64) -> Size
pub const fn from_width(width: f64) -> Size
Sourcepub const fn from_height(height: f64) -> Size
pub const fn from_height(height: f64) -> Size
Sourcepub const fn from_radius(radius: f64) -> Size
pub const fn from_radius(radius: f64) -> Size
Sourcepub fn is_infinite(&self) -> bool
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).
Sourcepub fn is_finite(&self) -> bool
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.
Sourcepub fn lt(&self, other: &Size) -> bool
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.
Sourcepub fn le(&self, other: &Size) -> bool
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.
Sourcepub fn gt(&self, other: &Size) -> bool
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.
Sourcepub fn ge(&self, other: &Size) -> bool
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.
Sourcepub fn aspect_ratio(&self) -> f64
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.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether this size encloses a zero area.
Negative areas are considered empty.
Sourcepub fn truncating_div(&self, operand: f64) -> Size
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.
Sourcepub fn shortest_side(&self) -> f64
pub fn shortest_side(&self) -> f64
Sourcepub fn longest_side(&self) -> f64
pub fn longest_side(&self) -> f64
Sourcepub fn top_left(&self, origin: Offset) -> Offset
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.
Sourcepub fn top_center(&self, origin: Offset) -> Offset
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.
Sourcepub fn top_right(&self, origin: Offset) -> Offset
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.
Sourcepub fn center_left(&self, origin: Offset) -> Offset
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.
Sourcepub fn center(&self, origin: Offset) -> Offset
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.
Sourcepub fn center_right(&self, origin: Offset) -> Offset
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.
Sourcepub fn bottom_left(&self, origin: Offset) -> Offset
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.
Sourcepub fn bottom_center(&self, origin: Offset) -> Offset
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.
Sourcepub fn bottom_right(&self, origin: Offset) -> Offset
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.
Sourcepub fn contains(&self, offset: Offset) -> bool
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.
Sourcepub fn lerp(a: Option<Size>, b: Option<Size>, t: f64) -> Option<Size>
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
impl Add<Offset> for 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§impl BitAnd<Size> for Offset
Rectangle constructor operator.
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)impl Copy for Size
Source§impl Div<f64> for Size
Division operator.
impl Div<f64> for Size
Division operator.
Source§impl Mul<f64> for Size
Multiplication operator.
impl Mul<f64> for Size
Multiplication operator.
Source§impl Rem<f64> for Size
Modulo (remainder) operator.
impl Rem<f64> for Size
Modulo (remainder) operator.
impl StructuralPartialEq for Size
Source§impl Sub for Size
Binary subtraction operator for Size.
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§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.
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.