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: u16X coordinate (column) of the top-left corner
y: u16Y coordinate (row) of the top-left corner
width: u16Width in columns
height: u16Height in rows
Implementations§
Source§impl Rect
impl Rect
Sourcepub const fn new(x: u16, y: u16, width: u16, height: u16) -> Self
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);Sourcepub const fn area(self) -> u32
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);Sourcepub const fn contains(self, pos: Position) -> bool
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)));Sourcepub const fn intersection(self, other: Self) -> Self
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));Sourcepub const fn contains_rect(self, other: Self) -> bool
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));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Rect
impl<'de> Deserialize<'de> for Rect
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
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 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§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.