Skip to content

fix(editor): unit-aware sidebar controls + preserve user-typed precision#248

Open
b9llach wants to merge 1 commit intopascalorg:mainfrom
b9llach:fix/unit-aware-sidebar-v2
Open

fix(editor): unit-aware sidebar controls + preserve user-typed precision#248
b9llach wants to merge 1 commit intopascalorg:mainfrom
b9llach:fix/unit-aware-sidebar-v2

Conversation

@b9llach
Copy link
Copy Markdown
Contributor

@b9llach b9llach commented Apr 16, 2026

Note: Supersedes #238, which became unmergeable after #231 (catalog-based material presets) rewrote adjacent code in the panel files. Same core fix, reapplied cleanly on current main. The panel-side `Math.round` removals from #238 are no longer needed — #231's panel restructuring already addressed those areas. This PR is reduced to the two essential files.

What does this PR do?

1. `SliderControl` is unit-aware

`useViewer.unit` (`'metric' | 'imperial'`) already existed and was toggled by the toolbar m/ft button, but the only places that actually respected it were `wall-measurement-label`, `site-edge-labels`, `metric-control`, and the 2D `floorplan-panel`. Every sidebar slider hard-coded `unit="m"` as its suffix and showed raw metres regardless of the user's preference. This PR teaches `SliderControl` to read `useViewer.unit` and, when the caller passes `unit="m"`, convert the value for display + editing while keeping scene data in metres (conversion is display-only). About 70 slider instances across every panel pick up imperial support with zero call-site changes.

Sliders with non-`"m"` unit strings (e.g. `"%"`, `"°"`) are unchanged.

2. Round-trip precision preserved

The `submitValue` path now rounds in the display unit before converting back to metres. Previously, typing `8.00 ft` with `precision=2` converted to `2.43840 m`, which was displayed back as `2.44 × 3.28084 = 8.0052` → `"8.01"`. Rounding in display units first preserves the user's typed value exactly.

New shared helper

`packages/editor/src/lib/units.ts` — `formatLength`, `formatArea`, `metersToFeet`, `feetToMeters`, `METERS_TO_FEET`.

How to test

  1. `bun dev`
  2. Click the m/ft toggle in the viewer toolbar.
  3. Click a door: every slider suffix should flip from `m` to `ft`, and the numbers should reflect the conversion (2.1 m height shows as 6.89 ft).
  4. Type `8.00` into any length slider while in imperial mode, press Enter: value should stay at `8.00 ft` (on `main` it snaps to `8.01 ft`).
  5. Flip back to metric: everything returns to metres, no precision loss.

Checklist

  • I've tested this locally with `bun dev`
  • My code follows the existing code style (`bun check` passes on the touched files)
  • I've updated relevant documentation (N/A — no docs affected)
  • This PR targets the `main` branch

`SliderControl` now reads `useViewer.unit` and, when the caller
passes `unit="m"`, converts the value for display and editing while
keeping scene data in metres. About 70 slider instances across every
panel pick up imperial support with zero call-site changes. Sliders
with non-`"m"` unit strings (percent, degrees, etc.) are unchanged.

The `submitValue` path rounds in the DISPLAY unit before converting
back to metres, so a typed "8.00 ft" stays "8.00 ft" on round-trip
instead of drifting to "8.01 ft" due to intermediate-precision loss.

New shared helper: `packages/editor/src/lib/units.ts` — `formatLength`,
`formatArea`, `metersToFeet`, `feetToMeters`, `METERS_TO_FEET`.

Supersedes pascalorg#238, which was opened against an older base and became
unmergeable after pascalorg#231 (catalog-based material presets) rewrote
adjacent code in the panel files.
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.

1 participant