Skip to content

Latest commit

 

History

History
55 lines (31 loc) · 2.4 KB

File metadata and controls

55 lines (31 loc) · 2.4 KB

Interpolated strategy (compose.interpolated / code.interpolated)

Artifact: io.github.bodenberg:appdimens-kmp-interpolated:1.0.1 (:library-interpolated) See MODULES.md · README installation

Same API surface as scaled with prefixes isdp / ihdp / iwdp / issp / … — see COMPOSE-API-CONVENTIONS.md §3.

What it is

Interpolated takes the arithmetic mean between the fixed base token (dp) and the fully linear value at the 300 dp reference: base + (linear − base) × 0.5. It is a compromise between “always the same dp” and “fully proportional to the axis”.

Calculation used

Mathematically:

  • linear = base × dim × (1/300) on the effective axis.
  • out = base + (linear − base) × 0.5f (equivalently out = base × (1 + (dim/300 − 1) × 0.5) when using SW).

Implementation note: For smallest-width + default inverter, the blended factor is derived from the immutable per-window snapshot (DimenCache.currentMetrics) at resolution time — no process-global pre-computation (out = base × scale). Other qualifiers still compute linear from readScreenDp and blend inline.

  • With a: multiply by the pre-computed aspect-ratio factor (DimenCache.currentAspectRatioMul); custom sensitivity uses 1 + k × logNormalizedAr.

Implementation: calculateInterpolatedDpCompose in DimenInterpolatedDp.kt.

How to use

import com.appdimens.kmp.compose.interpolated.isdp

Modifier.padding(14.isdp)

Prefixes: isdp, ihdp, iwdp (+ Sp, px, variants).

Code: com.appdimens.kmp.code.interpolated.

Why use it

Softens pure linear scaling on tablets without going as aggressive as logarithmic or power everywhere.

When to use it

  • When scaled pulls too hard but fixed dp tokens look too small on tablet.
  • Fine-tuning hierarchy between two reference sizes.

Advantages and trade-offs

  • Pros: one simple formula; easy to explain (“halfway”).
  • Cons: the 0.5 blend is fixed in the library — no knob; for other blends use conditional builders or another strategy.

Recommended usage strategy

Try interpolated on components where scaled and percent did not work; validate on a small phone and a 600+ sw tablet so the midpoint is acceptable.

Back to index