Skip to content

M3: Color Guide rules and options, Edit Colors dialogs, recolouring meshes, images and patterns (M3.53–M3.55) - #21

Merged
bflatastic merged 3 commits into
mainfrom
pr/m3-color-guide
Oct 4, 2026
Merged

bflatastic merged 3 commits into
mainfrom
pr/m3-color-guide

Conversation

@bflatastic

Copy link
Copy Markdown
Member

Part of M3 (Paint & appearance). The Color Guide gets its full rule set and options, Edit Colors gets real dialogs, and colour edits reach meshes, images and patterns.

  • M3.53: Color Guide.
    • Rules: 21 harmony rules, computed with our own math in color/harmony.rs. Each returns the base colour first, unchanged and in its own colour model.
    • Variation grid: Variation, GuideOptions (steps 1–20, amount) and variation() moved into the color crate.
    • New query: color.harmony {color, rule, steps?, variation?, amount?} returns {rule, colors, grid}.
    • Panel:
      • The grid has one row per harmony colour, with the colour itself in the centre column.
      • The base colour stays fixed until it is set.
      • Cells can be multi-selected and saved as swatches.
      • A Color Guide Options dialog (colorGuideOptions) with a preview row.
    • swatch.new: takes colors: [...] and makes one swatch per colour in one undo step.
  • M3.54: Edit Colors dialogs.
    • Dialogs: Adjust Color Balance (colorBalance: Grayscale/RGB/CMYK/Global, Convert, Fill/Stroke) and Saturate (saturate).
    • Behaviour: both preview live through session.preview and commit as one undo step; Cancel rolls back.
    • Global mode: returns a clear error until tints of global colours exist.
    • Shared helpers: form::slider, form::preview and form::commit_preview.
  • M3.55: meshes, images and patterns.
    • One shared colour visitor (colorcmds::Recolor) serves Edit Colors, recolor.apply, Blend, proxy Invert/Complement and Document Color Mode. It copies only the nodes it changes.
    • Meshes: mesh points are recoloured.
    • Images: embedded image pixels are recoloured (includeImages?). Linked images are skipped.
    • Patterns: pattern fills get a recoloured copy saved as a new pattern swatch (includePatterns?); the original pattern stays as it is.
    • New doc/pixels.rs (ImageBlob::map_rgb, content_key).
  • Colour models: harmony and variation colours keep the base colour's model, and recoloured colours keep the model of the colour they replace (the shared keep_model).

docs/mcp.md and docs/control-protocol.md cover the query and the three dialogs.

Known limits:

  • Recolor on images only replaces pixels that exactly match a mapped colour.
  • The Color Guide's rule and base colour are panel state; agents use color.harmony.

Checks

Rebased onto 6c25e54 (#20). cargo xtask ci passes all 7 steps (fmt, clippy, test, assets, brands, layers, wasm): 1,463 tests, 0 failed.

New tests:

  • every rule's colour count and base-first property;
  • the query's shape;
  • saving several cells makes N swatches;
  • dialog preview, commit and cancel;
  • a grey mesh;
  • an inverted 2×2 image;
  • a new pattern swatch while the original is unchanged;
  • one undo step each.

🤖 Generated with Claude Code

bflatastic and others added 3 commits October 5, 2026 00:13
… a fixed base colour and Save Colors as Swatches

The harmony rules (Complementary 1/2, Split Complementary, Left/Right Complement, Analogous 1/2,
Monochromatic, Shades, Triad 1-3, Tetrad 1-3, Compound 1/2, High Contrast 1-3, Pentagram) live in
the color crate with our own math, base colour first. The variation grid moves there too
(`harmony::Guide`): a row per harmony colour with the colour in the centre column, shades/cool/muted
to the left and tints/warm/vivid to the right, 1-20 steps and a variation amount.

- `color.harmony {color, rule, steps?, variation?, amount?}` query returns {rule, colors, grid}.
- The panel keeps its base colour until "Set base color" takes the current one; Shift/Cmd-click
  selects several cells and Save Colors as Swatches saves them (`swatch.new {colors}`, one step).
- Color Guide Options dialog (`ui.colorGuideOptions`, kind `colorGuideOptions`) with a preview row;
  the options persist in `UiState::color_guide`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ommitted as one undo step

- Edit > Edit Colors > Adjust Color Balance... opens Adjust Colors (`ui.colorBalanceDialog`, kind
  `colorBalance`): colour mode Grayscale, RGB, CMYK or Global, a slider and field per channel
  (-100..100 %), Convert, Fill and Stroke, and Preview.
- Saturate... opens Saturate (`ui.saturateDialog`, kind `saturate`): Intensity -100..100 % and
  Preview.
- Both preview through the session interaction (fields changed by `ui.dialog.set` preview on the
  next frame too); OK keeps the result as one undo step, Cancel rolls it back.
- `edit.colors.adjustBalance` takes `mode` (rgb|cmyk|gray|global; default from the channels
  given). Global mode needs tints of global and spot colours and answers with a clear error until
  they exist; the dialog stays open and the colours keep their links.
- Shared dialog helpers: `form::slider`, `form::preview`, `form::commit_preview`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… embedded images and pattern fills

One shared colour visitor (`colorcmds::Recolor`, used by Edit Colors, Recolor Artwork, the Blend
commands, the proxy Invert/Complement and Document Color Mode) maps solid colours, gradient stops
and text runs as before, and now also:
- gradient-mesh points (with fills); Blend grades meshes by their average and keeps their shading;
- embedded images' pixels (`includeImages?`, default on): the image becomes a recoloured copy under
  a content key, the original stays for undo and other objects; linked images are left alone;
- the tiles of pattern fills and strokes (`includePatterns?`, default on): one recoloured copy per
  pattern saved as a new pattern swatch ("Dots 2"), the original untouched.
Everything stays one undo step; only nodes that change are copied, in one walk of the tree.

- doc: `ImageBlob::map_rgb` (decode, map each distinct colour once, keep alpha, re-encode PNG),
  `ImageBlob::content_key` (now also used by image import) and `ImageBlob::png`.
- `recolor.colors` lists mesh points and pattern tile colours too.
- patterncmds: `add_pattern` adds a pattern and its swatch (shared by Make Pattern and Save a Copy).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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