pub trait Bounded {
// Required method
fn bounds(&self) -> Rect;
// Provided methods
fn width(&self) -> u16 { ... }
fn height(&self) -> u16 { ... }
fn contains(&self, pos: Position) -> bool { ... }
}Expand description
A value with a rectangular extent in terminal-cell coordinates.
Bounded is the base trait for readable and writable surfaces. It does
not imply that cells can be inspected or modified; it only describes the
region where a value exists in its own coordinate space.
Implement this trait for types that can answer “what rectangle do I
cover?” and then add Surface or SurfaceMut when cell access is
available.
Required Methods§
Sourcefn bounds(&self) -> Rect
fn bounds(&self) -> Rect
Return the valid region in this value’s own coordinate space.
§Returns
A Rect whose x/y form the top-left coordinate and whose
width/height form the extent in terminal cells.
§Panics
Implementations should not panic.
§Usage notes
For most storage-backed surfaces the origin is (0, 0). Clipping
adaptors may report non-zero origins when they expose a sub-rectangle
in the wrapped surface’s coordinate space.
Provided Methods§
Sourcefn width(&self) -> u16
fn width(&self) -> u16
Return the width of Self::bounds in terminal cell columns.
§Returns
self.bounds().width.
§Panics
Never panics unless Self::bounds panics.
§Usage notes
This is a convenience method; override only if computing full bounds is meaningfully more expensive than returning the width.
Sourcefn height(&self) -> u16
fn height(&self) -> u16
Return the height of Self::bounds in terminal cell rows.
§Returns
self.bounds().height.
§Panics
Never panics unless Self::bounds panics.
§Usage notes
This is a convenience method; override only if computing full bounds is meaningfully more expensive than returning the height.
Sourcefn contains(&self, pos: Position) -> bool
fn contains(&self, pos: Position) -> bool
Test whether a position lies inside Self::bounds.
§Parameters
pos: coordinate in this value’s coordinate space.
§Returns
true when pos is inside the half-open rectangle described by
Self::bounds, otherwise false.
§Panics
Never panics unless Self::bounds panics.
§Usage notes
Surfaces commonly use this to clip reads and writes before touching their backing storage.