Follow next's deliberate changes in the ui-egui tests; shape box drags skip their own layers as snap targets

- A shape scale box or corner widget press leaves the selected shape layers out of the snap targets, so a handle
  no longer snaps to the starting edges and centres of the shapes it scales. Corner drags keep the press offset
  since craft-libs 4a52a22e7a, which exposed the snap; the box test keeps its reference values.
- Number fields read their unit in the accessible value (craft-libs e695aadc6d): the skew field reads "0 °",
  Smoothing "10 %".
- The task bar keeps an unpinned drop as its offset from the unmoved place and follows its anchor (TaskBarPlace
  offset, craft-libs f4d0549502 and 5fecd6dbd6); ui.inspect reports taskBar.offset and the tests check it.
- Palette windows hide while a dialog shows and come back when it closes (craft-libs 5886f1ff30).
This commit is contained in:
aiongg committed 2026-11-24 06:52:26 +00:00
1 parent 0745370737
commit 340ad31411
8 files changed
+42 -21

No files matched your search

+3 -1
View File
@@ -55,7 +55,8 @@ fn selection_moves(app: &PhotocraftApp) -> bool {
/// The layers a drag moves or resizes: they are not targets. The selected layers when the Move tool drags and,
/// unless selected pixels float, what it moves whole (the layers linked to them and everything inside a group, so a
/// group does not snap to its own layers' starting edges), the type layer being edited (a paragraph-box handle drag
/// does not snap to the text it resizes, #6819) and the layers of the open Free Transform.
/// does not snap to the text it resizes, #6819), the layers of the open Free Transform and the shape layers the shape
/// scale box or a corner widget is pressing.
fn moving_set(app: &PhotocraftApp) -> Vec<LayerId> {
let mut set = Vec::new();
if moves_as_move_tool(app)
@@ -79,6 +80,7 @@ fn moving_set(app: &PhotocraftApp) -> Vec<LayerId> {
if let Some(t) = app.ui.transform.as_ref() {
set.extend(crate::transform_tool::moving_layers(t));
}
set.extend(crate::shape_controls::pressed_layers(app));
set
}
+1
View File
@@ -167,6 +167,7 @@ pub fn inspect(app: &PhotocraftApp, ctx: &egui::Context) -> Value {
"rect": task_bar_rect,
"pinned": app.ui.panels.task_bar.pinned,
"at": app.ui.panels.task_bar.at,
"offset": app.ui.panels.task_bar.offset,
}),
"dockTabs": legacy.get("dockTabs").cloned().unwrap_or(Value::Null),
"docking": app.ui.docking,
+7 -7
View File
@@ -22,7 +22,7 @@ fn harness() -> Harness<'static, Box<PhotocraftApp>> {
h
}
/// The value field showing `value`: the options bar's Smoothing is the brush's only one at 10.
/// The value field showing `value`, unit included: the options bar's Smoothing is the brush's only one at 10 %.
fn field<'a>(h: &'a Harness<'_, Box<PhotocraftApp>>, value: &str) -> egui_kittest::Node<'a> {
h.query_all_by_role(Role::SpinButton).find(|n| n.value().as_deref() == Some(value)).unwrap()
}
@@ -50,12 +50,12 @@ fn view(h: &Harness<'_, Box<PhotocraftApp>>) -> (f32, [f32; 2]) {
fn the_wheel_over_a_field_steps_it_without_a_click() {
let mut h = harness();
let before = view(&h);
let at = field(&h, "10").rect().center();
let at = field(&h, "10 %").rect().center();
wheel(&mut h, at, 1.0, egui::Modifiers::NONE);
assert!(h.query_all_by_role(Role::SpinButton).any(|n| n.value().as_deref() == Some("11")), "Smoothing stepped from 10 to 11");
assert!(h.query_all_by_role(Role::SpinButton).any(|n| n.value().as_deref() == Some("11 %")), "Smoothing stepped from 10 to 11");
wheel(&mut h, at, 1.0, egui::Modifiers::SHIFT);
assert!(h.query_all_by_role(Role::SpinButton).any(|n| n.value().as_deref() == Some("21")), "Shift: ten a notch");
assert!(!field(&h, "21").is_focused(), "hovering doesn't put the cursor in the field");
assert!(h.query_all_by_role(Role::SpinButton).any(|n| n.value().as_deref() == Some("21 %")), "Shift: ten a notch");
assert!(!field(&h, "21 %").is_focused(), "hovering doesn't put the cursor in the field");
assert_eq!(view(&h), before, "the canvas didn't move");
}
@@ -70,7 +70,7 @@ const TAIL_STEPS: usize = 4;
fn canvas_pan(focus: bool, delta: egui::Vec2, modifiers: egui::Modifiers) -> (f32, [f32; 2]) {
let mut h = harness();
if focus {
field(&h, "10").click();
field(&h, "10 %").click();
h.run();
}
let canvas = egui::pos2(640.0, 500.0);
@@ -85,7 +85,7 @@ fn canvas_pan(focus: bool, delta: egui::Vec2, modifiers: egui::Modifiers) -> (f3
modifiers,
});
h.run_steps(TAIL_STEPS);
assert!(h.query_all_by_role(Role::SpinButton).any(|n| n.value().as_deref() == Some("10")), "focus {focus}: the field wasn't stepped");
assert!(h.query_all_by_role(Role::SpinButton).any(|n| n.value().as_deref() == Some("10 %")), "focus {focus}: the field wasn't stepped");
let after = view(&h);
(after.0 / before.0, [after.1[0] - before.1[0], after.1[1] - before.1[1]])
}
@@ -240,7 +240,8 @@ fn a_menu_key_typed_in_a_panel_windows_text_field_goes_to_the_field() {
}
/// PhotoCraft's dialogs are framework layers, so the runtime's modal blocking reaches the panel windows:
/// under a dialog the window takes no click and no key, and once it is closed the window works again.
/// under a dialog the window takes no click and no key and is hidden, so a click cannot bring it over the dialog,
/// also while the app is in the background; once the dialog is closed the window shows and works again.
#[test]
fn a_dialog_blocks_the_panel_windows() {
for name in ["About", "Gaussian Blur"] {
@@ -263,12 +264,13 @@ fn a_dialog_blocks_the_panel_windows() {
assert_eq!(desktop.h.state().ui.tool, crate::state::Tool::Move, "{name}: nor do the shortcuts get its keys");
desktop.host.borrow_mut().focus = Some(ViewportId::from_hash_of("another app"));
desktop.steps(30);
assert!(!desktop.host.borrow().windows[&viewport].hidden, "{name}: the panel window stays shown while the app is in the background");
assert!(desktop.host.borrow().windows[&viewport].hidden, "{name}: the panel window stays hidden under the dialog while the app is in the background");
desktop.host.borrow_mut().focus = Some(viewport);
crate::dialogs::testing::cancel(desktop.h.state_mut(), id).unwrap();
desktop.steps(3);
assert!(!desktop.h.state().dialog_open(), "{name}");
assert!(!desktop.host.borrow().windows[&viewport].hidden, "{name}: the panel window shows again once the dialog is gone");
desktop.click(viewport, close);
assert!(!is_shown(desktop.h.state(), "layers"), "{name}: the × closes the panel once the dialog is gone");
}
@@ -76,6 +76,15 @@ fn box_shows(app: &PhotocraftApp) -> bool {
&& matches!(app.ui.tool, Tool::PathSelection | Tool::Rectangle | Tool::EllipseShape | Tool::Triangle | Tool::Polygon | Tool::Star | Tool::Line)
}
/// The shape layers the box or a corner widget is editing: the selected shape layers while one of them holds a press.
/// They are not snap targets, so a handle does not snap to the starting edges and centres of the shapes it scales.
pub(crate) fn pressed_layers(app: &PhotocraftApp) -> Vec<LayerId> {
if !box_shows(app) || !editing(app) {
return Vec::new();
}
selection(app, live_line(app).is_some()).map(|(layers, _)| layers.into_iter().map(LayerId).collect()).unwrap_or_default()
}
/// The selected shape layers and the box round their paths `[x0, y0, x1, y1]`. `None` unless at least
/// one layer is selected and all are shape layers. A box with no extent along one axis counts only
/// when `flat_ok` (a level or upright live line).
@@ -2204,7 +2204,8 @@ fn ending_the_transform_brings_back_the_tools_options_bar() {
}
}
/// #15548: Free Transform on an unturned, unskewed box shows the horizontal skew as "0", not "-0".
/// #15548: Free Transform on an unturned, unskewed box shows the horizontal skew as "0", not "-0". The field's value
/// reads the unit it draws after the number.
#[test]
fn an_unskewed_box_shows_its_horizontal_skew_as_zero() {
use egui_kittest::kittest::Queryable as _;
@@ -2213,5 +2214,5 @@ fn an_unskewed_box_shows_its_horizontal_skew_as_zero() {
let ctx = h.ctx.clone();
crate::menus::invoke(h.state_mut(), &ctx, "edit.freeTransform", json!({})).unwrap();
h.run_steps(2);
assert_eq!(h.get_by_label("Horizontal skew").value().as_deref(), Some("0"));
assert_eq!(h.get_by_label("Horizontal skew").value().as_deref(), Some("0 °"));
}
@@ -472,7 +472,8 @@ fn drag_task_bar_grip(h: &mut AppHarness) -> Rect {
let grip = h.get_by_label("Move bar").rect();
assert!(grip.is_positive(), "the named shared grip has real positive bounds: {grip:?}");
assert!(before.contains_rect(grip), "the pointer must hit the grip inside the visible bar");
assert!(h.state().ui.panels.task_bar.at.is_none(), "a fresh bar follows its frame before the drag");
let fresh = h.state().ui.panels.task_bar;
assert!(fresh.at.is_none() && fresh.offset.is_none(), "a fresh bar follows its frame before the drag");
let area = view(h.state()).rect;
let from = grip.center();
let delta = egui::vec2(40.0, -24.0);
@@ -485,10 +486,12 @@ fn drag_task_bar_grip(h: &mut AppHarness) -> Rect {
assert_eq!(after.size(), before.size(), "a grip drag moves the bar without resizing it");
let movement = after.min - before.min;
assert!(movement.length() > 12.0 && movement.dot(delta) > 0.0, "the grip must move the bar: {before:?} -> {after:?}");
// An unpinned bar keeps the drop as its offset from its unmoved place and goes on following the frame.
let place = h.state().ui.panels.task_bar;
let [x, y] = place.at.expect("a grip drag stores the canvas-relative bar position");
assert!((after.min - (area.min + egui::vec2(x, y))).length() <= 1.0, "the displayed bar must use the saved position");
assert_eq!(bar(h)["at"], json!([x, y]));
assert!(place.at.is_none(), "an unpinned bar keeps no fixed position: {place:?}");
let [x, y] = place.offset.expect("a grip drag stores the bar's offset from its unmoved place");
assert!((movement - egui::vec2(x, y)).length() <= 1.0, "the displayed bar must use the saved offset: {movement:?} vs {place:?}");
assert_eq!(bar(h)["offset"], json!([x, y]));
// This is the same serialized panel-layout field used across restarts, not a transient Area rect.
let restored: crate::state::TaskBarPlace = serde_json::from_value(serde_json::to_value(place).unwrap()).unwrap();
assert_eq!(restored, place);
+8 -5
View File
@@ -141,21 +141,24 @@ fn ui_set_changes_only_the_place_fields_it_names() {
draw_frame(&mut h, [40.0, 30.0], [260.0, 200.0]);
drag_grip(&mut h, vec2(-60.0, -120.0));
let dropped = bar(&h).expect("bar");
let at = h.state().ui.panels.task_bar.at;
// Pinning keeps the dragged place: the bar doesn't jump back under the frame.
// Unpinned, the drop is an offset from the bar's place under the frame.
let place = h.state().ui.panels.task_bar;
assert!(place.at.is_none() && place.offset.is_some(), "{place:?}");
// Pinning keeps the dragged place: the bar doesn't jump back under the frame, and stays where it shows.
control(&mut h, "ui.set", json!({"panels": {"task_bar": {"pinned": true}}}));
assert_eq!(h.state().ui.panels.task_bar.at, at);
assert!(h.state().ui.panels.task_bar.pinned);
assert!(h.state().ui.panels.task_bar.at.is_some(), "a pinned bar holds its position");
assert_eq!(bar(&h).expect("bar").left_top(), dropped.left_top());
// Placing it keeps the pin.
control(&mut h, "ui.set", json!({"panels": {"task_bar": {"at": [12.0, 34.0]}}}));
assert_eq!(h.state().ui.panels.task_bar, photocraft_ui_egui::state::TaskBarPlace::new(true, Some([12.0, 34.0])));
assert!(h.state().ui.panels.task_bar.pinned);
assert_eq!(h.state().ui.panels.task_bar.at, Some([12.0, 34.0]));
// A field the bar doesn't have is refused, and nothing changes.
let v = request(&mut h, "ui.set", json!({"panels": {"task_bar": {"pinned": false, "nope": 1}}}));
assert_eq!(v["ok"], false, "{v}");
assert!(h.state().ui.panels.task_bar.pinned);
// Reset bar position over the control channel.
control(&mut h, "ui.set", json!({"panels": {"task_bar": {"pinned": false, "at": null}}}));
control(&mut h, "ui.set", json!({"panels": {"task_bar": {"pinned": false, "at": null, "offset": null}}}));
assert_eq!(h.state().ui.panels.task_bar, Default::default());
let v = request(&mut h, "ui.inspect", json!({}));
assert_eq!(v["result"]["taskBar"]["at"], Value::Null, "after the reset the bar follows the frame again");