mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
ui: grey the Count tool's one-layer rows only with several pixel layers selected (#12358)
This commit is contained in:
1 parent
bef4613893
commit
9abf147684
2 files changed
+41
-4
No files matched your search
@@ -753,6 +753,15 @@ fn several_layers_selected(app: &PhotocraftApp) -> bool {
|
||||
app.session.active().is_some_and(|st| st.selected_layers().len() > 1)
|
||||
}
|
||||
|
||||
/// Several layers are selected in the front document, every one a pixel layer: the case #12358
|
||||
/// measured on the Count tool's layer menu.
|
||||
fn several_pixel_layers_selected(app: &PhotocraftApp) -> bool {
|
||||
app.session.active().is_some_and(|st| {
|
||||
let selected = st.selected_layers();
|
||||
selected.len() > 1 && selected.iter().all(|id| st.doc.layer(*id).is_some_and(|l| matches!(l.content, LayerContent::Raster(_))))
|
||||
})
|
||||
}
|
||||
|
||||
/// Is a path with at least two points being drawn with the Pen?
|
||||
pub(crate) fn pen_pending(app: &PhotocraftApp) -> bool {
|
||||
app.ui.pen.as_ref().is_some_and(|p| p.draft.knots.len() >= 2)
|
||||
@@ -1372,12 +1381,13 @@ pub fn entry_enabled(app: &PhotocraftApp, menu: &CanvasToolMenu, command: &str)
|
||||
if inside_selection(menu) && command == "select.loadSelection" {
|
||||
return app.session.active().is_some_and(|st| st.doc.channels.iter().any(|c| c.spot.is_none())) && crate::menus::is_enabled(app, command);
|
||||
}
|
||||
// #12358, measured on the Count tool's layer menu: with several layers selected, Blending
|
||||
// Options…, Color Range… and Load Selection… work on one layer, so they are greyed. The other
|
||||
// tools' layer menus weren't measured with several layers and keep `menus::is_enabled`.
|
||||
// #12358, measured on the Count tool's layer menu: with several pixel layers selected,
|
||||
// Blending Options…, Color Range… and Load Selection… work on one layer, so they are greyed.
|
||||
// Other layer kinds and the other tools' layer menus weren't measured with several layers and
|
||||
// keep `menus::is_enabled`.
|
||||
if menu.tool == Tool::Count
|
||||
&& matches!(command, "layer.layerStyle.blendingOptions" | "select.colorRange" | "select.loadSelection")
|
||||
&& several_layers_selected(app)
|
||||
&& several_pixel_layers_selected(app)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -169,3 +169,30 @@ fn delete_layers_still_deletes_the_selected_layers() {
|
||||
assert!(st.doc.layer(photocraft_doc::LayerId(id)).is_none(), "layer {id} deleted");
|
||||
}
|
||||
}
|
||||
|
||||
/// The greying is limited to the measured case, several pixel layers: with two shape layers
|
||||
/// selected, Blending Options…, Color Range… and Load Selection… follow `menus::is_enabled`.
|
||||
#[test]
|
||||
fn with_two_shape_layers_selected_the_one_layer_rows_follow_the_menu_bar() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 64, "height": 48})).unwrap();
|
||||
let shape = |app: &mut PhotocraftApp, rect: [u32; 4]| {
|
||||
app.run("shape.create", json!({"kind": "rect", "rect": rect, "fill": "#3070c0"})).unwrap()["layer"].as_u64().unwrap()
|
||||
};
|
||||
let first = shape(&mut app, [4, 4, 10, 10]);
|
||||
shape(&mut app, [30, 20, 10, 10]);
|
||||
app.run("layer.select", json!({"layer": first, "mode": "add"})).unwrap();
|
||||
app.sync_views();
|
||||
app.ui.tool = Tool::Count;
|
||||
let ctx = app.ctx().clone();
|
||||
assert_eq!(selected(&app), 2);
|
||||
right_click(&mut app, 50.0, 40.0);
|
||||
let entries = inspected(&mut app, &ctx);
|
||||
assert!(!entries.is_empty(), "the Count tool's layer menu is open");
|
||||
let rows = ["layer.layerStyle.blendingOptions", "select.colorRange", "select.loadSelection"];
|
||||
for id in rows {
|
||||
let enabled = entries.iter().find(|e| e.0 == id).map(|e| e.2);
|
||||
assert_eq!(enabled, Some(crate::menus::is_enabled(&app, id)), "{id}");
|
||||
}
|
||||
assert!(rows.iter().any(|id| crate::menus::is_enabled(&app, id)), "the menu bar enables one of them, so the case tells the rules apart");
|
||||
}
|
||||
Reference in new issue
Block a user