mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 01:18:43 +00:00
Merge pull request #9841 from Kaedo17/fix/zoom-tool-context-menu
fix: dismiss context menu without triggering tool action on outside click
This commit is contained in:
7 files changed
+380
-80
No files matched your search
@@ -316,6 +316,9 @@ sync_github_name = false
|
||||
real_name = "David Vanhoucke"
|
||||
sync_github_name = true
|
||||
|
||||
[people.Kaedo17]
|
||||
sync_github_name = true
|
||||
|
||||
[people.rmsff]
|
||||
real_name = "Serikov Roman"
|
||||
sync_github_name = false
|
||||
+145
-80
@@ -883,6 +883,7 @@ struct CanvasToolInput<'a> {
|
||||
hand_pan: bool,
|
||||
ppp: f32,
|
||||
under_dialog: bool,
|
||||
menu_dismiss_press: bool,
|
||||
zoom_out: &'a dyn Fn(bool) -> bool,
|
||||
display_zoom: f32,
|
||||
}
|
||||
@@ -902,9 +903,22 @@ fn handle_primary_canvas_input(app: &mut PhotocraftApp, ui: &mut egui::Ui, view:
|
||||
// (Preferences › Tools, `paint_mouse`).
|
||||
crate::paint_mouse::sync_tool_brush(app);
|
||||
let mut buttons = crate::paint_mouse::canvas_buttons(app, response, tool);
|
||||
if input.menu_dismiss_press {
|
||||
// Navigation and drags read `buttons` directly (zoom holds and drags, Rotate View):
|
||||
// starve them. The release click stays armed, so the click handling below consumes
|
||||
// it through the flag.
|
||||
buttons.started = false;
|
||||
buttons.dragged = false;
|
||||
buttons.stopped = false;
|
||||
}
|
||||
// The Crop tool's frame is edited from the press (before egui's drag threshold), so the
|
||||
// pixels past the canvas show at once, as in Photoshop.
|
||||
if tool == Tool::Crop && response.is_pointer_button_down_on() && ui.input(|i| i.pointer.primary_down()) && crate::crop_ui::press(app) {
|
||||
if tool == Tool::Crop
|
||||
&& !input.menu_dismiss_press
|
||||
&& response.is_pointer_button_down_on()
|
||||
&& ui.input(|i| i.pointer.primary_down())
|
||||
&& crate::crop_ui::press(app)
|
||||
{
|
||||
ctx.request_repaint();
|
||||
}
|
||||
// Capture intent at the press, before egui's drag threshold or click replay on release:
|
||||
@@ -913,6 +927,7 @@ fn handle_primary_canvas_input(app: &mut PhotocraftApp, ui: &mut egui::Ui, view:
|
||||
tool.is_type() || matches!(tool, Tool::RectMarquee | Tool::EllipseMarquee | Tool::SingleRowMarquee | Tool::SingleColumnMarquee | Tool::ObjectSelection);
|
||||
let tool_press = egui::Id::unique(("tool-pointer-press-modifiers", idx));
|
||||
if capture_press
|
||||
&& !input.menu_dismiss_press
|
||||
&& let Some((p, press_mods)) = ui.input(|i| {
|
||||
i.events.iter().find_map(|e| match e {
|
||||
egui::Event::PointerButton { pos, button: PointerButton::Primary, pressed: true, modifiers } if rect.contains(*pos) => Some((*pos, *modifiers)),
|
||||
@@ -932,6 +947,17 @@ fn handle_primary_canvas_input(app: &mut PhotocraftApp, ui: &mut egui::Ui, view:
|
||||
handle_canvas_tool_navigation(app, ui, view, input, &mut buttons);
|
||||
handle_canvas_tool_stroke(app, ui, input, mods, capture_press, tool_press, &mut buttons);
|
||||
handle_canvas_tool_clicks(app, ui, view, input, mods, tool_press, &buttons);
|
||||
// Clear the menu-dismissal flag on the gesture's pointer release, even when the release
|
||||
// occurs outside the canvas and produces no `buttons.clicked` event. It sits below (not
|
||||
// above) the click handling, so a release over the canvas in a later frame is first
|
||||
// consumed by the flag check there: clearing before it would let that release zoom
|
||||
// (CodeRabbit, #9841). The all-buttons-up check also covers a release that landed in a
|
||||
// frame this canvas didn't render.
|
||||
if app.ui.canvas_tool_menu_dismissed
|
||||
&& (ui.input(|i| i.pointer.primary_released()) || ui.input(|i| i.pointer.secondary_released()) || !ui.input(|i| i.pointer.any_down()))
|
||||
{
|
||||
app.ui.canvas_tool_menu_dismissed = false;
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_canvas_tool_menus(app: &mut PhotocraftApp, input: &CanvasToolInput<'_>, mods: egui::Modifiers, buttons: &mut crate::paint_mouse::Buttons) {
|
||||
@@ -958,8 +984,11 @@ fn handle_canvas_tool_menus(app: &mut PhotocraftApp, input: &CanvasToolInput<'_>
|
||||
};
|
||||
// The Lasso (and the Freeform Pen, which draws the same way) reads its own presses and
|
||||
// drops the moves of a drag it didn't start, so an open Free Transform box takes the
|
||||
// usual drag path instead (#2153).
|
||||
if crate::lasso_ui::owns(tool) && !transform_owns_pointer {
|
||||
// usual drag path instead (#2153). It reads the raw pointer events straight from the
|
||||
// context, so the `buttons` starvation above never reaches it: a press that dismisses the
|
||||
// canvas tool menu would draw a selection. Gate the dispatcher itself, as the Crop press
|
||||
// above is gated (#9841).
|
||||
if crate::lasso_ui::owns(tool) && !transform_owns_pointer && !input.menu_dismiss_press {
|
||||
crate::lasso_ui::canvas_input(app, ctx, xf, response);
|
||||
(buttons.started, buttons.dragged, buttons.stopped, buttons.clicked) = (false, false, false, false);
|
||||
}
|
||||
@@ -1047,10 +1076,11 @@ fn handle_canvas_tool_navigation(
|
||||
(buttons.started, buttons.dragged, buttons.stopped, buttons.clicked) = (false, false, false, false);
|
||||
}
|
||||
// Animated Zoom: a Zoom press held still zooms continuously (zoom_hold.rs); while it does,
|
||||
// it owns the press: no scrub, and its release is no click step.
|
||||
// it owns the press: no scrub, and its release is no click step. A menu-dismissal press
|
||||
// must not arm it: holding the dismissal click would zoom (CodeRabbit, #9841).
|
||||
if tool == Tool::Zoom && !transform_owns_pointer {
|
||||
let out = zoom_out(ui.input(|i| i.modifiers.alt));
|
||||
let on_canvas = !input.under_dialog && !over_compass && response.is_pointer_button_down_on();
|
||||
let on_canvas = !input.menu_dismiss_press && !input.under_dialog && !over_compass && response.is_pointer_button_down_on();
|
||||
let hold = crate::zoom_hold::hold_id(idx, primary, ctx.viewport_id());
|
||||
if crate::zoom_hold::update(ctx, view, xf, app.session.prefs().general.animated_zoom, out, ppp, on_canvas, hold) {
|
||||
(buttons.started, buttons.dragged, buttons.stopped, buttons.clicked) = (false, false, false, false);
|
||||
@@ -1092,6 +1122,7 @@ fn handle_canvas_tool_stroke(
|
||||
let right_down = ui.input(|i| i.pointer.secondary_down()) || physical_right;
|
||||
if strokes_live(tool)
|
||||
&& !right_down
|
||||
&& !input.menu_dismiss_press
|
||||
&& app.drag.is_none()
|
||||
&& response.is_pointer_button_down_on()
|
||||
&& ui.input(|i| i.pointer.primary_pressed())
|
||||
@@ -1111,6 +1142,7 @@ fn handle_canvas_tool_stroke(
|
||||
buttons.started = false;
|
||||
}
|
||||
if buttons.started
|
||||
&& !input.menu_dismiss_press
|
||||
&& let Some(p) = ui.input(|i| i.pointer.press_origin()).filter(|p| rect.contains(*p)).or(response.interact_pointer_pos())
|
||||
{
|
||||
// A press the controls refused (the Background among the layers) goes nowhere else (#11101).
|
||||
@@ -1125,7 +1157,7 @@ fn handle_canvas_tool_stroke(
|
||||
// recognises a drag (past its click distance): otherwise the first few points are lost
|
||||
// and the stroke starts with a straight segment and no pressure ramp.
|
||||
let press_stroke_moving = press_stroke && app.drag.is_some();
|
||||
if buttons.dragged || buttons.stopped || press_stroke_moving {
|
||||
if !input.menu_dismiss_press && (buttons.dragged || buttons.stopped || press_stroke_moving) {
|
||||
// Feed every pointer move the OS delivered this frame, not just the latest position, so
|
||||
// a fast stroke is sampled densely and renders as a smooth curve instead of a coarse
|
||||
// polyline. egui-winit pushes one `PointerMoved` per `CursorMoved`, and they accumulate
|
||||
@@ -1183,7 +1215,7 @@ fn handle_canvas_tool_stroke(
|
||||
feed_live_stroke(app);
|
||||
crate::magnetic_lasso_ui::flush(app);
|
||||
}
|
||||
if buttons.stopped {
|
||||
if buttons.stopped && !input.menu_dismiss_press {
|
||||
// The live painting press already created the stroke and this release commits it.
|
||||
// egui may also report clicked on the same release; replaying that click paints a
|
||||
// second full-pressure dab over the real (possibly light-pressure) pen dab.
|
||||
@@ -1208,7 +1240,7 @@ fn handle_canvas_tool_stroke(
|
||||
}
|
||||
// A stroke started on the press ends with the release, whether egui saw a drag, a click,
|
||||
// or neither (a long press that never moved).
|
||||
if press_stroke && !buttons.stopped && ui.input(|i| i.pointer.primary_released()) {
|
||||
if press_stroke && !buttons.stopped && !input.menu_dismiss_press && ui.input(|i| i.pointer.primary_released()) {
|
||||
buttons.clicked = false;
|
||||
let p = response.interact_pointer_pos().map(|p| xf.to_doc(p)).or_else(|| app.drag.as_ref().and_then(|d| d.points.last().map(|q| [q[0], q[1]])));
|
||||
if let Some(d) = p
|
||||
@@ -1241,66 +1273,17 @@ fn handle_canvas_tool_clicks(
|
||||
let ppp = input.ppp;
|
||||
let zoom_out = input.zoom_out;
|
||||
let display_zoom = input.display_zoom;
|
||||
if buttons.clicked
|
||||
&& let Some(p) = response.interact_pointer_pos()
|
||||
// Magnetic Lasso: between clicks the border follows the pointer with the button up. This is a
|
||||
// pointer-only gesture — `canvas_buttons` makes `clicked` false on frames without a button
|
||||
// event — so it must stay outside the click-only branch below, or live edge tracking and
|
||||
// automatic fastening freeze until the next click. A menu-dismissal gesture is inert, so the
|
||||
// hover is suppressed with the same flag that starves the rest of the input pass (#9841).
|
||||
if tool == Tool::MagneticLasso
|
||||
&& app.ui.magnetic.active()
|
||||
&& !input.menu_dismiss_press
|
||||
&& !(buttons.started || buttons.dragged || buttons.stopped)
|
||||
&& response.hovered()
|
||||
{
|
||||
let click_button = if app.secondary_erase { PointerButton::Secondary } else { PointerButton::Primary };
|
||||
let click_mods = ui.input(|i| pointer_button_modifiers(&i.events, click_button)).unwrap_or(mods);
|
||||
let click_mods = if tool == Tool::ObjectSelection && click_button == PointerButton::Primary {
|
||||
ctx.data(|d| d.get_temp(tool_press)).unwrap_or(click_mods)
|
||||
} else {
|
||||
click_mods
|
||||
};
|
||||
let d = xf.to_doc(p);
|
||||
match tool {
|
||||
Tool::Zoom if !transform_owns_pointer => {
|
||||
let nz = crate::zoom_levels::step(view.zoom, if zoom_out(click_mods.alt) { -1 } else { 1 }, view.doc_size);
|
||||
let center = app.session.prefs().tools.zoom_clicked_point_to_center;
|
||||
let doc_anchor = xf.to_doc(p);
|
||||
let screen_anchor = p;
|
||||
zoom_about(view, xf, p, nz, center, ppp);
|
||||
view.request_zoom_animation(app.session.prefs().general.animated_zoom && nz != display_zoom);
|
||||
view.zoom_anchor = (view.zoom_animating && !center).then_some((doc_anchor, [screen_anchor.x, screen_anchor.y]));
|
||||
}
|
||||
// A click with the (temporary) Hand does nothing, never the tool underneath.
|
||||
Tool::Hand | Tool::RotateView => {}
|
||||
// Double-clicking closes the polygonal lasso: the first click placed the last
|
||||
// vertex (or already closed it), so the second never starts a new polygon. egui
|
||||
// reports it as a triple click when a vertex went down shortly before.
|
||||
Tool::PolygonLasso if response.double_clicked() || response.triple_clicked() => commit_polygon(app),
|
||||
// The same for the Magnetic Lasso: along the edges, or straight with ⌥.
|
||||
Tool::MagneticLasso if response.double_clicked() || response.triple_clicked() => crate::magnetic_lasso_ui::close(app, mods.alt),
|
||||
// The first click placed (or grabbed) the point; the second toggles it.
|
||||
Tool::CurvaturePen if response.double_clicked() => crate::vector_ui::curvature_toggle(app, d[0], d[1]),
|
||||
// Double-clicking a guide opens Preferences › Guides, Grid & Slices, as in Photoshop.
|
||||
Tool::Move if response.double_clicked() && crate::rulers::guide_at(app, d[0], d[1]).is_some() => {
|
||||
if let Err(e) = crate::menus::invoke(app, ctx, "edit.preferences.guidesGridAndSlices", json!({})) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
}
|
||||
// A click the transform controls refused (the Background among the layers) goes
|
||||
// nowhere else (#11101).
|
||||
_ if tool == Tool::Move && app.ui.transform.is_none() && begin_transform_controls_at(app, ctx, xf, p) == ControlsPress::Refused => {}
|
||||
_ => {
|
||||
// If this tool was not handled on pointer-down, fall back to a
|
||||
// click-sized gesture while preserving pen pressure (mouse stays at 1).
|
||||
tool_event(app, ToolEvent::Down { x: d[0], y: d[1], pressure: app.stylus.pressure() }, click_mods);
|
||||
tap_at_peak_pressure(app);
|
||||
tool_event(app, ToolEvent::Up { x: d[0], y: d[1] }, click_mods);
|
||||
}
|
||||
}
|
||||
}
|
||||
// A Frame drag uses a temporary Free Transform for its image/both target. That owns
|
||||
// the release, so the generic tool-click gate can be false even for a double click.
|
||||
if tool == Tool::Frame
|
||||
&& response.contains_pointer()
|
||||
&& ctx.input(|i| i.pointer.button_double_clicked(PointerButton::Primary))
|
||||
&& let Some(p) = response.interact_pointer_pos().or_else(|| ctx.pointer_hover_pos())
|
||||
{
|
||||
crate::frame_tool::double_click(app, xf.to_doc(p));
|
||||
}
|
||||
// Magnetic Lasso: between clicks the border follows the pointer with the button up.
|
||||
if tool == Tool::MagneticLasso && app.ui.magnetic.active() && !(buttons.started || buttons.dragged || buttons.stopped) && response.hovered() {
|
||||
let moves: Vec<Pos2> = ui.input(|i| i.events.iter().filter_map(|e| if let egui::Event::PointerMoved(p) = e { Some(*p) } else { None }).collect());
|
||||
app.defer_live_stroke = true;
|
||||
for p in moves.into_iter().filter(|p| rect.contains(*p)) {
|
||||
@@ -1310,17 +1293,87 @@ fn handle_canvas_tool_clicks(
|
||||
app.defer_live_stroke = false;
|
||||
crate::magnetic_lasso_ui::flush(app);
|
||||
}
|
||||
// Move tool: a double-click on type edits it, as in Photoshop (#1132). Only the selected
|
||||
// Move tool, not ⌘ held over another tool; an open transform box keeps its double-click
|
||||
// (commit, below).
|
||||
if tool == Tool::Move
|
||||
&& app.ui.tool == Tool::Move
|
||||
&& app.ui.transform.is_none()
|
||||
&& response.double_clicked()
|
||||
if buttons.clicked
|
||||
&& let Some(p) = response.interact_pointer_pos()
|
||||
{
|
||||
let d = xf.to_doc(p);
|
||||
crate::type_tool::edit_at(app, d[0], d[1]);
|
||||
// If an outside press dismissed the canvas tool menu, consume this release click
|
||||
// so it doesn't also trigger a tool action (Photoshop behavior). A click outside a
|
||||
// still-open menu dismisses it and is consumed the same way (CodeRabbit, #9841).
|
||||
if app.ui.canvas_tool_menu_dismissed {
|
||||
app.ui.canvas_tool_menu_dismissed = false;
|
||||
} else if let Some(menu_rect) = crate::canvas_tool_menu::menu_rect_if_open(app, ctx)
|
||||
&& !menu_rect.contains(p)
|
||||
{
|
||||
// The click is outside the open menu: it dismisses the menu, no tool action.
|
||||
} else {
|
||||
let click_button = if app.secondary_erase { PointerButton::Secondary } else { PointerButton::Primary };
|
||||
let click_mods = ui.input(|i| pointer_button_modifiers(&i.events, click_button)).unwrap_or(mods);
|
||||
let click_mods = if tool == Tool::ObjectSelection && click_button == PointerButton::Primary {
|
||||
ctx.data(|d| d.get_temp(tool_press)).unwrap_or(click_mods)
|
||||
} else {
|
||||
click_mods
|
||||
};
|
||||
let d = xf.to_doc(p);
|
||||
match tool {
|
||||
Tool::Zoom if !transform_owns_pointer => {
|
||||
let nz = crate::zoom_levels::step(view.zoom, if zoom_out(click_mods.alt) { -1 } else { 1 }, view.doc_size);
|
||||
let center = app.session.prefs().tools.zoom_clicked_point_to_center;
|
||||
let doc_anchor = xf.to_doc(p);
|
||||
let screen_anchor = p;
|
||||
zoom_about(view, xf, p, nz, center, ppp);
|
||||
view.request_zoom_animation(app.session.prefs().general.animated_zoom && nz != display_zoom);
|
||||
view.zoom_anchor = (view.zoom_animating && !center).then_some((doc_anchor, [screen_anchor.x, screen_anchor.y]));
|
||||
}
|
||||
// A click with the (temporary) Hand does nothing, never the tool underneath.
|
||||
Tool::Hand | Tool::RotateView => {}
|
||||
// Double-clicking closes the polygonal lasso: the first click placed the last
|
||||
// vertex (or already closed it), so the second never starts a new polygon. egui
|
||||
// reports it as a triple click when a vertex went down shortly before.
|
||||
Tool::PolygonLasso if response.double_clicked() || response.triple_clicked() => commit_polygon(app),
|
||||
// The same for the Magnetic Lasso: along the edges, or straight with ⌥.
|
||||
Tool::MagneticLasso if response.double_clicked() || response.triple_clicked() => crate::magnetic_lasso_ui::close(app, mods.alt),
|
||||
// The first click placed (or grabbed) the point; the second toggles it.
|
||||
Tool::CurvaturePen if response.double_clicked() => crate::vector_ui::curvature_toggle(app, d[0], d[1]),
|
||||
// Double-clicking a guide opens Preferences › Guides, Grid & Slices, as in Photoshop.
|
||||
Tool::Move if response.double_clicked() && crate::rulers::guide_at(app, d[0], d[1]).is_some() => {
|
||||
if let Err(e) = crate::menus::invoke(app, ctx, "edit.preferences.guidesGridAndSlices", json!({})) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
}
|
||||
// A click the transform controls refused (the Background among the layers) goes
|
||||
// nowhere else (#11101).
|
||||
_ if tool == Tool::Move && app.ui.transform.is_none() && begin_transform_controls_at(app, ctx, xf, p) == ControlsPress::Refused => {}
|
||||
_ => {
|
||||
// If this tool was not handled on pointer-down, fall back to a
|
||||
// click-sized gesture while preserving pen pressure (mouse stays at 1).
|
||||
tool_event(app, ToolEvent::Down { x: d[0], y: d[1], pressure: app.stylus.pressure() }, click_mods);
|
||||
tap_at_peak_pressure(app);
|
||||
tool_event(app, ToolEvent::Up { x: d[0], y: d[1] }, click_mods);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Move tool: a double-click on type edits it, as in Photoshop (#1132). Only the selected
|
||||
// Move tool, not ⌘ held over another tool; an open transform box keeps its double-click
|
||||
// (commit, below).
|
||||
if tool == Tool::Move
|
||||
&& app.ui.tool == Tool::Move
|
||||
&& app.ui.transform.is_none()
|
||||
&& response.double_clicked()
|
||||
&& let Some(p) = response.interact_pointer_pos()
|
||||
{
|
||||
let d = xf.to_doc(p);
|
||||
crate::type_tool::edit_at(app, d[0], d[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// A Frame drag uses a temporary Free Transform for its image/both target. That owns
|
||||
// the release, so the generic tool-click gate can be false even for a double click.
|
||||
if tool == Tool::Frame
|
||||
&& response.contains_pointer()
|
||||
&& ctx.input(|i| i.pointer.button_double_clicked(PointerButton::Primary))
|
||||
&& let Some(p) = response.interact_pointer_pos().or_else(|| ctx.pointer_hover_pos())
|
||||
{
|
||||
crate::frame_tool::double_click(app, xf.to_doc(p));
|
||||
}
|
||||
// A double-click commits an open Free Transform only on the box (handles included); outside
|
||||
// it does nothing (#11100).
|
||||
@@ -2138,6 +2191,15 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
|
||||
// box is only drawn and driven on the primary canvas.
|
||||
let transform_owns_pointer = primary && app.ui.transform.is_some() && temporary.is_none() && !middle;
|
||||
let hand_pan = tool == Tool::Hand && !transform_owns_pointer;
|
||||
// A press outside an open canvas tool menu dismisses it (`canvas_tool_menu::show`, after this
|
||||
// input pass) and the whole gesture is consumed until its release, as in Photoshop: no tool
|
||||
// press, stroke, drag, pan or zoom step. The menu closes mid-frame (after this input pass), so
|
||||
// the open-menu hit test covers the dismissal frame, and the flag persists the block for the
|
||||
// frames after it, until the release clear below the click handling. It gates the Hand and
|
||||
// flick pans below too: they read `response.dragged()` directly and never see `buttons`
|
||||
// (CodeRabbit, #9841).
|
||||
let menu_dismiss_press = app.ui.canvas_tool_menu_dismissed
|
||||
|| crate::canvas_tool_menu::menu_rect_if_open(app, &ctx).is_some_and(|r| ui.input(|i| i.pointer.press_origin()).is_some_and(|p| !r.contains(p)));
|
||||
// The Hand pans with a drag of any button, but the selected Hand's right button is its view
|
||||
// menu, as in Photoshop: a drag with that button alone is a right-click that moved, which
|
||||
// opens the menu instead, until it strays past a right-click's reach and pans after all
|
||||
@@ -2164,9 +2226,11 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
|
||||
// other shown views follow this one.
|
||||
let scroll_all = hand_pan && crate::scroll_all_windows::active(app, crate::workspace_ui::sticky_mods(app, ctx.input(|i| i.modifiers)).shift);
|
||||
let scroll_source = crate::scroll_all_windows::source(app, idx);
|
||||
// A glide keeps the drag's choice after Space, Shift or the button is let go.
|
||||
let glide_scroll_all = crate::scroll_all_windows::glide_choice(&ctx, flick_id.with("scroll-all"), hand_drag && !stroke_dismissal, scroll_all);
|
||||
if let Some(d) = crate::flick_pan::frame(&ctx, flick_id, hand_drag && !stroke_dismissal, response.drag_delta(), flick_on) {
|
||||
// A glide keeps the drag's choice after Space, Shift or the button is let go; a menu-dismissal
|
||||
// press is no pan, so it neither arms the glide nor moves the other views.
|
||||
let glide_scroll_all =
|
||||
crate::scroll_all_windows::glide_choice(&ctx, flick_id.with("scroll-all"), hand_drag && !stroke_dismissal && !menu_dismiss_press, scroll_all);
|
||||
if let Some(d) = crate::flick_pan::frame(&ctx, flick_id, hand_drag && !stroke_dismissal && !menu_dismiss_press, response.drag_delta(), flick_on) {
|
||||
let d = xf.unmap_vec(d) / (view.zoom / ppp);
|
||||
let before = view.center;
|
||||
if d.is_finite() {
|
||||
@@ -2184,7 +2248,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
|
||||
}
|
||||
// A scroll or zoom while the right button is held moves the image under its press: no click.
|
||||
crate::paint_mouse::track_right_press_view(&response, &view, flip);
|
||||
if hand_drag && !stroke_dismissal {
|
||||
if hand_drag && !stroke_dismissal && !menu_dismiss_press {
|
||||
let d = xf.unmap_vec(response.drag_delta()) / (view.zoom / ppp);
|
||||
let before = view.center;
|
||||
view.center[0] -= d.x;
|
||||
@@ -2209,6 +2273,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
|
||||
hand_pan,
|
||||
ppp,
|
||||
under_dialog,
|
||||
menu_dismiss_press,
|
||||
zoom_out: &zoom_out,
|
||||
display_zoom: display_view.zoom,
|
||||
};
|
||||
|
||||
@@ -1312,9 +1312,25 @@ pub fn show(app: &mut PhotocraftApp, ctx: &Context) {
|
||||
choose(app, ctx, &command);
|
||||
} else if crate::canvas_popup::outside_pressed(ctx, id, area.response.rect) {
|
||||
app.ui.canvas_tool_menu = None;
|
||||
// A fast click can press and release in one frame: the canvas input above already
|
||||
// suppressed its action through the open-menu hit test, and the deferred release clear
|
||||
// (in `canvas_view`, below the click handling) would never fire after this frame. Don't
|
||||
// arm the flag then, or it would eat the next ordinary click (CodeRabbit, #9841).
|
||||
app.ui.canvas_tool_menu_dismissed = !ctx.input(|i| i.pointer.any_released());
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the menu rect if the canvas tool menu is currently open, for hit-testing
|
||||
/// outside-click dismissal in the click handler.
|
||||
pub fn menu_rect_if_open(app: &PhotocraftApp, ctx: &Context) -> Option<egui::Rect> {
|
||||
let menu = app.ui.canvas_tool_menu.as_ref()?;
|
||||
let id = menu_id();
|
||||
let screen = ctx.content_rect();
|
||||
let size = ctx.memory(|m| m.area_rect(id)).map_or(egui::vec2(210.0, 140.0), |r| r.size());
|
||||
let pos = egui::pos2(menu.pos[0].min(screen.right() - size.x).max(screen.left()), menu.pos[1].min(screen.bottom() - size.y).max(screen.top()));
|
||||
Some(egui::Rect::from_min_size(pos, size))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
|
||||
@@ -550,6 +550,143 @@ fn zoom_and_hand_right_click_opens_the_view_menu() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A zoom harness with a fixed camera: zoom 1.0 centred on the 400×300 document. `animated` is
|
||||
/// Preferences › General › Animated Zoom; each step is 0.1 s of egui time, so a hold can pass
|
||||
/// `zoom_hold::DELAY` within a few steps.
|
||||
fn zoom_harness(animated: bool) -> Harness<'static, PhotocraftApp> {
|
||||
let mut app = zoom_app(400, 300);
|
||||
app.ui.tool = Tool::Zoom;
|
||||
app.run("prefs.set", json!({"values": {"general.animatedZoom": animated, "tools.zoomClickedPointToCenter": false, "tools.overscroll": true}})).unwrap();
|
||||
app.sync_views();
|
||||
app.ui.extras.rulers = false;
|
||||
let mut h = Harness::builder().with_size(vec2(1000.0, 700.0)).with_step_dt(0.1).build_ui_state(
|
||||
|ui, app: &mut PhotocraftApp| {
|
||||
if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
|
||||
return;
|
||||
}
|
||||
egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui));
|
||||
},
|
||||
app,
|
||||
);
|
||||
PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::default());
|
||||
h.run_steps(4);
|
||||
let view = &mut h.state_mut().ui.views[0];
|
||||
view.zoom = 1.0;
|
||||
view.center = [200.0, 150.0];
|
||||
view.fit_pending = false;
|
||||
view.fill_pending = false;
|
||||
h.run_steps(2);
|
||||
h
|
||||
}
|
||||
|
||||
/// The menu opens at `[300, 100]` (doc points); this press lands 250 doc px to its left: outside
|
||||
/// the 200 px-wide menu, on the canvas.
|
||||
fn dismissal_point(h: &Harness<'static, PhotocraftApp>) -> Pos2 {
|
||||
screen_of(h.state(), [50.0, 250.0])
|
||||
}
|
||||
|
||||
/// #9832: a left press outside the open view menu dismisses it, and the whole gesture is
|
||||
/// consumed — the press, the held press, and the release never zoom, and the next ordinary
|
||||
/// click zooms again.
|
||||
#[test]
|
||||
fn dismissing_the_view_menu_consumes_the_whole_gesture() {
|
||||
let mut h = zoom_harness(false);
|
||||
let zoom = h.state().ui.views[0].zoom;
|
||||
let open_at = screen_of(h.state(), [300.0, 100.0]);
|
||||
right_click(&mut h, open_at, Modifiers::NONE);
|
||||
assert!(h.state().ui.canvas_tool_menu.is_some(), "right-click opens the view menu");
|
||||
// The dismissal press: the menu goes, the zoom does not.
|
||||
let far = dismissal_point(&h);
|
||||
h.event(egui::Event::PointerMoved(far));
|
||||
h.run_steps(1);
|
||||
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
assert!(h.state().ui.canvas_tool_menu.is_none(), "the outside press dismisses the menu");
|
||||
assert_eq!(h.state().ui.views[0].zoom, zoom, "the dismissal press does not zoom");
|
||||
// Holding it (a long press releases as a click) still does nothing…
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().ui.views[0].zoom, zoom, "a held dismissal press does not zoom");
|
||||
// …and the release over the canvas is consumed: no zoom step.
|
||||
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().ui.views[0].zoom, zoom, "the dismissal release does not zoom");
|
||||
// The next ordinary click zooms again: the gesture flag did not stick.
|
||||
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().ui.views[0].zoom, crate::zoom_levels::step(zoom, 1, h.state().ui.views[0].doc_size), "the next ordinary click zooms");
|
||||
}
|
||||
|
||||
/// #9832: a menu-dismissal press held past `zoom_hold::DELAY` must not arm the animated zoom
|
||||
/// hold: holding the dismissal click would otherwise zoom continuously.
|
||||
#[test]
|
||||
fn a_held_menu_dismissal_press_never_arms_the_zoom_hold() {
|
||||
let mut h = zoom_harness(true);
|
||||
let zoom = h.state().ui.views[0].zoom;
|
||||
let open_at = screen_of(h.state(), [300.0, 100.0]);
|
||||
right_click(&mut h, open_at, Modifiers::NONE);
|
||||
assert!(h.state().ui.canvas_tool_menu.is_some(), "right-click opens the view menu");
|
||||
let far = dismissal_point(&h);
|
||||
h.event(egui::Event::PointerMoved(far));
|
||||
h.run_steps(1);
|
||||
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
assert!(h.state().ui.canvas_tool_menu.is_none(), "the outside press dismisses the menu");
|
||||
// 0.8 s held still, well past the 0.3 s hold delay: every frame stays at the start zoom.
|
||||
for i in 0..8 {
|
||||
h.run_steps(1);
|
||||
assert_eq!(h.state().ui.views[0].zoom, zoom, "held dismissal press frame {i} must not zoom");
|
||||
}
|
||||
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().ui.views[0].zoom, zoom, "the dismissal release does not zoom either");
|
||||
}
|
||||
|
||||
/// #9832 (CodeRabbit): while the dismissal press stays down, the temporary Hand (Space) and the
|
||||
/// selected Hand must not pan either — the consumed gesture is inert until its release, and the
|
||||
/// pans read `response.dragged()` directly, so they need the gate up front.
|
||||
#[test]
|
||||
fn a_held_menu_dismissal_press_cannot_pan_the_view() {
|
||||
fn key(h: &mut Harness<'static, PhotocraftApp>, k: egui::Key, pressed: bool) {
|
||||
h.event(egui::Event::Key { key: k, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
}
|
||||
let mut h = zoom_harness(false);
|
||||
let (zoom, center0) = (h.state().ui.views[0].zoom, h.state().ui.views[0].center);
|
||||
let open_at = screen_of(h.state(), [300.0, 100.0]);
|
||||
right_click(&mut h, open_at, Modifiers::NONE);
|
||||
assert!(h.state().ui.canvas_tool_menu.is_some(), "right-click opens the view menu");
|
||||
// The dismissal press: the menu goes, and the button stays down.
|
||||
let far = dismissal_point(&h);
|
||||
h.event(egui::Event::PointerMoved(far));
|
||||
h.run_steps(1);
|
||||
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
assert!(h.state().ui.canvas_tool_menu.is_none(), "the outside press dismisses the menu");
|
||||
// Hold Space: the temporary Hand arms, but dragging must not pan the view.
|
||||
key(&mut h, egui::Key::Space, true);
|
||||
assert_eq!(crate::input::hold_keys::held_tool(h.state(), &h.ctx), Some(crate::input::hold_keys::Temporary::Hand), "Space arms the temporary hand");
|
||||
h.event(egui::Event::PointerMoved(far + vec2(120.0, -60.0)));
|
||||
h.run_steps(2);
|
||||
h.event(egui::Event::PointerMoved(far + vec2(240.0, -120.0)));
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().ui.views[0].center, center0, "a held dismissal press must not pan the view");
|
||||
assert_eq!(h.state().ui.views[0].zoom, zoom);
|
||||
// Release both: an ordinary Hand drag pans again, the flag did not stick.
|
||||
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
key(&mut h, egui::Key::Space, false);
|
||||
h.state_mut().ui.tool = Tool::Hand;
|
||||
h.run_steps(1);
|
||||
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
h.event(egui::Event::PointerMoved(far + vec2(100.0, 50.0)));
|
||||
h.run_steps(2);
|
||||
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(2);
|
||||
assert_ne!(h.state().ui.views[0].center, center0, "an ordinary Hand drag pans the view again");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn view_menu_zoom_in_keeps_the_view_centre() {
|
||||
let mut app = zoom_app(400, 300);
|
||||
|
||||
@@ -342,6 +342,10 @@ pub struct UiState {
|
||||
/// Selection-tool context menu opened by a plain canvas right-click.
|
||||
#[serde(default)]
|
||||
pub canvas_tool_menu: Option<crate::canvas_tool_menu::CanvasToolMenu>,
|
||||
/// An outside press dismissed the canvas tool menu; suppress the corresponding
|
||||
/// release click from triggering a tool action.
|
||||
#[serde(default)]
|
||||
pub canvas_tool_menu_dismissed: bool,
|
||||
/// The guide a Move-tool click selected (`guide_select`): drawn blue, Delete removes it.
|
||||
#[serde(default)]
|
||||
pub selected_guide: Option<crate::guide_select::SelectedGuide>,
|
||||
@@ -595,6 +599,7 @@ impl Default for UiState {
|
||||
color_hud: None,
|
||||
layer_menu: None,
|
||||
canvas_tool_menu: None,
|
||||
canvas_tool_menu_dismissed: false,
|
||||
selected_guide: None,
|
||||
brush_tool: Tool::Brush,
|
||||
tool_brushes: Vec::new(),
|
||||
|
||||
@@ -524,3 +524,39 @@ fn alt_clicking_narrow_and_rotated_polygons_keeps_the_fourth_corner() {
|
||||
assert!(app.session.active().unwrap().doc.selection.is_some());
|
||||
}
|
||||
}
|
||||
|
||||
/// #9841: the Lasso reads its own raw pointer events (`lasso_ui::canvas_input`), so the
|
||||
/// `Buttons` starvation the other tools get does not reach it. A press that dismisses the
|
||||
/// canvas tool menu must not draw a Lasso selection, and the next ordinary drag must work.
|
||||
#[test]
|
||||
fn a_menu_dismissal_press_never_draws_a_lasso_selection() {
|
||||
let mut h = harness();
|
||||
// Right-click on the canvas: the selection menu opens.
|
||||
let menu_at = crate::canvas::ViewXform::active(h.state()).unwrap().to_screen(300.0, 100.0);
|
||||
h.event(Event::PointerMoved(menu_at));
|
||||
h.run_steps(1);
|
||||
h.event(Event::PointerButton { pos: menu_at, button: PointerButton::Secondary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
h.event(Event::PointerButton { pos: menu_at, button: PointerButton::Secondary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(2);
|
||||
assert!(h.state().ui.canvas_tool_menu.is_some(), "right-click opens the selection menu");
|
||||
let revision = h.state().session.active().unwrap().revision;
|
||||
// The dismissal press and drag, well clear of the menu.
|
||||
mouse(&mut h, "down", 50.0, 250.0, Modifiers::NONE);
|
||||
assert!(h.state().ui.canvas_tool_menu.is_none(), "the outside press dismisses the menu");
|
||||
mouse(&mut h, "move", 50.0, 200.0, Modifiers::NONE);
|
||||
mouse(&mut h, "move", 150.0, 200.0, Modifiers::NONE);
|
||||
mouse(&mut h, "move", 150.0, 250.0, Modifiers::NONE);
|
||||
mouse(&mut h, "up", 150.0, 250.0, Modifiers::NONE);
|
||||
h.run_steps(2);
|
||||
assert!(h.state().drag.is_none(), "the consumed gesture must not leave a Lasso drag behind");
|
||||
assert!(h.state().session.active().unwrap().doc.selection.is_none(), "the consumed gesture must draw no selection");
|
||||
assert_eq!(h.state().session.active().unwrap().revision, revision, "and no history step");
|
||||
// The next ordinary drag draws one, so the guard did not stick.
|
||||
mouse(&mut h, "down", 50.0, 50.0, Modifiers::NONE);
|
||||
mouse(&mut h, "move", 90.0, 40.0, Modifiers::NONE);
|
||||
mouse(&mut h, "move", 150.0, 60.0, Modifiers::NONE);
|
||||
mouse(&mut h, "up", 150.0, 60.0, Modifiers::NONE);
|
||||
h.run_steps(2);
|
||||
assert!(h.state().session.active().unwrap().doc.selection.is_some(), "an ordinary Lasso drag draws again");
|
||||
}
|
||||
@@ -418,6 +418,44 @@ fn on_the_canvas_the_border_follows_the_hovering_pointer_and_keys_work() {
|
||||
assert!((area - 5600.0).abs() < 120.0, "{area}");
|
||||
}
|
||||
|
||||
/// #9841: the hover moves are a pointer-only gesture. Two things must hold: they keep running on
|
||||
/// frames with no button event at all (the freeze the main-merge regression reintroduced), and a
|
||||
/// consumed menu-dismissal gesture must not track the pointer.
|
||||
///
|
||||
/// A canvas menu cannot be open over a live border — `canvas_tool_menu::magnetic_drawing` refuses
|
||||
/// one for a Magnetic Lasso border in progress (#11689), on the canvas and through the control
|
||||
/// channel alike — so the `menu_dismiss_press` check on the hover block is a guard rather than a
|
||||
/// sequence a pointer can reach. The dismissal state is staged directly here, with the button held
|
||||
/// as the real gesture has it: the flag is scoped to a held button (a frame with every button up
|
||||
/// clears it), so a pointer-up frame would clear it before the gate reads it and test nothing.
|
||||
#[test]
|
||||
fn on_the_canvas_hover_moves_survive_a_menu_dismissal_and_resume() {
|
||||
let mut h = harness();
|
||||
ui_click(&mut h, 52.0, 37.0);
|
||||
assert!(h.state().ui.magnetic.active());
|
||||
h.run_steps(2);
|
||||
// Button up: the border follows the pointer with no button event at all.
|
||||
ui_hover(&mut h, &[[52.0, 37.0], [100.0, 36.0]]);
|
||||
let m = &h.state().ui.magnetic;
|
||||
let end = m.live.last().or(m.path.last()).copied().unwrap();
|
||||
assert!((end[0] - 100.0).abs() < 1.5 && (end[1] - 40.0).abs() < 0.01, "hover tracks with the button up: {end:?}");
|
||||
// A consumed dismissal gesture with its button still down: the hover must not advance.
|
||||
let far = screen(&h, 150.0, 130.0);
|
||||
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
h.state_mut().ui.canvas_tool_menu_dismissed = true;
|
||||
let held = h.state().ui.magnetic.clone();
|
||||
ui_hover(&mut h, &[[100.0, 36.0], [130.0, 36.0]]);
|
||||
assert_eq!(h.state().ui.magnetic, held, "a consumed dismissal gesture must not track the pointer");
|
||||
// Released: the very next pointer move tracks again.
|
||||
h.event(egui::Event::PointerButton { pos: far, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(2);
|
||||
ui_hover(&mut h, &[[130.0, 36.0], [120.0, 36.0]]);
|
||||
let m = &h.state().ui.magnetic;
|
||||
let end = m.live.last().or(m.path.last()).copied().unwrap();
|
||||
assert!((end[0] - 120.0).abs() < 1.5 && (end[1] - 40.0).abs() < 0.01, "hover resumes once released: {end:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn on_the_canvas_a_double_click_closes_the_border() {
|
||||
let mut h = harness();
|
||||
|
||||
Reference in new issue
Block a user