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.
This may be converted to Offset
with from
/ into
.
Tuple Fields§
§0: i32
§1: i32
Implementations§
source§impl Size
impl Size
sourcepub fn clamp(self, min: Size, max: Size) -> Size
pub fn clamp(self, min: Size, max: Size) -> Size
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>(self, dir: D) -> i32where
D: Directional,
pub fn extract<D>(self, dir: D) -> i32where
D: Directional,
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>(&mut self, dir: D, value: i32)where
D: Directional,
pub fn set_component<D>(&mut self, dir: D, value: i32)where
D: Directional,
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) -> Size
pub fn new(w: i32, h: i32) -> Size
Construct
In debug mode, this asserts that components are non-negative.
sourcepub fn splat(n: i32) -> Size
pub fn splat(n: i32) -> Size
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.
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.
sourcepub fn as_logical(self) -> Size
pub fn as_logical(self) -> Size
Convert to a “logical” [winit::dpi::Size
]
This implies that the Size
was calculated using scale_factor = 1
.
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: Size)
fn add_assign(&mut self, rhs: Size)
+=
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§impl ConvApprox<Vec2> for Size
impl ConvApprox<Vec2> for Size
source§impl ConvFloat<DVec2> for Size
impl ConvFloat<DVec2> for Size
source§fn try_conv_trunc(x: DVec2) -> Result<Size, Error>
fn try_conv_trunc(x: DVec2) -> Result<Size, Error>
source§fn try_conv_nearest(x: DVec2) -> Result<Size, Error>
fn try_conv_nearest(x: DVec2) -> Result<Size, Error>
source§fn try_conv_floor(x: DVec2) -> Result<Size, Error>
fn try_conv_floor(x: DVec2) -> Result<Size, Error>
source§fn try_conv_ceil(x: DVec2) -> Result<Size, Error>
fn try_conv_ceil(x: DVec2) -> Result<Size, Error>
§fn conv_trunc(x: T) -> Self
fn conv_trunc(x: T) -> Self
§fn conv_nearest(x: T) -> Self
fn conv_nearest(x: T) -> Self
§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<Size, Error>
fn try_conv_trunc(x: Vec2) -> Result<Size, Error>
source§fn try_conv_nearest(x: Vec2) -> Result<Size, Error>
fn try_conv_nearest(x: Vec2) -> Result<Size, Error>
source§fn try_conv_floor(x: Vec2) -> Result<Size, Error>
fn try_conv_floor(x: Vec2) -> Result<Size, Error>
source§fn try_conv_ceil(x: Vec2) -> Result<Size, Error>
fn try_conv_ceil(x: Vec2) -> Result<Size, Error>
§fn conv_trunc(x: T) -> Self
fn conv_trunc(x: T) -> Self
§fn conv_nearest(x: T) -> Self
fn conv_nearest(x: T) -> Self
§fn conv_floor(x: T) -> Self
fn conv_floor(x: T) -> Self
source§impl 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.
source§impl 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.
source§impl PartialEq for Size
impl PartialEq for Size
source§impl Sub for 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
impl SubAssign for Size
Subtract a Size
from a Size
This is saturating subtraction.
source§fn sub_assign(&mut self, rhs: Size)
fn sub_assign(&mut self, rhs: Size)
-=
operation. Read moreimpl 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§
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
§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
§fn cast_approx(self) -> T
fn cast_approx(self) -> T
§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
§fn cast_floor(self) -> T
fn cast_floor(self) -> T
§fn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
§fn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
§fn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
§fn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
§impl<S, T> ConvApprox<S> for Twhere
T: Conv<S>,
impl<S, T> ConvApprox<S> for Twhere
T: Conv<S>,
§fn try_conv_approx(x: S) -> Result<T, Error>
fn try_conv_approx(x: S) -> Result<T, Error>
§fn conv_approx(x: S) -> T
fn conv_approx(x: S) -> T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§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()
.