Skip to main content

Module density

Module density 

Source
Expand description

Density helpers — the three functions that turn a hard-coded dimension into a density-aware one.

These live in teksilo-core rather than teksilo-widgets so that teksilo-terminal, teksilo-webview, teksilo-scene and accessibility::target_audit can all reach them without a widgets dependency; teksilo-widgets re-exports them for ergonomics.

Each helper is the identity at TargetDensity::Compact for any value that already conforms, which is what makes the density layer a no-op until an app opts in:

use teksilo_core::styles::density::{dp, spacing};
use teksilo_tokens::{InputTokens, TargetDensity, TargetRole};

let compact = InputTokens::for_density(TargetDensity::Compact);
assert_eq!(dp(28.0, TargetRole::Target, &compact), 28.0);
assert_eq!(spacing(8.0, &compact), 8.0);

let touch = InputTokens::for_density(TargetDensity::Touch);
assert_eq!(dp(28.0, TargetRole::Target, &touch), 44.0);

Reference: docs/density-and-targets.md.

Functions§

density_min_size
Raise the named axes of a minimum size to tokens.target_size.
dp
Raise one dimension to the floor its TargetRole demands.
spacing
Scale a gap or padding by the density’s spacing_factor (1.00 / 1.15 / 1.30).