PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Channels: load the targeted layer mask as selection (#5562)
envy-aie47086717a18
diff --git a/crates/ui-egui/src/channels_panel.rs b/crates/ui-egui/src/channels_panel.rsindex f23238413..7f175b620 100644--- a/crates/ui-egui/src/channels_panel.rs+++ b/crates/ui-egui/src/channels_panel.rs@@ -330,7 +330,11 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui) {}let load = icons::button(ui, "circle-dashed", 26.0, false, tl!("Load channel as selection"));if load.clicked() {- actions.push(("select.loadSelection".into(), json!({ "channel": target_ref })));+ // The selected mask row can coexist with a Composite engine target while mask+ // painting is active. The footer follows the row the user sees as targeted.+ let params =+ if mask_targeted { json!({ "channel": "mask", "layer": masked.as_ref().map(|layer| layer.id.0) }) } else { json!({ "channel": target_ref }) };+ actions.push(("select.loadSelection".into(), params));}actions.extend(drop(ui, &load, Footer::Load));});@@ -615,6 +619,68 @@ mod tests {assert!(h.state().session.active().unwrap().doc.selection.is_some(), "the white channel selects everything");}+ /// The footer follows the targeted row shown by the panel when mask painting is active,+ /// even though the engine's channel-view target remains Composite. Other channel targets+ /// continue to load their own values, and each load remains one undoable selection change.+ #[test]+ fn footer_loads_the_selected_layer_mask_and_preserves_color_alpha_targets() {+ let (mut h, _) = channels_harness();+ h.state_mut().run("select.rect", json!({"x": 0, "y": 0, "width": 32, "height": 48})).unwrap();+ h.state_mut().run("layer.layerMask.hideAll", json!({})).unwrap();+ h.state_mut().run("layer.layerMask.revealSelection", json!({})).unwrap();+ h.state_mut().run("channel.target", json!({"channel": "composite"})).unwrap();+ h.state_mut().ui.mask_target = true;+ h.run_steps(2);++ let click_load = |h: &mut egui_kittest::Harness<'_, PhotocraftApp>| {+ use egui::{Modifiers, PointerButton};+ let p = at(h, "Load channel as selection");+ h.hover_at(p);+ h.run_steps(1);+ h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });+ h.run_steps(1);+ h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });+ h.run_steps(2);+ };+ let sample =+ |h: &egui_kittest::Harness<'_, PhotocraftApp>, x, y| h.state().session.active().unwrap().doc.selection.as_ref().unwrap().sample_channel(x, y, 0);++ assert_eq!(h.state().session.active().unwrap().channel_view.target, ChannelTarget::Composite);+ click_load(&mut h);+ assert_eq!((sample(&h, 8, 8), sample(&h, 48, 8)), (1.0, 0.0), "mask row selection wins over the Composite engine target");+ h.state_mut().run("edit.undo", json!({})).unwrap();+ assert!(h.state().session.active().unwrap().doc.selection.is_none());+ h.state_mut().run("edit.redo", json!({})).unwrap();+ assert_eq!((sample(&h, 8, 8), sample(&h, 48, 8)), (1.0, 0.0));++ h.state_mut().ui.mask_target = false;+ h.state_mut().run("channel.target", json!({"channel": "composite"})).unwrap();+ click_load(&mut h);+ assert_eq!((sample(&h, 8, 8), sample(&h, 48, 8)), (1.0, 1.0), "composite luminosity remains available");+ h.state_mut().run("edit.undo", json!({})).unwrap();+ assert_eq!((sample(&h, 8, 8), sample(&h, 48, 8)), (1.0, 0.0));+ h.state_mut().run("edit.redo", json!({})).unwrap();+ assert_eq!((sample(&h, 8, 8), sample(&h, 48, 8)), (1.0, 1.0));++ h.state_mut().run("select.rect", json!({"x": 0, "y": 0, "width": 32, "height": 48})).unwrap();+ h.state_mut().run("channel.new", json!({"fill": "selection"})).unwrap();+ h.state_mut().run("select.deselect", json!({})).unwrap();+ h.state_mut().run("channel.target", json!({"channel": "red"})).unwrap();+ click_load(&mut h);+ assert_eq!((sample(&h, 8, 8), sample(&h, 48, 8)), (1.0, 1.0), "color channel still loads its own plane");+ h.state_mut().run("edit.undo", json!({})).unwrap();+ h.state_mut().run("edit.redo", json!({})).unwrap();+ assert_eq!((sample(&h, 8, 8), sample(&h, 48, 8)), (1.0, 1.0));++ h.state_mut().run("channel.target", json!({"channel": 1})).unwrap();+ click_load(&mut h);+ assert_eq!((sample(&h, 8, 8), sample(&h, 48, 8)), (1.0, 0.0), "alpha channel still loads its own plane");+ h.state_mut().run("edit.undo", json!({})).unwrap();+ assert_eq!((sample(&h, 8, 8), sample(&h, 48, 8)), (1.0, 1.0));+ h.state_mut().run("edit.redo", json!({})).unwrap();+ assert_eq!((sample(&h, 8, 8), sample(&h, 48, 8)), (1.0, 0.0));+ }+/// A plain click on a row still targets it, and a drag released elsewhere does nothing.#[test]fn clicks_still_target_and_a_drop_elsewhere_does_nothing() {diff --git a/docs/ui-design.md b/docs/ui-design.mdindex c6135ff74..d4ac18d29 100644--- a/docs/ui-design.md+++ b/docs/ui-design.md@@ -58,6 +58,7 @@ curl -sfL -o assets/icons/<name>.svg https://raw.githubusercontent.com/lucide-ic| Quick layer pick | `quick_pick.rs` | macOS: ⌘⌥⌃-click with any tool selects the topmost visible layer with pixels under the pointer (`layer.pickAt`) without switching tools; the drag and release are swallowed. Windows/Linux have no third modifier distinct from the ⌃⌥ brush resize, so the gesture is a no-op there (use the Move tool's Auto-Select). A failed pick is a status-bar error. || Layers rows | `panels.rs` | Double-click: on the name renames in place; on the Background makes it a normal layer; on an adjustment or fill thumbnail opens its Properties; on a Smart Object thumbnail opens its contents (Edit Contents); anywhere else on the row opens Layer Style. || Layer masks | `panels.rs` | Clicking the mask thumbnail targets the mask (corner-bracket frame; the tab reads "Layer, Layer Mask/8"). Brush, eraser (paints background colour), gradient, bucket and moving the selected pixels (⌘-drag, `select.float`; the hole takes the background colour) then send `"target": "mask"`. Adjustment and fill layers target their mask automatically. |+| Channels selection | `channels_panel.rs` | Load channel as selection in the footer follows the highlighted channel row. When the active layer mask is targeted for painting while the underlying channel view remains Composite, it loads that layer mask; otherwise it loads the selected composite, color, alpha or vector mask channel. || Path thumbnails | `vector_ui.rs` | Ctrl/Cmd-click the thumbnail of a Work Path, saved path or layer path to load it as a selection; Shift adds, Alt subtracts, Shift+Alt intersects. Clicking the row name only selects the path. || Levels / Curves | `tone.rs` | Histogram of the image *below* the adjustment. Curves: click to add a point, drag out to delete. Every change is a coalesced `layer.setAdjustment`, so one drag = one undo step and the canvas updates at full resolution on the GPU. || Shape Stroke Options | `shape_stroke_ui.rs`, `vector_ui.rs` | Direct editing: valid changes apply immediately, with one numeric drag per undo step in Properties. Escape/outside click closes the popup and retains changes; a child dropdown keeps the parent open. The options bar sets new-shape defaults; Properties edits the selected shape. |