Files
figcraft/crates/engine/src/cmd/mod.rs
T
BFlatandClaude Opus 5.5 d3dbc6f495 M3: paint: colour profiles (Display P3), image adjustment presets, style picker (#54)
* M3: colour profiles: sRGB or Display P3 per file, convert or keep values, tagged exports

- color: ColorProfile (srgb, displayP3) with conversions derived from the primaries (shared D65
  white and sRGB curve; out-of-gamut channels clip), table-driven pixel conversion, a generated
  ICC v4 matrix/TRC profile and PNG cICP code points.
- doc: Document.color_profile (serde default sRGB, written only when set); every colour value
  (paints, text runs, effects, grids, page and prototype backgrounds, overlay backdrops, styles,
  colour variables, document colours) can be mapped; set_color_profile converts or reinterprets.
- engine: file.colorProfile {profile?, convert?} (File > Color profile...; without a profile it
  opens the dialog); document.inspect reports colorProfile.
- render: images are taken as sRGB and managed into the file's space; encode_export tags PNG
  (sRGB chunk, or iCCP + cICP for Display P3) and embeds the ICC profile in Display P3 JPG/WebP;
  SVG and PDF export Display P3 files converted to sRGB. The CLI exports the same way.
- ui: Color profile dialog (keep appearance / keep values) and a Color profile row on the page
  panel; the canvas, presenter, thumbnails, swatches and colour picker show a Display P3 file's
  colours converted to the screen's sRGB, and Copy as PNG converts too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* M3: image adjustment presets: built-in, saved in the file, reset

- color: ImageFilters::PRESETS (Vivid, Muted, Warm, Cool, Black & white, Fade, Reset), lookup by
  id or label, and sanitized values.
- doc: Document.image_presets (name + adjustments; written only when there are some).
- engine: image.adjust {ids?, target?, index?, preset?, filters?} sets the adjustments of image
  paints from a preset (built-in or saved) with values on top, one undo step; image.savePreset,
  image.deletePreset and image.presets.
- ui: the colour picker's image section gets a presets menu named after the preset in effect
  ("Custom" otherwise), saved presets with delete, "Save as preset...", a Reset button, and
  aligned adjustment sliders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* M3: style picker: search, folders, list or swatch grid, edit, create, detach

The Fill, Stroke, Effects and Layout grid sections' Styles button opens a popover laid out like
the variable picker (crates/ui-egui/src/style_picker.rs):

- search over style names; styles grouped by the folders of their `/`-separated names, which
  collapse (searching opens them); colour styles as a list or a grid of swatches;
- click applies, a check marks the applied style; the row's edit button (or a right-click) edits
  the name, description and values: colour style paints open the colour picker on the style,
  effect and grid styles update from the selection; delete;
- `+` creates a style from the selection's current values and opens it for naming; detach;
- colour slots still list colour variables to bind;
- the applied style chip opens the picker; new icons Adjust, ViewList, ViewGrid (drawn in code);
- control channel: ui.set {stylePicker, stylePickerEdit, stylePickerView}.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 07:38:17 +07:00

110 lines
3.0 KiB
Rust

//! The command registry. Each area module exposes `specs()`; [`all_commands`] collects them once.
pub mod arrange;
pub mod comment;
pub mod component;
pub mod create;
pub mod edit;
pub mod file;
pub mod image;
pub mod layout;
pub mod library;
pub mod page;
pub mod props;
pub mod proto;
pub mod structure;
pub mod styles;
pub mod text;
pub mod variables;
pub mod view;
use std::collections::HashMap;
use std::sync::OnceLock;
use serde_json::Value;
use crate::{Result, Session};
pub type RunFn = fn(&mut Session, &Value) -> Result<Value>;
/// A registered command.
pub struct CommandSpec {
pub id: &'static str,
pub label: &'static str,
/// Parameter documentation for agents (`list_commands`).
pub params: &'static str,
/// Whether the command edits the document (an undo step).
pub history: bool,
pub run: RunFn,
}
impl CommandSpec {
pub fn menu(&self) -> Option<&'static str> {
crate::catalog::MENU.iter().find(|m| m.id == self.id).map(|m| m.menu)
}
pub fn shortcut(&self) -> Option<&'static str> {
crate::catalog::shortcut(self.id)
}
}
/// Define a command spec: `spec!(id, label, params_doc, history, run)`.
#[macro_export]
macro_rules! spec {
($id:expr, $label:expr, $params:expr, $hist:expr, $run:expr) => {
$crate::cmd::CommandSpec { id: $id, label: $label, params: $params, history: $hist, run: $run }
};
}
struct Registry {
list: Vec<CommandSpec>,
index: HashMap<&'static str, usize>,
}
fn registry() -> &'static Registry {
static R: OnceLock<Registry> = OnceLock::new();
R.get_or_init(|| {
let mut list = Vec::new();
list.extend(create::specs());
list.extend(edit::specs());
list.extend(arrange::specs());
list.extend(structure::specs());
list.extend(layout::specs());
list.extend(file::specs());
list.extend(page::specs());
list.extend(view::specs());
list.extend(text::specs());
list.extend(styles::specs());
list.extend(image::specs());
list.extend(variables::specs());
list.extend(component::specs());
list.extend(library::specs());
list.extend(proto::specs());
list.extend(comment::specs());
list.extend(crate::vectoredit::specs());
list.extend(crate::shapebuilder::specs());
list.extend(crate::codegen::specs());
list.extend(crate::devinspect::specs());
let mut index = HashMap::new();
for (i, s) in list.iter().enumerate() {
if index.insert(s.id, i).is_some() {
log::warn!("duplicate command id {}", s.id);
}
}
Registry { list, index }
})
}
pub fn all_commands() -> &'static [CommandSpec] {
&registry().list
}
pub fn find_command(id: &str) -> Option<&'static CommandSpec> {
let r = registry();
r.index.get(id).and_then(|i| r.list.get(*i))
}
/// `{"ok": true}` shorthand.
pub fn ok() -> Result<Value> {
Ok(serde_json::json!({"ok": true}))
}