pub struct Rect {
pub x: u16,
pub y: u16,
pub width: u16,
pub height: u16,
}Expand description
A rectangle for scissor regions, layout bounds, and hit testing.
Uses terminal coordinates (0-indexed, origin at top-left).
Fields§
§x: u16Left edge (inclusive).
y: u16Top edge (inclusive).
width: u16Width in cells.
height: u16Height in cells.
Implementations§
Source§impl Rect
impl Rect
Sourcepub const fn from_size(width: u16, height: u16) -> Self
pub const fn from_size(width: u16, height: u16) -> Self
Create a rectangle from origin with given size.
Sourcepub fn intersection(&self, other: &Rect) -> Rect
pub fn intersection(&self, other: &Rect) -> Rect
Compute the intersection with another rectangle.
Returns an empty rectangle if the rectangles don’t overlap.
Sourcepub fn inner(&self, margin: Sides) -> Rect
pub fn inner(&self, margin: Sides) -> Rect
Create a new rectangle inside the current one with the given margin.
Sourcepub fn union(&self, other: &Rect) -> Rect
pub fn union(&self, other: &Rect) -> Rect
Create a new rectangle that is the union of this rectangle and another.
The result is the smallest rectangle that contains both.
Note: a rectangle’s position participates even when it is empty —
Rect::new(100, 100, 0, 0).union(&r) extends to x/y 100. When
accumulating a union over a collection, seed the fold with the first
element rather than Rect::default() (which would pin the result to
the origin).
Sourcepub fn intersection_opt(&self, other: &Rect) -> Option<Rect>
pub fn intersection_opt(&self, other: &Rect) -> Option<Rect>
Compute the intersection with another rectangle, returning None if no overlap.