diff --git a/assets/locales/pending/ribbon-panel-hover.json b/assets/locales/pending/ribbon-panel-hover.json new file mode 100644 index 000000000..f7fd88e09 --- /dev/null +++ b/assets/locales/pending/ribbon-panel-hover.json @@ -0,0 +1,34 @@ +{ + "ar": { + "prefs.layout_page.hover_panel_menus": "تبديل قوائم اللوحات عند مرور المؤشر", + "prefs.layout_page.hover_panel_menus_help": "انقر على اسم لوحة في الشريط لفتح قائمتها. مرّر المؤشر فوق اسم لوحة أخرى للتبديل. حرّك المؤشر خارج الشريط والقائمة المفتوحة لإغلاقها." + }, + "de": { + "prefs.layout_page.hover_panel_menus": "Bereichsmenüs beim Darüberfahren wechseln", + "prefs.layout_page.hover_panel_menus_help": "Klicken Sie auf einen Bereichsnamen, um das Menü zu öffnen. Bewegen Sie den Zeiger auf einen anderen Bereichsnamen, um das Menü zu wechseln. Außerhalb des Menübands und des geöffneten Menüs schließt es sich." + }, + "en": { + "prefs.layout_page.hover_panel_menus": "Switch panel menus on hover", + "prefs.layout_page.hover_panel_menus_help": "Click a ribbon panel name to open its menu. Hover another panel name to switch. Move outside the ribbon and open menu to close it." + }, + "he": { + "prefs.layout_page.hover_panel_menus": "מעבר בין תפריטי לוחות בריחוף", + "prefs.layout_page.hover_panel_menus_help": "לחצו על שם לוח ברצועת הכלים כדי לפתוח את התפריט שלו. העבירו את הסמן מעל שם של לוח אחר כדי לעבור לתפריט שלו. הזיזו את הסמן אל מחוץ לרצועת הכלים ולתפריט הפתוח כדי לסגור אותו." + }, + "ja": { + "prefs.layout_page.hover_panel_menus": "ポイントしてパネルメニューを切り替える", + "prefs.layout_page.hover_panel_menus_help": "リボンのパネル名をクリックしてメニューを開きます。別のパネル名にポインターを合わせると切り替わります。リボンと開いているメニューの外に移動すると閉じます。" + }, + "ko": { + "prefs.layout_page.hover_panel_menus": "포인터를 올려 패널 메뉴 전환", + "prefs.layout_page.hover_panel_menus_help": "리본의 패널 이름을 클릭하여 메뉴를 엽니다. 다른 패널 이름에 포인터를 올리면 메뉴가 전환됩니다. 리본과 열린 메뉴 밖으로 포인터를 이동하면 메뉴가 닫힙니다." + }, + "vi": { + "prefs.layout_page.hover_panel_menus": "Chuyển menu nhóm khi di chuột", + "prefs.layout_page.hover_panel_menus_help": "Nhấp vào tên nhóm trên dải công cụ để mở menu. Di chuột lên tên nhóm khác để chuyển menu. Di chuyển con trỏ ra ngoài dải công cụ và menu đang mở để đóng menu." + }, + "zh": { + "prefs.layout_page.hover_panel_menus": "悬停切换面板菜单", + "prefs.layout_page.hover_panel_menus_help": "点击功能区的面板名称打开菜单。将指针悬停在另一面板名称上即可切换菜单。将指针移到功能区和已打开菜单之外即可关闭菜单。" + } +} diff --git a/attribution/pending/ribbon-panel-hover.md b/attribution/pending/ribbon-panel-hover.md new file mode 100644 index 000000000..ff49db4db --- /dev/null +++ b/attribution/pending/ribbon-panel-hover.md @@ -0,0 +1 @@ +| assets/locales/pending/ribbon-panel-hover.json | SolidCraft contributors | Original ribbon panel menu preference labels and translations | MIT OR Apache-2.0 | diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index cdee926a5..1ad52ca80 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -1311,6 +1311,8 @@ preference_settings! { /// Show the ribbon's panel drop-downs as a grid of large icons, their names in the tooltips, /// instead of a list of small icons with names (#4739). ribbon_icon_grid: bool = false, PAGE_LAYOUT; + /// After a ribbon panel menu is open, hover another panel to switch to its menu. + ribbon_menus_follow_hover: bool = false, PAGE_LAYOUT; /// Leave the commands the ribbon shows as buttons (pinned ones) out of its panel drop-downs, /// which then list only the rest (#4739). ribbon_menus_skip_pinned: bool = false, PAGE_LAYOUT; @@ -6108,6 +6110,7 @@ mod tests { ("dialog_buttons", json!("top"), PAGE_LAYOUT), ("toast_place", json!("centre"), PAGE_LAYOUT), ("ribbon_icon_grid", json!(true), PAGE_LAYOUT), + ("ribbon_menus_follow_hover", json!(true), PAGE_LAYOUT), ("ribbon_menus_skip_pinned", json!(true), PAGE_LAYOUT), ("timeline_left", json!(true), PAGE_LAYOUT), ("timeline_under_browser", json!(true), PAGE_LAYOUT), diff --git a/crates/ui-egui/src/prefs/interface.rs b/crates/ui-egui/src/prefs/interface.rs index 9421717a6..6e75c0393 100644 --- a/crates/ui-egui/src/prefs/interface.rs +++ b/crates/ui-egui/src/prefs/interface.rs @@ -499,6 +499,7 @@ pub(super) fn layout(app: &mut SolveApp, ui: &mut egui::Ui) { app.tr("prefs.layout_page.active_commands"), app.tr("prefs.ribbon_reveal"), app.tr("prefs.layout_page.pinned_menus"), + app.tr("prefs.layout_page.hover_panel_menus"), ]; let widest = labels.iter().map(|label| ui_kit::ContentWidth::label(ui, label)).fold(0.0, f32::max) + t.space_14 + t.space_6 * 2.0 + t.space_16; @@ -506,10 +507,10 @@ pub(super) fn layout(app: &mut SolveApp, ui: &mut egui::Ui) { let width = (ui.available_width() - t.space_16 * (columns - 1) as f32) / columns as f32; ui.scope(|ui| { ui.spacing_mut().item_spacing.y = t.space_6; - for row in (0..4).step_by(columns) { + for row in (0..labels.len()).step_by(columns) { ui.horizontal_top(|ui| { ui.spacing_mut().item_spacing.x = t.space_16; - for index in row..(row + columns).min(4) { + for index in row..(row + columns).min(labels.len()) { ui.allocate_ui_with_layout( egui::vec2(width.max(0.0), t.control_height), egui::Layout::top_down(egui::Align::Min), @@ -550,6 +551,15 @@ pub(super) fn layout(app: &mut SolveApp, ui: &mut egui::Ui) { "ribbon_menus_skip_pinned", ); } + 4 => { + layout_check( + ui, + app.tr("prefs.layout_page.hover_panel_menus"), + app.tr("prefs.layout_page.hover_panel_menus_help"), + &mut app.preferences.ribbon_menus_follow_hover, + "ribbon_menus_follow_hover", + ); + } _ => {} }, ); diff --git a/crates/ui-egui/src/settings_profiles.rs b/crates/ui-egui/src/settings_profiles.rs index 779a07fc9..297c88931 100644 --- a/crates/ui-egui/src/settings_profiles.rs +++ b/crates/ui-egui/src/settings_profiles.rs @@ -38,9 +38,9 @@ const MAX_THEMES: usize = 4; /// Most characters in a command id or a key name. const MAX_ID: usize = 200; -/// The 98 stored keys selected dynamically before the split: Interface, Navigation and Sketch, plus -/// language, excluding space_mouse_* and orbit_cursor. Page moves and title tags must never -/// change profile contents (including the bridge, origin names and direct interaction). +/// The original 98 Interface, Navigation, Sketch and language keys, plus explicitly added +/// settings. Device-specific space_mouse_* and orbit_cursor stay outside profiles. Page moves +/// and title tags never remove stored keys such as the bridge, origin names and direct interaction. const PROFILE_KEYS: &[&str] = &[ "browser_bodies_folders", "browser_collapsed", @@ -93,6 +93,7 @@ const PROFILE_KEYS: &[&str] = &[ "ribbon_click_ends_tool", "ribbon_icon_grid", "ribbon_labels", + "ribbon_menus_follow_hover", "ribbon_menus_skip_pinned", "ribbon_reveal", "right_drag_orbits", diff --git a/crates/ui-egui/src/settings_profiles_tests.rs b/crates/ui-egui/src/settings_profiles_tests.rs index 09186542d..b099f6cc5 100644 --- a/crates/ui-egui/src/settings_profiles_tests.rs +++ b/crates/ui-egui/src/settings_profiles_tests.rs @@ -17,7 +17,7 @@ fn error(h: &mut Harness, id: &str, params: Value) -> String { #[test] fn a_profile_holds_input_and_interface_settings_but_not_the_machine() { let keys: Vec<&str> = keys().collect(); - assert_eq!(keys.len(), 98, "page presentation must not alter profile membership"); + assert_eq!(keys.len(), 99, "page presentation must not alter profile membership"); for key in [ "nav", "mouse_gestures", @@ -739,7 +739,7 @@ fn general_profile_row_rename_keeps_validation_and_unchanged_name_noop() { } #[test] -fn profile_keys_preserve_the_literal_pre_split_baseline() { +fn profile_keys_preserve_the_baseline_and_explicit_additions() { let expected = [ "browser_bodies_folders", "browser_collapsed", @@ -792,6 +792,7 @@ fn profile_keys_preserve_the_literal_pre_split_baseline() { "ribbon_click_ends_tool", "ribbon_icon_grid", "ribbon_labels", + "ribbon_menus_follow_hover", "ribbon_menus_skip_pinned", "ribbon_reveal", "right_drag_orbits", @@ -842,7 +843,7 @@ fn profile_keys_preserve_the_literal_pre_split_baseline() { ]; let mut actual: Vec<_> = keys().collect(); actual.sort_unstable(); - assert_eq!(expected.len(), 98); + assert_eq!(expected.len(), 99); assert_eq!(actual, expected); } @@ -850,7 +851,7 @@ fn profile_keys_preserve_the_literal_pre_split_baseline() { fn moved_profile_settings_survive_saved_roundtrip_and_apply() { let mut h = Harness::new(); let defaults = crate::prefs::Prefs::default(); - assert!(!defaults.keep_work_on_tab_switch && !defaults.line_hover_tangent_arc); + assert!(!defaults.keep_work_on_tab_switch && !defaults.line_hover_tangent_arc && !defaults.ribbon_menus_follow_hover); for (key, page) in [("keep_work_on_tab_switch", crate::prefs::PAGE_LAYOUT), ("line_hover_tangent_arc", crate::prefs::PAGE_SKETCH)] { let homes: Vec<_> = crate::prefs::FIELD_PAGES.iter().filter_map(|(field, page)| (*field == key).then_some(*page)).collect(); assert_eq!(homes, [Some(page)], "{key} keeps its new page home"); @@ -867,6 +868,7 @@ fn moved_profile_settings_survive_saved_roundtrip_and_apply() { h.app.preferences.invert_navigator_arrows = true; h.app.preferences.home_fit_size = 0.5; h.app.preferences.ribbon_click_ends_tool = false; + h.app.preferences.ribbon_menus_follow_hover = true; h.app.preferences.sketch_face_activates_part = true; run(&mut h, "settings.profile.save", json!({"name":"Moved"})); let saved = h.app.settings_profiles.prefs(); @@ -878,6 +880,7 @@ fn moved_profile_settings_survive_saved_roundtrip_and_apply() { ("invert_navigator_arrows", json!(true)), ("navigator_fit", json!(true)), ("ribbon_click_ends_tool", json!(false)), + ("ribbon_menus_follow_hover", json!(true)), ("sketch_face_activates_part", json!(true)), ] { assert_eq!(doc["preferences"][key], value, "capture retains {key}"); @@ -906,10 +909,11 @@ fn moved_profile_settings_survive_saved_roundtrip_and_apply() { h.app.preferences.invert_navigator_arrows = defaults.invert_navigator_arrows; h.app.preferences.home_fit_size = defaults.home_fit_size; h.app.preferences.ribbon_click_ends_tool = defaults.ribbon_click_ends_tool; + h.app.preferences.ribbon_menus_follow_hover = defaults.ribbon_menus_follow_hover; h.app.preferences.sketch_face_activates_part = defaults.sketch_face_activates_part; let out = run(&mut h, "settings.profile.apply", json!({"name":"Moved"})); assert_eq!(out["skipped"], json!([])); - assert!(h.app.preferences.keep_work_on_tab_switch && h.app.preferences.line_hover_tangent_arc); + assert!(h.app.preferences.keep_work_on_tab_switch && h.app.preferences.line_hover_tangent_arc && h.app.preferences.ribbon_menus_follow_hover); assert_eq!(capture(&h.app, "Moved"), doc); for value in [0.05, 1.1] { let mut invalid = doc.clone(); diff --git a/crates/ui-egui/src/toolbar.rs b/crates/ui-egui/src/toolbar.rs index ba3bec49f..b627e76ee 100644 --- a/crates/ui-egui/src/toolbar.rs +++ b/crates/ui-egui/src/toolbar.rs @@ -1644,6 +1644,16 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) { let mut toggle: Option<&'static str> = None; // The open drop-down (a button dropped on it leaves the toolbar). let mut popup_rect: Option = None; + // Search can draw a preview of its own. Only the open panel menu follows the pointer. + let mut open_panel_menu = None; + let mut hovered_panel_menu = None; + let follow_panel_hover = app.preferences.ribbon_menus_follow_hover + && ui.input(|i| { + !i.pointer.any_down() + && i.events.iter().any(|e| matches!(e, egui::Event::PointerMoved(_) | egui::Event::PointerGone)) + && !i.events.iter().any(|e| matches!(e, egui::Event::Touch { .. })) + }) + && !egui::DragAndDrop::has_payload_of_type::(ui.ctx()); let mut overflow = Vec::new(); // Every panel with all its buttons (the user's pins have no cap); a toolbar too narrow // for them narrows the buttons, then trims panels into their drop-down and the » menu. @@ -1763,6 +1773,7 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) { let free_x = bx + buttons_width + BUTTON_GAP; let free = Rect::from_min_size(pos2(free_x, top + 2.0), vec2((px + width - 4.0 - free_x).max(0.0), button_height)); let fresp = ui.interact(free, ui.id().with(("panel_free", panel)), if collapsed { Sense::click() } else { Sense::hover() }); + let collapsed_hovered = collapsed && fresp.hovered(); let mut opened = false; if collapsed { // One button: the panel's first command's icon over a caret; it opens the @@ -2032,6 +2043,9 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) { let panel_open = ui.ctx().data(|d| d.get_temp::(egui::Id::new("sc_panel_open"))) == Some(popup_id); let accent = crate::theme::TabAccent::for_tab(&t, &tab); let hot = lresp.hovered() && enabled_panel; + if follow_panel_hover && enabled_panel && !finish && (hot || collapsed_hovered) { + hovered_panel_menu = Some(popup_id); + } if hidden_running && !panel_open { // Its command is running from the drop-down: the label shows it like a pressed button. painter.rect(lr, t.radius_sm, accent.soft, Stroke::new(1.0, accent.color), egui::StrokeKind::Inside); @@ -2179,6 +2193,9 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) { }); }); popup_rect = Some(area.response.rect); + if open { + open_panel_menu = Some((popup_id, area.response.rect)); + } crate::scenario::publish_rect("toolbar_dropdown", area.response.rect); // A drag out of the drop-down ends with a release elsewhere: not a click elsewhere. let dragging = egui::DragAndDrop::has_payload_of_type::(ui.ctx()); @@ -2241,6 +2258,31 @@ pub fn toolbar(app: &mut SolveApp, ui: &mut egui::Ui) { // dispatched their actions. No already-painted old analysis can survive replacement. paint_persistent_ribbon(app, ui, persistent_paints, &tab, "ribbon"); + if follow_panel_hover { + let ribbon = Rect::from_min_max(pos2(ribbon_left, r.top()), r.max); + let pointer = ui.input(|i| i.pointer.hover_pos()); + let changed = ui.ctx().data_mut(|d| { + let key = egui::Id::new("sc_panel_open"); + let Some(open) = d.get_temp::(key) else { return false }; + let menu = open_panel_menu.filter(|(id, _)| *id == open).map(|(_, rect)| rect); + let stays_open = + pointer.zip(menu).is_some_and(|(p, menu)| ribbon.expand(t.space_4).contains(p) || menu.expand(t.space_4).contains(p)); + if !stays_open { + d.remove::(key); + true + } else if let Some(hovered) = hovered_panel_menu.filter(|hovered| *hovered != open) { + // Change the id after drawing all panels, so only one menu is drawn per pass. + d.insert_temp(key, hovered); + true + } else { + false + } + }); + if changed { + ui.ctx().request_repaint(); + } + } + // Dragging a command: its icon follows the pointer; a toolbar button dragged off the // toolbar (or into the open drop-down) shows it will be removed. let pointer = ui.input(|i| i.pointer.latest_pos()); @@ -5131,6 +5173,48 @@ mod dropdown_toggle_tests { assert!(rect_of("toolbar_dropdown").is_none(), "the second click closes it"); } + #[test] + fn ribbon_panel_menus_follow_hover_only_after_click_and_only_when_enabled() { + for follow_hover in [false, true] { + let mut h = Harness::new(); + h.app.home.open = false; + h.call("ui.resize", json!({"width":1600,"height":1000})); + let prefs = h.call("ui.prefs", json!({"ribbon_menus_follow_hover":follow_hover})); + assert_eq!(prefs["result"]["ribbon_menus_follow_hover"], follow_hover); + let create = "panel:MODEL:CREATE"; + let modify = "panel:MODEL:MODIFY"; + let move_to = |h: &mut Harness, handle| { + h.step(&json!({"move":{"handle":handle}})).unwrap(); + h.frames(3); + }; + move_to(&mut h, create); + assert!(rect_of("toolbar_dropdown").is_none(), "hover alone never opens a menu"); + h.step(&json!({"click":{"handle":create}})).unwrap(); + h.frames(3); + let create_menu = rect_of("toolbar_dropdown").expect("Create menu"); + move_to(&mut h, "dropdown:solid.box"); + assert_eq!(rect_of("toolbar_dropdown"), Some(create_menu), "moving into the menu keeps it open"); + + move_to(&mut h, modify); + if follow_hover { + let modify_menu = rect_of("toolbar_dropdown").expect("Modify menu"); + assert!(modify_menu.left() > create_menu.left(), "hover switches to the panel on the right"); + move_to(&mut h, create); + assert_eq!(rect_of("toolbar_dropdown"), Some(create_menu), "hover also switches to the left"); + } else { + assert_eq!(rect_of("toolbar_dropdown"), Some(create_menu), "click-only mode ignores sibling hover"); + } + let outside = h.app.viewport.rect.unwrap().right_bottom() - egui::vec2(40.0, 60.0); + h.step(&json!({"move":[outside.x,outside.y]})).unwrap(); + h.frames(3); + assert_eq!(rect_of("toolbar_dropdown"), (!follow_hover).then_some(create_menu), "only hover mode closes on leaving"); + if follow_hover { + move_to(&mut h, modify); + assert!(rect_of("toolbar_dropdown").is_none(), "returning to the ribbon still needs a click"); + } + } + } + /// A click on the lit button of the sketch tool in use ends it, so clicks in the view select /// again and Ctrl+click adds lines to the selection (#10151); a constraint in the ribbon's /// grid ends the same way. With the preference off, the click starts the tool again. diff --git a/docs/book/src/guide/ui-tour.md b/docs/book/src/guide/ui-tour.md index 6a9d67468..39ecb9c79 100644 --- a/docs/book/src/guide/ui-tour.md +++ b/docs/book/src/guide/ui-tour.md @@ -23,11 +23,14 @@ view. ASSEMBLE, INSERT, INSPECT, MANAGE, VIEW and SHEET METAL) hold sections of commands. SKETCH appears while editing a sketch; SHEET METAL is always there and is highlighted for the active sheet body. Both select automatically when entered, and the other tabs remain available. Click a - panel's name for all its commands. Drag a command from the dropdown onto a panel's label + panel's name for all its commands. With **Switch panel menus on hover** enabled in + **Preferences > Layout > Toolbar tabs**, click once to open a menu, then hover another + panel's name to switch. Move outside the ribbon and open menu to close it. + Drag a command from the dropdown onto a panel's label or empty space to append it; the insertion line shows its destination. Drop onto an existing button to insert before it. Buttons can also move between panels, and the layout is saved. Click the **+** after the tabs, right-click a tab or empty toolbar space, or use - **Preferences > Interface > Toolbar tabs** to hide or restore tabs. Every existing tab, + **Preferences > Layout > Toolbar tabs** to hide or restore tabs. Every existing tab, including Sheet Metal and Weldments, stays visible by default. Tabs you hide stay hidden in every design until you show them again. Hidden tabs keep their customised buttons, commands in search and shortcuts; with all tabs hidden, **+** remains. diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 88b029b2c..899e7a3ff 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -755,6 +755,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own - `placement_handles` (default false: handles on the preview of a Rest, Boss or Snap Fit that move it across the model and turn it) - `print_face_highlight` (0…1, default 0.2: how strongly a print face is tinted and outlined in the view, #8429; 0 draws no highlight) - `quick_measure` (default false: the selection's length, area or distance in the view's bottom right corner, the rect `measure:quick`; #7000) +- `ribbon_menus_follow_hover` (default false). Click a ribbon panel label to open its menu. Hover another panel label to switch, or move outside the ribbon and open menu to close it. - `ribbon_reveal` (default false: hovering a result in Search commands switches the ribbon to the command's tab and marks its button, or opens the panel drop-down that holds it on its row, handle `ribbon:reveal`; leaving the results goes back to the tab before; a command started from the search blinks there, and a running command from a drop-down marks its panel label, `ribbon:running_section::
`, #7287) - `right_drag_orbits` (default true; false: a right drag the mouse preset would orbit leaves the camera alone, #6492) - `select_hidden_edges` (default false: v0.30.1 visible-only edge picking; true allows ordinary edge picks through faces in Shaded with hidden edges, including Fillet inputs; hidden bodies and section-clipped edges stay excluded)