mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge pull request #12450 from qvest-ssels/feat/layer-thumb-select-pixels-12324
feat(ui): Select Pixels on a pixel layer thumbnail's right-click menu
This commit is contained in:
3 files changed
+92
-5
No files matched your search
@@ -599,3 +599,63 @@ fn every_entry_is_a_known_command() {
|
||||
assert!(crate::menu_catalog::CATALOG.iter().any(|m| m.3 == id) || photocraft_engine::commands::find(id).is_some(), "{id}");
|
||||
}
|
||||
}
|
||||
|
||||
/// #12324: right-clicking a pixel layer's thumbnail opens Photoshop's thumbnail menu; its Select Pixels
|
||||
/// loads the clicked layer's transparency, as a ⌘-click on the thumbnail does. The Background's
|
||||
/// thumbnail, with no transparency to load, keeps the layer menu.
|
||||
#[test]
|
||||
fn layer_thumbnail_context_menu_selects_the_clicked_layers_pixels() {
|
||||
use crate::PhotocraftApp;
|
||||
use egui::{Event, Modifiers, PointerButton, Pos2, vec2};
|
||||
use egui_kittest::{Harness, kittest::Queryable};
|
||||
|
||||
fn click(h: &mut Harness<'_, PhotocraftApp>, at: Pos2, button: PointerButton) {
|
||||
h.hover_at(at);
|
||||
h.step();
|
||||
for pressed in [true, false] {
|
||||
h.event(Event::PointerButton { pos: at, button, pressed, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
}
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
let mut s = photocraft_engine::Session::new();
|
||||
s.execute("file.new", json!({"width": 100, "height": 60})).unwrap();
|
||||
let background = s.active().unwrap().active_layer.unwrap();
|
||||
s.execute("layer.new.layer", json!({"name": "Painted"})).unwrap();
|
||||
s.execute("select.rect", json!({"x": 60, "y": 0, "width": 40, "height": 60})).unwrap();
|
||||
s.execute("edit.fill", json!({"color": "#b04020"})).unwrap();
|
||||
let painted = s.active().unwrap().active_layer.unwrap();
|
||||
// Another layer is active, and the current selection doesn't overlap the painted pixels.
|
||||
s.execute("layer.new.layer", json!({"name": "Other active layer"})).unwrap();
|
||||
s.execute("select.rect", json!({"x": 0, "y": 0, "width": 20, "height": 60})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).with_max_steps(64).build_eframe(move |cc| {
|
||||
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
|
||||
PhotocraftApp::new(s, crate::Services::default())
|
||||
});
|
||||
let ctx = h.ctx.clone();
|
||||
let (req, _rx) = crate::control::ControlRequest::new("ui.set", json!({"dock": {"collapsed": ["color", "properties", "history", "navigator"]}}));
|
||||
crate::control::handle(h.state_mut(), &ctx, &req);
|
||||
h.run_steps(8);
|
||||
let thumb = |h: &Harness<'_, PhotocraftApp>, layer: photocraft_doc::LayerId| {
|
||||
crate::layer_row_ui::recorded(&h.ctx).into_iter().find(|r| r.layer == layer.0).and_then(|r| r.thumbnail).expect("thumbnail drawn").center()
|
||||
};
|
||||
|
||||
let at = thumb(&h, painted);
|
||||
click(&mut h, at, PointerButton::Secondary);
|
||||
assert!(h.query_by_label("Blending Options…").is_none(), "the thumbnail menu, not the layer menu");
|
||||
for item in ["Small Thumbnails", "Clip Thumbnails to Layer Bounds"] {
|
||||
h.get_by_label(item);
|
||||
}
|
||||
let at = h.get_by_label("Select Pixels").rect().center();
|
||||
click(&mut h, at, PointerButton::Primary);
|
||||
let st = h.state().session.active().unwrap();
|
||||
let sel = st.doc.selection.as_ref().expect("a selection");
|
||||
assert!(sel.sample_channel(80, 30, 0) > 0.99, "the clicked layer's pixels are selected");
|
||||
assert!(sel.sample_channel(10, 30, 0) < 0.01, "the old selection is replaced");
|
||||
|
||||
let at = thumb(&h, background);
|
||||
click(&mut h, at, PointerButton::Secondary);
|
||||
assert!(h.query_by_label("Select Pixels").is_none(), "the Background has no pixels to load");
|
||||
h.get_by_label("Blending Options…");
|
||||
}
|
||||
@@ -568,16 +568,27 @@ fn handle_row_double_click(app: &mut PhotocraftApp, ctx: &egui::Context, rc: &Ro
|
||||
}
|
||||
}
|
||||
|
||||
/// The visibility icon has its own color menu, and the layer-mask thumbnail its mask menu (#4575).
|
||||
/// The visibility icon has its own color menu, the layer-mask thumbnail its mask menu (#4575)
|
||||
/// and a pixel layer's thumbnail Select Pixels and the thumbnail settings (#12324).
|
||||
fn row_context_menu(app: &mut PhotocraftApp, ui: &mut egui::Ui, rc: &RowCtx<'_>, eye_resp: &egui::Response, actions: &mut Vec<(String, Value)>) {
|
||||
let (l, resp, masks, row) = (rc.l, rc.resp, rc.masks, rc.row);
|
||||
let (ctx, selected) = (&ui.ctx().clone(), row.selected);
|
||||
// The visibility icon has its own color menu, and the layer-mask thumbnail its mask menu
|
||||
// (#4575); elsewhere use the full layer menu.
|
||||
// The visibility icon has its own color menu, the layer-mask thumbnail its mask menu
|
||||
// (#4575) and a pixel layer's thumbnail its thumbnail menu; elsewhere the full layer menu.
|
||||
let on_mask_id = ui.scope_id().with(("mask-menu", l.id.0));
|
||||
let on_thumb_id = ui.scope_id().with(("thumb-menu", l.id.0));
|
||||
if resp.secondary_clicked() {
|
||||
let on_mask = resp.interact_pointer_pos().and_then(|p| masks.hit(p)) == Some(crate::mask_thumbs_ui::MaskKind::Pixel);
|
||||
ctx.data_mut(|d| d.insert_temp(on_mask_id, on_mask));
|
||||
let pos = resp.interact_pointer_pos();
|
||||
let on_mask = pos.and_then(|p| masks.hit(p)) == Some(crate::mask_thumbs_ui::MaskKind::Pixel);
|
||||
// A pixel layer's thumbnail; not the Background's, which has no transparency to load.
|
||||
// Type, shape, smart object, fill, adjustment and group thumbnails keep the layer menu
|
||||
// with their own items (Rasterize, Edit Contents…).
|
||||
let pixels = matches!(l.content, LayerContent::Raster(_)) && l.frame.is_none() && !rc.doc.is_background(l.id);
|
||||
let on_thumb = !on_mask && pixels && rc.ts > 0.0 && pos.is_some_and(|p| masks.hit(p).is_none() && rc.thumb.expand(2.0).contains(p));
|
||||
ctx.data_mut(|d| {
|
||||
d.insert_temp(on_mask_id, on_mask);
|
||||
d.insert_temp(on_thumb_id, on_thumb);
|
||||
});
|
||||
}
|
||||
if !eye_resp.secondary_clicked() && !eye_resp.context_menu_opened() {
|
||||
resp.context_menu(|ui| {
|
||||
@@ -586,6 +597,10 @@ fn row_context_menu(app: &mut PhotocraftApp, ui: &mut egui::Ui, rc: &RowCtx<'_>,
|
||||
crate::layer_menu_ui::show_mask(app, ui, l, actions);
|
||||
return;
|
||||
}
|
||||
if ui.ctx().data(|d| d.get_temp::<bool>(on_thumb_id)).unwrap_or(false) {
|
||||
super::layers_empty_menu::show_thumbnail(app, ui, l.id.0, actions);
|
||||
return;
|
||||
}
|
||||
// Right-clicking inside a multi-selection keeps it and acts on every selected layer.
|
||||
let on_set = row.multi && selected;
|
||||
if crate::layer_menu_ui::show(app, ui, l, on_set, actions)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! The menu a right-click on the empty area below the last layer row opens (#11404): the
|
||||
//! thumbnail size and what a thumbnail frames. Both are the settings Panel Options... edits.
|
||||
//! A right-click on a layer's thumbnail opens the same menu under Select Pixels (#12324).
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
@@ -16,6 +17,17 @@ pub(super) fn sizes() -> [(LayerThumbnailSize, &'static str); 4] {
|
||||
]
|
||||
}
|
||||
|
||||
/// The layer thumbnail's menu: Select Pixels loads the layer's transparency as the selection,
|
||||
/// as a ⌘-click on the thumbnail does, then the thumbnail settings.
|
||||
pub(super) fn show_thumbnail(app: &mut PhotocraftApp, ui: &mut egui::Ui, layer: u64, actions: &mut Vec<(String, serde_json::Value)>) {
|
||||
if ui.button(tl!("Select Pixels")).clicked() {
|
||||
actions.push(("select.loadSelection".into(), json!({"channel": "transparency", "layer": layer, "operation": "new"})));
|
||||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
show(app, ui);
|
||||
}
|
||||
|
||||
pub(super) fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let current = app.ui.layers_panel_options.thumbnail_size;
|
||||
for (size, label) in sizes() {
|
||||
|
||||
Reference in new issue
Block a user