pub enum Position {
TopLeftCorner(Point),
Center(Point),
Rect(Rect),
}
Expand description
Where to draw a specific object.
Variants§
TopLeftCorner(Point)
Place the top left corner at a specific position, ignoring size. Only used in the most primitive situations
Center(Point)
Center the object at this position
Rect(Rect)
Draw the object in a specific rectangle
Implementations§
Source§impl Position
impl Position
Sourcepub fn into_rect_with_size(self, width: u32, height: u32) -> Rect
pub fn into_rect_with_size(self, width: u32, height: u32) -> Rect
Convert a Position
into a Rect with the specified size. The size is not gauranteed to be
(width, height) such as when the Position
is a Position::Rect
with a smaller size
For Position::Rect
the center is preserved, but the size is changed.
use ytesrev::{Point, Rect};
use ytesrev::drawable::Position;
let tlc = Position::TopLeftCorner(Point::new(10, 20));
assert_eq!(tlc.into_rect_with_size(5, 8), Rect::new(10, 20, 5, 8));
let center = Position::Center(Point::new(20, 30));
assert_eq!(center.into_rect_with_size(4, 10), Rect::new(18, 25, 4, 10));
let rect = Position::Rect(Rect::new(10, 40, 20, 20));
assert_eq!(rect.into_rect_with_size(6, 4), Rect::new(17, 48, 6, 4));
let rect_too_short = Position::Rect(Rect::new(10, 20, 30, 8));
assert_eq!(rect_too_short.into_rect_with_size(20, 69), Rect::new(15, 20, 20, 8));
Sourcepub fn into_rect_with_size_unbounded(self, width: u32, height: u32) -> Rect
pub fn into_rect_with_size_unbounded(self, width: u32, height: u32) -> Rect
Convert a Position into a Rect, like Position::into_rect_with_size
, but this doesn’t
check if the Position::Rect
is too small.
use ytesrev::{Point, Rect};
use ytesrev::drawable::Position;
let tlc = Position::TopLeftCorner(Point::new(20, 50));
assert_eq!(tlc.into_rect_with_size(2, 7), Rect::new(20, 50, 2, 7));
let center = Position::Center(Point::new(50, 10));
assert_eq!(center.into_rect_with_size(2, 8), Rect::new(49, 6, 2, 8));
let rect = Position::Rect(Rect::new(10, 40, 20, 20));
assert_eq!(rect.into_rect_with_size(6, 4), Rect::new(17, 48, 6, 4));
Trait Implementations§
impl Copy for Position
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnwindSafe for Position
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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 more