Skip to main content

uncurses/layout/
mod.rs

1//! Geometry primitives for the cell grid.
2//!
3//! Three `Copy`, zero-cost wrappers describe points and extents on the
4//! terminal grid:
5//!
6//! - [`Position`] - an `(x, y)` point.
7//! - [`Size`] - a `width × height` extent.
8//! - [`Rect`] - an axis-aligned rectangle, `(x, y, width, height)`.
9//!
10//! ## Coordinate system
11//!
12//! The origin is the **top-left** corner of the grid. `x` increases to the
13//! right and `y` increases **downward**, so `(0, 0)` is the first cell and a
14//! larger `y` is further down the screen. A [`Rect`] covers the half-open
15//! ranges `x..x + width` (columns) and `y..y + height` (rows):
16//!
17//! ```text
18//!       x:  0   1   2   3   4
19//!         ┌───┬───┬───┬───┬───┐
20//!   y: 0  │   │   │   │   │   │
21//!         ├───┼───┼───┼───┼───┤
22//!      1  │   │ ▓ │ ▓ │   │   │   Rect::new(1, 1, 2, 2)
23//!         ├───┼───┼───┼───┼───┤   origin (1, 1), 2 × 2 cells,
24//!      2  │   │ ▓ │ ▓ │   │   │   covering x ∈ 1..3, y ∈ 1..3
25//!         ├───┼───┼───┼───┼───┤
26//!      3  │   │   │   │   │   │
27//!         └───┴───┴───┴───┴───┘
28//! ```
29//!
30//! ## Tuple shorthand
31//!
32//! Most positional APIs accept `impl Into<Position>`, `impl Into<Size>`, and
33//! `impl Into<Rect>`, so plain tuples work as ergonomic shorthand:
34//!
35//! ```
36//! use uncurses::layout::{Position, Rect};
37//!
38//! let p: Position = (3, 5).into();
39//! assert_eq!(p, Position::new(3, 5));
40//!
41//! let r: Rect = (3, 5, 10, 2).into();
42//! assert_eq!(r, Rect::new(3, 5, 10, 2));
43//! ```
44
45mod position;
46mod rect;
47mod size;
48
49pub use position::Position;
50pub use rect::Rect;
51pub use size::Size;