fix(editor): unit-aware sidebar controls + preserve user-typed precision#248
Open
b9llach wants to merge 1 commit intopascalorg:mainfrom
Open
fix(editor): unit-aware sidebar controls + preserve user-typed precision#248b9llach wants to merge 1 commit intopascalorg:mainfrom
b9llach wants to merge 1 commit intopascalorg:mainfrom
Conversation
`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.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Checklist