Skip to main content

Density

Enum Density 

Source
#[non_exhaustive]
pub enum Density { Touch, Mouse, }
Expand description

How much room an interactive widget’s hit target should claim.

It exists so an app choosing between a phone-sized and a desktop-sized layout has one place to ask “how big should this button/row/slider be”, rather than inventing its own ad hoc breakpoint constants per widget. An InteractiveWidget reads min_target_size the same way it reads sense; for_width is the other half, turning a terminal width into a Density in the first place.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Touch

Larger interactive targets, for a fingertip on a phone-width terminal or other touch input, at the cost of showing fewer rows at once.

§

Mouse

Dense, single-line interactive targets, for a mouse on a normal desktop-sized terminal, where precise clicking doesn’t need extra height.

Implementations§

Source§

impl Density

Source

pub const DEFAULT_BREAKPOINT_WIDTH: u16 = 64

Below this width, in cells, for_width picks Density::Touch; at or above it, Density::Mouse. An app that wants a different breakpoint states it relative to this default (e.g. if width < Density::DEFAULT_BREAKPOINT_WIDTH - 4 { .. }) rather than inventing an unrelated constant from scratch.

64 sits between a phone-width terminal (roughly 40 to 50 columns, where fingertip sizing wins) and the classic 80-column desktop width (where a mouse and dense rows win). Lower keeps touch sizing only on very narrow terminals; higher applies it to wider ones that a mouse user would rather see packed densely. Picked by feel for that split, not measured.

Source

pub const fn min_target_size(self) -> Size

The minimum size, in cells, an interactive target should claim at this density.

Both densities are 6 cells wide: enough for a short bracketed label like [ OK ] plus a cell of breathing room, the narrowest a tappable/clickable control stays legible. Height is where they differ. Density::Mouse is a single row, since a mouse can land on one line precisely. Density::Touch is 3 rows so a fingertip has vertical slack to hit (and so a bordered one-line control fits: top border, content, bottom border), at the cost of showing fewer rows on screen. The exact 6/3/1 were picked by feel for readable terminal controls, not measured against touch-target studies.

Source

pub const fn for_width(width: u16) -> Self

Picks a density from a terminal (or pane) width, in cells, against DEFAULT_BREAKPOINT_WIDTH.

A one-line replacement for the ad hoc if width < N { .. } every consumer of this crate has otherwise had to write for itself, with a different N each time.

Trait Implementations§

Source§

impl Clone for Density

Source§

fn clone(&self) -> Self

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 Density

Source§

impl Debug for Density

Source§

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

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

impl<'de> Deserialize<'de> for Density

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Density

Source§

impl Hash for Density

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Density

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for Density

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Density

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<C> WithAlpha for C
where C: Copy,

Source§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see AlphaFirst).
Source§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see AlphaLast).