Merge queue batch: 5 PRs (#17421, #17420, #17440, #17441, #17434)
This commit is contained in:
David Mann authored and GitHub committed 2026-11-28 23:54:27 +01:00
commit d3b040392b
30 files changed
+803 -19

No files matched your search

+1
View File
@@ -19,6 +19,7 @@ next to them.
| `assets/icons/vector-shape.svg` | Vector path shape-layer glyph with four anchor points | @superplay2021 | Original work for PhotoCraft | MIT OR Apache-2.0 | | `assets/icons/vector-shape.svg` | Vector path shape-layer glyph with four anchor points | @superplay2021 | Original work for PhotoCraft | MIT OR Apache-2.0 |
| `assets/icons/spirit-level.svg` | Straighten tool glyph: a spirit level with its vial and bubble under a dotted arc | PhotoCraft contributors | Original work | MIT OR Apache-2.0 | | `assets/icons/spirit-level.svg` | Straighten tool glyph: a spirit level with its vial and bubble under a dotted arc | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
| `assets/icons/path-op-{new-layer,combine,subtract,intersect,exclude,merge}.svg` | Path Operations glyphs (Pen options bar): a single square for New Layer, and two overlapping squares showing the area each operation keeps (union, back minus front, overlap, everything but the overlap, the merged outline), drawn on Lucide's 24 px grid and stroke | PhotoCraft contributors | Original work | MIT OR Apache-2.0 | | `assets/icons/path-op-{new-layer,combine,subtract,intersect,exclude,merge}.svg` | Path Operations glyphs (Pen options bar): a single square for New Layer, and two overlapping squares showing the area each operation keeps (union, back minus front, overlap, everything but the overlap, the merged outline), drawn on Lucide's 24 px grid and stroke | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
| `assets/icons/arrange-{tile-all-vertically,tile-all-horizontally,two-up-horizontal,two-up-vertical,three-up-horizontal,three-up-vertical,three-up-stacked,four-up,six-up,consolidate-all-to-tabs}.svg` | Window › Arrange layout glyphs: a window outline split into the panes each entry lays out (columns, rows, the n-up splits, and one window with a tab row for Consolidate All to Tabs), drawn on Lucide's 24 px grid and stroke | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
| `assets/icons/history-brush.svg` | History Brush tool glyph: Lucide `brush` plus counter-clockwise history rewind arrow | Lucide Icons and Contributors; arrow by PhotoCraft contributors | Derived from <https://github.com/lucide-icons/lucide> `icons/brush.svg` | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) | | `assets/icons/history-brush.svg` | History Brush tool glyph: Lucide `brush` plus counter-clockwise history rewind arrow | Lucide Icons and Contributors; arrow by PhotoCraft contributors | Derived from <https://github.com/lucide-icons/lucide> `icons/brush.svg` | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
| `assets/dict/en_US-scowl-50.txt.gz` | English word list for Check Spelling (SCOWL 2020.12.07, size 50, en_US; 72,403 words) | Kevin Atkinson and the SCOWL contributors | <http://wordlist.aspell.net/> | SCOWL license (permissive, keep the notice), [`assets/dict/LICENSE-SCOWL.txt`](assets/dict/LICENSE-SCOWL.txt), which also has the build recipe | | `assets/dict/en_US-scowl-50.txt.gz` | English word list for Check Spelling (SCOWL 2020.12.07, size 50, en_US; 72,403 words) | Kevin Atkinson and the SCOWL contributors | <http://wordlist.aspell.net/> | SCOWL license (permissive, keep the notice), [`assets/dict/LICENSE-SCOWL.txt`](assets/dict/LICENSE-SCOWL.txt), which also has the build recipe |
| `assets/app-icon/` (all files) | PhotoCraft app icon (nine-tailed kitsune) | The project owner (drawn in ArtCraft, vectorised) | Original work, see [`assets/app-icon/README.md`](assets/app-icon/README.md) | MIT OR Apache-2.0, [`assets/app-icon/LICENSE.txt`](assets/app-icon/LICENSE.txt) | | `assets/app-icon/` (all files) | PhotoCraft app icon (nine-tailed kitsune) | The project owner (drawn in ArtCraft, vectorised) | Original work, see [`assets/app-icon/README.md`](assets/app-icon/README.md) | MIT OR Apache-2.0, [`assets/app-icon/LICENSE.txt`](assets/app-icon/LICENSE.txt) |
@@ -0,0 +1,15 @@
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="4" width="18" height="16" rx="2" />
<path d="M3 9h18" />
<path d="M9 4v5" />
</svg>

After

Width:  |  Height:  |  Size: 306 B

+15
View File
@@ -0,0 +1,15 @@
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="4" width="18" height="16" rx="2" />
<path d="M12 4v16" />
<path d="M3 12h18" />
</svg>

After

Width:  |  Height:  |  Size: 309 B

+16
View File
@@ -0,0 +1,16 @@
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="4" width="18" height="16" rx="2" />
<path d="M9 4v16" />
<path d="M15 4v16" />
<path d="M3 12h18" />
</svg>

After

Width:  |  Height:  |  Size: 332 B

@@ -0,0 +1,15 @@
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="4" width="18" height="16" rx="2" />
<path d="M3 9.33h18" />
<path d="M3 14.67h18" />
</svg>

After

Width:  |  Height:  |  Size: 314 B

+15
View File
@@ -0,0 +1,15 @@
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="4" width="18" height="16" rx="2" />
<path d="M12 4v16" />
<path d="M12 12h9" />
</svg>

After

Width:  |  Height:  |  Size: 309 B

@@ -0,0 +1,15 @@
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="4" width="18" height="16" rx="2" />
<path d="M9 4v16" />
<path d="M15 4v16" />
</svg>

After

Width:  |  Height:  |  Size: 308 B

@@ -0,0 +1,16 @@
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="4" width="18" height="16" rx="2" />
<path d="M3 8h18" />
<path d="M3 12h18" />
<path d="M3 16h18" />
</svg>

After

Width:  |  Height:  |  Size: 332 B

@@ -0,0 +1,16 @@
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="4" width="18" height="16" rx="2" />
<path d="M7.5 4v16" />
<path d="M12 4v16" />
<path d="M16.5 4v16" />
</svg>

After

Width:  |  Height:  |  Size: 336 B

@@ -0,0 +1,14 @@
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="4" width="18" height="16" rx="2" />
<path d="M3 12h18" />
</svg>

After

Width:  |  Height:  |  Size: 285 B

+14
View File
@@ -0,0 +1,14 @@
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="3" y="4" width="18" height="16" rx="2" />
<path d="M12 4v16" />
</svg>

After

Width:  |  Height:  |  Size: 285 B

@@ -349,6 +349,9 @@ fn select_data_points(s: &mut Session, p: &Value) -> Result<Value> {
// Keep the column order. // Keep the column order.
list.sort_by_key(|k| COLUMNS.iter().position(|c| c.0 == k)); list.sort_by_key(|k| COLUMNS.iter().position(|c| c.0 == k));
} }
if next.selection.is_empty() && next.ruler.is_empty() && next.count.is_empty() {
return Err(bad(CMD, "select at least one data point"));
}
s.analysis.data_points = next; s.analysis.data_points = next;
Ok( Ok(
json!({"dataPoints": s.analysis.data_points, "available": {"selection": available("selection"), "ruler": available("ruler"), "count": available("count")}, "columns": COLUMNS.iter().map(|c| json!({"key": c.0, "name": c.1})).collect::<Vec<_>>()}), json!({"dataPoints": s.analysis.data_points, "available": {"selection": available("selection"), "ruler": available("ruler"), "count": available("count")}, "columns": COLUMNS.iter().map(|c| json!({"key": c.0, "name": c.1})).collect::<Vec<_>>()}),
@@ -1409,4 +1412,6 @@ mod analysis_straighten_enabled_tests;
#[path = "analysis_straighten_selection_tests.rs"] #[path = "analysis_straighten_selection_tests.rs"]
mod analysis_straighten_selection_tests; mod analysis_straighten_selection_tests;
#[cfg(test)] #[cfg(test)]
mod data_points_empty_set_tests;
#[cfg(test)]
mod tests; mod tests;
@@ -0,0 +1,17 @@
use crate::EngineError;
use serde_json::json;
#[test]
fn select_data_points_rejects_an_empty_result_without_changing_the_previous_set() {
const COMMAND: &str = "image.analysis.selectDataPoints";
let mut session = crate::session();
session.execute("file.new", json!({"width": 16, "height": 16})).unwrap();
let partial = json!({"selection": [], "ruler": ["length"], "count": []});
let result = session.execute(COMMAND, partial.clone()).unwrap();
assert_eq!(result["dataPoints"], partial);
for params in [json!({"selection": [], "ruler": [], "count": []}), json!({"ruler": {"length": false}})] {
assert!(matches!(session.execute(COMMAND, params.clone()), Err(EngineError::BadParams { .. })), "{params} would empty the set");
assert_eq!(session.execute(COMMAND, json!({})).unwrap()["dataPoints"], partial);
}
}
+13 -6
View File
@@ -628,13 +628,13 @@ fn is_empty_layer(l: &Layer) -> bool {
} }
} }
/// Layer › Ungroup Layers: replace the selected group with its children in place, the topmost /// Layer › Ungroup Layers: replace the selected group with its children in place, selecting
/// child becoming active. Ungrouping an empty group next to other layers simply removes it; /// every former direct child with the topmost one active (#17362). Ungrouping an empty group
/// when it is the only root layer the edit is refused, as `layer.delete` refuses to drop the /// next to other layers simply removes it; when it is the only root layer the edit is refused,
/// last layer (#11118). /// as `layer.delete` refuses to drop the last layer (#11118).
fn ungroup(s: &mut Session, p: &Value) -> Result<Value> { fn ungroup(s: &mut Session, p: &Value) -> Result<Value> {
let id = layer_param(s, p)?; let id = layer_param(s, p)?;
s.edit("Ungroup Layers", |doc, active| { let former = s.edit("Ungroup Layers", |doc, active| {
let path = doc.path_of(id).ok_or(EngineError::NoLayer(id))?; let path = doc.path_of(id).ok_or(EngineError::NoLayer(id))?;
let g = doc.layer(id).ok_or(EngineError::NoLayer(id))?; let g = doc.layer(id).ok_or(EngineError::NoLayer(id))?;
let LayerContent::Group(group) = &g.content else { let LayerContent::Group(group) = &g.content else {
@@ -651,12 +651,19 @@ fn ungroup(s: &mut Session, p: &Value) -> Result<Value> {
let sib = if parent.is_empty() { &mut doc.layers } else { doc.layer_at_mut(parent).and_then(Layer::children_mut).ok_or(EngineError::NoLayer(id))? }; let sib = if parent.is_empty() { &mut doc.layers } else { doc.layer_at_mut(parent).and_then(Layer::children_mut).ok_or(EngineError::NoLayer(id))? };
sib.remove(idx); sib.remove(idx);
let top = children.last().map(|l| l.id); let top = children.last().map(|l| l.id);
let ids: Vec<LayerId> = children.iter().map(|l| l.id).collect();
for (k, l) in children.into_iter().enumerate() { for (k, l) in children.into_iter().enumerate() {
sib.insert(idx + k, l); sib.insert(idx + k, l);
} }
*active = top.or_else(|| doc.top_layer()); *active = top.or_else(|| doc.top_layer());
Ok(()) Ok(ids)
})?; })?;
// The measured reference row: every former direct child is selected and the first (topmost)
// one is active; any other selection is replaced. An empty group leaves today's target
// (not measured).
if let Some(top) = former.last().copied() {
crate::layer_multi_cmds::reselect(s, former, Some(top));
}
Ok(Value::Null) Ok(Value::Null)
} }
+15 -3
View File
@@ -2,7 +2,9 @@
//! //!
//! A group's open/closed state is document data ([`photocraft_doc::Group::expanded`], the PSD //! A group's open/closed state is document data ([`photocraft_doc::Group::expanded`], the PSD
//! section divider's open/closed folder type, saved in `.pcraft` too) but, as in Photoshop, //! section divider's open/closed folder type, saved in `.pcraft` too) but, as in Photoshop,
//! toggling it is a view change: no history step, and a clean document stays clean. //! toggling it is a view change: no history step, and a clean document stays clean. The panel's
//! Collapse All Groups is the one exception: it adds a single `Collapse All Groups` history step
//! (#17363), so one undo reopens the groups that were open.
use std::sync::Arc; use std::sync::Arc;
@@ -44,7 +46,9 @@ fn set_all(layers: &mut [Layer], expanded: bool) -> usize {
/// `{"layer":id?,"expanded":bool?,"all":bool?}`: open or close a group (no `expanded`: toggle). /// `{"layer":id?,"expanded":bool?,"all":bool?}`: open or close a group (no `expanded`: toggle).
/// With `all`, every group in the document takes the new state (Photoshop's ⌥-click on a /// With `all`, every group in the document takes the new state (Photoshop's ⌥-click on a
/// disclosure triangle); without a layer, `all` toggles from "any group open". /// disclosure triangle); without a layer, `all` toggles from "any group open". Without a layer,
/// closing every group is the panel's Collapse All Groups: one `Collapse All Groups` history
/// step (#17363); the row-addressed form and a single toggle stay view changes.
fn set_expanded(s: &mut Session, p: &Value) -> Result<Value> { fn set_expanded(s: &mut Session, p: &Value) -> Result<Value> {
let want = opt_bool(p, "expanded")?; let want = opt_bool(p, "expanded")?;
let all = opt_bool(p, "all")?.unwrap_or(false); let all = opt_bool(p, "all")?.unwrap_or(false);
@@ -62,6 +66,14 @@ fn set_expanded(s: &mut Session, p: &Value) -> Result<Value> {
None => st.doc.walk().iter().any(|(_, _, l)| matches!(&l.content, LayerContent::Group(g) if g.expanded)), None => st.doc.walk().iter().any(|(_, _, l)| matches!(&l.content, LayerContent::Group(g) if g.expanded)),
}; };
let expanded = want.unwrap_or(!current); let expanded = want.unwrap_or(!current);
if all && layer.is_none() && !expanded && current {
// The panel's Collapse All Groups, unlike any other use of this command: one history
// step named like the menu entry, so one undo reopens the groups that were open.
// `current` here means "some group is open"; over an already-closed tree the command
// stays the no-op view change it is today and records no empty step.
let changed = s.edit("Collapse All Groups", |doc, _| Ok(set_all(&mut doc.layers, false)))?;
return Ok(json!({"expanded": expanded, "groups": changed}));
}
let st = s.active_mut().ok_or(EngineError::NoDocument)?; let st = s.active_mut().ok_or(EngineError::NoDocument)?;
// Copy-on-write: history snapshots keep their own state (layers share tiles, so this is cheap). // Copy-on-write: history snapshots keep their own state (layers share tiles, so this is cheap).
let doc = Arc::make_mut(st.doc_mut()); let doc = Arc::make_mut(st.doc_mut());
@@ -86,7 +98,7 @@ pub fn specs() -> Vec<CommandSpec> {
label: "Expand/Collapse Group", label: "Expand/Collapse Group",
menu: &[], menu: &[],
shortcut: None, shortcut: None,
params: r##"{"layer":id?,"expanded":bool?,"all":bool?} (no expanded: toggle; all: every group; not an undo step)"##, params: r##"{"layer":id?,"expanded":bool?,"all":bool?} (no expanded: toggle; all: every group; the layer-less close-all is the panel's Collapse All Groups, one undo step; a single or row-addressed toggle is not)"##,
enabled: has_group, enabled: has_group,
run: set_expanded, run: set_expanded,
journal: false, journal: false,
@@ -0,0 +1,95 @@
//! Collapse All Groups as one history step. The Layers panel's Collapse All Groups
//! (`layer.setExpanded` with `all: true, expanded: false` and no layer) closes every group and
//! must leave exactly one undoable step named `Collapse All Groups`; one undo reopens the groups
//! that were open. Opening or closing one group, and the layer-addressed `all` form a modifier
//! click on a triangle sends, stay view changes with no step, as does an all-collapse over a
//! tree that is already closed.
use photocraft_doc::{LayerContent, LayerId};
use photocraft_engine::Session;
use serde_json::json;
fn expanded(s: &Session, id: LayerId) -> bool {
matches!(&s.active().unwrap().doc.layer(id).unwrap().content, LayerContent::Group(g) if g.expanded)
}
/// Three groups nested three deep, every one open.
fn three_nested_open() -> (Session, LayerId, LayerId, LayerId) {
let mut s = Session::new();
s.execute("file.new", json!({"width": 32, "height": 32})).unwrap();
s.execute("layer.new.layer", json!({"name": "deep"})).unwrap();
let inner = LayerId(s.execute("layer.groupLayers", json!({"name": "inner"})).unwrap()["layer"].as_u64().unwrap());
let middle = LayerId(s.execute("layer.groupLayers", json!({"layer": inner.0, "name": "middle"})).unwrap()["layer"].as_u64().unwrap());
let outer = LayerId(s.execute("layer.groupLayers", json!({"layer": middle.0, "name": "outer"})).unwrap()["layer"].as_u64().unwrap());
// Group Layers creates collapsed groups; the tests start with every group open.
s.execute("layer.setExpanded", json!({"all": true, "expanded": true})).unwrap();
assert!(expanded(&s, inner) && expanded(&s, middle) && expanded(&s, outer), "setup: all three groups open");
(s, inner, middle, outer)
}
fn collapse_all(s: &mut Session) {
s.execute("layer.setExpanded", json!({"all": true, "expanded": false})).unwrap();
}
fn history_len(s: &Session) -> usize {
s.active().unwrap().history.entries().len()
}
#[test]
fn collapse_all_groups_adds_exactly_one_named_history_step() {
let (mut s, inner, middle, outer) = three_nested_open();
let before = history_len(&s);
collapse_all(&mut s);
assert_eq!(history_len(&s), before + 1, "Collapse All Groups gains exactly one step");
assert_eq!(s.active().unwrap().history.undo_label().unwrap(), "Collapse All Groups", "the step is named like the menu entry");
assert!(!expanded(&s, inner) && !expanded(&s, middle) && !expanded(&s, outer), "every group, nested included, is closed");
}
#[test]
fn one_undo_reopens_every_group_that_was_open() {
let (mut s, inner, middle, outer) = three_nested_open();
let before = history_len(&s);
collapse_all(&mut s);
assert!(s.undo(), "the step is undoable");
assert_eq!(history_len(&s), before, "undo leaves one step, the state before Collapse All Groups");
assert!(expanded(&s, inner) && expanded(&s, middle) && expanded(&s, outer), "one undo restores all three expanded states");
}
#[test]
fn collapsing_one_group_by_id_still_adds_no_step() {
let (mut s, inner, middle, outer) = three_nested_open();
let before = history_len(&s);
s.execute("layer.setExpanded", json!({"layer": inner.0, "expanded": false})).unwrap();
assert_eq!(history_len(&s), before, "a single group's arrow toggle stays no step");
assert!(!expanded(&s, inner) && expanded(&s, middle) && expanded(&s, outer), "only that group closed");
}
#[test]
fn a_modifier_click_collapse_all_on_one_row_adds_no_step() {
// The panel's modifier-click on a disclosure triangle addresses that row with `all`.
let (mut s, inner, middle, outer) = three_nested_open();
let before = history_len(&s);
s.execute("layer.setExpanded", json!({"layer": outer.0, "expanded": false, "all": true})).unwrap();
assert_eq!(history_len(&s), before, "the row-addressed all form stays a view change");
assert!(!expanded(&s, inner) && !expanded(&s, middle) && !expanded(&s, outer), "it still closes every group");
}
#[test]
fn expanding_all_groups_adds_no_step() {
let (mut s, _, _, _) = three_nested_open();
collapse_all(&mut s);
let before = history_len(&s);
s.execute("layer.setExpanded", json!({"all": true, "expanded": true})).unwrap();
assert_eq!(history_len(&s), before, "Expand All keeps today's no-step view change (not measured)");
}
#[test]
fn collapse_all_on_an_already_collapsed_tree_adds_no_step() {
let (mut s, inner, middle, outer) = three_nested_open();
collapse_all(&mut s);
let before = history_len(&s);
let back = s.execute("layer.setExpanded", json!({"all": true, "expanded": false})).unwrap();
assert_eq!(history_len(&s), before, "nothing to close: no empty journal entry, as today");
assert_eq!(back["groups"], 3, "the reply keeps today's count of the groups it touched");
assert!(!expanded(&s, inner) && !expanded(&s, middle) && !expanded(&s, outer), "the tree stays closed");
}
+2
View File
@@ -47,6 +47,7 @@ mod canvas_artboard_crop;
mod clipping_semantics; mod clipping_semantics;
mod close_document; mod close_document;
mod cmyk_flatten_profile; mod cmyk_flatten_profile;
mod collapse_all_groups_history;
mod command_lookup; mod command_lookup;
mod content_aware_fill_atn; mod content_aware_fill_atn;
mod content_aware_fill_options; mod content_aware_fill_options;
@@ -194,6 +195,7 @@ mod transform_budget_unclamped;
mod type_format_targets; mod type_format_targets;
mod type_postscript_font; mod type_postscript_font;
mod undo_keeps_active_layer; mod undo_keeps_active_layer;
mod ungroup_selection;
mod unicode_colors; mod unicode_colors;
mod unsupported_smart_filters; mod unsupported_smart_filters;
mod vector_in_actions_record; mod vector_in_actions_record;
+132
View File
@@ -0,0 +1,132 @@
//! #17362 (epic #16768): Layer › Ungroup Layers selects every former direct child, with the
//! topmost one active. The measured reference rows cover the plain group, ungrouping while
//! another layer is selected (the selection is replaced), a group holding a group (one level
//! removed, the inner group moves up), and Undo restoring the group and the previous selection.
//! The empty-group case is not measured and keeps today's behaviour, pinned below.
use photocraft_doc::LayerId;
use photocraft_engine::Session;
use serde_json::json;
fn new_layer(s: &mut Session, name: &str) -> LayerId {
LayerId(s.execute("layer.new.layer", json!({ "name": name })).unwrap()["layer"].as_u64().unwrap())
}
fn group_layers(s: &mut Session) -> LayerId {
LayerId(s.execute("layer.groupLayers", json!({})).unwrap()["layer"].as_u64().unwrap())
}
fn target(s: &Session) -> (Option<LayerId>, Vec<LayerId>) {
let st = s.active().unwrap();
(st.active_layer, st.selected_layers().to_vec())
}
fn children_of(s: &Session, id: LayerId) -> Vec<LayerId> {
s.active().unwrap().doc.layer(id).and_then(|l| l.children().map(|ch| ch.iter().map(|c| c.id).collect())).unwrap_or_default()
}
/// Set equality, order-insensitive: the ticket row states which layers are selected, not an order.
fn selection_is(sel: &[LayerId], want: &[LayerId]) -> bool {
want.iter().all(|id| sel.contains(id)) && sel.len() == want.len()
}
fn session() -> Session {
let mut s = Session::new();
s.execute("file.new", json!({ "width": 16, "height": 16 })).unwrap();
s
}
#[test]
fn ungroup_selects_every_former_child_with_topmost_active() {
// "After Ungroup Layers every former direct child is selected; the topmost is active."
let mut s = session();
let a = new_layer(&mut s, "A");
let b = new_layer(&mut s, "B");
let c = new_layer(&mut s, "C");
s.execute("layer.select", json!({ "layers": [a.0, b.0, c.0] })).unwrap();
let group = group_layers(&mut s);
s.execute("layer.ungroupLayers", json!({})).unwrap();
let (active, sel) = target(&s);
assert_eq!(active, Some(c), "the topmost former child is the active layer");
assert!(selection_is(&sel, &[a, b, c]), "every former direct child is selected, got {sel:?}");
let st = s.active().unwrap();
assert!(st.doc.layer(group).is_none(), "the group itself is gone");
assert!(!sel.contains(&group), "the removed group is not part of the selection");
}
#[test]
fn ungroup_replaces_another_selection_with_the_former_children() {
// The measured row selects every former child, so a layer that was selected next to the
// group drops out of the selection.
let mut s = session();
let r = new_layer(&mut s, "R");
let u = new_layer(&mut s, "U");
let v = new_layer(&mut s, "V");
s.execute("layer.select", json!({ "layers": [u.0, v.0] })).unwrap();
let group = group_layers(&mut s);
// ⇧-click in the panel: R joins the group in the selection, and the group stays active.
s.execute("layer.select", json!({ "layers": [r.0, group.0] })).unwrap();
s.execute("layer.ungroupLayers", json!({})).unwrap();
let (active, sel) = target(&s);
assert_eq!(active, Some(v), "the topmost former child is the active layer");
assert!(selection_is(&sel, &[u, v]), "the selection is exactly the former children, got {sel:?}");
assert!(!sel.contains(&r), "the layer outside the group is no longer selected");
}
#[test]
fn ungroup_a_group_holding_a_group_selects_former_children_one_level_up() {
// "Ungroup Layers on a group that holds a group removes one level: the nested group moves
// up. The former children are all selected; the first (topmost) one is active."
let mut s = session();
let n1 = new_layer(&mut s, "N1");
let n2 = new_layer(&mut s, "N2");
let n3 = new_layer(&mut s, "N3");
s.execute("layer.select", json!({ "layers": [n2.0, n3.0] })).unwrap();
let inner = group_layers(&mut s);
s.execute("layer.select", json!({ "layers": [n1.0, inner.0] })).unwrap();
let outer = group_layers(&mut s);
s.execute("layer.ungroupLayers", json!({})).unwrap();
let (active, sel) = target(&s);
assert_eq!(active, Some(inner), "the topmost former child (the inner group) is the active layer");
assert!(selection_is(&sel, &[n1, inner]), "the former children — the inner group included — are all selected, got {sel:?}");
let st = s.active().unwrap();
assert!(st.doc.layer(outer).is_none(), "the outer group is gone: one level removed");
assert_eq!(children_of(&s, inner), vec![n2, n3], "the inner group keeps its own children: they were not selected");
// The inner group lands where the outer one was, above N1.
let outer_was_at = 1; // [Background, outer] with outer at root index 1 before ungroup
let doc = &st.doc;
assert_eq!(doc.path_of(inner).and_then(|p| p.first().copied()), Some(outer_was_at + 1), "the inner group sits at the outer group's top slot");
assert_eq!(doc.path_of(n1).and_then(|p| p.first().copied()), Some(outer_was_at), "N1 sits at the outer group's old bottom slot");
}
#[test]
fn undo_after_ungroup_restores_the_group_and_the_previous_selection() {
// "Undo restores the group and the previous selection."
let mut s = session();
let a = new_layer(&mut s, "A");
let b = new_layer(&mut s, "B");
s.execute("layer.select", json!({ "layers": [a.0, b.0] })).unwrap();
let group = group_layers(&mut s);
s.execute("layer.ungroupLayers", json!({})).unwrap();
assert!(s.undo(), "Ungroup Layers is one history step");
let (active, sel) = target(&s);
assert_eq!(active, Some(group), "undo makes the restored group active");
assert!(selection_is(&sel, &[group]), "undo restores the previous selection, got {sel:?}");
assert_eq!(children_of(&s, group), vec![a, b], "the group and its children come back");
}
#[test]
fn ungrouping_an_empty_group_next_to_other_layers_keeps_todays_target() {
// Not measured in the ticket: an empty group simply disappears. Today the active layer
// falls back to the document's top layer and the selection collapses to it; pinned here.
let mut s = session();
let l = new_layer(&mut s, "L");
let empty = LayerId(s.execute("layer.new.group", json!({ "name": "Empty" })).unwrap()["layer"].as_u64().unwrap());
s.execute("layer.select", json!({ "layers": [empty.0] })).unwrap();
s.execute("layer.ungroupLayers", json!({})).unwrap();
let (active, sel) = target(&s);
let st = s.active().unwrap();
assert!(st.doc.layer(empty).is_none(), "the empty group is gone");
assert_eq!(active, Some(l), "the top surviving layer stays active, as today");
assert!(selection_is(&sel, &[l]), "the selection collapses to the active layer, as today, got {sel:?}");
}
+4
View File
@@ -237,6 +237,10 @@ mod pattern_drag_tests;
#[cfg(test)] #[cfg(test)]
mod tabs_tests; mod tabs_tests;
#[cfg(test)]
#[path = "screen_mode_floating_documents_tests.rs"]
mod screen_mode_floating_documents_tests;
#[cfg(test)] #[cfg(test)]
mod canvas_settle_trials; mod canvas_settle_trials;
+16 -4
View File
@@ -154,9 +154,11 @@ pub(crate) fn publish_shown(app: &PhotocraftApp) {
let docs = app.session.documents(); let docs = app.session.documents();
let mut shown: Vec<usize> = match arranged_panes(app, app.last_canvas_rect) { let mut shown: Vec<usize> = match arranged_panes(app, app.last_canvas_rect) {
Some(cells) => cells.into_iter().map(|(d, _)| d).collect(), Some(cells) => cells.into_iter().map(|(d, _)| d).collect(),
None => main_canvas_document(app).into_iter().collect(), None => single_canvas_document(app).into_iter().collect(),
}; };
shown.extend(app.ui.document_windows.floating.iter().filter_map(|(group, _)| group.shown).filter_map(|id| document_index(app, id))); if !super::document_windows::full_screen_shows_active(app) {
shown.extend(app.ui.document_windows.floating.iter().filter_map(|(group, _)| group.shown).filter_map(|id| document_index(app, id)));
}
let mut shown: Vec<(u64, u64)> = shown.into_iter().filter_map(|d| docs.get(d)).map(|st| (st.doc.id.0, gpu.canvas_bytes(&st.doc))).collect(); let mut shown: Vec<(u64, u64)> = shown.into_iter().filter_map(|d| docs.get(d)).map(|st| (st.doc.id.0, gpu.canvas_bytes(&st.doc))).collect();
shown.sort_unstable(); shown.sort_unstable();
shown.dedup(); shown.dedup();
@@ -201,9 +203,19 @@ fn documents(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
} }
} }
/// The document the single canvas of the main window shows: the active document while the full-screen modes show it
/// in place of the floating windows (#16846), else the active docked document or the first docked one.
pub(super) fn single_canvas_document(app: &PhotocraftApp) -> Option<usize> {
if super::document_windows::full_screen_shows_active(app) {
return app.session.active_index();
}
main_canvas_document(app)
}
/// The document pane: an opening file's progress, the arranged panes, or the single canvas. With no docked document /// The document pane: an opening file's progress, the arranged panes, or the single canvas. With no docked document
/// it shows nothing over the surround: a floating document belongs to its own window, and drawing it here too would /// it shows nothing over the surround: a floating document belongs to its own window, and drawing it here too would
/// show the same page twice. /// show the same page twice. The full-screen modes are the exception: with every document floating they show the
/// active one here, without its window ([`single_canvas_document`]).
fn document(app: &mut PhotocraftApp, ui: &mut egui::Ui, rect: Rect) { fn document(app: &mut PhotocraftApp, ui: &mut egui::Ui, rect: Rect) {
// A tab click switches documents before any canvas is drawn this pass. // A tab click switches documents before any canvas is drawn this pass.
publish_shown(app); publish_shown(app);
@@ -213,7 +225,7 @@ fn document(app: &mut PhotocraftApp, ui: &mut egui::Ui, rect: Rect) {
return; return;
} }
let Some(active) = app.session.active_index() else { return }; let Some(active) = app.session.active_index() else { return };
let Some(idx) = main_canvas_document(app) else { return }; let Some(idx) = single_canvas_document(app) else { return };
// The panel's document area (`CanvasPanelOutput::document`). // The panel's document area (`CanvasPanelOutput::document`).
app.last_canvas_rect = rect; app.last_canvas_rect = rect;
app.last_canvas_layer = ui.layer_id(); app.last_canvas_layer = ui.layer_id();
@@ -68,6 +68,10 @@ impl CanvasHost {
/// the dialogs' canvas picks work on: the floating document window that draws it, else the main document area. /// the dialogs' canvas picks work on: the floating document window that draws it, else the main document area.
/// A New Window for Document keeps a view of its own, so it is never the document's own canvas. /// A New Window for Document keeps a view of its own, so it is never the document's own canvas.
pub(crate) fn primary(app: &PhotocraftApp, idx: usize) -> Self { pub(crate) fn primary(app: &PhotocraftApp, idx: usize) -> Self {
// The full-screen modes show a floating document in the main document area, its window put away (#16846).
if super::document_windows::full_screen_shows_active(app) {
return Self::main(idx);
}
let window = app let window = app
.ui .ui
.document_windows .document_windows
+17 -2
View File
@@ -8,7 +8,7 @@ use craft::host::target::WindowState;
use craft::ui::canvas::ToolHost; use craft::ui::canvas::ToolHost;
use craft::ui::contract::{ShowContainer as _, SizeLimits}; use craft::ui::contract::{ShowContainer as _, SizeLimits};
use craft::ui::runtime::windows::WindowHost; use craft::ui::runtime::windows::WindowHost;
use craft::ui::shell::{DocumentWindow, Title, TitleBar, Wrapped}; use craft::ui::shell::{DocumentWindow, ScreenMode, Title, TitleBar, Wrapped};
use craft::window::policy::Frame; use craft::window::policy::Frame;
use egui::{Rect, Vec2, vec2}; use egui::{Rect, Vec2, vec2};
use photocraft_doc::DocId; use photocraft_doc::DocId;
@@ -58,9 +58,24 @@ pub(crate) fn sync_documents(app: &mut PhotocraftApp, ids: &[DocId]) {
} }
} }
/// Whether the main window's document area shows the active document in place of the floating windows: in Full
/// Screen Mode With Menu Bar and Full Screen Mode while every open document floats (#16846). The windows are not
/// shown then, and they keep their places and sizes, so Standard Screen Mode floats them again where they were. A mix
/// of docked and floating documents keeps the windows.
pub(crate) fn full_screen_shows_active(app: &PhotocraftApp) -> bool {
app.ui.view.screen_mode != ScreenMode::Standard
&& !app.ui.document_windows.floating.is_empty()
&& app.session.active().is_some()
&& super::tabs::docked_document_indices(app).is_empty()
}
/// The floating document windows, each in its own OS window (or on the fallback layer where there is /// The floating document windows, each in its own OS window (or on the fallback layer where there is
/// none). `ui` is the frame's root `Ui`: `DocumentWindow` is a container shown in a parent. /// none). `ui` is the frame's root `Ui`: `DocumentWindow` is a container shown in a parent. None shows while the
/// document area shows the active document full screen ([`full_screen_shows_active`]).
pub fn extra_windows(app: &mut PhotocraftApp, ui: &mut egui::Ui) { pub fn extra_windows(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
if full_screen_shows_active(app) {
return;
}
let windows: Vec<(u64, Rect)> = app.ui.document_windows.floating.iter().map(|(g, rect)| (g.id, *rect)).collect(); let windows: Vec<(u64, Rect)> = app.ui.document_windows.floating.iter().map(|(g, rect)| (g.id, *rect)).collect();
let mut closed = Vec::new(); let mut closed = Vec::new();
let mut docked = Vec::new(); let mut docked = Vec::new();
+10
View File
@@ -8,6 +8,16 @@ pub static PHOTOCRAFT_ICONS: AppIcons = AppIcons::new("photocraft", Some(2.0), I
/// Every icon of the set: name and SVG document. /// Every icon of the set: name and SVG document.
pub static ICONS: &[(&str, &[u8])] = &[ pub static ICONS: &[(&str, &[u8])] = &[
("arrange-consolidate-all-to-tabs", include_bytes!("../../../assets/icons/arrange-consolidate-all-to-tabs.svg")),
("arrange-four-up", include_bytes!("../../../assets/icons/arrange-four-up.svg")),
("arrange-six-up", include_bytes!("../../../assets/icons/arrange-six-up.svg")),
("arrange-three-up-horizontal", include_bytes!("../../../assets/icons/arrange-three-up-horizontal.svg")),
("arrange-three-up-stacked", include_bytes!("../../../assets/icons/arrange-three-up-stacked.svg")),
("arrange-three-up-vertical", include_bytes!("../../../assets/icons/arrange-three-up-vertical.svg")),
("arrange-tile-all-horizontally", include_bytes!("../../../assets/icons/arrange-tile-all-horizontally.svg")),
("arrange-tile-all-vertically", include_bytes!("../../../assets/icons/arrange-tile-all-vertically.svg")),
("arrange-two-up-horizontal", include_bytes!("../../../assets/icons/arrange-two-up-horizontal.svg")),
("arrange-two-up-vertical", include_bytes!("../../../assets/icons/arrange-two-up-vertical.svg")),
("arrow-left-right", include_bytes!("../../../assets/icons/arrow-left-right.svg")), ("arrow-left-right", include_bytes!("../../../assets/icons/arrow-left-right.svg")),
("circle-dashed", include_bytes!("../../../assets/icons/circle-dashed.svg")), ("circle-dashed", include_bytes!("../../../assets/icons/circle-dashed.svg")),
("ellipsis", include_bytes!("../../../assets/icons/ellipsis.svg")), ("ellipsis", include_bytes!("../../../assets/icons/ellipsis.svg")),
@@ -346,6 +346,12 @@ pub(crate) fn command_rows(app: &PhotocraftApp) -> Vec<CommandDef> {
if let Some(&at) = index.get(crate::panels::QUICK_MASK) { if let Some(&at) = index.get(crate::panels::QUICK_MASK) {
rows[at].icon = Some("square-dashed".into()); rows[at].icon = Some("square-dashed".into());
} }
// Window › Arrange's layout entries show their layout (#16889); the menu rows draw their command's icon.
for &(id, icon) in crate::menu_catalog::ARRANGE_ICONS {
if let Some(&at) = index.get(id) {
rows[at].icon = Some(icon.into());
}
}
// Smart Objects › Reveal in Finder names this platform's file manager, in the list as in the menu. // Smart Objects › Reveal in Finder names this platform's file manager, in the list as in the menu.
if let Some(&at) = index.get("layer.smartObjects.revealInFinder") { if let Some(&at) = index.get("layer.smartObjects.revealInFinder") {
rows[at].label = crate::menus::reveal_label().into(); rows[at].label = crate::menus::reveal_label().into();
+16
View File
@@ -810,3 +810,19 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[
(&["Window"], "Tools", None, "window.panel.tools"), (&["Window"], "Tools", None, "window.panel.tools"),
(&["Window"], "Contextual Task Bar", None, "window.panel.contextualTaskBar"), (&["Window"], "Contextual Task Bar", None, "window.panel.contextualTaskBar"),
]; ];
/// The layout icons of the first ten Window › Arrange entries, by command id: each draws the panes its entry lays out
/// (columns, rows, the n-up splits, one tabbed window). Original artwork in `assets/icons/arrange-*.svg`. The other
/// Arrange entries have none, as in the reference application (#16889).
pub const ARRANGE_ICONS: &[(&str, &str)] = &[
("window.arrange.tileAllVertically", "arrange-tile-all-vertically"),
("window.arrange.tileAllHorizontally", "arrange-tile-all-horizontally"),
("window.arrange.twoUpHorizontal", "arrange-two-up-horizontal"),
("window.arrange.twoUpVertical", "arrange-two-up-vertical"),
("window.arrange.threeUpHorizontal", "arrange-three-up-horizontal"),
("window.arrange.threeUpVertical", "arrange-three-up-vertical"),
("window.arrange.threeUpStacked", "arrange-three-up-stacked"),
("window.arrange.fourUp", "arrange-four-up"),
("window.arrange.sixUp", "arrange-six-up"),
("window.arrange.consolidateAllToTabs", "arrange-consolidate-all-to-tabs"),
];
+3
View File
@@ -121,6 +121,9 @@ mod export_submenu_separator_tests;
#[cfg(test)] #[cfg(test)]
mod arrange_menu_order_tests; mod arrange_menu_order_tests;
#[cfg(test)]
mod arrange_menu_icons_tests;
#[cfg(test)] #[cfg(test)]
mod bar_cursor_tests; mod bar_cursor_tests;
@@ -0,0 +1,114 @@
//! #16889: the first ten Window › Arrange entries (Tile All Vertically to Consolidate All to Tabs) show a layout icon;
//! the other nine show none. The menu rows draw the icon their command resolves with, so these tests read what the
//! running app resolves for each entry.
use craft::behavior::IconId;
use craft::keymap::CommandRef;
use craft::ui::primitives::has_icon;
use egui::vec2;
use egui_kittest::Harness;
use serde_json::json;
use crate::PhotocraftApp;
use crate::menu_catalog::{ARRANGE_ICONS, CATALOG};
use crate::theme::AppTheme;
/// The ten entries with a layout icon, in menu order, and the icon of each.
const WITH_ICON: [(&str, &str); 10] = [
("window.arrange.tileAllVertically", "arrange-tile-all-vertically"),
("window.arrange.tileAllHorizontally", "arrange-tile-all-horizontally"),
("window.arrange.twoUpHorizontal", "arrange-two-up-horizontal"),
("window.arrange.twoUpVertical", "arrange-two-up-vertical"),
("window.arrange.threeUpHorizontal", "arrange-three-up-horizontal"),
("window.arrange.threeUpVertical", "arrange-three-up-vertical"),
("window.arrange.threeUpStacked", "arrange-three-up-stacked"),
("window.arrange.fourUp", "arrange-four-up"),
("window.arrange.sixUp", "arrange-six-up"),
("window.arrange.consolidateAllToTabs", "arrange-consolidate-all-to-tabs"),
];
/// The nine entries without one.
const WITHOUT_ICON: [&str; 9] = [
"window.arrange.cascade",
"window.arrange.tile",
"window.arrange.floatInWindow",
"window.arrange.floatAllInWindows",
"window.arrange.matchZoom",
"window.arrange.matchLocation",
"window.arrange.matchRotation",
"window.arrange.matchAll",
"window.arrange.newWindowForDocument",
];
/// The running app with `documents` documents open.
fn app(documents: usize) -> Harness<'static, Box<PhotocraftApp>> {
let mut h = Harness::builder().with_size(vec2(1000.0, 700.0)).with_max_steps(64).build_eframe(move |cc| {
let theme = AppTheme::pro();
PhotocraftApp::setup_context(&cc.egui_ctx, theme.clone());
let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), crate::Services::default());
app.save_theme(&theme).unwrap();
for n in 0..documents {
app.run("file.new", json!({"width": 200, "height": 100, "name": format!("W{n}")})).unwrap();
}
app
});
h.run_steps(4);
h
}
/// The icon the running app resolves command `id` with: the one its menu row draws.
fn icon_of(h: &Harness<'_, Box<PhotocraftApp>>, id: &str) -> Option<String> {
craft::ui::runtime::commands::resolve(&h.ctx, CommandRef::new(id)).icon.as_ref().map(ToString::to_string)
}
#[test]
fn the_ten_layout_entries_resolve_with_their_layout_icon() {
for documents in [0, 1, 6] {
let h = app(documents);
for (id, icon) in WITH_ICON {
assert_eq!(icon_of(&h, id).as_deref(), Some(icon), "{documents} documents: {id}");
}
}
}
#[test]
fn the_other_nine_entries_have_no_icon() {
let h = app(2);
for id in WITHOUT_ICON {
assert_eq!(icon_of(&h, id), None, "{id} shows no icon");
}
}
/// The two lists cover every Window › Arrange entry of the catalog, so a new entry has to pick a side here.
#[test]
fn every_arrange_entry_is_listed_once() {
let catalog: Vec<&str> = CATALOG.iter().filter(|(path, label, _, _)| *path == ["Window", "Arrange"] && *label != "---").map(|row| row.3).collect();
let mut listed: Vec<&str> = WITH_ICON.iter().map(|(id, _)| *id).chain(WITHOUT_ICON).collect();
let mut sorted = catalog.clone();
sorted.sort_unstable();
listed.sort_unstable();
assert_eq!(listed, sorted);
assert_eq!(ARRANGE_ICONS, &WITH_ICON[..], "the icon table holds the ten entries in menu order");
assert_eq!(&catalog[..10], &WITH_ICON.map(|(id, _)| id)[..], "and they are the menu's first ten entries");
}
/// Every icon is in PhotoCraft's icon set, so the row paints a glyph rather than nothing.
#[test]
fn every_layout_icon_is_registered() {
crate::icons::register();
for (_, icon) in WITH_ICON {
assert!(has_icon(&IconId::new(icon)), "{icon} is registered");
}
}
/// The icons are files, so each one is listed in ATTRIBUTION.md as original work.
#[test]
fn the_icon_files_are_attributed() {
let attribution = include_str!("../../../../ATTRIBUTION.md");
let row = attribution.lines().find(|line| line.contains("assets/icons/arrange-")).expect("ATTRIBUTION.md lists the arrange icons");
assert!(row.contains("Original work"), "{row}");
for (_, icon) in WITH_ICON {
let name = icon.trim_start_matches("arrange-");
assert!(row.contains(name), "the row names {icon}: {row}");
}
}
@@ -0,0 +1,152 @@
//! #16846: with every document in a floating window, Full Screen Mode With Menu Bar and Full Screen Mode show only the
//! active document, without its window, in the main window's document area. Ctrl+Tab shows the next document there,
//! and Standard Screen Mode floats every window again at its old place and size, the last active document still
//! active. The measurement had two documents floating, a big one and a small active one.
use craft::ui::canvas::ToolHost;
use craft::ui::shell::ScreenMode;
use egui::Rect;
use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable};
use serde_json::json;
use super::document_area::single_canvas_document;
use super::document_display::CanvasHost;
use super::document_windows::full_screen_shows_active;
use super::testing;
use crate::PhotocraftApp;
type AppHarness = Harness<'static, (Box<PhotocraftApp>, bool)>;
/// The measured start: a 1200 x 800 document and a 400 x 300 one, the small one active, each floated into its own
/// window by Window › Arrange › Float All in Windows; then the document area and the floating windows drawn in one
/// window (the windows on the fallback layer, where they have no OS window of their own).
fn floating_pair() -> AppHarness {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({"width": 1200, "height": 800, "name": "big"})).unwrap();
app.run("file.new", json!({"width": 400, "height": 300, "name": "small"})).unwrap();
app.sync_views();
let ctx = app.ctx().clone();
crate::menus::invoke(&mut app, &ctx, "window.arrange.floatAllInWindows", json!({})).expect("both documents float");
let mut h = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_context(ctx).build_ui_state(
|ui, (app, ready): &mut (Box<PhotocraftApp>, bool)| {
if *ready {
egui::CentralPanel::default().frame(egui::Frame::NONE).show(ui, |ui| testing::document_area(app, ui));
crate::canvas::extra_windows(app, ui);
}
},
(app, false),
);
PhotocraftApp::setup_context(&h.ctx, crate::theme::AppTheme::pro());
h.state_mut().1 = true;
h.run_steps(3);
h
}
fn app(h: &AppHarness) -> &PhotocraftApp {
&h.state().0
}
fn set_mode(h: &mut AppHarness, mode: ScreenMode) {
h.state_mut().0.ui.view.screen_mode = mode;
h.run_steps(3);
}
/// The titles of the floating windows drawn this pass: each window, a group on the fallback layer, is named
/// "<document> — window <id>".
fn windows_shown(h: &AppHarness) -> Vec<String> {
h.query_all_by_role(egui::accesskit::Role::Group).filter_map(|n| n.accesskit_node().label()).filter(|label| label.contains("— window")).collect()
}
fn index_of(app: &PhotocraftApp, name: &str) -> usize {
app.session.documents().iter().position(|st| st.doc.name == name).expect("the document is open")
}
/// The rect the main area's canvas of document `idx` showed in its last pass, `None` before its first.
fn main_canvas_rect(app: &PhotocraftApp, idx: usize) -> Option<Rect> {
ToolHost::shown_space(app.ctx(), CanvasHost::main(idx).canvas_id()).map(|space| space.view.rect)
}
#[test]
fn standard_screen_mode_keeps_both_windows_and_no_document_in_the_main_area() {
let h = floating_pair();
let app = app(&h);
assert_eq!(app.ui.view.screen_mode, ScreenMode::Standard);
assert!(!full_screen_shows_active(app), "Standard Screen Mode leaves the floating windows as they are");
assert_eq!(windows_shown(&h).len(), 2, "both floating windows show: {:?}", windows_shown(&h));
assert_eq!(single_canvas_document(app), None, "the main area shows no document of its own");
assert!(app.drop_canvas_rect.is_none(), "so no canvas drew there");
}
#[test]
fn the_full_screen_modes_show_only_the_active_document_without_its_window() {
for mode in [ScreenMode::FullScreenWithMenuBar, ScreenMode::FullScreen] {
let mut h = floating_pair();
let small = index_of(app(&h), "small");
assert_eq!(app(&h).session.active_index(), Some(small), "the small document is active");
set_mode(&mut h, mode);
let app = app(&h);
assert!(full_screen_shows_active(app), "{mode:?}");
assert_eq!(windows_shown(&h), Vec::<String>::new(), "{mode:?}: no floating window shows, framed or not");
assert_eq!(single_canvas_document(app), Some(small), "{mode:?}: the main area shows the active document");
let area = app.drop_canvas_rect.expect("a canvas drew in the main area");
assert_eq!(main_canvas_rect(app, small), Some(area), "{mode:?}: the active document's canvas takes the whole document area");
assert_eq!(CanvasHost::primary(app, small), CanvasHost::main(small), "{mode:?}: the tools and dialogs work on that canvas");
let big = index_of(app, "big");
assert_eq!(main_canvas_rect(app, big), None, "{mode:?}: the other document is not drawn");
}
}
#[test]
fn ctrl_tab_in_a_full_screen_mode_shows_the_next_document_in_the_same_place() {
for mode in [ScreenMode::FullScreenWithMenuBar, ScreenMode::FullScreen] {
let mut h = floating_pair();
set_mode(&mut h, mode);
let area = app(&h).drop_canvas_rect.expect("the active document shows");
// Ctrl+Tab runs document.activate one document on.
h.state_mut().0.run("document.activate", json!({"offset": 1})).expect("the next document activates");
h.run_steps(3);
let app = app(&h);
let big = index_of(app, "big");
assert_eq!(app.session.active_index(), Some(big), "{mode:?}: Ctrl+Tab wrapped to the big document");
assert_eq!(single_canvas_document(app), Some(big), "{mode:?}: the main area now shows it");
assert_eq!(main_canvas_rect(app, big), Some(area), "{mode:?}: in the place the other one had");
assert_eq!(windows_shown(&h), Vec::<String>::new(), "{mode:?}: still no floating window");
}
}
#[test]
fn standard_screen_mode_floats_every_window_again_where_it_was() {
let mut h = floating_pair();
let before: Vec<(u64, Rect)> = app(&h).ui.document_windows.floating.iter().map(|(g, rect)| (g.id, *rect)).collect();
assert_eq!(before.len(), 2);
set_mode(&mut h, ScreenMode::FullScreenWithMenuBar);
set_mode(&mut h, ScreenMode::FullScreen);
h.state_mut().0.run("document.activate", json!({"offset": 1})).expect("the next document activates");
h.run_steps(3);
let last_active = app(&h).session.active_index();
set_mode(&mut h, ScreenMode::Standard);
let app = app(&h);
let after: Vec<(u64, Rect)> = app.ui.document_windows.floating.iter().map(|(g, rect)| (g.id, *rect)).collect();
assert_eq!(after, before, "every window is back at its old place and size");
assert_eq!(windows_shown(&h).len(), 2, "both windows float again: {:?}", windows_shown(&h));
assert_eq!(app.session.active_index(), last_active, "the document active last stays active");
assert_eq!(single_canvas_document(app), None, "the main area gives the document back to its window");
}
/// Not measured: a mix of docked and floating documents keeps today's behaviour, the floating window over the full
/// screen and the docked document in the main area.
#[test]
fn a_mix_of_docked_and_floating_documents_keeps_its_windows() {
let mut h = floating_pair();
let big = index_of(app(&h), "big");
let big_id = app(&h).session.documents()[big].doc.id;
let window = app(&h).ui.document_windows.floating.iter().find(|(g, _)| g.documents.contains(&big_id)).map(|(g, _)| g.id).expect("big floats");
// Docking the big document back: its window closes and it joins the tabs.
h.state_mut().0.ui.document_windows.close_window(window);
h.run_steps(2);
set_mode(&mut h, ScreenMode::FullScreen);
let app = app(&h);
assert!(!full_screen_shows_active(app), "a docked document keeps the full-screen modes as they were");
assert_eq!(windows_shown(&h).len(), 1, "the floating window still shows: {:?}", windows_shown(&h));
}
@@ -5,16 +5,17 @@ use egui::accesskit::Role;
use egui_kittest::Harness; use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable}; use egui_kittest::kittest::{NodeT, Queryable};
use photocraft_engine::analysis_cmds; use photocraft_engine::analysis_cmds;
use serde_json::json; use serde_json::{Value, json};
use super::sources; use super::sources;
use crate::PhotocraftApp; use crate::PhotocraftApp;
type H = Harness<'static, Box<PhotocraftApp>>; type H = Harness<'static, Box<PhotocraftApp>>;
fn open_dialog() -> H { fn open_dialog(data_points: Value) -> H {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({"width": 64, "height": 64})).unwrap(); app.run("file.new", json!({"width": 64, "height": 64})).unwrap();
app.run("image.analysis.selectDataPoints", data_points).unwrap();
let mut h = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_max_steps(64).with_context(app.ctx().clone()).build_ui_state( let mut h = Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_max_steps(64).with_context(app.ctx().clone()).build_ui_state(
|ui, app: &mut Box<PhotocraftApp>| { |ui, app: &mut Box<PhotocraftApp>| {
if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
@@ -49,7 +50,7 @@ fn rect(r: egui::accesskit::Rect) -> egui::Rect {
#[test] #[test]
fn every_check_box_draws_its_data_point_name_and_each_column_its_title_above() { fn every_check_box_draws_its_data_point_name_and_each_column_its_title_above() {
let h = open_dialog(); let h = open_dialog(json!({}));
let mut boxes: Vec<Shown> = h let mut boxes: Vec<Shown> = h
.query_all_by_role(Role::CheckBox) .query_all_by_role(Role::CheckBox)
.map(|b| { .map(|b| {
@@ -95,3 +96,25 @@ fn every_check_box_draws_its_data_point_name_and_each_column_its_title_above() {
assert!(heading.bottom() <= title.top() + 0.5, "{source}: \"Data Points:\" {heading:?} is above the title {title:?}"); assert!(heading.bottom() <= title.top() + 0.5, "{source}: \"Data Points:\" {heading:?} is above the title {title:?}");
} }
} }
#[test]
fn select_data_points_disables_ok_and_enter_until_a_point_is_checked() {
let mut h = open_dialog(json!({"selection": [], "ruler": ["length"], "count": []}));
assert!(!h.get_by_role_and_label(Role::Button, "OK").accesskit_node().is_disabled());
h.get_by_role_and_label(Role::CheckBox, "Length").click();
h.run_steps(4);
assert!(h.get_by_role_and_label(Role::Button, "OK").accesskit_node().is_disabled(), "no points are checked");
h.key_press(egui::Key::Enter);
h.run_steps(4);
assert!(h.query_by_role_and_label(Role::CheckBox, "Length").is_some(), "Enter leaves the dialog open");
assert_eq!(h.state().session.analysis.data_points.ruler, ["length"]);
h.get_by_role_and_label(Role::CheckBox, "Angle").click();
h.run_steps(4);
assert!(!h.get_by_role_and_label(Role::Button, "OK").accesskit_node().is_disabled());
h.get_by_role_and_label(Role::Button, "OK").click();
h.run_steps(4);
assert!(h.query_by_role_and_label(Role::CheckBox, "Angle").is_none(), "OK closes the dialog");
assert_eq!(h.state().session.analysis.data_points.ruler, ["angle"]);
}
+4 -1
View File
@@ -196,7 +196,10 @@ fn form(kind: Kind, fields: &mut DialogFields) -> ParamDialog<'_> {
.output .output
}) })
.full_width(); .full_width();
ParamDialog::command(key, tl!("Select Data Points"), vec![row]) let has_points = sources()
.into_iter()
.any(|(source, _)| analysis_cmds::available(source).into_iter().any(|column| fields.bool(&point_key(source, column)) == Some(true)));
ParamDialog::command(key, tl!("Select Data Points"), vec![row]).ok_enabled(has_points)
} }
Kind::ScaleMarker => { Kind::ScaleMarker => {
let rows = vec![ let rows = vec![