PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Control: ui.inspect reports the open Brush Preset picker (#1672)
Nigel Ihza Firdausy75e6bad453ea
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rsindex c422d4b3e..c834c82ac 100644--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@ -767,6 +767,10 @@ pub fn inspect(app: &PhotocraftApp, ctx: &egui::Context) -> Value {"textEdit": app.ui.text_edit,"typeTransform": app.ui.type_transform,"layerMenu": app.ui.layer_menu,+ "brushPicker": app.ui.brush_picker.map(|pos| json!({+ "pos": pos,+ "list": app.ui.brush_picker_list,+ })),"canvasToolMenu": app.ui.canvas_tool_menu.as_ref().map(|menu| {json!({"pos": menu.pos,@@ -1044,6 +1048,40 @@ mod tests {assert_eq!(app.ui.brush_picker, None);}+ #[test]+ fn ui_inspect_tracks_brush_picker_open_and_closed() {+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ let ctx = egui::Context::default();+ app.run("file.new", json!({"width": 128, "height": 128})).unwrap();++ let closed = call(&mut app, &ctx, "ui.inspect", json!({}));+ assert!(closed["result"]["brushPicker"].is_null());++ // A right-click on the canvas with Brush opens the same picker as the options bar.+ assert_eq!(call(&mut app, &ctx, "ui.set", json!({"tool": "brush"}))["ok"], true);+ let click = call(+ &mut app,+ &ctx,+ "ui.pointer",+ json!({+ "button": "right",+ "events": [{"kind": "down", "x": 64, "y": 64}, {"kind": "up", "x": 64, "y": 64}]+ }),+ );+ assert_eq!(click["ok"], true, "{click}");+ let open = call(&mut app, &ctx, "ui.inspect", json!({}));+ assert!(open["result"]["brushPicker"]["pos"].is_array(), "{open}");+ assert_eq!(open["result"]["brushPicker"]["list"]["view"], "grid");++ assert_eq!(call(&mut app, &ctx, "ui.set", json!({"brushPickerView": "list"}))["ok"], true);+ let changed = call(&mut app, &ctx, "ui.inspect", json!({}));+ assert_eq!(changed["result"]["brushPicker"]["list"]["view"], "list");++ assert_eq!(call(&mut app, &ctx, "ui.set", json!({"brushPicker": null}))["ok"], true);+ let closed_again = call(&mut app, &ctx, "ui.inspect", json!({}));+ assert!(closed_again["result"]["brushPicker"].is_null());+ }+#[test]fn ui_set_applies_all_fields_or_none() {let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());diff --git a/docs/control-protocol.md b/docs/control-protocol.mdindex 366a3f1cf..69611687f 100644--- a/docs/control-protocol.md+++ b/docs/control-protocol.md@@ -36,7 +36,7 @@ The transport is `apps/photocraft/src/control_server.rs`, and the handlers are i- `engine.execute {command, params}`: run any engine or UI command by id. Engine commands run directly with their default params and never open a dialog. Use `ui.menu.invoke` for menu-click behaviour, which opens a command's dialog when no params are given. `params` must be a JSON object (omit it or pass `null` for none); an array, string, number or boolean is an error naming the command, in every transport (control channel, `serve`, MCP and the CLI)- `engine.commands`: list commands with enablement-- `ui.inspect`: full UI state (tool, panels, views, dialogs, windows, window size). The menu tree is not included; use `ui.menu.list`. `view` holds the View/Window/Type preferences: `screen_mode`, `extras`, `show` and `snap_to` flags, `flip_horizontal`, `arrange` (Window › Arrange layout), pixel aspect, font preview size, language options. `perf.timings.gpuInfo` holds the graphics adapter, backend, driver, the backend chosen at launch and why, the canvas renderer (`gpu`/`cpu`) and, after a device loss, `lost` (`help.systemInfo` returns the same as `info`)+- `ui.inspect`: full UI state (tool, panels, views, dialogs, windows, window size). The menu tree is not included; use `ui.menu.list`. `brushPicker` is `null` while closed and `{pos: [x, y], list: {collapsed, filter, view, renaming}}` while the Brush Preset picker is open (coordinates in screen points). `view` holds the View/Window/Type preferences: `screen_mode`, `extras`, `show` and `snap_to` flags, `flip_horizontal`, `arrange` (Window › Arrange layout), pixel aspect, font preview size, language options. `perf.timings.gpuInfo` holds the graphics adapter, backend, driver, the backend chosen at launch and why, the canvas renderer (`gpu`/`cpu`) and, after a device loss, `lost` (`help.systemInfo` returns the same as `info`)- `ui.set {tool?, panels?, dockTabs?, dock?, dockWidth?, colorPanel?, maskTarget?, vectorMaskTarget?, selectionMode?, zoom?, center?, rotation?, fit?, theme?, brushSize?, brushSection?, brushTab?, brushesView?, brushPicker?, brushPickerView?, gradientBlendMode?, gradientClassic?}`: change UI state; any other field is an error, checked before anything changes (`theme` is `pro`, `proMedium`, `studio`, `studioLight` or `classic`; `selectionMode` is the selection tools' options-bar mode, 0 New, 1 Add, 2 Subtract, 3 Intersect; `brushSection` indexes the Brush Settings sections, `brushTab` 0 = Brush Settings, 1 = Brushes; `brushesView` and `brushPickerView` are `list` or `grid` for the Brushes panel and the Brush Preset picker; `brushPicker` is `[x, y]` in screen points to open the Brush Preset picker there (as a right-click with a painting tool does) or `null` to close it, and picking a preset in it is `tools.setBrush {"preset": name}`; `dock` is `{order: ["layers", …], heights: {"properties": 180}, collapsed: ["color"]}`, the right-dock groups top to bottom, their heights in points and the groups collapsed to their tab strip; `dockWidth` sets the right dock width in points, clamped to 250..520; `colorPanel` is `{background}`, whether the Color panel edits the background colour)- `typeTransform` is `null` outside a temporary Ctrl/Cmd Type-tool drag. During a drag it reports its source document/revision, original affine, oriented `frame` (layer, local bounds, document-space corners and pivot), and captured `gesture`. Drive it with `ui.pointer` and `command: true` at `down`; `move`/`up` may release the modifier. The document/history remain unchanged during preview, and `up` applies one `type.edit` within `textEdit`'s session. Pressing Escape during the drag cancels only the preview. This pointer state is never restored from saved UI state.- `ui.menu.invoke {id, params?, wait?}` / `ui.menu.list`: activate a menu item by id; list the menu tree. A menu item that starts a background job (a filter without a dialog, such as Blur More) replies with the job's result once it has been applied; with `"wait": false` the reply is `{job, pending: true}` at once