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 rectangular area in the terminal.

Fields§

§x: u16

Column of the top-left corner.

§y: u16

Row of the top-left corner.

§width: u16

Width in columns.

§height: u16

Height in rows.

Implementations§

Source§

impl Rect

Source

pub const MAX: Self

A rect that covers the entire addressable terminal area.

Source

pub const MIN: Self = Self::ZERO

The smallest possible rect (same as ZERO).

Source

pub const ZERO: Self

A zero-width, zero-height rect at the origin.

Source

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

Create a new rect, clamping width/height so the rect does not overflow u16.

Source

pub const fn area(self) -> u32

Total number of cells inside this rect.

Source

pub const fn is_empty(self) -> bool

Returns true if the rect has zero width or height.

Source

pub const fn left(self) -> u16

The leftmost column (same as x).

Source

pub const fn right(self) -> u16

The first column after the right edge (x + width).

Source

pub const fn top(self) -> u16

The topmost row (same as y).

Source

pub const fn bottom(self) -> u16

The first row after the bottom edge (y + height).

Source

pub const fn row(self) -> u16

The row of the top edge (same as y).

Source

pub const fn col(self) -> u16

The column of the left edge (same as x).

Source

pub const fn inner(self, margin: Margin) -> Self

Shrink this rect by the given margin on all sides.

Source

pub const fn outer(self, margin: Margin) -> Self

Expand this rect by the given margin on all sides.

Source

pub fn offset(self, offset: Offset) -> Self

Move this rect by the given offset, clamping to the valid u16 range.

Source

pub const fn resize(self, size: Size) -> Self

Resize this rect to the given dimensions, keeping the top-left corner.

Source

pub fn union(self, other: Self) -> Self

The smallest rect that contains both self and other.

Source

pub fn intersection(self, other: Self) -> Self

The overlap between self and other.

Returns a zero-area rect if they do not intersect.

Source

pub const fn intersects(self, other: Self) -> bool

Returns true if self and other overlap.

Source

pub const fn contains(self, position: Position) -> bool

Returns true if the given position lies inside this rect.

Source

pub fn clamp(self, other: Self) -> Self

Clamp this rect so it fits entirely inside other.

Source

pub const fn rows(self) -> Rows

Iterate over each row in this rect as a 1-cell-high Rect.

Source

pub const fn columns(self) -> Columns

Iterate over each column in this rect as a 1-cell-wide Rect.

Source

pub const fn positions(self) -> Positions

Iterate over every cell position in this rect.

Source

pub const fn as_position(self) -> Position

Return the top-left corner as a Position.

Source

pub const fn as_size(self) -> Size

Return the dimensions as a Size.

Trait Implementations§

Source§

impl Add<Offset> for Rect

Source§

type Output = Rect

The resulting type after applying the + operator.
Source§

fn add(self, offset: Offset) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Rect

Source§

fn clone(&self) -> Rect

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() -> Rect

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

impl Display for Rect

Source§

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

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

impl Eq for Rect

Source§

impl From<(Position, Size)> for Rect

Source§

fn from((position, size): (Position, Size)) -> Self

Converts to this type from the input type.
Source§

impl From<Rect> for Position

Source§

fn from(rect: Rect) -> Self

Converts to this type from the input type.
Source§

impl From<Size> for Rect

Source§

fn from(size: Size) -> Self

Converts to this type from the input type.
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: &Rect) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Rect

Source§

impl Sub<Offset> for Rect

Source§

type Output = Rect

The resulting type after applying the - operator.
Source§

fn sub(self, offset: Offset) -> Self::Output

Performs the - operation. Read more

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

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, 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.