pub struct Size(pub i32, pub i32);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.
Size implements PartialOrd such that the comparison must be true of
all components: for example a < b == a.0 < b.0 && a.1 < b.1.
If c == Size(0, 1) and d == Size(1, 0) then
c != d && !(c < d) && !(c > d). Size does not implement Ord.
This may be converted to Offset with from / into.
Tuple Fields§
§0: i32§1: i32Implementations§
Source§impl Size
impl Size
Sourcepub fn as_physical(self) -> Size
pub fn as_physical(self) -> Size
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.
Source§impl 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.
Source§impl 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§
Source§impl AddAssign<Size> for Coord
impl AddAssign<Size> for Coord
Source§fn add_assign(&mut self, rhs: Size)
fn add_assign(&mut self, rhs: Size)
+= operation. Read moreSource§impl AddAssign for Size
impl AddAssign for Size
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl Conv<Size> for LogicalSize
impl Conv<Size> for LogicalSize
Source§impl ConvApprox<DVec2> for Size
impl ConvApprox<DVec2> for Size
Source§fn try_conv_approx(arg: DVec2) -> Result<Self>
fn try_conv_approx(arg: DVec2) -> Result<Self>
Source§fn conv_approx(x: T) -> Self
fn conv_approx(x: T) -> Self
Source§impl ConvApprox<Vec2> for Size
impl ConvApprox<Vec2> for Size
Source§fn try_conv_approx(arg: Vec2) -> Result<Self>
fn try_conv_approx(arg: Vec2) -> Result<Self>
Source§fn conv_approx(x: T) -> Self
fn conv_approx(x: T) -> Self
Source§impl ConvFloat<DVec2> for Size
impl ConvFloat<DVec2> for Size
Source§fn try_conv_trunc(x: DVec2) -> Result<Self>
fn try_conv_trunc(x: DVec2) -> Result<Self>
Source§fn conv_trunc(x: T) -> Self
fn conv_trunc(x: T) -> Self
Source§fn conv_nearest(x: T) -> Self
fn conv_nearest(x: T) -> Self
Source§fn conv_floor(x: T) -> Self
fn conv_floor(x: T) -> Self
Source§impl ConvFloat<Vec2> for Size
impl ConvFloat<Vec2> for Size
Source§fn try_conv_trunc(x: Vec2) -> Result<Self>
fn try_conv_trunc(x: Vec2) -> Result<Self>
Source§fn conv_trunc(x: T) -> Self
fn conv_trunc(x: T) -> Self
Source§fn conv_nearest(x: T) -> Self
fn conv_nearest(x: T) -> Self
Source§fn conv_floor(x: T) -> Self
fn conv_floor(x: T) -> Self
Source§impl<'de> Deserialize<'de> for Size
impl<'de> Deserialize<'de> for Size
Source§fn 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>,
Source§impl Div<i32> for Size
Divide a Size by an integer
impl Div<i32> for Size
Divide a Size by an integer
In debug mode this asserts that the result is non-negative.
Source§impl Mul<i32> for Size
Multiply a Size by an integer
impl Mul<i32> for Size
Multiply a Size by an integer
In debug mode this asserts that the result is non-negative.
Source§impl PartialOrd for Size
impl PartialOrd for Size
Source§impl Sub for Size
Subtract a Size from a Size
impl Sub for Size
Subtract a Size from a Size
This is saturating subtraction: Size::ZERO - Size::splat(6) == Size::ZERO.
Source§impl SubAssign<Size> for Coord
impl SubAssign<Size> for Coord
Source§fn sub_assign(&mut self, rhs: Size)
fn sub_assign(&mut self, rhs: Size)
-= operation. Read moreSource§impl SubAssign for Size
Subtract a Size from a Size
impl SubAssign for Size
Subtract a Size from a Size
This is saturating subtraction.
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreimpl Copy for Size
impl Eq for Size
impl StructuralPartialEq for Size
Auto Trait Implementations§
impl Freeze for Size
impl RefUnwindSafe for Size
impl Send for Size
impl Sync for Size
impl Unpin for Size
impl UnwindSafe for Size
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<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
Source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
Source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> ConvApprox<S> for Twhere
T: Conv<S>,
impl<S, T> ConvApprox<S> for Twhere
T: Conv<S>,
Source§fn try_conv_approx(x: S) -> Result<T, Error>
fn try_conv_approx(x: S) -> Result<T, Error>
Source§fn conv_approx(x: S) -> T
fn conv_approx(x: S) -> T
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<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().