diff --git a/crates/ui-egui/src/canvas/snap_ui.rs b/crates/ui-egui/src/canvas/snap_ui.rs index 3be26746b2..2fa083206f 100644 --- a/crates/ui-egui/src/canvas/snap_ui.rs +++ b/crates/ui-egui/src/canvas/snap_ui.rs @@ -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 { let mut set = Vec::new(); if moves_as_move_tool(app) @@ -79,6 +80,7 @@ fn moving_set(app: &PhotocraftApp) -> Vec { 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 } diff --git a/crates/ui-egui/src/control/inspect.rs b/crates/ui-egui/src/control/inspect.rs index 7494050968..fab45b9d7a 100644 --- a/crates/ui-egui/src/control/inspect.rs +++ b/crates/ui-egui/src/control/inspect.rs @@ -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, diff --git a/crates/ui-egui/src/field_wheel_app_tests.rs b/crates/ui-egui/src/field_wheel_app_tests.rs index f45db09970..d66801f5bb 100644 --- a/crates/ui-egui/src/field_wheel_app_tests.rs +++ b/crates/ui-egui/src/field_wheel_app_tests.rs @@ -22,7 +22,7 @@ fn harness() -> Harness<'static, Box> { 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>, 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>) -> (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]]) } diff --git a/crates/ui-egui/src/panels/panel_docking/native_tests.rs b/crates/ui-egui/src/panels/panel_docking/native_tests.rs index ba5abe2605..2c48ea1f70 100644 --- a/crates/ui-egui/src/panels/panel_docking/native_tests.rs +++ b/crates/ui-egui/src/panels/panel_docking/native_tests.rs @@ -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"); } diff --git a/crates/ui-egui/src/tools/shape_controls.rs b/crates/ui-egui/src/tools/shape_controls.rs index db78d7fc4a..6003a01898 100644 --- a/crates/ui-egui/src/tools/shape_controls.rs +++ b/crates/ui-egui/src/tools/shape_controls.rs @@ -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 { + 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). diff --git a/crates/ui-egui/src/tools/transform_tool/tests.rs b/crates/ui-egui/src/tools/transform_tool/tests.rs index 287db1c95d..25abb9852f 100644 --- a/crates/ui-egui/src/tools/transform_tool/tests.rs +++ b/crates/ui-egui/src/tools/transform_tool/tests.rs @@ -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 °")); } diff --git a/crates/ui-egui/src/transform_task_bar_tests.rs b/crates/ui-egui/src/transform_task_bar_tests.rs index 86bee01fad..b40e8a18c4 100644 --- a/crates/ui-egui/src/transform_task_bar_tests.rs +++ b/crates/ui-egui/src/transform_task_bar_tests.rs @@ -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); diff --git a/crates/ui-egui/tests/it/crop_task_bar.rs b/crates/ui-egui/tests/it/crop_task_bar.rs index 100fb88ee3..dc48db1ebd 100644 --- a/crates/ui-egui/tests/it/crop_task_bar.rs +++ b/crates/ui-egui/tests/it/crop_task_bar.rs @@ -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");