pub struct Dims { /* private fields */ }
Expand description
A horizontal and vertical rectangular dimension with no specified location.
Implementations§
source§impl Dims
impl Dims
sourcepub fn dim(&self, dir: Dir) -> i64
pub fn dim(&self, dir: Dir) -> i64
Returns the dimension in the specified direction.
§Example
let dims = Dims::new(100, 200);
assert_eq!(dims.dim(Dir::Vert), 200);
assert_eq!(dims.dim(Dir::Horiz), 100);
sourcepub fn longer_dir(&self) -> Dir
pub fn longer_dir(&self) -> Dir
Returns the direction of the longer dimension.
If the width and height are equal, returns Dir::Horiz
.
§Example
let dims = Dims::new(100, 200);
assert_eq!(dims.longer_dir(), Dir::Vert);
let dims = Dims::new(200, 100);
assert_eq!(dims.longer_dir(), Dir::Horiz);
let dims = Dims::new(100, 100);
assert_eq!(dims.longer_dir(), Dir::Horiz);
sourcepub fn longer_dir_strict(&self) -> Option<Dir>
pub fn longer_dir_strict(&self) -> Option<Dir>
Returns the direction of the longer dimension.
If the width and height are equal, returns None
.
Otherwise, returns a Some
variant containing the longer direction.
sourcepub fn transpose(self) -> Self
pub fn transpose(self) -> Self
Returns a new Dims
object with the horizontal and vertical dimensions flipped.
sourcepub fn w(&self) -> i64
pub fn w(&self) -> i64
Returns the width (i.e. the horizontal dimension).
A shorthand for Dims::width
.
sourcepub fn h(&self) -> i64
pub fn h(&self) -> i64
Returns the height (i.e. the vertical dimension).
A shorthand for Dims::height
.
sourcepub fn into_rect(self) -> Rect
pub fn into_rect(self) -> Rect
Converts this dimension object into a Rect
.
See Rect::from_dims
for more information.
sourcepub fn into_point(self) -> Point
pub fn into_point(self) -> Point
Converts this dimension object into a Point
with coordinates (self.w(), self.h())
.
Trait Implementations§
source§impl AddAssign<Dims> for Point
impl AddAssign<Dims> for Point
source§fn add_assign(&mut self, rhs: Dims)
fn add_assign(&mut self, rhs: Dims)
+=
operation. Read moresource§impl AddAssign for Dims
impl AddAssign for Dims
source§fn add_assign(&mut self, rhs: Dims)
fn add_assign(&mut self, rhs: Dims)
+=
operation. Read moresource§impl<'de> Deserialize<'de> for Dims
impl<'de> Deserialize<'de> for Dims
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 MulAssign<i64> for Dims
impl MulAssign<i64> for Dims
source§fn mul_assign(&mut self, rhs: i64)
fn mul_assign(&mut self, rhs: i64)
*=
operation. Read moresource§impl Ord for Dims
impl Ord for Dims
source§impl PartialEq for Dims
impl PartialEq for Dims
source§impl PartialOrd for Dims
impl PartialOrd for Dims
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl SubAssign for Dims
impl SubAssign for Dims
source§fn sub_assign(&mut self, rhs: Dims)
fn sub_assign(&mut self, rhs: Dims)
-=
operation. Read more