Expand description
A 2D size, also known as an extent
This is both a size and a relative position. One can add or subtract a size
from a Coord. One can multiply a size by a scalar.
A Size is expected to be non-negative; some methods such as Size::new
and implementations of subtraction will check this, but only in debug mode
(similar to overflow checks on integers).
Subtraction is defined to be saturating subtraction.
This may be converted to Offset with from / into.
Tuple Fields
0: i321: i32Implementations
sourceimpl Size
impl Size
sourcepub fn as_physical(self) -> Size
Available on crate feature winit only.
pub fn as_physical(self) -> Size
winit only.Convert to a “physical” winit::dpi::Size
This implies that the Size was calculated using the correct
scale factor. Before the window has been constructed (when the
scale factor is supposedly unknown) this should not be used.
sourcepub fn as_logical(self) -> Size
Available on crate feature winit only.
pub fn as_logical(self) -> Size
winit only.Convert to a “logical” winit::dpi::Size
This implies that the Size was calculated using scale_factor = 1.
sourceimpl Size
impl Size
sourcepub fn clamp(self, min: Self, max: Self) -> Self
pub fn clamp(self, min: Self, max: Self) -> Self
Restrict a value to the specified interval, componentwise
sourcepub fn distance_l1(self) -> i32
pub fn distance_l1(self) -> i32
Return the L1 (rectilinear / taxicab) distance
sourcepub fn distance_l_inf(self) -> i32
pub fn distance_l_inf(self) -> i32
Return the L-inf (max) distance
sourcepub fn extract<D: Directional>(self, dir: D) -> i32
pub fn extract<D: Directional>(self, dir: D) -> i32
Extract one component, based on a direction
This merely extracts the horizontal or vertical component. It never negates it, even if the axis is reversed.
sourcepub fn set_component<D: Directional>(&mut self, dir: D, value: i32)
pub fn set_component<D: Directional>(&mut self, dir: D, value: i32)
Set one component of self, based on a direction
This does not negate components when the direction is reversed.
sourceimpl Size
impl Size
sourcepub fn new(w: i32, h: i32) -> Self
pub fn new(w: i32, h: i32) -> Self
Construct
In debug mode, this asserts that components are non-negative.
sourcepub fn splat(n: i32) -> Self
pub fn splat(n: i32) -> Self
Construct, using the same value on all axes
In debug mode, this asserts that components are non-negative.
sourcepub fn aspect_scale_to(self, target: Size) -> Option<Size>
pub fn aspect_scale_to(self, target: Size) -> Option<Size>
Scale to fit within the target size, keeping aspect ratio
If either dimension of self is 0, this returns None.
Trait Implementations
sourceimpl AddAssign<Size> for Coord
impl AddAssign<Size> for Coord
sourcefn add_assign(&mut self, rhs: Size)
fn add_assign(&mut self, rhs: Size)
Performs the += operation. Read more
sourceimpl AddAssign<Size> for Size
impl AddAssign<Size> for Size
sourcefn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the += operation. Read more
sourceimpl Conv<Size> for LogicalSize
impl Conv<Size> for LogicalSize
sourceimpl ConvApprox<DVec2> for Size
impl ConvApprox<DVec2> for Size
sourcefn try_conv_approx(arg: DVec2) -> Result<Self>
fn try_conv_approx(arg: DVec2) -> Result<Self>
Try converting from T to Self, allowing approximation of value Read more
sourcefn conv_approx(x: T) -> Self
fn conv_approx(x: T) -> Self
Converting from T to Self, allowing approximation of value Read more
sourceimpl ConvApprox<Vec2> for Size
impl ConvApprox<Vec2> for Size
sourcefn try_conv_approx(arg: Vec2) -> Result<Self>
fn try_conv_approx(arg: Vec2) -> Result<Self>
Try converting from T to Self, allowing approximation of value Read more
sourcefn conv_approx(x: T) -> Self
fn conv_approx(x: T) -> Self
Converting from T to Self, allowing approximation of value Read more
sourceimpl ConvFloat<DVec2> for Size
impl ConvFloat<DVec2> for Size
sourcefn try_conv_trunc(x: DVec2) -> Result<Self>
fn try_conv_trunc(x: DVec2) -> Result<Self>
Try converting to integer with truncation Read more
sourcefn try_conv_nearest(x: DVec2) -> Result<Self>
fn try_conv_nearest(x: DVec2) -> Result<Self>
Try converting to the nearest integer Read more
sourcefn try_conv_floor(x: DVec2) -> Result<Self>
fn try_conv_floor(x: DVec2) -> Result<Self>
Try converting the floor to an integer Read more
sourcefn try_conv_ceil(x: DVec2) -> Result<Self>
fn try_conv_ceil(x: DVec2) -> Result<Self>
Try convert the ceiling to an integer Read more
sourcefn conv_trunc(x: T) -> Self
fn conv_trunc(x: T) -> Self
Convert to integer with truncatation Read more
sourcefn conv_nearest(x: T) -> Self
fn conv_nearest(x: T) -> Self
Convert to the nearest integer Read more
sourcefn conv_floor(x: T) -> Self
fn conv_floor(x: T) -> Self
Convert the floor to an integer Read more
sourceimpl ConvFloat<Vec2> for Size
impl ConvFloat<Vec2> for Size
sourcefn try_conv_trunc(x: Vec2) -> Result<Self>
fn try_conv_trunc(x: Vec2) -> Result<Self>
Try converting to integer with truncation Read more
sourcefn try_conv_nearest(x: Vec2) -> Result<Self>
fn try_conv_nearest(x: Vec2) -> Result<Self>
Try converting to the nearest integer Read more
sourcefn try_conv_floor(x: Vec2) -> Result<Self>
fn try_conv_floor(x: Vec2) -> Result<Self>
Try converting the floor to an integer Read more
sourcefn try_conv_ceil(x: Vec2) -> Result<Self>
fn try_conv_ceil(x: Vec2) -> Result<Self>
Try convert the ceiling to an integer Read more
sourcefn conv_trunc(x: T) -> Self
fn conv_trunc(x: T) -> Self
Convert to integer with truncatation Read more
sourcefn conv_nearest(x: T) -> Self
fn conv_nearest(x: T) -> Self
Convert to the nearest integer Read more
sourcefn conv_floor(x: T) -> Self
fn conv_floor(x: T) -> Self
Convert the floor to an integer Read more
sourceimpl<'de> Deserialize<'de> for Size
impl<'de> Deserialize<'de> for Size
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Div<i32> for Size
impl Div<i32> for Size
Divide a Size by an integer
In debug mode this asserts that the result is non-negative.
sourceimpl Mul<i32> for Size
impl Mul<i32> for Size
Multiply a Size by an integer
In debug mode this asserts that the result is non-negative.
sourceimpl PartialEq<Size> for Size
impl PartialEq<Size> for Size
sourceimpl Sub<Size> for Size
impl Sub<Size> for Size
Subtract a Size from a Size
This is saturating subtraction: Size::ZERO - Size::splat(6) == Size::ZERO.
sourceimpl SubAssign<Size> for Coord
impl SubAssign<Size> for Coord
sourcefn sub_assign(&mut self, rhs: Size)
fn sub_assign(&mut self, rhs: Size)
Performs the -= operation. Read more
sourceimpl SubAssign<Size> for Size
impl SubAssign<Size> for Size
Subtract a Size from a Size
This is saturating subtraction.
sourcefn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the -= operation. Read more
impl Copy for Size
impl Eq for Size
impl StructuralEq for Size
impl StructuralPartialEq for Size
Auto Trait Implementations
impl RefUnwindSafe for Size
impl Send for Size
impl Sync for Size
impl Unpin for Size
impl UnwindSafe for Size
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
sourcefn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Try approximate conversion from Self to T Read more
sourcefn cast_approx(self) -> T
fn cast_approx(self) -> T
Cast approximately from Self to T Read more
sourceimpl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
sourcefn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Cast to integer, truncating Read more
sourcefn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Cast to the nearest integer Read more
sourcefn cast_floor(self) -> T
fn cast_floor(self) -> T
Cast the floor to an integer Read more
sourcefn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
Try converting to integer with truncation Read more
sourcefn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
Try converting to the nearest integer Read more
sourcefn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
Try converting the floor to an integer Read more
sourcefn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
Try convert the ceiling to an integer Read more
sourceimpl<S, T> ConvApprox<S> for Twhere
T: Conv<S>,
impl<S, T> ConvApprox<S> for Twhere
T: Conv<S>,
sourcefn try_conv_approx(x: S) -> Result<T, Error>
fn try_conv_approx(x: S) -> Result<T, Error>
Try converting from T to Self, allowing approximation of value Read more
sourcefn conv_approx(x: S) -> T
fn conv_approx(x: S) -> T
Converting from T to Self, allowing approximation of value Read more
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key and return true if they are equal.