Skip to main content

Bounded

Trait Bounded 

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

Source

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§

Source

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.

Source

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.

Source

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.

Implementors§

Source§

impl Bounded for Rect

Source§

impl Bounded for Buffer

Source§

impl Bounded for TextBuffer

Source§

impl Bounded for Window

Source§

impl<'s, S: TextSurface + ?Sized> Bounded for Painter<'s, S>

Source§

impl<I, O> Bounded for Screen<I, O>
where I: Input, O: Write,

Source§

impl<T: Bounded + ?Sized> Bounded for View<'_, T>