rat_focus

Struct ZRect

source
pub struct ZRect {
    pub x: u16,
    pub y: u16,
    pub z: u16,
    pub width: u16,
    pub height: u16,
}
Expand description

Extension of Rect.

Adds a z value for stacking overlaying areas.

This is useful when handling mouse events for widgets with overlays/popups.

Fields§

§x: u16

Coordinates

§y: u16§z: u16§width: u16§height: u16

Implementations§

source§

impl ZRect

source

pub const ZERO: Self = _

source

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

source

pub const fn as_rect(self) -> Rect

source

pub const fn is_empty(self) -> bool

Returns true if the Rect has no area.

source

pub const fn left(self) -> u16

Returns the left coordinate of the Rect.

source

pub const fn right(self) -> u16

Returns the right coordinate of the Rect. This is the first coordinate outside of the Rect.

If the right coordinate is larger than the maximum value of u16, it will be clamped to u16::MAX.

source

pub const fn top(self) -> u16

Returns the top coordinate of the Rect.

source

pub const fn bottom(self) -> u16

Returns the bottom coordinate of the Rect. This is the first coordinate outside of the Rect.

If the bottom coordinate is larger than the maximum value of u16, it will be clamped to u16::MAX.

source

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

Returns a new Rect inside the current one, with the given margin on each side.

If the margin is larger than the Rect, the returned Rect will have no area.

source

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

Moves the Rect without modifying its size.

Moves the Rect according to the given offset without modifying its width or height.

  • Positive x moves the whole Rect to the right, negative to the left.
  • Positive y moves the whole Rect to the bottom, negative to the top.

See Offset for details.

source

pub fn union_all(areas: &[ZRect]) -> Option<ZRect>

Apply union to all rects.

source

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

Returns a new Rect that contains both the current one and the given one. The z-value is set to max(self.z, other.z).

source

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

Returns true if the given position is inside the Rect.

The position is considered inside the Rect if it is on the Rect’s border.

§Examples
let rect = Rect::new(1, 2, 3, 4);
assert!(rect.contains(Position { x: 1, y: 2 }));
source

pub const fn rows(self) -> Rows

An iterator over rows within the Rect.

§Example
fn render(area: Rect, buf: &mut Buffer) {
    for row in area.rows() {
        Line::raw("Hello, world!").render(row, buf);
    }
}
source

pub const fn columns(self) -> Columns

An iterator over columns within the Rect.

§Example
fn render(area: Rect, buf: &mut Buffer) {
    if let Some(left) = area.columns().next() {
        Block::new().borders(Borders::LEFT).render(left, buf);
    }
}
source

pub const fn positions(self) -> Positions

An iterator over the positions within the Rect.

The positions are returned in a row-major order (left-to-right, top-to-bottom).

§Example
fn render(area: Rect, buf: &mut Buffer) {
    for position in area.positions() {
        buf.get_mut(position.x, position.y).set_symbol("x");
    }
}
source

pub const fn as_position(self) -> Position

Returns a Position with the same coordinates as this Rect.

§Examples
let rect = Rect::new(1, 2, 3, 4);
let position = rect.as_position();
source

pub const fn as_size(self) -> Size

Converts the Rect into a size struct.

Trait Implementations§

source§

impl Clone for ZRect

source§

fn clone(&self) -> ZRect

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for ZRect

source§

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

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

impl Default for ZRect

source§

fn default() -> ZRect

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

impl From<(Position, Size)> for ZRect

source§

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

Converts to this type from the input type.
source§

impl From<(u16, Rect)> for ZRect

source§

fn from(plane_rect: (u16, Rect)) -> Self

Converts to this type from the input type.
source§

impl From<Rect> for ZRect

source§

fn from(base_plane: Rect) -> Self

Converts to this type from the input type.
source§

impl Hash for ZRect

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 ZRect

source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Copy for ZRect

source§

impl Eq for ZRect

source§

impl StructuralPartialEq for ZRect

Auto Trait Implementations§

§

impl Freeze for ZRect

§

impl RefUnwindSafe for ZRect

§

impl Send for ZRect

§

impl Sync for ZRect

§

impl Unpin for ZRect

§

impl UnwindSafe for ZRect

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<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> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
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 = 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.