feat(color_picker): editable hex field with a per-picker reuse palette - #59
Merged
Conversation
MoonColorPicker's hex readout was a plain read-only label. Add a hex MoonInput to the popover (accepts #RRGGBB/RRGGBB, case-insensitive; a value that fails to parse is rejected without touching the held colour), and let a committed value join a most-recent-first custom-colour list shown ahead of the caller's fixed palette for quick reuse. Fixes hex_label's truncating byte conversion (now rounds, matching every other Hsla->u8 path in this codebase) so the label and the new field agree exactly. Caps the swatch grid's height with a scroll region, since a caller-supplied 65-swatch palette plus a full custom list would otherwise grow the popover past the window. default_value keeps its exact signature (a hex_dirty flag drained at render time instead), so no MoonTerminal or gallery call site needs touching for that alone.
Round-trip and rejection cases for parse_hex_rgb, and push_custom's front-insert, no-op-on-recommit, dedupe-by-move, and MAX_CUSTOM_COLORS cap. Each mutated and reddened for its named reason before landing (breakage-prover dispatch).
… order Both fed an already most-recent-first list straight into push_custom, which inserts each colour at the front -- so a two-Codex-angle review (Job 1, flow + contracts) independently caught the same reversal: seeding/replacing with [newest, older] produced [older, newest], and over the 20-entry cap it kept the OLDEST 20 instead of the newest. New push_all_custom processes the source in reverse so push_custom's per-call front-insertion restores the intended order.
…d-trip seeded_custom_colours_preserve_most_recent_first_order pins push_all_custom's reverse-iteration fix (Job 1 caught the reversal independently, twice). hsl_middle_gray_rounds_to_the_picker_hex_byte uses an HSL-derived (non-byte-sourced) 50% gray to demonstrate the rounding-vs-truncation difference a byte-sourced value cannot expose (breakage-prover dispatch, round 2).
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 & why
MoonColorPickerrendered its hex value as aMoonTextlabel — readable, not typeable — so a colour outside the supplied swatch list was unreachable. A consumer with more items than swatches (MoonTerminal's detect badges: 23 types) had no way to give each one a distinct colour.This adds:
#RRGGBBand bareRRGGBB, case-insensitive, rejecting an invalid value without destroying what the field held;custom_colors(..)/set_custom_colors(..)/custom()and a newMoonColorPickerEvent::CustomAdded(Hsla)so a parent can fan one picker's new colour out to its siblings;rgb8_of, replacing a truncating conversion with a rounding one.The swatch grid is capped at
GRID_MAX_HEIGHT_UIwithoverflow_y_scroll()so a large supplied palette does not grow the popover without bound.default_value's signature is unchanged — ahex_dirtyflag carries the state instead, which avoided a mechanical change across every existing call site and a "signature changed" entry in the component API baseline.How to verify
moon/color_picker/tests.rscover hex parsing, the reuse list, MRU ordering and the hex-rounding round-trip.moon-ui-gallery's demo seeds.custom_colors(..)— run the gallery and type a hex into the picker.Notes
27deda9fixes a real bug caught during review:custom_colors/set_custom_colorsreversed the MRU order, so remembered colours came back oldest-first.docs/component-api-baseline.jsonis refreshed — pure additions plus one signature-text reformat.color_pickermanifest class isMirrorand tracks only the separate root Longbridge-fork file, so editingmoon/color_picker.rsneeds no class change.