diff --git a/assets/locales/pending/toast-place.json b/assets/locales/pending/toast-place.json new file mode 100644 index 000000000..1a1f79810 --- /dev/null +++ b/assets/locales/pending/toast-place.json @@ -0,0 +1,42 @@ +{ + "en": { + "prefs.bottom_centre": "Bottom centre", + "prefs.bottom_right": "Bottom right", + "prefs.toast_place": "Notices" + }, + "ar": { + "prefs.bottom_centre": "أسفل الوسط", + "prefs.bottom_right": "أسفل اليمين", + "prefs.toast_place": "الإشعارات" + }, + "de": { + "prefs.bottom_centre": "Unten mittig", + "prefs.bottom_right": "Unten rechts", + "prefs.toast_place": "Hinweise" + }, + "he": { + "prefs.bottom_centre": "למטה במרכז", + "prefs.bottom_right": "למטה מימין", + "prefs.toast_place": "הודעות" + }, + "ja": { + "prefs.bottom_centre": "下中央", + "prefs.bottom_right": "右下", + "prefs.toast_place": "通知" + }, + "ko": { + "prefs.bottom_centre": "하단 가운데", + "prefs.bottom_right": "오른쪽 아래", + "prefs.toast_place": "알림" + }, + "vi": { + "prefs.bottom_centre": "Giữa phía dưới", + "prefs.bottom_right": "Góc dưới bên phải", + "prefs.toast_place": "Thông báo" + }, + "zh": { + "prefs.bottom_centre": "底部居中", + "prefs.bottom_right": "右下角", + "prefs.toast_place": "通知" + } +} diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 8a82c6aaf..89c658e3c 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -2377,6 +2377,7 @@ impl SolveApp { } self.ui.layout.publish(ui.ctx()); self.preferences.dialog_buttons.publish(ui.ctx()); + self.preferences.toast_place.publish(ui.ctx()); scenario::clear_handles(); self.poll_feature_edit(ui.ctx()); self.poll_deferred(ui.ctx()); diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index 746b4877e..3f97777b6 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -930,6 +930,9 @@ preference_settings! { sketch_tab_always: bool = false, PAGE_INTERFACE => check_id("prefs.sketch_tab_always"); /// Where a dialog's OK and Cancel sit: under its inputs (the default) or in its title row (#6708). dialog_buttons: crate::ui_kit::DialogButtons = Default::default(), PAGE_INTERFACE; + /// Where notices and offers stack: the view's bottom-right corner (the default) or the bottom + /// centre, as before #7893. + toast_place: crate::viewport::ToastPlace = Default::default(), PAGE_INTERFACE; /// Interface scale (1 = 100 %). ui_scale: f32 = 1.0, PAGE_INTERFACE, accept(0.5..=2.5); /// Interface font: an installed font family (or a font file), or empty for the built-in one @@ -4515,6 +4518,7 @@ mod tests { ("ribbon_labels", json!(false), PAGE_INTERFACE), ("sketch_tab_always", json!(true), PAGE_INTERFACE), ("dialog_buttons", json!("top"), PAGE_INTERFACE), + ("toast_place", json!("centre"), PAGE_INTERFACE), ("timeline_left", json!(true), PAGE_INTERFACE), ("timeline_under_browser", json!(true), PAGE_INTERFACE), ("history_sketches", json!("under_feature"), PAGE_INTERFACE), diff --git a/crates/ui-egui/src/prefs/interface.rs b/crates/ui-egui/src/prefs/interface.rs index 8e6f0605d..f992166a7 100644 --- a/crates/ui-egui/src/prefs/interface.rs +++ b/crates/ui-egui/src/prefs/interface.rs @@ -104,6 +104,22 @@ pub(super) fn interface(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) { crate::scenario::publish_handle(&format!("prefs:dialog_buttons:{key}"), at); } } + // Where notices and offers stack (#7893). + ui_kit::row(ui, app.tr("prefs.toast_place"), |ui| { + let places = [crate::viewport::ToastPlace::Corner, crate::viewport::ToastPlace::Centre]; + let mut selected = places.iter().position(|p| *p == app.preferences.toast_place).unwrap_or(0); + if ui_kit::segmented(ui, &mut selected, &[app.tr("prefs.bottom_right"), app.tr("prefs.bottom_centre")], Default::default()) + && let Some(place) = places.get(selected) + { + app.preferences.toast_place = *place; + } + }); + let row = app.tr("prefs.toast_place"); + for (label, key) in [("prefs.bottom_right", "corner"), ("prefs.bottom_centre", "centre")] { + if let Some(at) = crate::scenario::handle_at(&format!("dialog:{row}:{}", app.tr(label))) { + crate::scenario::publish_handle(&format!("prefs:toast_place:{key}"), at); + } + } ui_kit::row(ui, app.tr("prefs.history"), |ui| { let mut selected = if app.preferences.history_in_browser { 3 diff --git a/crates/ui-egui/src/sketch_corner_ui_tests.rs b/crates/ui-egui/src/sketch_corner_ui_tests.rs index bef5975d5..245c369f6 100644 --- a/crates/ui-egui/src/sketch_corner_ui_tests.rs +++ b/crates/ui-egui/src/sketch_corner_ui_tests.rs @@ -748,6 +748,10 @@ fn centre_circle_clicked_through_a_line_end_stays_on_it() { let sid = h.app.session.active_sketch.unwrap(); h.step(&json!({"start":"sketch.circle.center"})).unwrap(); for at in [[20, 30, 0], [40, 30, 0]] { + // The line's end lands in the view's bottom-right corner, where notices stack and take clicks + // (#7893): this test is about the circle, so the transient status notice goes before each click. + h.app.status = None; + h.frame(); h.step(&json!({"move":{"world":at}})).unwrap(); h.step(&json!({"click":{"world":at}})).unwrap(); } diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rs index 32ea91e07..bf08971ce 100644 --- a/crates/ui-egui/src/viewport.rs +++ b/crates/ui-egui/src/viewport.rs @@ -4704,6 +4704,9 @@ fn transient_messages(app: &mut SolveApp, ui: &egui::Ui, viewport: Rect) -> Vec< } let view = crate::shell::content_rect(app, viewport); let mut free = crate::viewport_layout::free_rect(view, &obstacles).shrink(t.space_8); + if ToastPlace::current(ui.ctx()) == ToastPlace::Corner { + free = corner_free(view, &obstacles); + } // The note offering to stand up a file just opened from a program not known to save Y up // (#7717): the shared toast with its buttons, which go by themselves and never block input. if let Some(text) = crate::stand_up::note_due(app, ui.ctx()) { @@ -4789,6 +4792,42 @@ fn transient_messages(app: &mut SolveApp, ui: &egui::Ui, viewport: Rect) -> Vec< shown } +/// Where toasts stack (Preferences › Interface › Notices, #7893). +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum ToastPlace { + /// One column in the view's bottom-right corner, every toast `TOAST_WIDTH` wide, buttons as in + /// the dialogs: right-aligned, dismissals first and the main action right-most. + #[default] + Corner, + /// At the bottom centre, above the view toolbar, each as wide as its text (as before #7893). + /// Also what a value this version doesn't know reads as (`prefs::lenient`). + Centre, +} + +impl ToastPlace { + pub(crate) fn publish(self, ctx: &egui::Context) { + ctx.data_mut(|data| data.insert_temp(egui::Id::new("sc_toast_place"), self)); + } + + pub(crate) fn current(ctx: &egui::Context) -> Self { + ctx.data(|data| data.get_temp(egui::Id::new("sc_toast_place"))).unwrap_or_default() + } +} + +/// Every toast's width in the corner stack: room for three buttons on one row; longer text wraps. +pub(crate) const TOAST_WIDTH: f32 = 340.0; + +/// Where the corner stack may go: the largest free rect in a `TOAST_WIDTH` column at the right of +/// `view`, clear of `obstacles` (the axis view and cube at the top, the view toolbar when a narrow +/// window brings it under the column, docked panels), less the usual margin. +pub(crate) fn corner_free(view: Rect, obstacles: &[Rect]) -> Rect { + let t = Tokens::get(); + let left = (view.right() - TOAST_WIDTH - 2.0 * t.space_8).max(view.left()); + let column = Rect::from_min_max(pos2(left, view.top()), view.max); + crate::viewport_layout::free_rect(column, obstacles).shrink(t.space_8) +} + /// What a toast's button is for, which sets its look and where it goes: the main action first /// (the accent button), then an alternative, then the quiet dismissals. #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -4829,6 +4868,49 @@ fn toast_action_spots(buttons: &[(f32, ToastKind)], row_width: f32, gap: f32, he spots } +/// The corner stack's buttons, as the dialogs place theirs: right-aligned, dismissals first, then +/// the alternative, then the main action right-most. Rows fill from the main action leftwards; a +/// button that doesn't fit starts a row above, so the row with the main action is the bottom one. +/// Positions are relative to the rows' top left, within `row_width`. +fn toast_action_spots_trailing(buttons: &[(f32, ToastKind)], row_width: f32, gap: f32, height: f32) -> Vec { + let rank = |kind: ToastKind| match kind { + ToastKind::Dismiss => 0, + ToastKind::Secondary => 1, + ToastKind::Primary => 2, + }; + let mut order: Vec = (0..buttons.len()).collect(); + order.sort_by_key(|&i| rank(buttons[i].1)); + let mut rows: Vec> = Vec::new(); + let mut used = 0.0_f32; + for &i in order.iter().rev() { + let width = buttons[i].0; + match rows.last_mut() { + Some(row) if used + gap + width <= row_width => { + row.push(i); + used += gap + width; + } + _ => { + rows.push(vec![i]); + used = width; + } + } + } + let mut spots = vec![Rect::NOTHING; buttons.len()]; + let count = rows.len(); + for (k, row) in rows.iter().enumerate() { + let y = (count - 1 - k) as f32 * (height + gap); + let mut x = row_width; + for &i in row { + x -= buttons[i].0; + if let Some(spot) = spots.get_mut(i) { + *spot = Rect::from_min_size(pos2(x, y), vec2(buttons[i].0, height)); + } + x -= gap; + } + } + spots +} + /// What leads a toast's text: a dot (red for an error) or a spinner. #[derive(Clone, Copy)] enum ToastLead { @@ -4853,16 +4935,21 @@ fn paint_toast_with( lead: ToastLead, actions: &[(&str, ToastKind)], ) -> Option<(Rect, Option, Vec)> { - if !free.is_finite() || !free.is_positive() || free.width() <= 40.0 { + // Rects no screen has are rejected too: the corner layout anchors to `free`'s right edge. + if !free.is_finite() || !free.is_positive() || free.width() <= 40.0 || free.max.x.abs().max(free.max.y.abs()) > 1.0e7 { return None; } let t = Tokens::get(); + let corner = ToastPlace::current(ui.ctx()) == ToastPlace::Corner; let painter = ui.painter().with_clip_rect(free); - let galley = painter.layout(text, crate::fonts::medium(t.font_label), t.text, (free.width() - 40.0).min(440.0)); + // In the corner every toast is `TOAST_WIDTH` wide (or the room there is); at the centre each + // is as wide as its text, up to 440 points. + let wrap = if corner { (TOAST_WIDTH.min(free.width()) - 40.0).max(0.0) } else { (free.width() - 40.0).min(440.0) }; + let galley = painter.layout(text, crate::fonts::medium(t.font_label), t.text, wrap); // The buttons: each as wide as its text and a margin, in rows no wider than the text may be. let gap = t.space_8; let button_height = crate::ui_kit::row_height(); - let row_width = (free.width() - 40.0).clamp(0.0, 440.0); + let row_width = if corner { wrap } else { (free.width() - 40.0).clamp(0.0, 440.0) }; let sizes: Vec<(f32, ToastKind)> = actions .iter() .map(|(label, kind)| { @@ -4871,16 +4958,24 @@ fn paint_toast_with( (width.min(row_width), *kind) }) .collect(); - let spots = toast_action_spots(&sizes, row_width, gap, button_height); + let spots = if corner { + toast_action_spots_trailing(&sizes, row_width, gap, button_height) + } else { + toast_action_spots(&sizes, row_width, gap, button_height) + }; let widest = spots.iter().map(|spot| spot.right()).fold(0.0, f32::max); let y = spots.iter().map(|spot| spot.top()).fold(0.0, f32::max); let actions_height = if spots.is_empty() { 0.0 } else { y + button_height + gap }; let content = vec2(galley.size().x.max(widest), galley.size().y + actions_height); - let size = content + vec2(40.0, 16.0); + let mut size = content + vec2(40.0, 16.0); + if corner { + size.x = row_width + 40.0; + } if !size.is_finite() || size.x > free.width() || size.y > free.height() { return None; } - let r = Rect::from_center_size(pos2(free.center().x, free.bottom() - size.y * 0.5), size); + let x = if corner { free.right() - size.x * 0.5 } else { free.center().x }; + let r = Rect::from_center_size(pos2(x, free.bottom() - size.y * 0.5), size); if !r.is_finite() { return None; } diff --git a/crates/ui-egui/src/viewport_overlays_tests.rs b/crates/ui-egui/src/viewport_overlays_tests.rs index 47528e3e2..601dbf4fe 100644 --- a/crates/ui-egui/src/viewport_overlays_tests.rs +++ b/crates/ui-egui/src/viewport_overlays_tests.rs @@ -155,14 +155,15 @@ fn toast_stays_in_free_content_above_history_and_navigation() { let content = crate::shell::content_rect(&h.app, layout.viewport); let mut obstacles = crate::shell::covered_rects(&h.app); obstacles.extend([layout.navigation, layout.axis_view]); - let free = crate::viewport_layout::free_rect(content, &obstacles).shrink(Tokens::get().space_8); + // The default place: the bottom of the corner column (#7893). + let free = corner_free(content, &obstacles); if let Some(toast) = crate::scenario::rect_of("toast") { assert!(toast.is_finite() && toast.is_positive()); assert!(content.contains_rect(toast), "{mode:?}, {scale}, {width}x{height}: {toast:?}"); for obstacle in obstacles { assert!(!toast.intersect(obstacle).is_positive(), "{toast:?} intersects {obstacle:?}"); } - assert!((toast.center().x - free.center().x).abs() < 0.01); + assert!((toast.right() - free.right()).abs() < 0.01, "against the column's right: {toast:?} {free:?}"); assert!((toast.bottom() - free.bottom()).abs() < 0.01); } else { assert!(free.width() < 200.0 || free.height() < 40.0, "toast unexpectedly absent: {free:?}"); @@ -359,11 +360,13 @@ fn compass_circle_grabs_on_hover_and_the_home_chip_points() { assert_ne!(h.output.cursor_icon, egui::CursorIcon::Grab, "no hand away from the compass"); } -/// The status and computing toasts keep the size and place they always had: the text's size plus -/// 40 by 16, centred at the bottom of the free rect. +/// At the bottom centre (the `centre` preference, the place before #7893) the status and computing +/// toasts keep the size and place they always had: the text's size plus 40 by 16, centred at the +/// bottom of the free rect. #[test] fn the_shared_toast_draws_old_callers_exactly_as_before() { let ctx = crate::fonts::test_context(); + ToastPlace::Centre.publish(&ctx); for width in [200.0_f32, 300.0, 500.0, 900.0] { let free = Rect::from_min_size(pos2(10.0, 20.0), vec2(width, 200.0)); for (error, computing) in [(false, false), (true, false), (false, true)] { @@ -674,3 +677,66 @@ fn view_angles_readout_shows_only_when_on_and_applies_typed_angles() { assert!(h.app.session.undo.is_empty()); } } + +/// In the corner (#7893) the buttons sit as in the dialogs: right-aligned, dismissals first and the +/// main action right-most; when they wrap, the row with the main action is the bottom one. +#[test] +fn corner_toast_buttons_follow_the_dialogs_and_keep_the_main_action_bottom_right() { + use ToastKind::{Dismiss, Primary, Secondary}; + let row_width = TOAST_WIDTH - 40.0; + // Three short ones fit one row: Close, Don't ask again, Stand it up. + let three = [(90.0, Primary), (110.0, Secondary), (50.0, Dismiss)]; + let spots = toast_action_spots_trailing(&three, row_width, 8.0, 28.0); + assert!(spots.iter().all(|s| s.top() == 0.0), "one row: {spots:?}"); + assert!((spots[0].right() - row_width).abs() < 0.01, "the main action is right-most: {spots:?}"); + assert!(spots[2].right() < spots[1].left() && spots[1].right() < spots[0].left(), "dismiss, alternative, main: {spots:?}"); + // The 3D mouse offer's four wrap: the main action and its alternative below, the dismissals above. + let four = [(90.0, Primary), (190.0, Secondary), (50.0, Dismiss), (120.0, Dismiss)]; + let spots = toast_action_spots_trailing(&four, row_width, 8.0, 28.0); + let bottom = spots.iter().map(|s| s.top()).fold(0.0, f32::max); + assert!(bottom > 0.0, "wrapped: {spots:?}"); + assert_eq!(spots[0].top(), bottom, "the main action is on the bottom row"); + assert!((spots[0].right() - row_width).abs() < 0.01, "and right-most"); + for (i, spot) in spots.iter().enumerate() { + assert!(spot.left() >= -0.01 && spot.right() <= row_width + 0.01, "inside the row: {spot:?}"); + for other in &spots[i + 1..] { + assert!(!spot.intersects(*other), "{spot:?} overlaps {other:?}"); + } + } + // Hostile widths never panic and give one spot per button. + for bad in [f32::NAN, f32::INFINITY, -5.0, 0.0] { + assert_eq!(toast_action_spots_trailing(&four, bad, 8.0, 28.0).len(), 4); + } +} + +/// In the corner every toast is `TOAST_WIDTH` wide, whatever its text, and sits against the right of +/// `free`; at the centre (the old place, a preference) each is as wide as its text, centred. +#[test] +fn corner_toasts_share_one_width_against_the_right_edge() { + let ctx = crate::fonts::test_context(); + let free = Rect::from_min_size(pos2(0.0, 0.0), vec2(1200.0, 700.0)); + for place in [ToastPlace::Corner, ToastPlace::Centre] { + place.publish(&ctx); + let mut rects = Vec::new(); + draw(&ctx, |ui| { + for text in ["Open done", "Calibrating your 3D mouse fixes swapped or reversed axes and sets its speed and feel."] { + rects.push(paint_toast(ui, free, text.into(), false, false).unwrap()); + } + }); + match place { + ToastPlace::Corner => { + for r in &rects { + assert!((r.width() - TOAST_WIDTH).abs() < 0.5, "{r:?}"); + assert!((r.right() - free.right()).abs() < 0.5, "against the right edge: {r:?}"); + } + } + ToastPlace::Centre => { + assert!(rects[0].width() < rects[1].width(), "as wide as their text: {rects:?}"); + for r in &rects { + assert!((r.center().x - free.center().x).abs() < 0.5, "centred: {r:?}"); + } + } + } + } + ToastPlace::Corner.publish(&ctx); +} diff --git a/crates/ui-egui/tests/scenarios/sketch_pattern_rect_window.json b/crates/ui-egui/tests/scenarios/sketch_pattern_rect_window.json index bf8e5af7e..ef97faa4d 100644 --- a/crates/ui-egui/tests/scenarios/sketch_pattern_rect_window.json +++ b/crates/ui-egui/tests/scenarios/sketch_pattern_rect_window.json @@ -58,15 +58,15 @@ {"expect": {"query": {"command": "sketch.inspect", "path": ["curves", 10, "center_at", 1], "value": 75}}}, {"shot": "sketch_pattern_rect_grid"}, - {"note": "A picked Direction reaches the command's dir: along the Y origin axis the instances run up the sketch, not across it. The grid above has grown the sketch well past the frame the first circle was drawn in, so refit the view before clicking a point 100 mm out."}, + {"note": "A picked Direction reaches the command's dir: along the Y origin axis the instances run up the sketch, not across it. The grid above has grown the sketch well past the frame the first circle was drawn in, so refit the view before clicking a point 100 mm out. It sits 40 mm up, clear of the bottom-right corner where the tool's prompt stacks and takes clicks (#7893)."}, {"call": "ui.view", "params": {"view": "fit"}}, {"start": "sketch.circle.center"}, - {"click": {"sketch": [100, 0]}}, - {"click": {"sketch": [105, 0]}}, + {"click": {"sketch": [100, 40]}}, + {"click": {"sketch": [105, 40]}}, {"key": "Escape"}, {"expect": {"sketch_curves": {"own": 12}, "errors": 0}}, {"start": "sketch.pattern.rectangular"}, - {"click": {"sketch": [105, 0]}}, + {"click": {"sketch": [105, 40]}}, {"click": {"handle": "dialog:Direction"}}, {"note": "The dense dialog covers the old viewport axis target. Pick the same Y axis through Origin in the Browser."}, {"click": {"handle": "fold:Origin"}}, @@ -80,11 +80,11 @@ {"click": {"handle": "dialog:OK"}}, {"expect": {"dialog": null, "errors": 0, "sketch_curves": {"own": 15}}}, {"expect": {"query": {"command": "sketch.inspect", "path": ["curves", 14, "center_at", 0], "value": 100}}}, - {"expect": {"query": {"command": "sketch.inspect", "path": ["curves", 14, "center_at", 1], "value": 30}}}, + {"expect": {"query": {"command": "sketch.inspect", "path": ["curves", 14, "center_at", 1], "value": 70}}}, {"note": "Escape closes the window and leaves the sketch and its undo history exactly as they were."}, {"start": "sketch.pattern.rectangular"}, - {"click": {"sketch": [105, 0]}}, + {"click": {"sketch": [105, 40]}}, {"expect": {"dialog": "PatternRect"}}, {"key": "Escape"}, {"expect": {"dialog": null, "errors": 0, "sketch_curves": {"own": 15}}} diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 089346536..9a8e2cb40 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -377,6 +377,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own - `theme_import` (a `solidcraft-theme/1` file's JSON or text: adds the theme and turns it on; the reply's `theme_imported` is its id) - `theme_remove` (an imported theme's id) - `timeline_origin_bodies` (default false: the History on the left or under the browser starts with the active component's Bodies folder and the Origin, the browser's rows with their eyes, folds and menus; the bottom History is unchanged) +- `toast_place` (`corner` (default: notices and offers stack in one column in the view's bottom-right corner, each 340 points wide, buttons right-aligned with the main action right-most, #7893), `centre` (at the bottom centre above the view toolbar, each as wide as its text, as before)) - `trackpad_pan` (default true: two-finger scroll pans, except Touchpad always zooms; pinch zooms) - `ui_font` (an installed font family or a font file for the interface; empty for the built-in font) - `ui_scale`