From c94b868b2ed87122edfe75bc1ca4e5fc697be0fc Mon Sep 17 00:00:00 2001 From: astar76 Date: Wed, 18 Nov 2026 10:06:17 -0600 Subject: [PATCH] S005: overlay layer, menu with submenu, modal dialog, toast stack Menus, dialogs and toasts draw on an own full-window layer so they can play exit motion; gallery pages show them open for screenshots. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 1 + FEATURES.md | 2 +- Plans/02 App skeleton/S005-menus-dialogs.md | 12 +- Plans/INDEX.md | 2 +- crates/tunal/src/main.rs | 40 +- crates/tunal/ui/app.slint | 2 +- crates/tunal/ui/components/dialog.slint | 188 +++++++++ crates/tunal/ui/components/icon.slint | 9 + crates/tunal/ui/components/menu.slint | 386 +++++++++++++++++++ crates/tunal/ui/components/overlay.slint | 55 +++ crates/tunal/ui/components/state-layer.slint | 33 +- crates/tunal/ui/components/toast.slint | 231 +++++++++++ crates/tunal/ui/components/tooltip.slint | 35 ++ crates/tunal/ui/gallery.slint | 89 ++++- crates/tunal/ui/motion.slint | 8 + crates/tunal/ui/theme.slint | 10 + docs/DECISIONS.md | 1 + docs/PROGRESS.md | 7 + 18 files changed, 1071 insertions(+), 40 deletions(-) create mode 100644 crates/tunal/ui/components/dialog.slint create mode 100644 crates/tunal/ui/components/menu.slint create mode 100644 crates/tunal/ui/components/overlay.slint create mode 100644 crates/tunal/ui/components/toast.slint create mode 100644 crates/tunal/ui/components/tooltip.slint diff --git a/CLAUDE.md b/CLAUDE.md index 188c69c..8b79fdf 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -86,6 +86,7 @@ Never modify: `PROMPT.md` (the user's brief), the user's other projects under `~ | `cargo run -p tunal -- --screenshot [--dark] [--size WxH]` (software renderer, offscreen, default 960x640; env `TUNAL_SEED=#rrggbb`, `TUNAL_REDUCED_MOTION=1`) | single-PNG visual check; full state matrix in phase 12 | S003 | | `XDG_DATA_HOME=/data cargo run -p tunal-core --example ops -- ` (refuses unless XDG_DATA_HOME is inside ``) | job engine + trash smoke run: conflicts, cancel, trash/restore/empty | S007 | | `cargo run -p tunal -- --gallery --screenshot [--dark] --size 1200x1000` (`--gallery` alone opens it in a window) | every control in rest/hover/pressed/focused/disabled; press squeeze not drawn by the software renderer | S004 | +| `cargo run -p tunal -- --gallery --page menu\|dialog --screenshot [--dark] --size 960x640` | open menu + submenu + two toasts, or dialog + indeterminate toast, over a stand-in folder | S005 | Don't assume a tool exists: check first. When your plan creates a tool, add its row here. diff --git a/FEATURES.md b/FEATURES.md index 2b32f4f..0f8cd20 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -24,7 +24,7 @@ Status: planned → done (later plans update their rows when they ship a feature |---|---|---|---| | Material You colours from the portal accent and light/dark mode, live updates | planned | S002 | tunal-theme | | Theme and Motion token globals, window, screenshot command | planned | S003 | tunal | -| Animated base controls, menus, dialogs, toasts | planned | S004, S005 | tunal | +| Animated base controls, menus, dialogs, toasts | done | S004, S005 | tunal | | List insert / remove / reorder motion | planned | S009 | tunal | | Material icons for files and folders | planned | S008 | tunal | | Thumbnails: images, video frames, embedded album art | planned | S017, S018 | tunal-thumbs | diff --git a/Plans/02 App skeleton/S005-menus-dialogs.md b/Plans/02 App skeleton/S005-menus-dialogs.md index 173313c..4a171bc 100644 --- a/Plans/02 App skeleton/S005-menus-dialogs.md +++ b/Plans/02 App skeleton/S005-menus-dialogs.md @@ -10,12 +10,12 @@ Surfaces with entry and exit motion: a popup menu (icons, shortcuts, separators, CLAUDE.md §2 Motion rules; `animate` skill; crates/tunal/ui/components/*.slint from S004. ## Steps -- [ ] Overlay layer in the window for menus/dialogs/toasts (Slint `PopupWindow` closes instantly, so exit motion needs our own layer); clamp to window edges. -- [ ] `Menu`: opens scaled from the anchor, keyboard navigation (arrows, Enter, Esc), submenu, disabled items, closes on outside click. -- [ ] `Dialog`: scrim fade, surface scale-in, title/body/actions slots, Esc and default button, focus stays inside. -- [ ] `Toast` stack: message, progress bar (determinate/indeterminate), action and cancel; slide in/out, re-stack animated. `Tooltip` after hover delay. -- [ ] Gallery states for menu open, dialog open, two toasts; screenshots. -- [ ] PROGRESS entry, INDEX line, commit `S005: …` +- [x] Overlay layer in the window for menus/dialogs/toasts (Slint `PopupWindow` closes instantly, so exit motion needs our own layer); clamp to window edges. +- [x] `Menu`: opens scaled from the anchor, keyboard navigation (arrows, Enter, Esc), submenu, disabled items, closes on outside click. +- [x] `Dialog`: scrim fade, surface scale-in, title/body/actions slots, Esc and default button, focus stays inside. +- [x] `Toast` stack: message, progress bar (determinate/indeterminate), action and cancel; slide in/out, re-stack animated. `Tooltip` after hover delay. +- [x] Gallery states for menu open, dialog open, two toasts; screenshots. +- [x] PROGRESS entry, INDEX line, commit `S005: …` ## End criteria - `cargo build --workspace`, `cargo clippy --workspace --all-targets -- -D warnings` and `cargo fmt --check` pass. diff --git a/Plans/INDEX.md b/Plans/INDEX.md index a12e833..d8bf65b 100644 --- a/Plans/INDEX.md +++ b/Plans/INDEX.md @@ -13,7 +13,7 @@ Tracker: https://claude.ai/artifact/4X8YCk3cQjUGyuyCqGuU7v - [x] [S002 — Portal theme and Material schemes](02%20App%20skeleton/S002-theme-portal.md) · Opus high - [x] [S003 — Window, Theme and Motion globals, screenshot command](02%20App%20skeleton/S003-window-tokens.md) · Opus high - [x] [S004 — Base animated controls](02%20App%20skeleton/S004-base-controls.md) · Opus high -- [ ] [S005 — Menus, dialogs and toasts](02%20App%20skeleton/S005-menus-dialogs.md) · Opus high +- [x] [S005 — Menus, dialogs and toasts](02%20App%20skeleton/S005-menus-dialogs.md) · Opus high ## 03 File browsing diff --git a/crates/tunal/src/main.rs b/crates/tunal/src/main.rs index 2a49f35..8cb29ad 100644 --- a/crates/tunal/src/main.rs +++ b/crates/tunal/src/main.rs @@ -5,13 +5,14 @@ use std::process::ExitCode; slint::include_modules!(); -const USAGE: &str = "usage: tunal [--gallery] [--screenshot [--dark] [--size WxH]]"; +const USAGE: &str = + "usage: tunal [--gallery [--page menu|dialog]] [--screenshot [--dark] [--size WxH]]"; fn main() -> ExitCode { let result = parse(std::env::args().skip(1)).and_then(|args| match args.screenshot { - None if args.gallery => Gallery::new().and_then(run).map_err(|e| e.to_string()), + None if args.gallery => gallery(args.page).and_then(run).map_err(|e| e.to_string()), None => MainWindow::new().and_then(run).map_err(|e| e.to_string()), - Some(options) if args.gallery => screenshot::run(options, Gallery::new), + Some(options) if args.gallery => screenshot::run(options, || gallery(args.page)), Some(options) => screenshot::run(options, MainWindow::new), }); match result { @@ -23,6 +24,13 @@ fn main() -> ExitCode { } } +fn gallery(page: GalleryPage) -> Result { + let ui = Gallery::new()?; + ui.set_page(page); + ui.invoke_stage(); + Ok(ui) +} + fn run(ui: impl theme_bridge::Themed) -> Result<(), slint::PlatformError> { theme_bridge::start(&ui, theme_bridge::Overrides::from_env()); ui.run() @@ -30,11 +38,13 @@ fn run(ui: impl theme_bridge::Themed) -> Result<(), slint::PlatformError> { struct Args { gallery: bool, + page: GalleryPage, screenshot: Option, } fn parse(mut args: impl Iterator) -> Result { let mut gallery = false; + let mut page = GalleryPage::Controls; let mut options = screenshot::Options { path: String::new(), dark: false, @@ -43,23 +53,40 @@ fn parse(mut args: impl Iterator) -> Result { }; let mut screenshot_flags = false; while let Some(arg) = args.next() { - screenshot_flags |= arg != "--gallery"; match arg.as_str() { "--gallery" => gallery = true, - "--screenshot" => options.path = args.next().ok_or(USAGE)?, - "--dark" => options.dark = true, + "--page" => { + page = match args.next().as_deref() { + Some("menu") => GalleryPage::Menu, + Some("dialog") => GalleryPage::Dialog, + _ => return Err(USAGE.into()), + } + } + "--screenshot" => { + options.path = args.next().ok_or(USAGE)?; + screenshot_flags = true; + } + "--dark" => { + options.dark = true; + screenshot_flags = true; + } "--size" => { let size = args.next().ok_or(USAGE)?; let (w, h) = size.split_once('x').ok_or(USAGE)?; let parse = |n: &str| n.parse::().ok().filter(|&n| n > 0).ok_or(USAGE); options.size = (parse(w)?, parse(h)?); + screenshot_flags = true; } _ => return Err(USAGE.into()), } } + if page != GalleryPage::Controls && !gallery { + return Err(USAGE.into()); + } if !screenshot_flags { return Ok(Args { gallery, + page, screenshot: None, }); } @@ -69,6 +96,7 @@ fn parse(mut args: impl Iterator) -> Result { options.reduced_motion = gallery; Ok(Args { gallery, + page, screenshot: Some(options), }) } diff --git a/crates/tunal/ui/app.slint b/crates/tunal/ui/app.slint index f4df2d8..a078384 100644 --- a/crates/tunal/ui/app.slint +++ b/crates/tunal/ui/app.slint @@ -4,7 +4,7 @@ import { Motion, MotionPrefs } from "motion.slint"; import { Icon, Icons } from "components/icon.slint"; export { Theme, MotionPrefs } -export { Gallery } from "gallery.slint"; +export { Gallery, GalleryPage } from "gallery.slint"; // Placeholder shell (sidebar + content) until the views land. export component MainWindow inherits Window { diff --git a/crates/tunal/ui/components/dialog.slint b/crates/tunal/ui/components/dialog.slint new file mode 100644 index 0000000..e55b35b --- /dev/null +++ b/crates/tunal/ui/components/dialog.slint @@ -0,0 +1,188 @@ +import { Theme } from "../theme.slint"; +import { Motion } from "../motion.slint"; +import { Button, ButtonKind } from "button.slint"; +import { Overlay } from "overlay.slint"; + +// One button of a dialog's action row. +export struct DialogAction { + text: string, + kind: ButtonKind, +} + +// A modal dialog: the scrim fades in, the surface scales in from the centre. Title, one or +// two lines of body, the children (a field, a list) and the action row, main action last. +// Place it last in the window (`width: 100%; height: 100%;`), call `show()`, and close it +// with `close()` from `action`: the dialog never closes itself, so an owner can keep it open +// while the input is invalid. +// +// Enter runs `default-action` (a focused button runs itself), Escape and a scrim click run +// `cancel-action`. Tab stays inside: the children may hold one focus stop of their own; set +// `content-focus` and focus it in `focus-content`. +export component Dialog inherits Overlay { + in property title; + in property body; + // Left to right; the main action last. + in property <[DialogAction]> actions; + in property default-action: root.actions.length - 1; + // -1: Escape and the scrim do nothing. + in property cancel-action: 0; + // Fixed per kind of dialog so it doesn't resize while typing. + in property dialog-width: 400px; + in property content-focus; + callback action(index: int); + callback focus-content; + + public function show() { + root.open = true; + if root.content-focus { + root.focus-content(); + } else { + root.focus-action(root.default-action, false); + } + } + + public function close() { + root.open = false; + trap.clear-focus(); + } + + modal: true; + enter-duration: Motion.medium2; + exit-duration: Motion.short4; + dismissed => { + root.cancel(); + } + + // The action button that has focus, -1 when focus is in the children (or nowhere). + property focused-action: -1; + // Each request bumps the serial; the button at `focus-target` takes the focus. + property focus-target: -1; + property focus-ring; + property focus-serial; + + function focus-action(index: int, ring: bool) { + root.focus-target = index; + root.focus-ring = ring; + root.focus-serial += 1; + } + + function cancel() { + if root.open && root.cancel-action >= 0 { + root.action(root.cancel-action); + } + } + + // Wraps Tab at the ends of the dialog's focus stops instead of leaving to the window. + function wrap-focus(forward: bool) -> bool { + let last = root.actions.length - 1; + if forward && root.focused-action == last { + if root.content-focus { + root.focus-content(); + } else { + root.focus-action(0, true); + } + return true; + } + if !forward && (root.focused-action == 0 || (root.focused-action == -1 && root.content-focus)) { + if root.focused-action == 0 && root.content-focus { + root.focus-content(); + } else { + root.focus-action(last, true); + } + return true; + } + false + } + + surface := Rectangle { + width: min(root.dialog-width, root.width - 2 * Theme.window-margin); + height: column.preferred-height; + x: (root.width - self.width) / 2; + y: max(Theme.window-margin, (root.height - self.height) / 2); + background: Theme.surface-container-high; + border-radius: Theme.corner-xl; + drop-shadow-blur: Theme.float-shadow-blur; + drop-shadow-offset-y: Theme.float-shadow-offset; + drop-shadow-color: Theme.shadow.with-alpha(Theme.float-shadow-opacity); + opacity: root.progress; + transform-scale: Motion.enter-scale + (1 - Motion.enter-scale) * root.progress; + + accessible-role: groupbox; + accessible-label: root.title; + accessible-description: root.body; + + // Clicks on the surface stay on the dialog instead of cancelling it. + TouchArea { } + + trap := FocusScope { + focus-on-click: false; + focus-on-tab-navigation: false; + + // Runs before the focused child sees the key. + capture-key-pressed(event) => { + if event.text == Key.Escape { + root.cancel(); + return accept; + } + if event.text == Key.Tab || event.text == Key.Backtab { + return root.wrap-focus(event.text == Key.Tab && !event.modifiers.shift) ? accept : reject; + } + if event.text == Key.Return && root.focused-action == -1 && root.default-action >= 0 { + root.action(root.default-action); + return accept; + } + reject + } + + column := VerticalLayout { + padding: Theme.space-6; + spacing: Theme.space-4; + + Text { + text: root.title; + color: Theme.on-surface; + font-size: Theme.title-large.size; + font-weight: Theme.title-large.weight; + wrap: word-wrap; + } + + if root.body != "": Text { + text: root.body; + color: Theme.on-surface-variant; + font-size: Theme.body-medium.size; + font-weight: Theme.body-medium.weight; + wrap: word-wrap; + } + + @children + + HorizontalLayout { + alignment: end; + spacing: Theme.space-2; + + for item[i] in root.actions: Button { + property serial: root.focus-serial; + + text: item.text; + kind: item.kind; + changed serial => { + if i == root.focus-target { + self.grab-focus(root.focus-ring); + } + } + changed has-focus => { + if self.has-focus { + root.focused-action = i; + } else if root.focused-action == i { + root.focused-action = -1; + } + } + clicked => { + root.action(i); + } + } + } + } + } + } +} diff --git a/crates/tunal/ui/components/icon.slint b/crates/tunal/ui/components/icon.slint index b9b160b..8dcd5ea 100644 --- a/crates/tunal/ui/components/icon.slint +++ b/crates/tunal/ui/components/icon.slint @@ -32,4 +32,13 @@ export global Icons { out property grid-view: "\u{e9b0}"; out property music-note: "\u{e405}"; out property description: "\u{e873}"; + out property chevron-right: "\u{e5cc}"; + out property content-copy: "\u{e14d}"; + out property content-cut: "\u{e14e}"; + out property content-paste: "\u{e14f}"; + out property edit: "\u{e3c9}"; + out property delete: "\u{e872}"; + out property open-in-new: "\u{e89e}"; + out property sort: "\u{e164}"; + out property info: "\u{e88e}"; } diff --git a/crates/tunal/ui/components/menu.slint b/crates/tunal/ui/components/menu.slint new file mode 100644 index 0000000..0ddb8ce --- /dev/null +++ b/crates/tunal/ui/components/menu.slint @@ -0,0 +1,386 @@ +import { Theme } from "../theme.slint"; +import { Motion } from "../motion.slint"; +import { Icon, Icons } from "icon.slint"; +import { ForceState, StateLayer } from "state-layer.slint"; +import { Overlay } from "overlay.slint"; + +// One entry of a submenu (and the fields every menu item shares). `shortcut` is shown, not +// bound: the window owns the key bindings. +export struct MenuEntry { + text: string, + // Glyph from `Icons`; empty for none. + icon: string, + shortcut: string, + disabled: bool, + separator: bool, +} + +// One entry of a menu; a non-empty `submenu` opens one more level (and no deeper). +export struct MenuItem { + text: string, + icon: string, + shortcut: string, + disabled: bool, + separator: bool, + submenu: [MenuEntry], +} + +component MenuRow inherits StateLayer { + in property entry; + in property leading-icon; + in property has-submenu; + // Keyboard highlight, or its submenu is open. + in property highlighted; + + property content: root.enabled ? Theme.on-surface : Theme.on-surface.with-alpha(Theme.disabled-content); + property detail: root.enabled ? Theme.on-surface-variant : Theme.on-surface.with-alpha(Theme.disabled-content); + + enabled: !root.entry.separator && !root.entry.disabled; + force-state: root.highlighted ? ForceState.hover : ForceState.none; + height: root.entry.separator ? Theme.space-2 + Theme.hairline : 32px; + border-radius: Theme.corner-xs; + squeeze: Motion.squeeze-large; + + accessible-role: list-item; + accessible-label: root.entry.text; + accessible-enabled: root.enabled; + accessible-action-default => { + self.activate(); + } + + if root.entry.separator: Rectangle { + y: Theme.space-1; + height: Theme.hairline; + background: Theme.outline-variant; + } + + // Always present (hidden for a separator) so the menu can size to the widest label. + preferred-width: content.preferred-width; + + content := HorizontalLayout { + visible: !root.entry.separator; + padding-left: Theme.space-3; + padding-right: Theme.space-3; + spacing: Theme.space-3; + + if root.leading-icon: VerticalLayout { + alignment: center; + + Icon { + glyph: root.entry.icon; + size: 20px; + color: root.detail; + } + } + + Text { + horizontal-stretch: 1; + text: root.entry.text; + color: root.content; + font-size: Theme.body-medium.size; + font-weight: Theme.body-medium.weight; + vertical-alignment: center; + overflow: elide; + } + + if root.entry.shortcut != "": Text { + text: root.entry.shortcut; + color: root.detail; + font-size: Theme.body-small.size; + font-weight: Theme.body-small.weight; + vertical-alignment: center; + } + + if root.has-submenu: VerticalLayout { + alignment: center; + + Icon { + glyph: Icons.chevron-right; + size: 20px; + color: root.detail; + } + } + } +} + +// The floating surface of a menu or submenu: grows from `origin` while `progress` rises. +component MenuSurface inherits Rectangle { + in property progress; + in property origin; + + background: Theme.surface-container; + border-radius: Theme.corner-sm; + drop-shadow-blur: Theme.float-shadow-blur; + drop-shadow-offset-y: Theme.float-shadow-offset; + drop-shadow-color: Theme.shadow.with-alpha(Theme.float-shadow-opacity); + opacity: root.progress; + transform-origin: root.origin; + transform-scale: Motion.enter-scale + (1 - Motion.enter-scale) * root.progress; + visible: root.progress > 0; + + // Clicks between rows stay on the menu instead of dismissing it. + TouchArea { } + + @children +} + +// A popup menu: icons, shortcuts, separators, disabled items and one submenu level. Place it +// last in the window (`width: 100%; height: 100%;`) and call `open-at` with window +// coordinates, e.g. a button's `absolute-position` plus its height, or the pointer. +// It flips to stay inside the window, closes on a click outside or Escape, and reports the +// chosen item through `activated` (`sub-index` is -1 for a top-level item). +export component Menu inherits Overlay { + in property <[MenuItem]> items; + // Reserve a leading icon column so labels line up; set it when any item has an icon. + in property leading-icons; + callback activated(index: int, sub-index: int); + // After the menu was closed for any reason: give focus back to the opener here. + callback closed; + + public function open-at(x: length, y: length) { + root.anchor-x = x - root.absolute-position.x; + root.anchor-y = y - root.absolute-position.y; + root.current = -1; + root.close-sub(); + root.open = true; + keys.focus(); + } + + // Highlights `index` and opens its submenu as the Right key does (a menu bar moving in). + public function expand(index: int) { + root.current = index; + root.choose(index, true); + } + + public function close() { + if !root.open { + return; + } + root.open = false; + root.close-sub(); + keys.clear-focus(); + root.closed(); + } + + property anchor-x; + property anchor-y; + // Highlighted rows: keyboard or pointer, -1 for none. + property current: -1; + property sub-current: -1; + // The item whose submenu shows; kept while the submenu plays its exit. + property sub-index: -1; + property sub-open; + // Arrow keys are in the submenu. + property in-sub; + // Top of the row the submenu belongs to (that row reports it). + property sub-row-y; + property <[MenuEntry]> sub-items: root.sub-index >= 0 && root.sub-index < root.items.length ? root.items[root.sub-index].submenu : []; + property sub-progress: root.open && root.sub-open ? 1 : 0; + animate sub-progress { + duration: Motion.time(root.sub-open ? Motion.short4 : Motion.short3); + easing: root.sub-open ? Motion.emphasized-decelerate : Motion.standard; + } + + // Arrow keys skip separators and disabled rows: a step lands, and `changed` steps again + // in the same direction until a selectable row (or a full lap) is reached. + property step: 1; + property hops; + + pure function selectable(separator: bool, disabled: bool) -> bool { + !separator && !disabled + } + + pure function wrap(from: int, dir: int, count: int) -> int { + if count == 0 { + return -1; + } + if from < 0 { + return dir > 0 ? 0 : count - 1; + } + Math.mod(from + dir + count, count) + } + + function move(dir: int) { + root.step = dir; + root.hops = 0; + if root.in-sub { + root.sub-current = root.wrap(root.sub-current, dir, root.sub-items.length); + } else { + root.current = root.wrap(root.current, dir, root.items.length); + } + } + + changed current => { + if root.current >= 0 && root.hops < root.items.length && !root.selectable(root.items[root.current].separator, root.items[root.current].disabled) { + root.hops += 1; + root.current = root.wrap(root.current, root.step, root.items.length); + } + } + + changed sub-current => { + if root.sub-current >= 0 && root.hops < root.sub-items.length && !root.selectable(root.sub-items[root.sub-current].separator, root.sub-items[root.sub-current].disabled) { + root.hops += 1; + root.sub-current = root.wrap(root.sub-current, root.step, root.sub-items.length); + } + } + + function open-sub(index: int) { + if root.sub-open && root.sub-index == index { + return; + } + root.sub-index = index; + root.sub-current = -1; + root.in-sub = false; + root.sub-open = true; + } + + function close-sub() { + root.sub-open = false; + root.in-sub = false; + root.sub-current = -1; + } + + // Pointer over a row (or the keyboard landing on it): submenus open on hover. + function hover(index: int) { + root.current = index; + if root.items[index].submenu.length > 0 { + root.open-sub(index); + } else { + root.close-sub(); + } + } + + function choose(index: int, keyboard: bool) { + if index < 0 || !root.selectable(root.items[index].separator, root.items[index].disabled) { + return; + } + if root.items[index].submenu.length > 0 { + root.open-sub(index); + if keyboard { + root.in-sub = true; + root.move(1); + } + return; + } + root.activated(index, -1); + root.close(); + } + + function choose-sub(index: int) { + if index < 0 || !root.selectable(root.sub-items[index].separator, root.sub-items[index].disabled) { + return; + } + root.activated(root.sub-index, index); + root.close(); + } + + dismissed => { + root.close(); + } + + keys := FocusScope { + x: 0; + width: 0; + focus-on-click: false; + focus-on-tab-navigation: false; + + // Everything else is swallowed while the menu is open, Tab included. + key-pressed(event) => { + if event.text == Key.DownArrow { + root.move(1); + } else if event.text == Key.UpArrow { + root.move(-1); + } else if event.text == Key.RightArrow { + if !root.in-sub && root.current >= 0 && root.items[root.current].submenu.length > 0 { + root.choose(root.current, true); + } + } else if event.text == Key.LeftArrow { + root.close-sub(); + } else if event.text == Key.Escape { + if root.sub-open { + root.close-sub(); + } else { + root.close(); + } + } else if event.text == Key.Return || event.text == Key.Space { + if root.in-sub { + root.choose-sub(root.sub-current); + } else { + root.choose(root.current, true); + } + } + accept + } + } + + surface := MenuSurface { + property w: clamp(column.preferred-width, 112px, 280px); + + width: self.w; + height: column.preferred-height; + x: root.place(root.anchor-x, root.anchor-x, self.width, root.width); + y: root.place(root.anchor-y, root.anchor-y, self.height, root.height); + origin: { + x: clamp(root.anchor-x - self.x, 0, self.width), + y: clamp(root.anchor-y - self.y, 0, self.height), + }; + progress: root.progress; + + column := VerticalLayout { + padding: Theme.space-1; + + for item[i] in root.items: MenuRow { + entry: { text: item.text, icon: item.icon, shortcut: item.shortcut, disabled: item.disabled, separator: item.separator }; + leading-icon: root.leading-icons; + has-submenu: item.submenu.length > 0; + highlighted: i == root.current || (root.sub-open && i == root.sub-index); + property owns-sub: i == root.sub-index; + + changed hovered => { + if self.hovered && i != root.current { + root.hover(i); + } + } + changed owns-sub => { + if self.owns-sub { + root.sub-row-y = self.y; + } + } + clicked => { + root.choose(i, false); + } + } + } + } + + MenuSurface { + // The parent row's top, so the first submenu row lines up with it. + property row-y: surface.y + root.sub-row-y - Theme.space-1; + + width: clamp(sub-column.preferred-width, 112px, 280px); + height: sub-column.preferred-height; + x: root.place(surface.x + surface.width - Theme.space-1, surface.x + Theme.space-1, self.width, root.width); + y: root.place(self.row-y, root.height, self.height, root.height); + origin: { x: surface.x + surface.width - self.x, y: self.row-y - self.y }; + progress: root.sub-progress; + + sub-column := VerticalLayout { + padding: Theme.space-1; + + for entry[j] in root.sub-items: MenuRow { + entry: entry; + leading-icon: root.leading-icons; + highlighted: j == root.sub-current; + changed hovered => { + if self.hovered && j != root.sub-current { + root.in-sub = true; + root.sub-current = j; + } + } + clicked => { + root.choose-sub(j); + } + } + } + } +} diff --git a/crates/tunal/ui/components/overlay.slint b/crates/tunal/ui/components/overlay.slint new file mode 100644 index 0000000..0a56690 --- /dev/null +++ b/crates/tunal/ui/components/overlay.slint @@ -0,0 +1,55 @@ +import { Theme } from "../theme.slint"; +import { Motion } from "../motion.slint"; + +// The layer a menu or dialog draws on. Slint's PopupWindow closes at once, so floating +// surfaces live here instead and stay until their exit motion has played. Put the layer +// last in the window with `width: 100%; height: 100%;` so it covers everything and its +// origin is the window's; open it with window coordinates (`absolute-position`). +// +// While open it takes every click and scroll: a click outside the surface calls `dismissed`. +export component Overlay { + // Whether the surface shows. Closing mid-entrance reverses from where it is. + in-out property open; + // Dims the window below while open. + in property modal; + in property enter-duration: Motion.short4; + in property exit-duration: Motion.short3; + + // 0 closed, 1 open. Surfaces derive their opacity and scale from it. + out property progress: root.open ? 1 : 0; + animate progress { + duration: Motion.time(root.open ? root.enter-duration : root.exit-duration); + easing: root.open ? Motion.emphasized-decelerate : Motion.standard; + } + + // A click or Escape outside the surface; the user closes the overlay in response. + callback dismissed; + + // Keeps a surface of `size` starting at `pos` inside `extent`, flipping it to end at + // `flip` when it doesn't fit (a menu opens above or left of its anchor). + public pure function place(pos: length, flip: length, size: length, extent: length) -> length { + if pos + size <= extent - Theme.window-margin { + return pos; + } + clamp(flip - size, Theme.window-margin, max(Theme.window-margin, extent - Theme.window-margin - size)) + } + + // Hidden (and out of the focus chain) once the exit has finished: nothing is left drawing. + visible: root.progress > 0; + + Rectangle { + background: root.modal ? Theme.scrim.with-alpha(Theme.scrim-opacity * root.progress) : transparent; + } + + TouchArea { + enabled: root.open; + clicked => { + root.dismissed(); + } + scroll-event(event) => { + accept + } + } + + @children +} diff --git a/crates/tunal/ui/components/state-layer.slint b/crates/tunal/ui/components/state-layer.slint index 8ea4c77..f10f226 100644 --- a/crates/tunal/ui/components/state-layer.slint +++ b/crates/tunal/ui/components/state-layer.slint @@ -1,31 +1,10 @@ import { Theme } from "../theme.slint"; import { Motion } from "../motion.slint"; +import { Tooltip } from "tooltip.slint"; // A state shown regardless of the pointer and focus, for gallery screenshots. export enum ForceState { none, hover, pressed, focused } -// The small label an icon-only control shows on hover. -export component Tooltip inherits Rectangle { - in property text; - - background: Theme.inverse-surface; - border-radius: Theme.corner-xs; - height: 24px; - - HorizontalLayout { - padding-left: Theme.space-2; - padding-right: Theme.space-2; - - Text { - text: root.text; - color: Theme.inverse-on-surface; - font-size: Theme.body-small.size; - font-weight: Theme.body-small.weight; - vertical-alignment: center; - } - } -} - // Shared by every control: hover and press tint, press squeeze, keyboard focus ring and // tooltip. A control inherits it, sets its shape (`border-radius`) and container colours, and // puts its content in as children. Space and Enter activate the control when it has focus. @@ -73,7 +52,15 @@ export component StateLayer inherits Rectangle { root.clicked(); } - FocusScope { + // Moves keyboard focus here from code (a dialog focusing its default button); `ring` + // shows the focus ring as Tab would. + out property has-focus: keys.has-focus; + public function grab-focus(ring: bool) { + keys.focus(); + root.keyboard-focus = ring; + } + + keys := FocusScope { x: 0; width: 0; enabled: root.enabled; diff --git a/crates/tunal/ui/components/toast.slint b/crates/tunal/ui/components/toast.slint new file mode 100644 index 0000000..cec2ed2 --- /dev/null +++ b/crates/tunal/ui/components/toast.slint @@ -0,0 +1,231 @@ +import { Theme } from "../theme.slint"; +import { Motion } from "../motion.slint"; +import { Icon, Icons } from "icon.slint"; +import { StateLayer } from "state-layer.slint"; + +export enum ToastProgress { none, determinate, indeterminate } + +export struct ToastData { + message: string, + // Button label, e.g. "Undo"; empty for none. + action: string, + // Shows a cancel button (a running file operation). + cancellable: bool, + progress-kind: ToastProgress, + // 0 to 1 for `determinate`. + progress: float, + // Set by the owner to end the toast (the operation finished); it then plays its exit. + closing: bool, +} + +// A button on the inverse surface of a toast: label (action) or icon (cancel). +component ToastButton inherits StateLayer { + in property text; + in property icon; + + property content: root.icon != "" ? Theme.inverse-on-surface : Theme.inverse-primary; + + height: 32px; + width: root.icon != "" ? self.height : label.preferred-width + 2 * Theme.space-3; + border-radius: Theme.corner-full(self.height); + tint: root.content; + squeeze: root.icon != "" ? Motion.squeeze-small : Motion.squeeze; + + accessible-role: button; + accessible-label: root.icon != "" ? root.tooltip : root.text; + accessible-action-default => { + self.activate(); + } + + if root.icon != "": Icon { + x: (root.width - self.width) / 2; + y: (root.height - self.height) / 2; + glyph: root.icon; + size: 20px; + color: root.content; + } + + label := Text { + visible: root.icon == ""; + x: Theme.space-3; + text: root.text; + color: root.content; + font-size: Theme.label-large.size; + font-weight: Theme.label-large.weight; + vertical-alignment: center; + } +} + +component Toast inherits Rectangle { + in property data; + // 0 is the bottom of the stack. + in property slot; + callback action; + callback cancelled; + callback removed; + + // Set once created so the entrance animates; set again when the toast leaves by itself. + property entered; + property dismissed; + property leaving: root.data.closing || root.dismissed; + property progress: root.entered && !root.leaving ? 1 : 0; + animate progress { + duration: Motion.time(root.leaving ? Motion.short4 : Motion.medium1); + easing: root.leaving ? Motion.standard : Motion.emphasized-decelerate; + } + // Rises or falls as toasts below it come and go. + property stack-offset: root.slot * (root.height + Theme.space-2); + animate stack-offset { + duration: Motion.time(Motion.medium1); + easing: Motion.emphasized; + } + // Where the parent wants the bottom toast's top edge. + in property base-y; + + init => { + self.entered = true; + } + + height: 48px; + y: root.base-y - root.stack-offset + (1 - root.progress) * Theme.space-6; + opacity: root.progress; + background: Theme.inverse-surface; + border-radius: Theme.corner-xs; + drop-shadow-blur: Theme.float-shadow-blur; + drop-shadow-offset-y: Theme.float-shadow-offset; + drop-shadow-color: Theme.shadow.with-alpha(Theme.float-shadow-opacity); + + accessible-role: text; + accessible-label: root.data.message; + + // Hover keeps the toast up while the pointer is on it. + touch := TouchArea { } + + // A message without progress or action goes after a while; it waits while hovered. + Timer { + interval: Motion.toast-timeout; + running: root.entered && !root.leaving && !touch.has-hover && root.data.progress-kind == ToastProgress.none && root.data.action == ""; + triggered => { + root.dismissed = true; + } + } + + // Runs only during the exit: then the owner removes the toast from its model. + property gone; + Timer { + interval: Motion.short4; + running: root.leaving && !root.gone; + triggered => { + root.gone = true; + root.removed(); + } + } + + HorizontalLayout { + padding-left: Theme.space-4; + padding-right: Theme.space-2; + padding-bottom: root.data.progress-kind == ToastProgress.none ? 0 : Theme.space-1; + spacing: Theme.space-1; + + Text { + horizontal-stretch: 1; + text: root.data.message; + color: Theme.inverse-on-surface; + font-size: Theme.body-medium.size; + font-weight: Theme.body-medium.weight; + vertical-alignment: center; + overflow: elide; + } + + if root.data.action != "": VerticalLayout { + alignment: center; + + ToastButton { + text: root.data.action; + enabled: !root.leaving; + clicked => { + root.dismissed = true; + root.action(); + } + } + } + + if root.data.cancellable: VerticalLayout { + alignment: center; + + ToastButton { + icon: Icons.close; + tooltip: "Cancel"; + enabled: !root.leaving; + clicked => { + root.dismissed = true; + root.cancelled(); + } + } + } + } + + if root.data.progress-kind != ToastProgress.none: track := Rectangle { + x: Theme.space-4; + y: root.height - Theme.space-2; + width: root.width - 2 * Theme.space-4; + height: Theme.space-1; + border-radius: Theme.corner-full(self.height); + background: Theme.inverse-on-surface.with-alpha(Theme.disabled-container); + clip: true; + + if root.data.progress-kind == ToastProgress.determinate: Rectangle { + x: 0; + width: parent.width * clamp(root.data.progress, 0, 1); + border-radius: parent.border-radius; + background: Theme.inverse-primary; + animate width { + duration: Motion.time(Motion.short4); + easing: Motion.standard; + } + } + + // A segment sweeps while the toast shows (the work is moving, so the bar does too). + // Reduced motion: a still, dimmed full bar instead. + if root.data.progress-kind == ToastProgress.indeterminate && Motion.reduced: Rectangle { + background: Theme.inverse-primary.with-alpha(Theme.disabled-content); + } + if root.data.progress-kind == ToastProgress.indeterminate && !Motion.reduced && !root.leaving: Rectangle { + property phase: Math.mod(animation-tick() / Motion.indeterminate-period, 1); + + width: parent.width * 0.4; + x: -self.width + self.phase * (parent.width + self.width); + border-radius: parent.border-radius; + background: Theme.inverse-primary; + } + } +} + +// The toasts of a window, newest at the bottom, centred above the bottom edge. Place it +// last in the window (`width: 100%; height: 100%;`); it takes input only on the toasts. +// The owner appends to `toasts`, sets `closing` to end one, and removes the entry when +// `removed(index)` fires (after its exit). Action and cancel also end the toast. +export component ToastStack { + in property <[ToastData]> toasts; + in property toast-width: 400px; + callback action(index: int); + callback cancelled(index: int); + callback removed(index: int); + + for toast[i] in root.toasts: Toast { + data: toast; + slot: root.toasts.length - 1 - i; + width: min(root.toast-width, root.width - 2 * Theme.window-margin); + x: (root.width - self.width) / 2; + base-y: root.height - Theme.space-6 - self.height; + action => { + root.action(i); + } + cancelled => { + root.cancelled(i); + } + removed => { + root.removed(i); + } + } +} diff --git a/crates/tunal/ui/components/tooltip.slint b/crates/tunal/ui/components/tooltip.slint new file mode 100644 index 0000000..9144298 --- /dev/null +++ b/crates/tunal/ui/components/tooltip.slint @@ -0,0 +1,35 @@ +import { Theme } from "../theme.slint"; +import { Motion } from "../motion.slint"; + +// The small label an icon-only control shows after hovering for `Motion.tooltip-delay` +// (StateLayer's `tooltip`). It fades in; it leaves at once with its popup. +export component Tooltip inherits Rectangle { + in property text; + + property shown; + init => { + self.shown = true; + } + + background: Theme.inverse-surface; + border-radius: Theme.corner-xs; + height: 24px; + opacity: root.shown ? 1 : 0; + animate opacity { + duration: Motion.time(Motion.short3); + easing: Motion.standard; + } + + HorizontalLayout { + padding-left: Theme.space-2; + padding-right: Theme.space-2; + + Text { + text: root.text; + color: Theme.inverse-on-surface; + font-size: Theme.body-small.size; + font-weight: Theme.body-small.weight; + vertical-alignment: center; + } + } +} diff --git a/crates/tunal/ui/gallery.slint b/crates/tunal/ui/gallery.slint index 0cdfc52..f52d3f6 100644 --- a/crates/tunal/ui/gallery.slint +++ b/crates/tunal/ui/gallery.slint @@ -1,6 +1,7 @@ import { Theme } from "theme.slint"; import { Icon, Icons } from "components/icon.slint"; -import { ForceState, Tooltip } from "components/state-layer.slint"; +import { ForceState } from "components/state-layer.slint"; +import { Tooltip } from "components/tooltip.slint"; import { Button, ButtonKind } from "components/button.slint"; import { IconButton } from "components/icon-button.slint"; import { Chip, ChipKind } from "components/chip.slint"; @@ -8,6 +9,12 @@ import { Switch } from "components/switch.slint"; import { ListRow } from "components/list-row.slint"; import { Tab, TabBar } from "components/tab.slint"; import { TextField } from "components/text-field.slint"; +import { Menu } from "components/menu.slint"; +import { Dialog } from "components/dialog.slint"; +import { ToastStack, ToastProgress } from "components/toast.slint"; + +// What the gallery shows: every control, or a stand-in folder under open overlays. +export enum GalleryPage { controls, menu, dialog } // Every control in every state, for screenshots: `tunal --gallery --screenshot `. // Columns force the state; the last one is the disabled control. @@ -57,8 +64,19 @@ export component Gallery inherits Window { property <[ForceState]> states: [ForceState.none, ForceState.hover, ForceState.pressed, ForceState.focused, ForceState.none]; property disabled-column: 4; + in property page; - VerticalLayout { + // Opens the page's overlays; Rust calls it before taking the screenshot. + public function stage() { + if root.page == GalleryPage.menu { + menu.open-at(200px, 120px); + menu.expand(7); + } else if root.page == GalleryPage.dialog { + dialog.show(); + } + } + + if root.page == GalleryPage.controls: VerticalLayout { padding: Theme.space-6; spacing: Theme.space-3; alignment: start; @@ -323,4 +341,71 @@ export component Gallery inherits Window { } } } + + if root.page != GalleryPage.controls: VerticalLayout { + padding: Theme.space-6; + spacing: Theme.space-1; + alignment: start; + + for name[i] in ["Documents", "Downloads", "Music", "Pictures", "Videos", "notes.txt", "Quarterly report.pdf"]: ListRow { + width: 360px; + icon: i < 5 ? Icons.folder : Icons.description; + title: name; + selected: i == 2; + } + } + + ToastStack { + width: 100%; + height: 100%; + toasts: root.page == GalleryPage.menu ? [ + { message: "Copying 12 files to Music", cancellable: true, progress-kind: ToastProgress.determinate, progress: 0.62 }, + { message: "Moved 3 items to the trash", action: "Undo" }, + ] : root.page == GalleryPage.dialog ? [ + { message: "Counting files in Videos", cancellable: true, progress-kind: ToastProgress.indeterminate }, + ] : []; + } + + menu := Menu { + width: 100%; + height: 100%; + leading-icons: true; + items: [ + { text: "Open", icon: Icons.open-in-new, shortcut: "Enter" }, + { separator: true }, + { text: "Cut", icon: Icons.content-cut, shortcut: "Ctrl+X" }, + { text: "Copy", icon: Icons.content-copy, shortcut: "Ctrl+C" }, + { text: "Paste", icon: Icons.content-paste, shortcut: "Ctrl+V", disabled: true }, + { separator: true }, + { text: "Rename", icon: Icons.edit, shortcut: "F2" }, + { + text: "Sort by", + icon: Icons.sort, + submenu: [{ text: "Name" }, { text: "Size" }, { text: "Modified" }, { separator: true }, { text: "Type", disabled: true }], + }, + { separator: true }, + { text: "Move to trash", icon: Icons.delete, shortcut: "Delete" }, + ]; + } + + dialog := Dialog { + width: 100%; + height: 100%; + title: "Rename folder"; + body: "Other apps that point at this folder lose track of it."; + content-focus: true; + actions: [{ text: "Cancel", kind: ButtonKind.text }, { text: "Rename", kind: ButtonKind.filled }]; + focus-content => { + name-field.focus(); + } + action => { + self.close(); + } + + name-field := TextField { + label: "Name"; + text: "Music"; + } + } + } diff --git a/crates/tunal/ui/motion.slint b/crates/tunal/ui/motion.slint index d5aa5e3..57ceab0 100644 --- a/crates/tunal/ui/motion.slint +++ b/crates/tunal/ui/motion.slint @@ -36,6 +36,14 @@ export global Motion { out property squeeze: 0.96; out property squeeze-large: 0.985; + // Scale a floating surface starts from (and leaves towards), never 0. + out property enter-scale: 0.92; + + // How long a toast without progress or action stays. A delay, not motion. + out property toast-timeout: 4s; + // One sweep of an indeterminate progress bar. + out property indeterminate-period: 1500ms; + // Hover time before a tooltip shows. A delay, not motion: reduced motion keeps it. out property tooltip-delay: 500ms; diff --git a/crates/tunal/ui/theme.slint b/crates/tunal/ui/theme.slint index 8a96bd2..b5bf4bf 100644 --- a/crates/tunal/ui/theme.slint +++ b/crates/tunal/ui/theme.slint @@ -68,6 +68,16 @@ export global Theme { // Hairline borders. out property hairline: 1px; + // Floating surfaces (menus, dialogs, toasts, tooltips): one soft shadow, mixed from + // `shadow`. Resting surfaces have none. + out property float-shadow-blur: 12px; + out property float-shadow-offset: 4px; + out property float-shadow-opacity: 0.18; + // Dims the window behind a modal dialog, mixed from `scrim`. + out property scrim-opacity: 0.32; + // Gap kept between a floating surface and the window edge. + out property window-margin: 8px; + // Keyboard focus ring, drawn outside the control's shape. out property focus-ring-width: 2px; out property focus-ring-offset: 2px; diff --git a/docs/DECISIONS.md b/docs/DECISIONS.md index 643e89c..eb4cf25 100644 --- a/docs/DECISIONS.md +++ b/docs/DECISIONS.md @@ -31,3 +31,4 @@ D-026 — 2026-11-18 — File operations run as jobs in `tunal-core::ops`: `Jobs D-027 — 2026-11-18 — UI sessions look at the user's other Material You apps (Damson, Mulberry, Nacre; egui) as design references for colour roles, state layers, shape, spacing and motion, porting ideas to our Slint Theme/Motion tokens; the stack (Slint 1.19) stays; library defaults that don't match are replaced by own components — user — all UI plans (S004–S031, S034, S035). D-028 — 2026-11-18 — The user's old, buggy Tunal prototype (`/home/astar76/Documents/Apps/tunal-files/tunal/`, Python) is a UI reference only: look at its screens and elements for ideas (layout, panels, playlists, tag editor, dialogs), never copy its code, never port its bugs; the new UI should be fresh, not a re-skin — user — all UI plans, S008 (playlist sort), S021, S023. D-029 — 2026-11-18 — Orchestration: backend-only plans whose dependencies are done and whose files are a crate of their own (S017, S019, S020, S022, S025, S027) may run out of INDEX order in the second parallel slot beside the UI chain; still at most 2 sessions at once; each commits with explicit paths — orchestrator (user asked to keep everything runnable going) — S017–S027. +D-029 — 2026-11-18 — Floating surfaces don't use `PopupWindow` (it closes without exit motion): `Menu` and `Dialog` inherit `Overlay` and `ToastStack` is a plain layer, each placed last in the window at `width: 100%; height: 100%` in the order ToastStack, Dialog, Menu; they open with window coordinates and play exit motion by animating a `progress` that reverses mid-flight. Dialogs never close themselves (owner calls `close()` from `action`); toast models are owned outside (`closing` ends one, `removed(index)` drops it). Tooltips stay on `PopupWindow` (fade in, leave at once) — S005 — every UI plan with menus, dialogs or toasts (S010–S013, S018–S031). diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index 140788b..923b875 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -42,5 +42,12 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done, - Not verified: per-mount `.Trash-$uid` trash and cross-device move (no second filesystem inside the scratchpad). Workspace `cargo fmt --check` fails only on S005's in-progress `crates/tunal/src/main.rs`. - Later: trash `directorysizes` cache; orphan `.trashinfo` cleanup on empty; trash watch for live trash view; checking free space before copy. +## S005 — Menus, dialogs and toasts +- Done: `components/overlay.slint` `Overlay { open, modal, enter/exit-duration; out progress; dismissed; place() }` (full-window layer, scrim, outside click/scroll swallowed, hidden once its exit ends). `Menu { items: [MenuItem { text, icon, shortcut, disabled, separator, submenu: [MenuEntry] }], leading-icons; activated(index, sub-index), closed; open-at(x, y), expand(i), close() }`: scale + fade from the anchor, flips/clamps at window edges, arrows skip separators/disabled, Right/Left/Enter/Space/Esc, hover opens the submenu. `Dialog { title, body, actions: [DialogAction { text, kind }], default-action, cancel-action, dialog-width, content-focus; action(i), focus-content; show(), close() }` + children slot: scrim fade, scale-in, Enter/Esc/scrim click, Tab wraps inside. `ToastStack { toasts: [ToastData { message, action, cancellable, progress-kind: ToastProgress, progress, closing }], toast-width; action(i), cancelled(i), removed(i) }`: slide/fade in and out, animated re-stack, auto-dismiss after `Motion.toast-timeout` (paused on hover), determinate bar / indeterminate sweep. `Tooltip` moved to `tooltip.slint`, fades in. `StateLayer.has-focus` + `grab-focus(ring)`. Tokens: `Theme.float-shadow-*`, `scrim-opacity`, `window-margin`; `Motion.enter-scale`, `toast-timeout`, `indeterminate-period`; 9 icons. `tunal --gallery --page menu|dialog`. +- Overlay API: put `ToastStack`, `Dialog`, `Menu` last in the window (`width: 100%; height: 100%`), then `menu.open-at(btn.absolute-position.x, btn.absolute-position.y + btn.height)`, `dialog.show()` / `close()` from `action`, append `ToastData` to the model and remove it on `removed(i)` (D-029). +- Verified: workspace build, clippy -D warnings, fmt --check, literal grep empty; looked at menu/dialog pages light + dark at 960×640, menu flipped at 720×480, controls page unchanged. Keys injected once through a temporary, uncommitted `dispatch_event` hook: arrow skip and wrap, Esc closing submenu then menu, Enter activating, dialog Tab/Shift+Tab wrap, Enter default, Esc cancel. +- Not done: motion (scale, slide, re-stack, sweep) not watched live (screenshots force reduced motion; software renderer ignores `transform-scale`, D-025); pointer outside-click and hover-open not exercised. Dialog content should hold one focus stop: a `TextField` with text has two (input + clear), so Shift+Tab from its clear button wraps to the last action. +- Later: focus doesn't return to the opener by itself (use `closed` / after `close()`); a menu opened from a button flips to end at the anchor point, not above the button. + ## Later -