Skip to main content

Surface

Struct Surface 

Source
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: f32

The base unit, in this surface’s units.

§quantum: f32

The smallest step this surface can represent, in the same units.

Implementations§

Source§

impl Surface

Source

pub fn web() -> Self

A display measuring in CSS pixels: a 16px base, one-pixel quantum.

Source

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?
examples/dump.rs (line 12)
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}
Source

pub fn resolve(self, ratio: Ratio) -> f32

Resolve a ratio on this surface, snapped to its quantum.

Source

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.

Source

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?
examples/dump.rs (line 17)
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}

Trait Implementations§

Source§

impl Clone for Surface

Source§

fn clone(&self) -> Surface

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Surface

Source§

impl Debug for Surface

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Surface

Source§

fn eq(&self, other: &Surface) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Surface

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.