Skip to content

Custom: scalingFormula one-liner and inline 16.cdp("formula") - #4

Open
bodenberg wants to merge 7 commits into
mainfrom
claude/custom-scaling-config-jrgis5
Open

bodenberg wants to merge 7 commits into
mainfrom
claude/custom-scaling-config-jrgis5

Conversation

@bodenberg

Copy link
Copy Markdown
Owner

Follow-up to #3. The simplest custom strategy is now the formula itself: base is the value you pass, and the result is the scaled value.

Modifier.padding(16.cdp("base * pow(sw / 360, 0.8)"))
val Hud = scalingFormula("base * (tablet ? 0.9 : 1) * clamp(sw / 360, 0.85, 1.6)")
val Fancy = scalingFormula { base, screen -> base * (screen.smallestWidthDp / 360f).pow(0.8f) }
  • scalingFormula(text): shared per text, capped at 256 texts. scalingFormula(text, id): registered. scalingFormula { base, screen -> }: code form, not JSON-serializable. Also ScalingStrategies.formula(text).
  • String overloads: Compose cdp, cdpPx, csp, cspPx; code API cdp, cdpDp, csp, cspUnits.
  • Fast path: a formula shaped base, base * E or E * base, where E does not read base, scaled or factor, depends only on the screen. E is evaluated once per window, so each value costs one multiply. The result is bit-identical to evaluating the formula per value.
  • explain() shows the formula.
  • Docs, README, LLMS, skill, CHANGELOG, beginner guide and demo updated.
  • Tests: ScalingFormulaTest (8). The existing engine, JSON and expression tests and the cross-platform fixture are unchanged.

Same feature as bodenberg/appdimens-dynamic#16 (commit b140ca0c).


Generated by Claude Code

The simplest custom strategy is now the formula itself: base is the
value passed, the result is the scaled value.

- scalingFormula("base * pow(sw / 360, 0.8)") (shared per text, bounded
  at 256 texts; ScalingStrategies.formula) and
  scalingFormula { base, screen -> ... } (code, no limits)
- Compose 16.cdp("...") / cdpPx / csp / cspPx and code.custom
  16.cdp(appContext, "...") / cdpDp / csp / cspUnits
- Formulas shaped base * (E), with E free of base/scaled/factor, are
  screen-only: E is evaluated once per window and the strategy skips the
  per-value cache, bit-identical to evaluating the formula per value
- explain() shows the formula; docs, README, guide, LLMS, skill,
  CHANGELOG and demo

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012PgB1P23sEhr2a9Wmu5M1h
Plain-Kotlin factor lambda; screen-only, so it runs once per window and
each value costs one multiply. Auto scale#N id; an id registers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012PgB1P23sEhr2a9Wmu5M1h
scalingFormula { base * pow(sw / 360f, 0.8f) } and
CustomScaleStrategy { (width / 360f).coerceIn(0.85f, 1.8f) } take
receiver lambdas (FormulaScope / ScreenScope) with the same names as
the text language, so the IDE autocompletes them and typos fail at
compile time. Replaces the unreleased (base, screen) / (screen)
lambdas. Docs lead with the typed form; text stays for JSON.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012PgB1P23sEhr2a9Wmu5M1h
@bodenberg
bodenberg marked this pull request as ready for review October 24, 2026 13:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-24T13:46:36.523346Z
We couldn’t complete this review. Comment @codex review to try again.
528e45a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

- A rule range (smallestWidth/width/height/aspectRatio) that is not an
  object now fails with its JSON path instead of being ignored, which
  made the rule match every screen.
- ignoreMultiWindow in multi-window also skips the formula / transform:
  the value stays unscaled (value bounds still apply).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012PgB1P23sEhr2a9Wmu5M1h
- Rule 'when' / 'set', clamp and valueClamp must be objects, and
  ignoreMultiWindow / multiWindow / aspectRatio.enabled must be booleans:
  a mistyped value now fails with its JSON path instead of being ignored
  (a non-object 'when' used to match every screen).
- Value bounds must be >= 0 (they clamp the magnitude).
- loadJson resolves 'default' before registering, so a failed load
  leaves the registry untouched.
- withAxis variants are cached per source instance, not per id, so a
  re-registered id never returns another config's variant.
- A sensitivity-only rule patch is exported (it was dropped).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012PgB1P23sEhr2a9Wmu5M1h
Add quick start, code formulas, text formulas, configuration, JSON,
API reference, performance, cookbook and troubleshooting guides for
appdimens-kmp-custom; turn DOCUMENTATION/custom.md into an entry page;
add library-custom/README.md and skills/custom.md; link them from the
docs indexes, README, LLMS.txt and the skills files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012PgB1P23sEhr2a9Wmu5M1h
The how-it-computes block read value = formula(clampValue(base × factor)),
which suggested the formula runs on top of the default scaling. It now
shows scaled = clampValue(base × factor) and
value = formula ? formula(base, scaled, factor) : scaled: a formula gets
the original base and replaces the result; scaled and factor are only
for post-processing. Same fix as the hub review (bodenberg/appdimens#31).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012PgB1P23sEhr2a9Wmu5M1h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants