Repository navigation
Colours: one shared rule reads and writes #rrggbb text, so a stray + or ## is refused (#5184) - #16716
Conversation
… and appearances (CE15, tangency-labs#5184) Colours as `#rrggbb` text were read in four places and written in seven, with different rules. Two copies took a leading `+` as a digit (`u8::from_str_radix("+f", 16)` is 15), and one took any number of `#`. `solidcraft_color::hex` now holds the rule once, beside `srgb`: `#` and exactly 6 or 8 ASCII hex digits, either case, alpha straight; `parse_digits` for readers that let the `#` be left out; `format` and `format_alpha` write lower case. Nothing trims; callers that read files trim first, as they did. Switched to it: the colour field's hex text and recent swatches and theme files' colours and icon palettes (ui-kit), the 3MF reader's display colours (io), `Look::hex` (doc), and the appearance dialog's reader and `hex` (ui-egui). The ui-kit field and theme files accept exactly what they did. The 3MF reader and the dialog's reader now refuse a `+` where a digit belongs, and the dialog's reader refuses `##`. Well-formed colours read and write as before. Left as they are, each for its own change: the command colour parameter (`inspect::color_param`, whose looser text form is a published schema pattern), the 3MF writer (upper case in exported files), and the CLI's preview check (no colour dependency). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Requested by Cam
Change
SolidCraft reads and writes colours as
#rrggbbtext in many places: theme files, the colour field's hex box, 3MF files and the appearance dialog. This PR gives that text one rule in one place, so every reader accepts the same colours.It is one of the cleanups in the live co-editing plan (#5184). The plan found the rule written four times for reading and seven times for writing, with different results.
Before this change:
u8::from_str_radixaccepts a leading+, so"#+f0000"read as a colour.#.Now:
solidcraft_color::hexholds the rule, besidesrgbin the shared colour crate. A colour is#and exactly 6 or 8 ASCII hex digits, in either case. The alpha is straight (not premultiplied), as CSS Color 4 §5.2 and the 3MFST_ColorValuetype write it.parse_digitsis for readers that let the#be left out.formatandformat_alphawrite lower case.Look::hex(doc), and the appearance dialog's reader andhex(ui-egui).+where a digit belongs, and the dialog's reader refuses##. Every well-formed colour reads and writes as before, and no saved or exported text changes.Changes a default: no
Follow-ups, not in this PR
inspect::color_param). Its looser text form is a published schema pattern, so a change there changes what agents may send, with its own pattern.format!("#{:02x}...")lines incrates/engine/src/cmd/inspect.rs, after Appearance dialog: "In This Design" lists imported and material colours, not only assigned looks (#14856) #14858 lands (it edits around them).solidcraft-colordependency.parse_kicad_color,crates/engine/src/cmd/file.rs:871) and its writer (crates/ui-egui/src/kicad_import_dialog.rs:38) don't use the shared rule yet. A follow-up PR onmainmoves them onto it and decides the 3-digit#fffform, which KiCad's reader accepts.Validation
Tested on Windows,
--profile ci, onmain22aa00d (14 Nov):hex::tests, 3srgb).color_testsandtheme_files: 28 passed.threemf: 27 passed, including the newdisplay_colours_read_only_hex_digits.appearance: 18 passed.dialogs_appearanceandtheme_files_tests: 47 passed, including the new refusals incolours_parse_both_ways.schema::appearance::testsandcmd::inspect::pbr_tests: 34 passed (the replies' colours, and the command pattern this PR leaves alone).crates/color/src/hex.rs, each caught, then a clean run:only_a_hash_and_six_or_eight_hex_digits_readanddigits_without_the_hash;only_a_hash_and_six_or_eight_hex_digits_read;every_byte_writes_and_reads_backand doc'sappearance::tests::library_and_materials.cargo clippy -D warnings, all targets, on color, ui-kit, io, doc and ui-egui: clean.cargo check --target wasm32-unknown-unknownon color, doc and io: clean.cargo xtask lists: passes.rustfmt --checkon the 7 changed Rust files: clean.What the tests don't cover: the preference fields that read through the dialog's
parse_colorare not exercised on their own.colours_parse_both_wayscovers the text forms they send (with and without the#).Screenshots of the behavior (when observable)
Nothing changes on screen. Well-formed colours read and write exactly as before. The only difference is that malformed text (
"#+f0000","##0a1b2c") is refused, and the tests above show it.Integration status
Checked on 14 Nov 2026: one commit on
mainf63f3b8, no conflicts. The twomaincommits since the tested base change only solidcore's AGENTS.md. No open PR touchescrates/color,crates/ui-kit/src/color.rsorcrates/io/src/threemf.rs. #14858 (appearance dialog), #2717, #10968 and #14259 (theme files) change the same files in other places, at least 4 lines away from these hunks.Summary by CodeRabbit
#rrggbband#rrggbbaaformats, accepting uppercase or lowercase digits.#prefix; alpha-bearing values are accepted only where supported.