pub struct Rect {
pub x: u16,
pub y: u16,
pub width: u16,
pub height: u16,
}Expand description
A rectangle of cells.
Fields§
§x: u16§y: u16§width: u16§height: u16Implementations§
Source§impl Rect
impl Rect
pub const fn new(x: u16, y: u16, width: u16, height: u16) -> Rect
pub fn right(&self) -> u16
pub fn bottom(&self) -> u16
pub fn is_empty(&self) -> bool
pub fn contains(&self, column: u16, row: u16) -> bool
Sourcepub fn intersection(&self, other: Rect) -> Rect
pub fn intersection(&self, other: Rect) -> Rect
The part of this rectangle inside other.
Sourcepub fn inset(&self, top: u16, right: u16, bottom: u16, left: u16) -> Rect
pub fn inset(&self, top: u16, right: u16, bottom: u16, left: u16) -> Rect
This rectangle without top, right, bottom and left cells on
those sides (CSS’s order), never less than empty.
use rich_ext::surface::Rect;
assert_eq!(Rect::new(0, 0, 10, 5).inset(1, 2, 0, 3), Rect::new(3, 1, 5, 4));
assert!(Rect::new(0, 0, 4, 4).inset(0, 3, 0, 3).is_empty());Sourcepub fn centered(&self, width: u16, height: u16) -> Rect
pub fn centered(&self, width: u16, height: u16) -> Rect
A rectangle width x height in the middle of this one, cut to it
when it is larger (an odd cell left over goes after it): where a
pop-up or a dialog goes.
use rich_ext::surface::Rect;
assert_eq!(Rect::new(0, 0, 20, 10).centered(8, 3), Rect::new(6, 3, 8, 3));
assert_eq!(Rect::new(2, 2, 4, 4).centered(10, 2), Rect::new(2, 3, 4, 2));Sourcepub fn offset(&self, dx: i32, dy: i32) -> Rect
pub fn offset(&self, dx: i32, dy: i32) -> Rect
This rectangle moved dx columns right and dy rows down (left and
up when negative), its size kept and its corner kept on the grid:
at least 0, and no further than its size allows.
use rich_ext::surface::Rect;
assert_eq!(Rect::new(5, 5, 2, 2).offset(3, -2), Rect::new(8, 3, 2, 2));
assert_eq!(Rect::new(1, 1, 2, 2).offset(-4, 0), Rect::new(0, 1, 2, 2));Sourcepub fn union(&self, other: Rect) -> Rect
pub fn union(&self, other: Rect) -> Rect
The smallest rectangle holding both. An empty rectangle holds nothing, so it adds nothing.
use rich_ext::surface::Rect;
let a = Rect::new(0, 0, 2, 2);
assert_eq!(a.union(Rect::new(5, 1, 1, 4)), Rect::new(0, 0, 6, 5));
assert_eq!(a.union(Rect::default()), a);Sourcepub fn intersects(&self, other: Rect) -> bool
pub fn intersects(&self, other: Rect) -> bool
Whether the two share a cell.
use rich_ext::surface::Rect;
let a = Rect::new(0, 0, 4, 4);
assert!(a.intersects(Rect::new(3, 3, 2, 2)));
assert!(!a.intersects(Rect::new(4, 0, 2, 2)), "touching is not sharing");Sourcepub fn rows(self) -> impl DoubleEndedIterator<Item = Rect> + ExactSizeIterator
pub fn rows(self) -> impl DoubleEndedIterator<Item = Rect> + ExactSizeIterator
Each of its rows, top to bottom, as a rectangle one cell tall.
use rich_ext::surface::Rect;
let rows: Vec<Rect> = Rect::new(1, 2, 3, 2).rows().collect();
assert_eq!(rows, [Rect::new(1, 2, 3, 1), Rect::new(1, 3, 3, 1)]);Sourcepub fn columns(
self,
) -> impl DoubleEndedIterator<Item = Rect> + ExactSizeIterator
pub fn columns( self, ) -> impl DoubleEndedIterator<Item = Rect> + ExactSizeIterator
Each of its columns, left to right, as a rectangle one cell wide.
use rich_ext::surface::Rect;
let columns: Vec<Rect> = Rect::new(1, 2, 2, 3).columns().collect();
assert_eq!(columns, [Rect::new(1, 2, 1, 3), Rect::new(2, 2, 1, 3)]);Trait Implementations§
impl Copy for Rect
impl Eq for Rect
impl StructuralPartialEq for Rect
Auto Trait Implementations§
impl Freeze for Rect
impl RefUnwindSafe for Rect
impl Send for Rect
impl Sync for Rect
impl Unpin for Rect
impl UnsafeUnpin for Rect
impl UnwindSafe for Rect
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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
Compare self to
key and return true if they are equal.