Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge upstream main and restore toolbar press-drag flyout selection

Nigel Ihza Firdausyb314f9c565b5
diff --cc crates/ui-egui/src/panels.rs
index 4b7e58588,2ab7fbf79..fa6eedb3c
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@@ -76,18 -78,6 +78,17 @@@ fn visible_sections(hidden: &[String])
sections
}
- /// Opening by dragging requires leaving the original button while it remains held (#2301).
- fn tool_flyout_drag_open(dragged: bool, hovered: bool) -> bool {
- dragged && !hovered
++/// A primary-button gesture started on this tool; open only after it leaves its hit area.
++/// Using pointer origin rather than `Response::dragged` also works for click-only icon buttons.
++fn tool_flyout_drag_open(button: Rect, origin: Option<Pos2>, pointer: Option<Pos2>, primary_down: bool) -> bool {
++ primary_down && origin.is_some_and(|p| button.contains(p)) && pointer.is_some_and(|p| !button.contains(p))
+}
+
- /// A drag/hold started on the original tool button, not on a menu row. Select the
- /// row under the primary pointer release rather than waiting for `ir.clicked()`, which
- /// cannot fire when the pointer press occurred on the toolbar button (#2301).
- fn tool_flyout_release(row: Rect, pointer: Option<Pos2>, released: bool, from_origin: bool) -> bool {
- released && from_origin && pointer.is_some_and(|p| row.contains(p))
++/// A toolbar press cannot click a flyout row in egui because the press began elsewhere.
++fn tool_flyout_release(row: Rect, pointer: Option<Pos2>, released: bool, from_button: bool) -> bool {
++ released && from_button && pointer.is_some_and(|p| row.contains(p))
+}
+
pub fn toolbar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let t = Tokens::get(ui.ctx());
let (w1, bx, m) = if t.pro { (40.0, 30.0, 5i8) } else { (50.0, 36.0, 7i8) };
@@@ -129,198 -123,258 +134,267 @@@
if ui.input(|i| i.pointer.any_pressed()) {
ui.data_mut(|d| d.remove::<egui::Id>(held_id));
}
- egui::ScrollArea::vertical().id_salt("toolbar-columns").show(ui, |ui| {
- // Pro has no group dividers, so its two columns fill every row across groups.
- let sections: Vec<Vec<(usize, Vec<Tool>)>> = if t.pro { vec![sections.into_iter().flatten().collect()] } else { sections };
- for (si, section) in sections.iter().enumerate() {
- // Photoshop 2026 draws one uninterrupted column (no group dividers).
- if si > 0 && !t.pro {
- ui.add_space(4.0);
- let (r, _) = ui.allocate_exact_size(vec2(if double { bx * 2.0 + 2.0 } else { bx }, 1.0), Sense::hover());
- ui.painter().line_segment([r.left_center() + vec2(8.0, 0.0), r.right_center() - vec2(8.0, 0.0)], Stroke::new(1.0, t.separator));
- ui.add_space(4.0);
- }
- let rows: Vec<&[(usize, Vec<Tool>)]> = if double { section.chunks(2).collect() } else { section.chunks(1).collect() };
- for row in rows {
- ui.horizontal(|ui| {
- for (slot_index, slot) in row.iter() {
- let key = egui::Id::new(("tool-slot", *slot_index));
- let tool = slot_tool(ui, app.ui.tool, slot, key);
- let sel = slot.contains(&app.ui.tool);
- let tip = if tool.key() == '\0' { tl!(tool.label()).to_string() } else { format!("{} ({})", tl!(tool.label()), tool.key()) };
- let resp = icons::button(ui, icons::tool_icon(tool), bx, sel, &tip);
- if slot.len() > 1 {
- paint_toolbar_flyout_indicator(ui, &t, &resp);
- }
- if resp.clicked() && ui.data(|d| d.get_temp::<egui::Id>(held_id)) != Some(key) {
- app.ui.tool = tool;
- }
- // Double-clicking the Hand tool fits the image on screen (Photoshop).
- if resp.double_clicked() && tool == Tool::Hand {
- app.ui.tool = tool;
- // With no document open there is nothing to fit.
- let _ = app.run("view.fitOnScreen", json!({}));
- }
- // Double-clicking the Zoom tool zooms to 100% (Photoshop).
- if resp.double_clicked() && tool == Tool::Zoom {
- app.ui.tool = tool;
- // With no document open there is nothing to zoom.
- let _ = app.run("view.actualPixels", json!({}));
- }
- // Right-click, long-press, or drag off the tool button opens its flyout (Photoshop).
- let held_for =
- resp.is_pointer_button_down_on().then(|| ui.input(|i| i.pointer.press_start_time().map(|t0| i.time - t0))).flatten();
- if slot.len() > 1
- && let Some(seconds) = held_for
- && seconds < 0.35
- {
- ui.ctx().request_repaint_after(std::time::Duration::from_secs_f64(0.35 - seconds));
- }
- let long_press = held_for.is_some_and(|seconds| seconds >= 0.35);
- let drag_open = tool_flyout_drag_open(resp.dragged(), resp.hovered());
- if slot.len() > 1 && (resp.secondary_clicked() || long_press || drag_open) {
- ui.data_mut(|d| {
- d.insert_temp(flyout_id, (key, resp.rect));
- if long_press || drag_open {
- d.insert_temp(held_id, key);
- }
+ // No tool tooltips over an open flyout, or while a button is held to open one (#4450):
+ // Photoshop shows none there. (The flyout is our own Area, so egui's rule for popups
+ // doesn't hide them.)
+ let tool_tips = ui.data(|d| d.get_temp::<(egui::Id, Rect)>(flyout_id)).is_none() && !ui.input(|i| i.pointer.primary_down());
+ let ctx = ui.ctx().clone();
+ let footer = (if t.pro { 8.0 } else { 14.0 })
+ + chips_height(t.pro, t.round_chips, t.round_chips && double)
+ + if t.pro { 8.0 + if double { bx } else { bx * 2.0 + 3.0 } } else { 0.0 }
+ + 6.0;
+ // As tall as the tools, so the colour chips sit right under them (Photoshop); a column
+ // taller than the window scrolls and keeps the chips at the bottom.
+ egui::ScrollArea::vertical()
+ .id_salt("toolbar-columns")
+ .auto_shrink([false, true])
+ .max_height((ui.available_height() - footer).max(0.0))
+ .min_scrolled_height(0.0)
+ .show(ui, |ui| {
+ // Pro has no group dividers, so its two columns fill every row across groups.
+ let sections: Vec<Vec<(usize, Vec<Tool>)>> = if t.pro { vec![sections.into_iter().flatten().collect()] } else { sections };
+ for (si, section) in sections.iter().enumerate() {
+ // Photoshop 2026 draws one uninterrupted column (no group dividers).
+ if si > 0 && !t.pro {
+ ui.add_space(4.0);
+ let (r, _) = ui.allocate_exact_size(vec2(if double { bx * 2.0 + 2.0 } else { bx }, 1.0), Sense::hover());
+ ui.painter().line_segment([r.left_center() + vec2(8.0, 0.0), r.right_center() - vec2(8.0, 0.0)], Stroke::new(1.0, t.separator));
+ ui.add_space(4.0);
+ }
+ let rows: Vec<&[(usize, Vec<Tool>)]> = if double { section.chunks(2).collect() } else { section.chunks(1).collect() };
+ for row in rows {
+ ui.horizontal(|ui| {
+ for (slot_index, slot) in row.iter() {
+ let key = egui::Id::new(("tool-slot", *slot_index));
+ let tool = slot_tool(ui, app.ui.tool, slot, key);
+ let sel = slot.contains(&app.ui.tool);
+ let tip = match crate::tool_shortcuts::shortcut(app, tool) {
+ Some(sc) => format!("{} ({})", tl!(tool.label()), crate::shortcuts::pretty(&sc)),
+ None => tl!(tool.label()).to_string(),
+ };
+ let resp =
+ icons::button_with_icon_size_tip(ui, icons::tool_icon(tool), bx, toolbar_icon_size(bx, t.pro), sel, &tip, tool_tips);
+ if slot.len() > 1 {
+ paint_toolbar_flyout_indicator(ui, &t, &resp);
+ }
+ if resp.clicked() && ui.data(|d| d.get_temp::<egui::Id>(held_id)) != Some(key) {
+ app.ui.tool = tool;
+ }
+ // Double-clicking the Hand tool fits the image on screen (Photoshop).
+ if resp.double_clicked() && tool == Tool::Hand {
+ app.ui.tool = tool;
+ // With no document open there is nothing to fit.
+ let _ = app.run("view.fitOnScreen", json!({}));
+ }
+ if resp.double_clicked() && tool == Tool::Zoom {
+ app.ui.tool = tool;
+ let _ = app.run("view.actualPixels", json!({}));
+ }
- // Right-click or long-press opens the flyout (Photoshop).
++ // Right-click, long-press, or press-drag away opens the flyout (Photoshop).
+ let held_for =
+ resp.is_pointer_button_down_on().then(|| ui.input(|i| i.pointer.press_start_time().map(|t0| i.time - t0))).flatten();
+ if slot.len() > 1
+ && let Some(seconds) = held_for
+ && seconds < 0.35
+ {
+ ui.ctx().request_repaint_after(std::time::Duration::from_secs_f64(0.35 - seconds));
+ }
+ let long_press = held_for.is_some_and(|seconds| seconds >= 0.35);
- if slot.len() > 1 && (resp.secondary_clicked() || long_press) {
++ let drag_open = ui.input(|i| {
++ tool_flyout_drag_open(resp.rect, i.pointer.press_origin(), i.pointer.hover_pos(), i.pointer.primary_down())
+ });
- }
- if slot.len() > 1 && long_press {
- ui.ctx().request_repaint();
- }
- if let Some((open_key, anchor)) = ui.data(|d| d.get_temp::<(egui::Id, Rect)>(flyout_id))
- && open_key == key
- {
- let area = egui::Area::new(key.with("flyout"))
- .order(egui::Order::Foreground)
- .fixed_pos(anchor.right_top() + vec2(6.0, 0.0))
- .show(ui.ctx(), |ui| {
- egui::Frame::popup(ui.style()).show(ui, |ui| {
- let label_w = slot
- .iter()
- .map(|it| {
- ui.painter()
- .layout_no_wrap(tl!(it.label()).to_string(), egui::FontId::proportional(12.5), t.text)
- .size()
- .x
- })
- .fold(0.0f32, f32::max);
- let fw = (label_w + 42.0 + 40.0).max(180.0);
- for &item in slot.iter() {
- let (r, ir) = ui.allocate_exact_size(vec2(fw, 26.0), Sense::click());
- if ir.hovered() {
- ui.painter().rect_filled(r, 3.0, t.hover);
- }
- if item == tool {
- ui.painter().rect_filled(
- Rect::from_center_size(pos2(r.left() + 8.0, r.center().y), vec2(4.0, 4.0)),
- 0.0,
- t.text,
++ if slot.len() > 1 && (resp.secondary_clicked() || long_press || drag_open) {
+ ui.data_mut(|d| {
+ d.insert_temp(flyout_id, (key, resp.rect));
- if long_press {
++ if long_press || drag_open {
+ d.insert_temp(held_id, key);
+ }
+ });
+ }
+ if slot.len() > 1 && long_press {
+ // Holding a tool button selects the tool it shows, as a click would (#4453).
+ app.ui.tool = tool;
+ ui.ctx().request_repaint();
+ }
+ if let Some((open_key, anchor)) = ui.data(|d| d.get_temp::<(egui::Id, Rect)>(flyout_id))
+ && open_key == key
+ {
+ // Beside the tool, towards the canvas.
+ let (pivot, pos) = if crate::direction::is_rtl() {
+ (egui::Align2::RIGHT_TOP, anchor.left_top() - vec2(6.0, 0.0))
+ } else {
+ (egui::Align2::LEFT_TOP, anchor.right_top() + vec2(6.0, 0.0))
+ };
+ let area = egui::Area::new(key.with("flyout")).order(egui::Order::Foreground).pivot(pivot).fixed_pos(pos).show(
+ ui.ctx(),
+ |ui| {
+ egui::Frame::popup(ui.style()).show(ui, |ui| {
+ let label_w = slot
+ .iter()
+ .map(|it| {
+ ui.painter()
+ .layout_no_wrap(tl!(it.label()).to_string(), egui::FontId::proportional(12.5), t.text)
+ .size()
+ .x
+ })
+ .fold(0.0f32, f32::max);
+ let fw = (label_w + 42.0 + 40.0).max(180.0);
+ for &item in slot.iter() {
+ let (r, ir) = ui.allocate_exact_size(vec2(fw, 26.0), Sense::click());
+ if ir.hovered() {
+ ui.painter().rect_filled(r, 3.0, t.hover);
+ }
+ if item == tool {
+ ui.painter().rect_filled(
+ Rect::from_center_size(pos2(r.left() + 8.0, r.center().y), vec2(4.0, 4.0)),
+ 0.0,
+ t.text,
+ );
+ }
+ icons::paint(
+ ui,
+ Rect::from_center_size(pos2(r.left() + 26.0, r.center().y), vec2(18.0, 18.0)),
+ icons::tool_icon(item),
+ 14.0,
+ t.icon,
);
- }
- icons::paint(
- ui,
- Rect::from_center_size(pos2(r.left() + 26.0, r.center().y), vec2(18.0, 18.0)),
- icons::tool_icon(item),
- 14.0,
- t.icon,
- );
- ui.painter().text(
- pos2(r.left() + 42.0, r.center().y),
- Align2::LEFT_CENTER,
- tl!(item.label()),
- egui::FontId::proportional(12.5),
- t.text,
- );
- if item.key() != '\0' {
ui.painter().text(
- pos2(r.right() - 8.0, r.center().y),
- Align2::RIGHT_CENTER,
- item.key().to_string(),
- egui::FontId::proportional(12.0),
- t.text_dim,
+ pos2(r.left() + 42.0, r.center().y),
+ Align2::LEFT_CENTER,
+ tl!(item.label()),
+ egui::FontId::proportional(12.5),
+ t.text,
);
+ if let Some(sc) = crate::tool_shortcuts::shortcut(app, item) {
+ ui.painter().text(
+ pos2(r.right() - 8.0, r.center().y),
+ Align2::RIGHT_CENTER,
+ crate::shortcuts::pretty(&sc),
+ egui::FontId::proportional(12.0),
+ t.text_dim,
+ );
+ }
- if ir.clicked() {
++ let drag_release = tool_flyout_release(
++ r,
++ ui.input(|i| i.pointer.hover_pos()),
++ ui.input(|i| i.pointer.primary_released()),
++ ui.data(|d| d.get_temp::<egui::Id>(held_id)) == Some(key),
++ );
++ if ir.clicked() || drag_release {
+ app.ui.tool = item;
+ ui.data_mut(|d| d.remove::<(egui::Id, Rect)>(flyout_id));
+ }
}
- let release_from_origin = tool_flyout_release(
- r,
- ui.input(|i| i.pointer.hover_pos()),
- ui.input(|i| i.pointer.primary_released()),
- ui.data(|d| d.get_temp::<egui::Id>(held_id)) == Some(key),
- );
- if ir.clicked() || release_from_origin {
- app.ui.tool = item;
- ui.data_mut(|d| d.remove::<(egui::Id, Rect)>(flyout_id));
- }
- }
- });
+ });
+ },
+ );
+ // Any press outside the flyout and its button closes it, as in Photoshop: a
+ // drag on the canvas (cropping, painting) isn't a click (#4460).
+ let pressed_outside = ui.input(|i| {
+ i.pointer.any_pressed()
+ && i.pointer.press_origin().is_some_and(|p| !area.response.rect.contains(p) && !resp.rect.contains(p))
});
- let held_release = resp.clicked() && ui.data(|d| d.get_temp::<egui::Id>(held_id)) == Some(key);
- let clicked_outside = ui.input(|i| i.pointer.any_click()) && !held_release && !area.response.hovered() && !resp.hovered();
- if clicked_outside || ui.input(|i| i.key_pressed(egui::Key::Escape)) {
- ui.data_mut(|d| d.remove::<(egui::Id, Rect)>(flyout_id));
+ if pressed_outside || ui.input(|i| i.key_pressed(egui::Key::Escape)) {
+ ui.data_mut(|d| d.remove::<(egui::Id, Rect)>(flyout_id));
+ }
}
}
- }
- });
+ });
+ }
}
- }
- let ctx = ui.ctx().clone();
- if t.pro && icons::button(ui, "ellipsis", bx, false, tl!("Edit Toolbar…")).clicked() {
- let _ = crate::menus::invoke(app, &ctx, "edit.toolbar", json!({}));
- }
- ui.add_space(if t.pro { 8.0 } else { 14.0 });
- color_chips(app, ui, double);
- if t.pro {
- ui.add_space(8.0);
-
- let layout = if double { egui::Layout::left_to_right(egui::Align::Min) } else { egui::Layout::top_down(egui::Align::Min) };
+ if t.pro && icons::button(ui, "ellipsis", bx, false, tl!("Edit Toolbar…")).clicked() {
+ let _ = crate::menus::invoke(app, &ctx, "edit.toolbar", json!({}));
+ }
+ reveal_focused_control(ui);
+ });
+ ui.add_space(if t.pro { 8.0 } else { 14.0 });
+ color_chips(app, ui, double);
+ if t.pro {
+ ui.add_space(8.0);
- ui.with_layout(layout, |ui| {
- let quick_mask = app.session.active().is_some_and(|s| s.doc.quick_mask.is_some());
- if icons::button(
- ui,
- "square-dashed",
- bx,
- quick_mask,
- if quick_mask { tl!("Edit in Standard Mode (Q)") } else { tl!("Edit in Quick Mask Mode (Q)") },
- )
- .clicked()
- {
- let _ = crate::menus::invoke(app, &ctx, "select.editInQuickMaskMode", json!({}));
- }
- let sm = icons::button(ui, "app-window", bx, false, tl!("Change Screen Mode (F)"));
- paint_toolbar_flyout_indicator(ui, &t, &sm);
+ let layout = if double { egui::Layout::left_to_right(egui::Align::Min) } else { egui::Layout::top_down(egui::Align::Min) };
- if sm.clicked() {
- let _ = crate::menus::invoke(app, &ctx, "view.screenMode.cycle", json!({}));
- }
- // Right-click (or long-press) lists the modes, like Photoshop's flyout.
- egui::Popup::context_menu(&sm).show(|ui| {
- ui.set_min_width(220.0);
- for (id, label) in [
- ("view.screenMode.standard", tl!("Standard Screen Mode")),
- ("view.screenMode.fullScreenWithMenuBar", tl!("Full Screen Mode With Menu Bar")),
- ("view.screenMode.fullScreen", tl!("Full Screen Mode")),
- ] {
- let on = crate::view_cmds::checked(app, id).unwrap_or(false);
- if ui.add(egui::Button::selectable(on, label)).clicked() {
- let _ = crate::menus::invoke(app, &ctx, id, json!({}));
- ui.close();
- }
+ ui.with_layout(layout, |ui| {
+ let quick_mask = app.session.active().is_some_and(|s| s.doc.quick_mask.is_some());
+ if icons::button_with_icon_size_tip(
+ ui,
+ "square-dashed",
+ bx,
+ (bx * 0.52).round(),
+ quick_mask,
+ if quick_mask { tl!("Edit in Standard Mode (Q)") } else { tl!("Edit in Quick Mask Mode (Q)") },
+ tool_tips,
+ )
+ .clicked()
+ {
+ let _ = crate::menus::invoke(app, &ctx, "select.editInQuickMaskMode", json!({}));
+ }
+ let sm = icons::button_with_icon_size_tip(ui, "app-window", bx, (bx * 0.52).round(), false, tl!("Change Screen Mode (F)"), tool_tips);
+ paint_toolbar_flyout_indicator(ui, &t, &sm);
+
+ // Right-click, or click and hold like the tool flyouts (#4444), lists the modes,
+ // like Photoshop's flyout. The release that ends a hold doesn't cycle the mode.
+ let held_id = sm.id.with("held");
+ let was_held = ui.data(|d| d.get_temp::<bool>(held_id)).unwrap_or(false);
+ let held_for = sm.is_pointer_button_down_on().then(|| ui.input(|i| i.pointer.press_start_time().map(|t0| i.time - t0))).flatten();
+ if let Some(seconds) = held_for
+ && seconds < 0.35
+ {
+ ui.ctx().request_repaint_after(std::time::Duration::from_secs_f64(0.35 - seconds));
+ }
+ let long_press = !was_held && held_for.is_some_and(|seconds| seconds >= 0.35);
+ if long_press {
+ ui.data_mut(|d| d.insert_temp(held_id, true));
+ } else if was_held && !sm.is_pointer_button_down_on() {
+ ui.data_mut(|d| d.remove::<bool>(held_id));
+ }
+ let cycle = sm.clicked() && !was_held;
+ if cycle {
+ let _ = crate::menus::invoke(app, &ctx, "view.screenMode.cycle", json!({}));
+ }
+ let open = if sm.secondary_clicked() || long_press {
+ Some(egui::SetOpenCommand::Bool(true))
+ } else if cycle {
+ Some(egui::SetOpenCommand::Bool(false))
+ } else {
+ None
+ };
+ // The release ending the hold counts as a click; it mustn't close the list it opened.
+ let close = if was_held || long_press { egui::PopupCloseBehavior::IgnoreClicks } else { egui::PopupCloseBehavior::CloseOnClick };
+ egui::Popup::menu(&sm).open_memory(open).close_behavior(close).at_pointer_fixed().show(|ui| {
+ ui.set_min_width(220.0);
+ for (id, label) in [
+ ("view.screenMode.standard", tl!("Standard Screen Mode")),
+ ("view.screenMode.fullScreenWithMenuBar", tl!("Full Screen Mode With Menu Bar")),
+ ("view.screenMode.fullScreen", tl!("Full Screen Mode")),
+ ] {
+ let on = crate::view_cmds::checked(app, id).unwrap_or(false);
+ if ui.add(egui::Button::selectable(on, label)).clicked() {
+ let _ = crate::menus::invoke(app, &ctx, id, json!({}));
+ ui.close();
}
- });
+ }
});
- }
- });
- },
- );
+ });
+ }
+ });
+ }
+
+ /// Glyph size of a toolbar tool button. Pro fills two thirds of the button, close to Photoshop's
+ /// toolbar glyphs (#2665); the other themes keep the general icon-button proportion.
+ fn toolbar_icon_size(box_size: f32, pro: bool) -> f32 {
+ (box_size * if pro { 2.0 / 3.0 } else { 0.52 }).round()
}
- /// Paints a triangle on the bottom right corner of an icon button to indicate that a toolbar item has a submenu.
+ /// Paints a triangle on the bottom corner of an icon button that faces the canvas (bottom right,
+ /// bottom left in a right-to-left UI) to indicate that a toolbar item has a submenu.
pub fn paint_toolbar_flyout_indicator(ui: &mut egui::Ui, tokens: &Tokens, resp: &egui::Response) {
let r = resp.rect;
- let tri = vec![r.right_bottom() + vec2(-2.0, -2.0), r.right_bottom() + vec2(-6.0, -2.0), r.right_bottom() + vec2(-2.0, -6.0)];
+ let tri = if crate::direction::is_rtl() {
+ vec![r.left_bottom() + vec2(2.0, -2.0), r.left_bottom() + vec2(6.0, -2.0), r.left_bottom() + vec2(2.0, -6.0)]
+ } else {
+ vec![r.right_bottom() + vec2(-2.0, -2.0), r.right_bottom() + vec2(-6.0, -2.0), r.right_bottom() + vec2(-2.0, -6.0)]
+ };
ui.painter().add(egui::Shape::convex_polygon(tri, tokens.text_faint, Stroke::NONE));
}
@@@ -3946,6 -4722,6 +4742,78 @@@ mod swatch_type_tests
}
}
++#[cfg(test)]
++mod tool_flyout_drag_tests {
++ use super::*;
++
++ fn frame(app: &mut PhotocraftApp, ctx: &egui::Context, time: f64, events: Vec<egui::Event>) {
++ let mut out = ctx.run_ui(
++ egui::RawInput { time: Some(time), events, screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1200.0, 1800.0))), ..Default::default() },
++ |ui| toolbar(app, ui),
++ );
++ out.textures_delta.clear();
++ }
++
++ fn primary(pos: Pos2, pressed: bool) -> egui::Event {
++ egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }
++ }
++
++ #[test]
++ fn flyout_drag_only_opens_after_a_primary_press_leaves_its_button() {
++ let button = Rect::from_min_size(pos2(20.0, 20.0), vec2(36.0, 36.0));
++ let inside = button.center();
++ let outside = pos2(120.0, 34.0);
++ assert!(!tool_flyout_drag_open(button, Some(inside), Some(inside), true));
++ assert!(!tool_flyout_drag_open(button, Some(inside), Some(outside), false));
++ assert!(!tool_flyout_drag_open(button, Some(outside), Some(outside), true));
++ assert!(!tool_flyout_drag_open(button, None, Some(outside), true));
++ assert!(tool_flyout_drag_open(button, Some(inside), Some(outside), true));
++ let row = Rect::from_min_size(pos2(90.0, 20.0), vec2(160.0, 26.0));
++ assert!(tool_flyout_release(row, Some(row.center()), true, true));
++ assert!(!tool_flyout_release(row, Some(row.center()), false, true));
++ assert!(!tool_flyout_release(row, Some(row.center()), true, false));
++ assert!(!tool_flyout_release(row, Some(outside + vec2(0.0, 200.0)), true, true));
++ assert!(!tool_flyout_release(row, None, true, true));
++ }
++
++ /// #2301: the press begins on the toolbar button, not on a flyout row. No long-press
++ /// delay is needed; releasing over the second row picks it and closes the flyout.
++ #[test]
++ fn flyout_press_drag_release_selects_the_row_without_long_press() {
++ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
++ let ctx = egui::Context::default();
++ PhotocraftApp::setup_context(&ctx, crate::theme::ThemeKind::ALL[0]);
++ frame(&mut app, &ctx, 0.0, vec![]);
++ frame(&mut app, &ctx, 0.1, vec![]);
++ let slot_index = TOOL_SECTIONS.iter().flat_map(|section| section.iter()).position(|slot| slot.contains(&Tool::Brush)).unwrap();
++ let bx = if Tokens::get(&ctx).pro { 30.0 } else { 36.0 };
++ let mut buttons: Vec<Rect> = ctx.viewport(|v| {
++ v.prev_pass.widgets.layers().flat_map(|(_, w)| w.iter())
++ .filter(|w| w.rect.size() == egui::Vec2::splat(bx) && w.sense.senses_click())
++ .map(|w| w.rect).collect()
++ });
++ buttons.sort_by(|a, b| a.top().total_cmp(&b.top()));
++ let origin = buttons[slot_index].center();
++ let key = egui::Id::new(("tool-slot", slot_index));
++ let flyout_id = egui::Id::new("tool-flyout");
++ let initial = app.ui.tool;
++ frame(&mut app, &ctx, 1.0, vec![egui::Event::PointerMoved(origin), primary(origin, true)]);
++ assert!(ctx.data(|d| d.get_temp::<(egui::Id, Rect)>(flyout_id)).is_none());
++ // Move right of the icon, still held. The flyout must appear before 350 ms.
++ frame(&mut app, &ctx, 1.08, vec![egui::Event::PointerMoved(origin + vec2(bx + 70.0, 0.0))]);
++ assert_eq!(ctx.data(|d| d.get_temp::<(egui::Id, Rect)>(flyout_id)).map(|(id, _)| id), Some(key));
++ assert_eq!(app.ui.tool, initial, "drag-opening doesn't activate the starting tool");
++ let menu = ctx.memory(|m| m.area_rect(key.with("flyout"))).expect("flyout area");
++ let row = pos2(menu.left() + 65.0, menu.top() + 47.0);
++ frame(&mut app, &ctx, 1.12, vec![egui::Event::PointerMoved(row)]);
++ frame(&mut app, &ctx, 1.16, vec![primary(row, false)]);
++ assert_eq!(app.ui.tool, Tool::Pencil);
++ assert!(ctx.data(|d| d.get_temp::<(egui::Id, Rect)>(flyout_id)).is_none());
++ frame(&mut app, &ctx, 1.2, vec![]);
++ assert_eq!(app.ui.tool, Tool::Pencil, "the original button cannot activate on release");
++ }
++}
++
#[cfg(test)]
mod type_flyout_tests {
use super::*;