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 PartialOrd for Dims
impl PartialOrd for Dims
Source§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