Skip to main content

centered_rect

Function centered_rect 

Source
pub fn centered_rect(screen: Rect, width: u16, height: u16) -> Rect
Expand description

Compute a width×height Rect centered within screen.

width/height are clamped down to screen’s own dimensions if larger, so the result never extends past screen’s edges: a modal, dialog, or tooltip box built from this is always fully on-screen, even on a terminal too small to fit the box’s requested size. Pure layout math: no drawing, no Terminal. Pairs with panel/modal in retroglyph-ui (the draw module) for a centered, bordered box.

Never panics: the clamp and centering offsets are computed with saturating arithmetic, so a zero-size screen, width, or height resolves to a zero-size or edge-pinned rect instead of under/overflowing.