pub struct Surface {
pub base: f32,
pub quantum: f32,
}Expand description
What the layout is being drawn on: a base unit, and the smallest step the surface can actually represent.
Both are in the surface’s own units, and the crate never assumes those are pixels. A display measures in pixels and can represent one of them; a terminal measures in cells and cannot represent less than one. That single difference is the whole of the terminal story — a TUI is not a density, it is a surface with a coarse quantum, and the relational vocabulary above crosses over untouched.
Quantising is not a terminal special case. A display does it too; it is just that rounding 6.0 to the nearest pixel is uninteresting, whereas rounding three eighths of a cell to the nearest cell is a design decision the surface makes for you.
Fields§
§base: f32The base unit, in this surface’s units.
quantum: f32The smallest step this surface can represent, in the same units.
Implementations§
Source§impl Surface
impl Surface
Sourcepub fn terminal() -> Self
pub fn terminal() -> Self
A terminal measuring in cells: a one-cell base, one-cell quantum.
The coarsest surface in the family, and the one that proves the
vocabulary. bound and peer collapse to no cells at all, which is
correct — in a grid this dense, “belongs to” and “is a peer of” are
both expressed by adjacency, not by a gap.
Examples found in repository?
6fn main() {
7 print!("{}", geometry_css_vars(Density::Pointer));
8 println!();
9 print!("{}", gap_css_overrides(".ui-mode-mobile", Density::Touch));
10
11 println!("\n/* the same relationships on a terminal, in cells */");
12 let t = Surface::terminal();
13 for gap in Gap::all() {
14 println!(
15 "/* {:<8} {} */",
16 gap.token().trim_start_matches("gap-"),
17 t.gap(gap, Density::Pointer)
18 );
19 }
20}Sourcepub fn resolve(self, ratio: Ratio) -> f32
pub fn resolve(self, ratio: Ratio) -> f32
Resolve a ratio on this surface, snapped to its quantum.
Sourcepub fn quanta(self, ratio: Ratio) -> u32
pub fn quanta(self, ratio: Ratio) -> u32
How many whole quanta a ratio is worth here.
What a cell-addressed layout actually wants: the count, not the size.
Sourcepub fn gap(self, gap: Gap, density: Density) -> u32
pub fn gap(self, gap: Gap, density: Density) -> u32
Resolve a relationship on this surface at a given density, in quanta.
The whole model in one call: what is being separated, who is operating it, what it is drawn on.
Examples found in repository?
6fn main() {
7 print!("{}", geometry_css_vars(Density::Pointer));
8 println!();
9 print!("{}", gap_css_overrides(".ui-mode-mobile", Density::Touch));
10
11 println!("\n/* the same relationships on a terminal, in cells */");
12 let t = Surface::terminal();
13 for gap in Gap::all() {
14 println!(
15 "/* {:<8} {} */",
16 gap.token().trim_start_matches("gap-"),
17 t.gap(gap, Density::Pointer)
18 );
19 }
20}