#[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
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
impl Density
Sourcepub const DEFAULT_BREAKPOINT_WIDTH: u16 = 64
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.
Sourcepub const fn min_target_size(self) -> Size
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.
Sourcepub const fn for_width(width: u16) -> Self
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<'de> Deserialize<'de> for Density
impl<'de> Deserialize<'de> for Density
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for Density
impl Eq for Density
impl StructuralPartialEq for Density
Auto Trait Implementations§
impl Freeze for Density
impl RefUnwindSafe for Density
impl Send for Density
impl Sync for Density
impl Unpin for Density
impl UnsafeUnpin for Density
impl UnwindSafe for Density
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).