From fea4a5e627f611e76e584f5eee26b471da8ba907 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Thu, 26 Nov 2026 00:53:35 +0100 Subject: [PATCH 1/2] Shift+click on a mask thumbnail switches the mask on or off, the material thumbnail leaves mask view Shift+click on a mask thumbnail runs mask.toggle on that layer instead of selecting the mask. The mask thumbnail exposes a Mask off description while the mask is bypassed. Clicking the material thumbnail returns the viewport from mask view to the material view. --- crates/ui-egui/src/dock.rs | 17 +++++-- crates/ui-egui/tests/it/layers_panel.rs | 60 +++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs index b1ecd8b8..0f202dd1 100644 --- a/crates/ui-egui/src/dock.rs +++ b/crates/ui-egui/src/dock.rs @@ -556,6 +556,9 @@ fn layer_row(app: &mut TextureCraftApp, ui: &mut Ui, layer: &Layer, depth: usize if content_response.clicked() { let modifiers = ui.input(|input| input.modifiers); click_layer(app, modifiers, layer.id.0, Some("content")); + if matches!(app.session.view, texturecraft_engine::ViewMode::Mask(_)) { + app.run("viewport.view", json!({"mode": "material"})); + } } thumbnail_context_menu(ui, &content_response, content_label, &layer.name, content_target, |ui| layer_context_menu(app, ui, layer, true)); x = thumbnail.right() + THUMBNAIL_SPACING; @@ -594,17 +597,25 @@ fn layer_row(app: &mut TextureCraftApp, ui: &mut Ui, layer: &Layer, depth: usize if !mask_enabled { painter.line_segment([mask_rect.left_top(), mask_rect.right_bottom()], Stroke::new(HIDDEN_STRIKE_WIDTH, tokens.danger)); } - let mask_label = tr("Select the mask (Alt+click: show it in the viewport)"); + let mask_label = tr("Select the mask (Alt+click: show it in the viewport, Shift+click: switch it on or off)"); let mask_response = ui.interact(mask_rect, ui.scope_id().with(("mask", layer.id.0)), Sense::click()).on_hover_text(mask_label); if mask_response.clicked() { - app.run("layer.select", json!({"layer": layer.id.0, "target": "mask"})); - if ui.input(|input| input.modifiers.alt) { + let modifiers = ui.input(|input| input.modifiers); + if modifiers.shift && !modifiers.alt { + app.run("mask.toggle", json!({"layer": layer.id.0})); + } else { + app.run("layer.select", json!({"layer": layer.id.0, "target": "mask"})); + } + if modifiers.alt { let showing = app.session.view == texturecraft_engine::ViewMode::Mask(layer.id); let view = if showing { json!({"mode": "material"}) } else { json!({"mode": "mask", "layer": layer.id.0}) }; app.run("viewport.view", view); } } thumbnail_context_menu(ui, &mask_response, mask_label, &layer.name, mask_target, |ui| mask_management_menu(app, ui, layer, true)); + if !mask_enabled { + ui.ctx().accesskit_node_builder(mask_response.id, |node| node.set_description(tr("Mask off"))); + } if app.session.view == texturecraft_engine::ViewMode::Mask(layer.id) { painter.rect_stroke( mask_rect.expand(HIGHLIGHT_OUTSET), diff --git a/crates/ui-egui/tests/it/layers_panel.rs b/crates/ui-egui/tests/it/layers_panel.rs index 72b5ad4b..edb8b8d9 100644 --- a/crates/ui-egui/tests/it/layers_panel.rs +++ b/crates/ui-egui/tests/it/layers_panel.rs @@ -37,6 +37,9 @@ fn thumb(h: &Harness<'_, TextureCraftApp>, name: &str, mask: bool) -> egui::Pos2 egui::pos2(x, row.center().y) } +/// The accessible name of the mask thumbnail of the layer "Masked fill" +const MASK_THUMBNAIL_NAME: &str = "Select the mask (Alt+click: show it in the viewport, Shift+click: switch it on or off) (Masked fill)"; + /// The `label` header that follows the "Masked fill" row (other layers have groups too). fn header(h: &mut Harness<'_, TextureCraftApp>, label: &str) { let top = h.get_by_label("Masked fill").rect().top(); @@ -352,7 +355,7 @@ fn thumbnail_menus_apply_actions_to_the_clicked_layer_and_stack() { #[test] fn focused_mask_thumbnail_opens_and_dismisses_its_menu_from_the_keyboard() { let (mut h, _) = harness(); - let thumbnail = "Select the mask (Alt+click: show it in the viewport) (Masked fill)"; + let thumbnail = MASK_THUMBNAIL_NAME; h.get_by_label(thumbnail).focus(); h.run_steps(3); assert!(h.get_by_label(thumbnail).is_focused()); @@ -425,10 +428,15 @@ fn alt_click_on_the_eye_solos_and_a_plain_click_still_hides() { } fn alt_click(h: &mut Harness<'_, TextureCraftApp>, at: egui::Pos2) { - h.event(egui::Event::ModifiersChanged(egui::Modifiers::ALT)); + click_with(h, at, egui::Modifiers::ALT); +} + +/// A primary click at `at` with `modifiers` held, as a user does +fn click_with(h: &mut Harness<'_, TextureCraftApp>, at: egui::Pos2, modifiers: egui::Modifiers) { + h.event(egui::Event::ModifiersChanged(modifiers)); h.hover_at(at); for pressed in [true, false] { - h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::ALT }); + h.event(egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers }); h.run_steps(2); } h.event(egui::Event::ModifiersChanged(egui::Modifiers::NONE)); @@ -467,6 +475,52 @@ fn alt_click_on_the_content_thumbnail_leaves_the_view_alone() { assert_eq!(h.state().session.view, texturecraft_engine::ViewMode::Material); } +/// Whether the red strike of a bypassed mask is painted across the thumbnail at `at` +fn mask_strike_shown(h: &Harness<'_, TextureCraftApp>, at: egui::Pos2) -> bool { + let danger = texturecraft_ui_egui::theme::Tokens::get(&h.ctx).danger; + shapes(h).iter().any(|shape| matches!(shape, egui::Shape::LineSegment { points, stroke } if stroke.color == danger && egui::Rect::from_two_pos(points[0], points[1]).contains(at))) +} + +#[test] +fn shift_click_on_a_mask_thumbnail_switches_the_mask_off_and_on_in_one_undo_step_each() { + let (mut h, layer) = harness(); + let at = thumb(&h, "Masked fill", true); + let target = h.state().session.target; + let history = h.state().session.history_labels().len(); + let mask = h.state().session.doc.project.layers[&layer].mask.clone().unwrap(); + assert!(!mask_strike_shown(&h, at)); + + click_with(&mut h, at, egui::Modifiers::SHIFT); + let off = h.state().session.doc.project.layers[&layer].mask.clone().unwrap(); + assert!(!off.enabled); + assert_eq!(off.effects, mask.effects, "the mask keeps its effects while bypassed"); + assert_eq!(h.state().session.history_labels().len(), history + 1); + assert_eq!(h.state().session.target, target, "Shift+click toggles instead of selecting the mask"); + assert!(mask_strike_shown(&h, at), "the disabled indicator shows while the mask is bypassed"); + assert_eq!(h.get_by_label(MASK_THUMBNAIL_NAME).accesskit_node().description().as_deref(), Some("Mask off"), "assistive tech hears the state"); + + click_with(&mut h, at, egui::Modifiers::SHIFT); + assert_eq!(h.state().session.doc.project.layers[&layer].mask, Some(mask), "toggling back restores the mask as it was"); + assert_eq!(h.state().session.history_labels().len(), history + 2); + assert!(!mask_strike_shown(&h, at)); + + h.state_mut().session.undo().unwrap(); + assert!(!h.state().session.doc.project.layers[&layer].mask.as_ref().unwrap().enabled, "one undo undoes one toggle"); +} + +#[test] +fn clicking_the_material_thumbnail_leaves_the_mask_view() { + let (mut h, layer) = harness(); + let at = thumb(&h, "Masked fill", true); + alt_click(&mut h, at); + assert_eq!(h.state().session.view, texturecraft_engine::ViewMode::Mask(layer)); + + let at = thumb(&h, "Masked fill", false); + click(&mut h, at); + assert_eq!(h.state().session.view, texturecraft_engine::ViewMode::Material); + assert_eq!(h.state().session.target, StackTarget::Content, "the layer content is selected"); +} + /// Pointer moves of the opacity cell drag, one per frame const OPACITY_DRAG_MOVES: usize = 4; From 632b2698c3d9e86dde72dff4fa222abf0c984c88 Mon Sep 17 00:00:00 2001 From: chasse20 Date: Thu, 26 Nov 2026 01:12:03 +0000 Subject: [PATCH 2/2] Auto: Preserve mask view on Alt-clicking the content thumbnail Keep content selection active while Alt-click preserves the current viewport. Extend the Layers panel regression to exercise the gesture from Mask view. All 20 Layers panel tests, UI Clippy, formatting, layering, and the isolated UI WebAssembly check passed. --- crates/ui-egui/src/dock.rs | 3 ++- crates/ui-egui/tests/it/layers_panel.rs | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs index 53672f61..e51abaca 100644 --- a/crates/ui-egui/src/dock.rs +++ b/crates/ui-egui/src/dock.rs @@ -557,10 +557,11 @@ fn layer_row(app: &mut TextureCraftApp, ui: &mut Ui, layer: &Layer, depth: usize let modifiers = ui.input(|input| input.modifiers); click_layer(app, modifiers, layer.id.0, Some("content")); - if matches!(app.session.view, texturecraft_engine::ViewMode::Mask(_)) { + if !modifiers.alt && matches!(app.session.view, texturecraft_engine::ViewMode::Mask(_)) { app.run("viewport.view", json!({"mode": "material"})); } } + thumbnail_context_menu(ui, &content_response, content_label, &layer.name, content_target, |ui| layer_context_menu(app, ui, layer, true)); x = thumbnail.right() + THUMBNAIL_SPACING; diff --git a/crates/ui-egui/tests/it/layers_panel.rs b/crates/ui-egui/tests/it/layers_panel.rs index 459109f8..25819847 100644 --- a/crates/ui-egui/tests/it/layers_panel.rs +++ b/crates/ui-egui/tests/it/layers_panel.rs @@ -472,11 +472,23 @@ fn alt_click_on_a_mask_thumbnail_shows_that_mask_alone_without_changing_the_docu #[test] fn alt_click_on_the_content_thumbnail_leaves_the_view_alone() { - let (mut h, _) = harness(); - let at = thumb(&h, "Masked fill", false); - alt_click(&mut h, at); + let (mut h, layer) = harness(); + let content_thumbnail = thumb(&h, "Masked fill", false); + let mask_thumbnail = thumb(&h, "Masked fill", true); + + alt_click(&mut h, content_thumbnail); assert_eq!(h.state().session.view, texturecraft_engine::ViewMode::Material); + + alt_click(&mut h, mask_thumbnail); + + assert_eq!(h.state().session.view, texturecraft_engine::ViewMode::Mask(layer)); + assert_eq!(h.state().session.target, StackTarget::Mask); + + alt_click(&mut h, content_thumbnail); + + assert_eq!(h.state().session.view, texturecraft_engine::ViewMode::Mask(layer)); + assert_eq!(h.state().session.target, StackTarget::Content); } /// Whether a bypassed mask's strike is painted across the thumbnail at `position`