pub struct Rect {
pub x: u16,
pub y: u16,
pub width: u16,
pub height: u16,
}Expand description
A rectangular region defined by position and dimensions.
Used for:
- Tracking dirty regions that need redrawing
- Clipping child elements to parent bounds
- Hit testing for mouse events
§Coordinate System
(0,0) ─────────────▶ x
│ ┌─────────┐
│ │ (x,y) │
│ │ ┌─────┐ │
│ │ │ │ │ height
│ │ └─────┘ │
│ └─────────┘
▼ width
yFields§
§x: u16X coordinate of the top-left corner
y: u16Y coordinate of the top-left corner
width: u16Width in terminal columns
height: u16Height in terminal rows
Implementations§
Source§impl Rect
impl Rect
Sourcepub fn new(x: u16, y: u16, width: u16, height: u16) -> Self
pub fn new(x: u16, y: u16, width: u16, height: u16) -> Self
Creates a new rectangle with the given position and dimensions.
Sourcepub fn contains_point(&self, x: u16, y: u16) -> bool
pub fn contains_point(&self, x: u16, y: u16) -> bool
Checks if this rectangle contains the given point.
§Example
Rect { x: 10, y: 5, width: 20, height: 10 }
contains(15, 7) → true
contains(5, 7) → falseSourcepub fn intersection(&self, other: &Rect) -> Rect
pub fn intersection(&self, other: &Rect) -> Rect
Calculates the intersection of two rectangles.
Returns the overlapping region, or an empty rectangle if no overlap.
§Example
┌─────┐
│ A │──┐
└─────┘ │ intersection
│ ┌──▼──┐
└──│ │
│ B │
└─────┘Sourcepub fn intersects(&self, other: &Rect) -> bool
pub fn intersects(&self, other: &Rect) -> bool
Checks if two rectangles intersect.
Sourcepub fn union(&self, other: &Rect) -> Rect
pub fn union(&self, other: &Rect) -> Rect
Calculates the union of two rectangles.
Returns the smallest rectangle that contains both rectangles.
§Example
┌─────────────┐ union
│ ┌─────┐ │
│ │ A │ B │
│ └─────┘ │
└─────────────┘Sourcepub fn clip_to(&self, bounds: &Rect) -> Rect
pub fn clip_to(&self, bounds: &Rect) -> Rect
Clips this rectangle to fit within the given bounds.
Returns the intersection of this rectangle with the bounds.
Trait Implementations§
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 UnsafeUnpin 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