Skip to main content

Rect

Struct Rect 

Source
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: u16

Implementations§

Source§

impl Rect

Source

pub const fn new(x: u16, y: u16, width: u16, height: u16) -> Rect

Source

pub fn right(&self) -> u16

Source

pub fn bottom(&self) -> u16

Source

pub fn is_empty(&self) -> bool

Source

pub fn contains(&self, column: u16, row: u16) -> bool

Source

pub fn intersection(&self, other: Rect) -> Rect

The part of this rectangle inside other.

Source

pub fn inner(&self, n: u16) -> Rect

This rectangle without a border of n cells on each side.

Source

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());
Source

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));
Source

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));
Source

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);
Source

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");
Source

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)]);
Source

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§

Source§

impl Clone for Rect

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Rect

Source§

impl Debug for Rect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Rect

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Rect

Source§

impl Hash for Rect

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Rect

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more