Rect

Struct Rect 

Source
pub struct Rect {
    pub x: u16,
    pub y: u16,
    pub width: u16,
    pub height: u16,
}
Expand description

A rectangular region in the terminal.

Represents a region with position (x, y) and dimensions (width, height). All coordinates use zero-based indexing.

Fields§

§x: u16

X coordinate (column) of the top-left corner

§y: u16

Y coordinate (row) of the top-left corner

§width: u16

Width in columns

§height: u16

Height in rows

Implementations§

Source§

impl Rect

Source

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

Create a new rectangle.

§Example
use tuxtui_core::geometry::Rect;

let rect = Rect::new(0, 0, 80, 24);
assert_eq!(rect.width, 80);
assert_eq!(rect.height, 24);
Source

pub const fn zero() -> Self

Create a zero-sized rectangle at the origin.

Source

pub const fn area(self) -> u32

Get the area (width × height) of the rectangle.

§Example
use tuxtui_core::geometry::Rect;

let rect = Rect::new(0, 0, 10, 5);
assert_eq!(rect.area(), 50);
Source

pub const fn is_empty(self) -> bool

Check if the rectangle is empty (zero width or height).

Source

pub const fn left(self) -> u16

Get the left edge x coordinate.

Source

pub const fn right(self) -> u16

Get the right edge x coordinate (exclusive).

Source

pub const fn top(self) -> u16

Get the top edge y coordinate.

Source

pub const fn bottom(self) -> u16

Get the bottom edge y coordinate (exclusive).

Source

pub const fn position(self) -> Position

Get the position of the top-left corner.

Source

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

Check if this rectangle contains a position.

§Example
use tuxtui_core::geometry::{Rect, Position};

let rect = Rect::new(0, 0, 10, 10);
assert!(rect.contains(Position::new(5, 5)));
assert!(!rect.contains(Position::new(15, 5)));
Source

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

Compute the intersection of two rectangles.

§Example
use tuxtui_core::geometry::Rect;

let a = Rect::new(0, 0, 10, 10);
let b = Rect::new(5, 5, 10, 10);
let intersection = a.intersection(b);
assert_eq!(intersection, Rect::new(5, 5, 5, 5));
Source

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

Check if this rectangle fully contains another rectangle.

§Example
use tuxtui_core::geometry::Rect;

let outer = Rect::new(0, 0, 10, 10);
let inner = Rect::new(2, 2, 5, 5);
assert!(outer.contains_rect(inner));
Source

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

Compute the union of two rectangles.

Source

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

Apply a margin (padding) inset to the rectangle.

§Example
use tuxtui_core::geometry::{Rect, Margin};

let rect = Rect::new(0, 0, 10, 10);
let inner = rect.inner(Margin::new(1, 1));
assert_eq!(inner, Rect::new(1, 1, 8, 8));
Source

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

Clamp this rectangle to fit within another rectangle.

Trait Implementations§

Source§

impl Clone for Rect

Source§

fn clone(&self) -> Rect

Returns a duplicate 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 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<'de> Deserialize<'de> for Rect

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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 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 · 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 Serialize for Rect

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Rect

Source§

impl Eq for Rect

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 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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,