* claim: #6657 * Context menu: the Appearance flyout closes when the pointer moves to another row (#6657) Hovering Appearance opened its quick-choice flyout, but resting on a plain row of the same menu never closed it: only another submenu row replaced it. Now a flyout closes once the pointer moves onto another row and rests there for 0.3 s, so a diagonal path to the flyout across a neighbour keeps it open. A flyout opened with the keys stays open while the pointer is still. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -202,6 +202,9 @@ pub struct MenuState {
|
||||
pub key_row: Option<usize>,
|
||||
submenu: Option<usize>,
|
||||
submenu_key: Option<usize>,
|
||||
/// When the pointer came to rest on another row while a flyout was open (it closes the
|
||||
/// flyout after [`SUBMENU_CLOSE_DELAY`]).
|
||||
submenu_leave: Option<f64>,
|
||||
/// The radial ring is shown (viewport menus).
|
||||
pub radial: bool,
|
||||
/// The right button is held through the menu: releasing over a direction picks it.
|
||||
@@ -262,6 +265,9 @@ const DIRS: usize = 8;
|
||||
/// Half axes of the ring of radial items.
|
||||
const RX: f32 = crate::ui_kit::RADIAL_RADIUS;
|
||||
const RY: f32 = crate::ui_kit::RADIAL_RADIUS;
|
||||
/// Seconds the pointer rests on another row before an open flyout closes: a path to the flyout
|
||||
/// that crosses a neighbouring row keeps it open.
|
||||
const SUBMENU_CLOSE_DELAY: f64 = 0.3;
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// What the menus offer
|
||||
@@ -1678,6 +1684,7 @@ pub fn open_for(app: &mut SolveApp, at: Pos2, target: Target) {
|
||||
app.menu.key_row = None;
|
||||
app.menu.submenu = None;
|
||||
app.menu.submenu_key = None;
|
||||
app.menu.submenu_leave = None;
|
||||
app.menu.radial = target == Target::Viewport && app.preferences.radial_context_menu;
|
||||
app.menu.target = target;
|
||||
app.menu.flick = false;
|
||||
@@ -1937,6 +1944,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
app.menu.submenu_key = None;
|
||||
}
|
||||
let mut submenu_row = None;
|
||||
let mut other_row = false;
|
||||
let key_row = app.menu.key_row;
|
||||
let resp = Container::new(ctx, Surface::Popup)
|
||||
.area(egui::Id::new("sc_context_menu"))
|
||||
@@ -1949,10 +1957,14 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
} else {
|
||||
menu_frame(ui, |ui| {
|
||||
for (k, item) in list.iter().enumerate() {
|
||||
if item.children.is_empty() {
|
||||
if let Some(p) = list_row_lit(ui, item, key_row == Some(k)) {
|
||||
picked = Some(p);
|
||||
if item.is_sep() || item.is_heading() {
|
||||
let _ = list_row_lit(ui, item, false);
|
||||
} else if item.children.is_empty() {
|
||||
let row = kit_item(item, key_row == Some(k)).show(ui);
|
||||
if row.clicked() && item.enabled {
|
||||
picked = Some(item.clone());
|
||||
}
|
||||
other_row |= row.hovered();
|
||||
} else {
|
||||
let row = kit_item(item, key_row == Some(k) || app.menu.submenu == Some(k)).show(ui);
|
||||
if item.enabled && ((row.hovered() && ctx.input(|i| i.pointer.delta() != Vec2::ZERO)) || row.clicked()) {
|
||||
@@ -1971,6 +1983,25 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
});
|
||||
inside |= resp.response.contains_pointer() || resp.response.rect.contains(pointer.unwrap_or(Pos2::ZERO));
|
||||
|
||||
// A flyout closes once the pointer moves on to another row of its menu and rests there
|
||||
// (#6657). A pointer that is still (the flyout opened with the keys) leaves it open.
|
||||
let moved = ctx.input(|i| i.pointer.delta() != Vec2::ZERO);
|
||||
if app.menu.submenu.is_some() && other_row && (moved || app.menu.submenu_leave.is_some()) {
|
||||
let now = ctx.input(|i| i.time);
|
||||
let since = *app.menu.submenu_leave.get_or_insert(now);
|
||||
let left = SUBMENU_CLOSE_DELAY - (now - since);
|
||||
if left <= 0.0 || !left.is_finite() {
|
||||
app.menu.submenu = None;
|
||||
app.menu.submenu_key = None;
|
||||
app.menu.submenu_leave = None;
|
||||
submenu_row = None;
|
||||
} else {
|
||||
ctx.request_repaint_after(std::time::Duration::from_secs_f64(left));
|
||||
}
|
||||
} else {
|
||||
app.menu.submenu_leave = None;
|
||||
}
|
||||
|
||||
if let Some((k, row)) = submenu_row
|
||||
&& let Some(parent) = list.get(k)
|
||||
{
|
||||
|
||||
@@ -1337,6 +1337,38 @@ fn appearance_submenu_keyboard_opens_beside_parent_and_left_returns_to_it() {
|
||||
assert!(h.app.viewport.context_menu.is_none());
|
||||
}
|
||||
|
||||
/// The Appearance flyout opened by hovering its row closes once the pointer moves to another
|
||||
/// row of the same menu (#6657).
|
||||
#[test]
|
||||
fn appearance_submenu_closes_when_the_pointer_moves_to_another_row() {
|
||||
use crate::scenario::{Harness, rect_of};
|
||||
let mut h = Harness::new();
|
||||
h.app = sample_app();
|
||||
h.frames(3);
|
||||
let target = Target::Body { name: body(&h.app) };
|
||||
let rows = context_menu::items(&h.app, &target);
|
||||
context_menu::open_for(&mut h.app, pos2(400.0, 180.0), target);
|
||||
h.frames(2);
|
||||
let flyout = "menu:appearance.assign:Aluminum - Satin";
|
||||
h.step(&json!({"move":[10, 10]})).unwrap();
|
||||
h.step(&json!({"move":{"handle":"menu:ui.appearance"}})).unwrap();
|
||||
h.frames(2);
|
||||
assert!(rect_of(flyout).is_some(), "hovering Appearance opens its flyout");
|
||||
let other = rows.iter().find(|i| i.enabled && i.children.is_empty()).unwrap();
|
||||
h.step(&json!({"move":{"handle":format!("menu:{}", other.id)}})).unwrap();
|
||||
h.frames(2);
|
||||
assert!(rect_of(flyout).is_some(), "passing over {} on the way keeps the flyout for a moment", other.label);
|
||||
h.frames(30);
|
||||
assert!(rect_of(flyout).is_none(), "resting on {} closes the Appearance flyout", other.label);
|
||||
assert!(h.app.viewport.context_menu.is_some(), "the menu itself stays open");
|
||||
h.step(&json!({"move":{"handle":"menu:ui.appearance"}})).unwrap();
|
||||
h.frames(2);
|
||||
assert!(rect_of(flyout).is_some(), "hovering Appearance again reopens it");
|
||||
h.step(&json!({"key":"Escape"})).unwrap();
|
||||
assert!(h.app.viewport.context_menu.is_none());
|
||||
assert!(h.app.dialog.is_none(), "closing the flyout runs nothing");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn narrow_overflow_submenu_keeps_opening_click_and_accepts_the_next_click() {
|
||||
use crate::scenario::Harness;
|
||||
|
||||
Reference in New Issue
Block a user