feat(ui): one type scale, and one estimate of how wide a character is - #80
Merged
Conversation
Eight sizes across 249 call sites, and six file-local constants duplicating each other: `ITEM_SIZE = 13.0` written out three separate times in three widgets, `CODE_SIZE = 12.0` three more. Every one of them is now a step on a named scale, and the guard added with the layout scale grows a second list to keep them there. The guard is split by scale rather than by file, because the two migrate at different speeds. A widget can be entirely on the type scale while its paddings are still hand-picked, and one list for both would force converting everything about a file at once or nothing at all. Two sizes are deliberately left out. `14.0` and `16.0` are each a third spelling of "the title of something", a pixel from `LEAD`, and the settings panel shows why that is not a naming problem: its header is 14 while the option labels beneath it are 15, so the heading is smaller than what it heads. Deciding what those sites should say is a question about hierarchy, so they keep their literals and the six files holding them stay off the type list until it is answered. The character-width estimate is reconciled rather than documented. The canvas has no cheap text measurement, so `format::truncate` and the graph's `badge_width` both estimate — and they estimated differently, 0.62 against 0.58, for the same font. The smaller one is the graph's, which is the direction that clips: a badge too narrow for a label truncation had already called short enough. `badge_width`'s own doc comment warns that two copies of its arithmetic would drift, and the ratio was quietly the second copy. That one is pinned by a `const _: () = assert!(…)` rather than a test. Both sides are constants, so clippy is right that a runtime assertion on them says nothing — and a wrong value should fail the build rather than a run. Putting 0.58 back is a compile error. No visual change: every size that moved onto the scale kept its value, which is why the six files that could not are excluded rather than approximated.
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.
T2. Eight sizes across 249 call sites, and six file-local constants duplicating each other —
ITEM_SIZE = 13.0written out three separate times in three widgets,CODE_SIZE = 12.0three more. All of them are now steps on a named scale.Six steps, named for the job
MICRO LABEL CODE BODY LEAD DISPLAY.LABELcarries structure — section headings and secondary text, the commonest size in the interface — andBODYcarries content.The guard is split by scale, not by file
The two scales migrate at different speeds. A widget can be entirely on the type scale while its paddings are still hand-picked, and one list for both would force converting everything about a file at once or nothing at all.
So
ON_THE_LAYOUT_SCALEandON_THE_TYPE_SCALEare separate lists over separate property sets, and a test pins that one guard does not see the other's numbers.Two sizes deliberately left out — and why that is a finding
14.0and16.0are each a third spelling of "the title of something", a pixel away fromLEAD.The settings panel shows why that is a hierarchy question rather than a rename:
Deciding what those sites should say is a visual decision, not a substitution, so it is not in this change. The six files holding a 14 or a 16 stay off the type list until it is made. That is also why this PR has no visual change at all: every size that moved kept its value, and the ones that could not are excluded rather than approximated.
One estimate of character width
The canvas has no cheap text measurement, so
format::truncateand the graph'sbadge_widthboth estimate. They estimated differently — 0.62 against 0.58, for the same font.The smaller one is the graph's, which is the direction that hurts: a badge too narrow for a label that truncation had already called short enough. And
badge_width's own doc comment warns that "two copies of this arithmetic would drift" — the ratio was quietly the second copy.Pinned by a compile-time assertion rather than a test:
Clippy is right that a runtime assertion over two constants says nothing, and a wrong value here should fail the build, not a run. I wrote it as a test first, clippy caught it, and the const assertion is the better answer.
Sabotage — three, all confirmed
.size(11.0)returns tosidebar.rsmigrated_files_carry_no_raw_type_sizestabs.rsmigrated_files_carry_no_raw_layout_numbers, proving the split lists still work0.58evaluation panicked: assertion failedDocs
UI_SPEC.md's Layout scale section gains a Type subsection: the six steps, the measurement that motivated them, the 14/16 hierarchy problem stated plainly, and the character-width reconciliation.Gate
cargo fmt --all -- --check,cargo clippy --workspace --all-targets --all-features --locked -- -D warnings,cargo test --workspace --all-features --locked— 895 tests, all green.