diff --git a/crates/eggshell-ui-shadcn/src/preset.rs b/crates/eggshell-ui-shadcn/src/preset.rs index 470c26be..f1b4cb2f 100644 --- a/crates/eggshell-ui-shadcn/src/preset.rs +++ b/crates/eggshell-ui-shadcn/src/preset.rs @@ -1,10 +1,10 @@ use std::time::Duration; use eggshell_ui::contract::{ - self, Colors, Focus, Keyed, Look as BoxLook, Metrics, Paint, Size, States, SwitchMetrics, - Variant, + self, Colors, Entry, Focus, Keyed, KindMotion, Look as BoxLook, Metrics, Paint, Size, States, + SwitchMetrics, Variant, }; -use eggshell_ui::{Opacity, TextSpec, Tracking}; +use eggshell_ui::{Easing, Opacity, TextSpec, Tracking}; use egui::{Color32, Context, Id, Shadow, Theme}; use crate::styles::{DestructiveLook, HoverSurface, SecondaryHover, ShadcnStyle}; @@ -496,8 +496,33 @@ impl Shadcn { style.scroll.thumb_active = t.border; style.scroll.track = clear; style.scroll.radius = egui::CornerRadius::same(u8::MAX); - // shadcn's overlays: `bg-black/50`. - style.scrim = Color32::from_black_alpha(128); + // shadcn's overlays are `bg-black/50`; with no backdrop blur (#40) the + // scrim alone separates a dialog from the page, so it is darker. + style.scrim = Color32::from_black_alpha(204); + // shadcn's `animate-in` (150 ms) for popovers, dropdown menus and + // selects: `zoom-in-95 slide-in-from-*-2`. DialogContent: + // `zoom-in-95 duration-200`. SheetContent: + // `slide-in-from-*`, `ease-in-out`, 500 ms open and 300 ms close. + let animate = KindMotion { + entry: Entry::Pop, + enter: Duration::from_millis(150), + exit: Duration::from_millis(150), + easing: Easing::Default, + }; + style.motion.popover = animate; + style.motion.menu = animate; + style.motion.dialog = KindMotion { + entry: Entry::Zoom, + enter: Duration::from_millis(200), + exit: Duration::from_millis(200), + easing: Easing::Default, + }; + style.motion.sheet = KindMotion { + entry: Entry::Slide, + enter: Duration::from_millis(500), + exit: Duration::from_millis(300), + easing: Easing::InOut, + }; style } diff --git a/docs/overlays.md b/docs/overlays.md index 698e21f0..81115e69 100644 --- a/docs/overlays.md +++ b/docs/overlays.md @@ -394,7 +394,7 @@ New entries in `Style` (each a `Look` with a rest state, border, radius, shadow, | `dialog` | box, header/footer, title and description text, close button | width, radius, padding, footer layout, close button present or not | | `sheet` | box per side, border side, header/footer | default width, border, shadow | | `tooltip` | bubble, arrow | **inverted vs popover look**, radius, padding, arrow on or off, delay | -| `scrim` | modal backdrop | colour/alpha (shadcn `bg-black/50`), blur is out of scope (#40, known difference). Built in PR 4 as `Style::scrim`, a colour: shadcn black at 128/255, neutral `from_black_alpha(100)` (egui's own modal backdrop). | +| `scrim` | modal backdrop | colour/alpha (shadcn `bg-black/50`), blur is out of scope (#40, known difference). Built in PR 4 as `Style::scrim`, a colour: shadcn black at 204/255 (80%, darker than shadcn's `bg-black/50` because there is no blur; user's pick from rendered candidates, 2026-11-12), neutral `from_black_alpha(100)` (egui's own modal backdrop). | | `motion` | open/close duration, easing, entrance per kind | the numbers and curves | The select's list is drawn from `Style::menu` (PR 6b): `SelectStyle` lost its `popup*` and `item*` fields to `MenuStyle`, so the list and the menus cannot drift. @@ -684,3 +684,18 @@ Where the build differs from, or settles, what sections 4, 5 and 9 leave open. - **`CustomChain::role`.** `CustomChain::role(Role)` gives a custom-painted node the semantics of `NodeHandle::role`, with `named` as its name. Test: a swatch painted with `.custom(..)` and `MenuItemRadio` in a `Nav::Menu` overlay is reached by the arrows and activated by Enter. - **Examples.** The `menu` example's popover is a stock dropdown (actions, a disabled item, headings, check and radio items, a submenu, a destructive item); its tall scrolling list stays hand-built, since stock menus do not scroll. The dialog's role picker stays hand-built: it is width-matched to its trigger and marks the current role in the label, which the stock dropdown (a `min-w` box with radio marks) does not do. - **Not yet.** Typeahead, hover-open from closed, the safe triangle, a menu bar, scrolling stock menus, `.command(id)` (#125), keyboard opening of a context menu (Shift+F10, the Menu key), a controlled mode. + +## As built in PR 6a (presence, sheets) + +- **API.** On the overlay chain: `.shown(Shown | bool)`, `.transition(Duration)` (enter and exit), `.exit_transition(Duration)` (exit only; order against `transition` does not matter), `.easing(Easing)` with `.ease_linear/in/out/in_out()`, `.entrance(Entrance)` and `.on_exited(|app| ..)`. `Entrance` is `Fade | Zoom | Pop | Slide(Side)` (`SlideFade` of §7 is gone). **The box and its contents are never faded**: without group opacity (#40) a per-shape fade lets the page show through the box mid-motion, so only a modal's scrim fades with progress. `Zoom` scales the box up from 95% about its centre (shadcn's `zoom-in-95`); `Pop` is `Zoom` plus the 8 pt `slide-in-from-*-2` away from the anchor (a modal has no anchor and only zooms); `Slide` moves the box by its own size from that side. `Fade` has no motion of the box, so the box appears and vanishes at once while the scrim fades (a floating overlay has nothing to fade: it is instant, though it stays mounted, inert and blocking, for the exit's duration). `Shown` has no `From`: no naked bool arguments. +- **Deviation from §7: `shown` is optional** (§7 says required; decided to keep it optional). An overlay declared without `shown` is open exactly in the frames that declare it and has no motion, so every existing overlay (the stock select, menus and the tests) is unchanged. The motion methods without `shown` are a debug panic naming the declaration site. +- **State.** The phase (`Closed | Entering | Open | Exiting`) is `Kept::presences`, per `LayoutState`: a `Transition` per overlay id, stepped at build with `transition::Transition::toward`, so there is no second clock; the progress is the eased `Progress`, reversed from where it is (and lasting in proportion to the distance left, as CSS does). Entries of overlays not declared in a frame are swept. `children` is not called while the overlay is closed, and no root is declared for it. `on_exited` is queued at the build that finds the overlay closed after being present, and runs at the end of that frame's draw, once. Repaints are requested only while in flight. +- **Exiting overlays.** Inert (the subtree is drawn inert), but the root's blocker stays live, so the page behind takes no pointer input until the overlay is gone; a press on the scrim or Esc does nothing. An exiting overlay is not one of `open_overlays`: it is not judged by `dismissals` (outside press, focus leaving, window blur), takes no `Nav` keys, no Esc, no Return default action, and is not entered with focus. It stays in the stacking (the repair, `root_at`, the focus trap) and in the library's stack until it is closed, so focus is restored when the exit has run, not when it starts. An overlay that is entering is live in every respect: Esc while it enters dismisses it and it turns round. +- **Paint.** Layout and hit rects are final from the first frame; the draw moves what the box painted (`transform_range` on the shapes it pushed, so draw closures and shadows move with it). A modal's root paints the scrim at the progress, and its children are the box. A floating overlay's root is the box. Zoom scales the painted shapes (text included, through egui's mesh transform, so glyphs are resampled while moving) and hit rects stay where layout put them. +- **Style.** `Style::motion: MotionStyle { popover, menu, dialog, sheet }`, each a `KindMotion { entry, enter, exit, easing }` with `Entry::{Fade, Zoom, Pop, Slide, SlideFade}` (a `Slide` entry takes the edge of the `Modal::Edge` it is for; without one it fades). The chain's kind is `dialog` for `Modal::Center`, `sheet` for `Modal::Edge`, `menu` for a floating overlay with a `Nav`, `popover` otherwise. The neutral default is instant. shadcn preset: popover and menu `Pop` 150 ms; dialog `Zoom` 200 ms; sheet `Slide` 500 ms in, 300 ms out, `ease-in-out` (the tailwindcss-animate `ease` curve is not one of `Easing`, so the default curve stands in). +- **Continuity.** `Motion::Presents` marks the nodes of an entering or leaving overlay; the teleport check judges them like slides. A test records a sheet opening and closing and asserts `assert_continuous`. +- **Examples.** The dialog example's dialog, confirmation and sheet use `shown`; the role picker is still declared only while open. +- **Stock widgets.** The select's list and the dropdown menu are always declared with `shown(open)`, so they enter and leave with the style's `menu` motion (shadcn: `Pop`, 150 ms). The open state is still the widget's own (`Listing`, `Menus`); closing it makes the overlay `Closed` while the list or menu is built one more time for the exit. Tests that look for a closed list or menu to be gone settle for the exit first. Submenus and the context menu are declared only while open and have no exit yet (the context menu's position is dropped with its open state). +- **One `LayoutState` per frame is not supported with motion.** The presence is `Kept` state, so a layout recreated every frame never leaves progress 0 and a moving overlay is never drawn (the stack and the layout animation already need the state to persist: see `LayoutState`). `tests/it/popup_style.rs` held a throwaway layout and now keeps one. +- **Review images.** `cargo test --features snapshots --test it -- --ignored motion_strips` (with `EGGSHELL_MOTION_DIR` and the lavapipe `VK_ICD_FILENAMES`, as `cargo xtask snapshots` sets) writes frames at 0, 25, 50, 75 and 100% of the enter and of the exit of the dialog, the sheet and the menu, in both themes. +- **Not yet.** Submenu and context-menu exits; the tooltip (PR 7); drawers. diff --git a/examples/dialog.rs b/examples/dialog.rs index f0ca56e8..9276b1ab 100644 --- a/examples/dialog.rs +++ b/examples/dialog.rs @@ -15,7 +15,7 @@ #[path = "common/mod.rs"] mod common; -use eggshell_ui::overlay::{DismissOn, Modal, Nav, Side}; +use eggshell_ui::overlay::{DismissOn, Modal, Nav, Shown, Side}; use eggshell_ui::prim::text_field::Field; use eggshell_ui::scroll::Axis; use eggshell_ui::{Builder, Scope, Tw, tw}; @@ -55,10 +55,10 @@ const ROWS: u32 = 40; #[derive(Default)] pub struct State { - pub dialog: bool, - pub confirm: bool, + pub dialog: Shown, + pub confirm: Shown, pub picker: bool, - pub sheet: bool, + pub sheet: Shown, pub name: String, pub role: usize, pub saved: Option, @@ -155,10 +155,10 @@ pub fn layout(b: &mut Builder<'_, '_, State>, state: &State) { s.div_id(Part::Intro, tw().flex().flex_col().gap(6.0).p(6.0), |s| { s.div_id(Part::Actions, tw().flex().items_center().gap(2.0), |s| { s.button(Part::OpenDialog, "Edit profile") - .on_click(|state: &mut State| state.dialog = true); + .on_click(|state: &mut State| state.dialog = Shown::Open); s.button(Part::OpenSheet, "Open sheet") .variant(variant::OUTLINE) - .on_click(|state: &mut State| state.sheet = true); + .on_click(|state: &mut State| state.sheet = Shown::Open); if let Some(saved) = &state.saved { s.text( tw().text(t.muted_foreground), @@ -180,22 +180,19 @@ pub fn layout(b: &mut Builder<'_, '_, State>, state: &State) { } }); }); - if state.dialog { - dialog(b, state, &t); - } - if state.sheet { - sheet(b, &t); - } + dialog(b, state, &t); + sheet(b, state, &t); } fn dialog(b: &mut Builder<'_, '_, State>, state: &State, t: &Tokens) { let dialog = dialog_box(t); b.overlay(Part::Dialog) .modal(Modal::Center) + .shown(state.dialog) .role(Role::Dialog) .named("Edit profile") .on_dismiss(|state: &mut State| { - state.dialog = false; + state.dialog = Shown::Closed; state.picker = false; }) .children(|s| { @@ -229,13 +226,13 @@ fn dialog(b: &mut Builder<'_, '_, State>, state: &State, t: &Tokens) { s.div_id(Part::Footer, tw().flex().justify_between(), |s| { s.button(Part::Delete, "Delete") .variant(variant::DESTRUCTIVE) - .on_click(|state: &mut State| state.confirm = true); + .on_click(|state: &mut State| state.confirm = Shown::Open); s.div(tw().flex().gap(2.0), |s| { s.button(Part::Cancel, "Cancel") .variant(variant::OUTLINE) .cancel_action() .on_click(|state: &mut State| { - state.dialog = false; + state.dialog = Shown::Closed; state.picker = false; }); s.button(Part::Save, "Save changes") @@ -243,14 +240,12 @@ fn dialog(b: &mut Builder<'_, '_, State>, state: &State, t: &Tokens) { .default_action() .on_click(|state: &mut State| { state.saved = Some(state.name.clone()); - state.dialog = false; + state.dialog = Shown::Closed; state.picker = false; }); }); }); - if state.confirm { - confirm(s, t); - } + confirm(s, state, t); }); }); } @@ -294,14 +289,15 @@ fn role_menu(s: &mut Scope<'_, '_, State>, state: &State) { }); } -fn confirm(s: &mut Scope<'_, '_, State>, t: &Tokens) { +fn confirm(s: &mut Scope<'_, '_, State>, state: &State, t: &Tokens) { let dialog = dialog_box(t); s.overlay(Part::Confirm) .modal(Modal::Center) + .shown(state.confirm) .role(Role::AlertDialog) .named("Are you absolutely sure?") .dismiss_on(DismissOn::EscOnly) - .on_dismiss(|state: &mut State| state.confirm = false) + .on_dismiss(|state: &mut State| state.confirm = Shown::Closed) .children(|s| { s.div_id(Part::Box, dialog.max_w_px(448.0), |s| { header( @@ -314,14 +310,14 @@ fn confirm(s: &mut Scope<'_, '_, State>, t: &Tokens) { s.button(Part::Cancel, "Cancel") .variant(variant::OUTLINE) .cancel_action() - .on_click(|state: &mut State| state.confirm = false); + .on_click(|state: &mut State| state.confirm = Shown::Closed); s.button(Part::Continue, "Continue") .variant(variant::DESTRUCTIVE) .default_action() .on_click(|state: &mut State| { state.deleted += 1; - state.confirm = false; - state.dialog = false; + state.confirm = Shown::Closed; + state.dialog = Shown::Closed; state.picker = false; }); }); @@ -329,13 +325,14 @@ fn confirm(s: &mut Scope<'_, '_, State>, t: &Tokens) { }); } -fn sheet(b: &mut Builder<'_, '_, State>, t: &Tokens) { +fn sheet(b: &mut Builder<'_, '_, State>, state: &State, t: &Tokens) { let sheet = sheet_box(t); b.overlay(Part::Sheet) .modal(Modal::Edge(Side::Right)) + .shown(state.sheet) .role(Role::Dialog) .named("Settings") - .on_dismiss(|state: &mut State| state.sheet = false) + .on_dismiss(|state: &mut State| state.sheet = Shown::Closed) .children(|s| { s.div_id(Part::Box, sheet, |s| { header( @@ -348,7 +345,7 @@ fn sheet(b: &mut Builder<'_, '_, State>, t: &Tokens) { s.button(Part::Close, "Close") .variant(variant::OUTLINE) .cancel_action() - .on_click(|state: &mut State| state.sheet = false); + .on_click(|state: &mut State| state.sheet = Shown::Closed); }); }); }); diff --git a/src/builder.rs b/src/builder.rs index 8e999c3a..bd9db24d 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -20,6 +20,7 @@ use crate::pipeline::{ BuildState, ColorSource, DismissFn, DrawKind, Frame, Interaction, MeasureFn, Node, NodeKind, ScrollNode, }; +use crate::presence::{self, Motion, Step}; use crate::prim::{Icon, Prim}; use crate::roots::{OverlayDecl, Presentation, RootDecl, overlay_style}; use crate::scroll::TabRule; @@ -305,8 +306,21 @@ impl<'b, 'f, A> Builder<'b, 'f, A> { slot: &Slot, decl: OverlayDecl, on_dismiss: Option>, + (motion, on_exited): (Option, Option>), body: impl FnOnce(&mut Scope<'_, 'f, A>), ) { + let mut decl = decl; + if let Some(motion) = motion { + match presence::step(&self.st.kept, self.frame.ctx, slot.id, &motion) { + Step::Closed { exited } => { + if let Some(then) = on_exited.filter(|_| exited) { + self.frame.exited.push(then); + } + return; + } + Step::Present(staged) => decl.staged = staged, + } + } let band = decl.band; let classes = match decl.presentation { Presentation::Modal(_) => tw().bg(Style::of(self.ctx()).scrim), diff --git a/src/continuity.rs b/src/continuity.rs index 828072bb..d7ab2175 100644 --- a/src/continuity.rs +++ b/src/continuity.rs @@ -22,13 +22,19 @@ use egui::{Context, Id, Rect, Vec2}; use crate::tw::{Opacity, Progress}; -/// Whether a node declared `animate_layout`. +/// How a node may move on its own: by sliding over a layout change, or as part +/// of an overlay's entrance or exit. #[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[non_exhaustive] pub enum Motion { /// A change of its layout position is painted at once. Snaps, /// A change of its layout position is slid over. Slides, + /// The node is the box (or the scrim) of an overlay that enters or leaves + /// with motion, which moves and fades it from frame to frame while its + /// layout stays put. Judged like a slide: it may not jump. + Presents, } /// Names one slide: the same for every frame of it, and different for the @@ -488,7 +494,9 @@ impl Timeline { let own_offset_change: Vec2 = p - l - moved_by_ancestors; let jumped = p.length() > step; match now.motion { - Motion::Slides => (p - moved_by_scrolling).length() > step, + Motion::Slides | Motion::Presents => { + (p - moved_by_scrolling).length() > step + } Motion::Snaps => jumped && own_offset_change.length() > step, } }); diff --git a/src/contract.rs b/src/contract.rs index 6a1151e7..e9ed5f81 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -20,6 +20,7 @@ use std::time::Duration; use egui::{Color32, Context, FontFamily, Id, Shadow, Theme, Vec2, vec2}; +pub use crate::presence::{Entry, KindMotion, MotionStyle}; use crate::{Opacity, Progress, TextSpec, Tracking}; /// A button variant, named by the style that defines it. @@ -812,6 +813,8 @@ pub struct Style { /// What a modal overlay paints over the screen behind its box. Usually /// translucent. pub scrim: Color32, + /// How overlays that declare when they are shown enter and leave. + pub motion: MotionStyle, } #[derive(Clone)] @@ -1248,6 +1251,7 @@ impl Style { }, scroll: ScrollStyle::from_egui(egui), scrim: Color32::from_black_alpha(100), + motion: MotionStyle::INSTANT, } } diff --git a/src/draw.rs b/src/draw.rs index 75c06896..75749d3b 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -26,12 +26,13 @@ use crate::overlay::{Anchored, Band, Nav}; use crate::overlay_input::Blur; use crate::overlay_input::{self, press_origin}; use crate::pipeline::{ColorSource, DrawFn, Flow, NodeKind, Placed, PlacedNode}; +use crate::presence::Staged; use crate::prim::{Icon, Prim}; use crate::roots::{Form, PlacedRoot, covers_screen, root_of, stacked_top_down}; use crate::scroll::{self, Moved}; use crate::scroll_keys; use crate::shadow_corners::{Corner, arc_segments, clip_mesh_to_triangle, outside_corner_fan}; -use crate::stack::{self, Shown}; +use crate::stack::{self, Drawn}; use crate::text::{Interactive, TextAlign, TextStyle}; use crate::transition::{self, LayoutAnimation}; use crate::tw::{ @@ -484,6 +485,15 @@ fn image_for(icon: Icon, tint: Color32) -> Image<'static> { .rotate(rotate.into(), Vec2::splat(0.5)) } +/// `rect` scaled by `scale` about its centre. +fn scaled_about_centre(rect: Rect, scale: f32) -> Rect { + if scale == 1.0 { + rect + } else { + Rect::from_center_size(rect.center(), rect.size() * scale) + } +} + /// What the walk of a frame accumulates, whichever `Ui` it is in. struct Shared { prims: Vec>, @@ -500,6 +510,18 @@ struct Shared { highlighted: Vec, /// Why a field losing focus in this pass does, told to its hooks. blur: Blur, + /// The nodes of overlays that are entering or leaving, by index. + stages: HashMap, +} + +/// How an entering or leaving overlay is painted at one of its nodes. +#[derive(Clone, Copy)] +enum Stage { + /// The root of a modal: its own fill is the scrim, which fades with the + /// overlay's progress, while the box in it has the overlay's entrance. + Scrim(Opacity), + /// A box that scales and moves with the overlay's progress. + Box { staged: Staged, form: Form }, } /// How far two boxes may overlap and still only touch: layout leaves @@ -637,6 +659,15 @@ impl Walk<'_, A> { let described = overlay .map(|overlay| &overlay.description) .filter(|description| description.is_set()); + // An overlay that is leaving is inert, but its blocker keeps the page + // from taking the pointer until it is gone. + let inherited = match overlay { + Some(_) => Inherited { + inertness: Inertness::Live, + ..inherited + }, + None => inherited, + }; node_ui( self.ui, UiBuilder::new().max_rect(boxes.border), @@ -931,7 +962,18 @@ impl Walk<'_, A> { }) }; + let stage = self.shared.stages.get(&index).copied(); + let (staged_offset, staged_scale, scrim) = match stage { + Some(Stage::Box { staged, form }) => ( + staged.offset(node.rect().size(), form), + staged.scale(), + Opacity::OPAQUE, + ), + Some(Stage::Scrim(scrim)) => (Vec2::ZERO, 1.0, scrim), + None => (Vec2::ZERO, 1.0, Opacity::OPAQUE), + }; let opacity = parent.opacity * look.paint.opacity; + let own_opacity = opacity * scrim; let lifted = self.lift.filter(|lift| lift.index == index); let slide = match (interaction.variants.animate_layout, node.id(), lifted) { (Some(duration), Some(id), None) => self.shared.animation.offset( @@ -949,7 +991,7 @@ impl Walk<'_, A> { let (translate, shift) = match lifted { Some(lift) => (lift.min - node.rect().min, Vec2::ZERO), None => { - let translate = look.translate + slide; + let translate = look.translate + slide + staged_offset; (translate, parent.shift + translate) } }; @@ -958,16 +1000,17 @@ impl Walk<'_, A> { id, path: node.path().to_owned(), layout_rect: node.rect(), - painted_rect: node.rect().translate(shift), + painted_rect: scaled_about_centre(node.rect(), staged_scale).translate(shift), ancestors: if lifted.is_some() { Vec2::ZERO } else { parent.shift }, scrolled: parent.scrolled, - opacity, - motion: match (interaction.variants.animate_layout, lifted) { - (Some(_), None) => Motion::Slides, + opacity: own_opacity, + motion: match (interaction.variants.animate_layout, lifted, stage) { + (_, None, Some(_)) => Motion::Presents, + (Some(_), None, None) => Motion::Slides, _ => Motion::Snaps, }, slide: self @@ -976,9 +1019,10 @@ impl Walk<'_, A> { .slide(id, interaction.variants.easing, translate), }); } - let moved_from = (translate != Vec2::ZERO || lifted.is_some()).then(|| self.next_shape()); + let moved_from = (translate != Vec2::ZERO || lifted.is_some() || staged_scale != 1.0) + .then(|| self.next_shape()); paint_box( - &self.painter(parent.clip, opacity), + &self.painter(parent.clip, own_opacity), &look.paint, &boxes, node.border, @@ -1044,7 +1088,8 @@ impl Walk<'_, A> { )); } if let Some(first) = moved_from { - self.translate_shapes_since(first, translate); + let about = node.rect().center().to_vec2() * (1.0 - staged_scale); + self.transform_shapes_since(first, TSTransform::new(about + translate, staged_scale)); if lifted.is_some() { self.lift_shapes_since(first); } @@ -1184,12 +1229,12 @@ impl Walk<'_, A> { /// Moves what the subtree painted since `first`, and the clips it was /// painted with, as a CSS transform does: layout and hit rects stay. - fn translate_shapes_since(&self, first: ShapeIdx, by: Vec2) { + fn transform_shapes_since(&self, first: ShapeIdx, by: TSTransform) { let layer = self.ui.layer_id(); self.ui.ctx().graphics_mut(|graphics| { let list = graphics.entry(layer); let end = list.next_idx(); - list.transform_range(first, end, TSTransform::from_translation(by)); + list.transform_range(first, end, by); }); } @@ -1321,10 +1366,29 @@ impl Walk<'_, A> { } impl Walk<'_, A> { + /// Notes how the overlay rooted at `first` is painted while it enters or + /// leaves. + fn stage(&mut self, first: usize, form: Form, staged: Staged) { + let boxed = Stage::Box { staged, form }; + match form { + Form::Modal(_) => { + self.shared + .stages + .insert(first, Stage::Scrim(staged.scrim())); + for child in children_of(self.nodes, first) { + self.shared.stages.insert(child, boxed); + } + } + Form::Floating(_) => { + self.shared.stages.insert(first, boxed); + } + } + } + /// Draws every attached overlay, in the order they were declared, each in /// a layer of its own, and returns the ones drawn in the order they were /// opened. Walks `self` from the page's `Ui`. - fn overlays(&mut self) -> Vec { + fn overlays(&mut self) -> Vec { let ctx = self.ui.ctx().clone(); let screen = ctx.content_rect(); let mut shown = Vec::new(); @@ -1354,6 +1418,14 @@ impl Walk<'_, A> { ); }); self.shared.beneath.clear(); + let staged = overlay.staged; + let mut inherited = Inherited::root(screen, root_rect.min); + if !staged.is_steady() { + self.stage(root.first, overlay.form, staged); + } + if staged.is_exiting() { + inherited.inertness = Inertness::Inert; + } egui::Area::new(layer.id) .order(layer.order) .fixed_pos(rect.min) @@ -1366,12 +1438,11 @@ impl Walk<'_, A> { if swallows { ui.interact(rect, overlay.id.with("swallow"), Sense::CLICK | Sense::DRAG); } - self.in_layer(ui) - .visit(root.first, Inherited::root(screen, root_rect.min)); + self.in_layer(ui).visit(root.first, inherited); }); shown.push(( overlay.stack_index, - Shown { + Drawn { id: overlay.id, band: overlay.band, }, @@ -1446,6 +1517,7 @@ impl Placed { mut drag, mut dismiss, roots, + exited, root: _, } = self; let overflow = (Debug::of(ui.ctx()) == Debug::Outlines) @@ -1485,6 +1557,7 @@ impl Placed { beneath: Vec::new(), highlighted: nav::highlighted(&kept), blur: Blur::Elsewhere, + stages: HashMap::new(), }; nav::activate_highlighted(ui.ctx(), &kept); nav::apply_deferred(ui.ctx()); @@ -1522,6 +1595,9 @@ impl Placed { app, ); finish.finish(&ctx, &nodes, &mut drag, app); + for then in exited { + then(app); + } scroll_keys::note_press(&ctx, &nodes); scroll_keys::apply_keys(&ctx, &nodes); scroll_keys::follow_focus(&ctx, &shared.subtrees); diff --git a/src/kept.rs b/src/kept.rs index b086d886..6fa22b4f 100644 --- a/src/kept.rs +++ b/src/kept.rs @@ -13,6 +13,7 @@ use egui::Rect; use crate::nav::Active; use crate::overlay_input::Typing; use crate::owned::Menus; +use crate::presence::Presences; use crate::stack::Stack; use crate::transition::Tracking; @@ -23,6 +24,7 @@ pub(crate) struct Kept { pub(crate) typing: Typing, pub(crate) menus: Menus, pub(crate) animation: Tracking, + pub(crate) presences: Presences, /// The area the last layout placed things in. pub(crate) area: Option, } diff --git a/src/lib.rs b/src/lib.rs index b15bc83f..ca44dd78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -226,6 +226,7 @@ mod overlay_chain; mod overlay_input; pub mod owned; mod pipeline; +mod presence; pub mod prim; mod roots; pub mod scroll; diff --git a/src/overlay.rs b/src/overlay.rs index e8691986..fe593d0d 100644 --- a/src/overlay.rs +++ b/src/overlay.rs @@ -10,6 +10,7 @@ use egui::{Id, Order, Pos2, Rect, Vec2, pos2, vec2}; pub use crate::overlay_chain::{Floating, Modally, OverlayChain, Unplaced}; +pub use crate::presence::{Entrance, Shown}; /// A signed length in points: a gap, a shift or a margin. /// diff --git a/src/overlay_chain.rs b/src/overlay_chain.rs index 1abada6c..3bb08b09 100644 --- a/src/overlay_chain.rs +++ b/src/overlay_chain.rs @@ -1,5 +1,7 @@ //! The chain `Builder::overlay` starts. +use core::time::Duration; + use egui::Role; use crate::builder::{Builder, Scope, Slot}; @@ -7,8 +9,10 @@ use crate::overlay::{ Anchor, Band, Behavior, DismissOn, Focus, MatchWidth, Modal, Nav, Outside, Placement, Wrap, }; use crate::pipeline::DismissFn; +use crate::presence::{Entrance, ExitedFn, Motion, Shown, Staged}; use crate::roots::{OverlayDecl, Presentation}; use crate::scroll::Description; +use crate::tw::Easing; /// An overlay chain that has no anchor yet. #[derive(Clone, Copy, Debug)] @@ -64,10 +68,35 @@ pub struct OverlayChain<'b, 'f, A, State> { description: Description, behavior: Behavior, on_dismiss: Option>, + presence: Presence, declared_at: &'static std::panic::Location<'static>, state: State, } +/// What the chain said of the overlay's presence; the style fills in the +/// rest. +struct Presence { + shown: Option, + transition: Option, + exit: Option, + easing: Option, + entrance: Option, + on_exited: Option>, +} + +impl Default for Presence { + fn default() -> Self { + Self { + shown: None, + transition: None, + exit: None, + easing: None, + entrance: None, + on_exited: None, + } + } +} + impl<'b, 'f, A> OverlayChain<'b, 'f, A, Unplaced> { #[track_caller] pub(crate) fn new(b: Builder<'b, 'f, A>, slot: Slot) -> Self { @@ -79,6 +108,7 @@ impl<'b, 'f, A> OverlayChain<'b, 'f, A, Unplaced> { description: Description::default(), behavior: Behavior::default(), on_dismiss: None, + presence: Presence::default(), state: Unplaced, } } @@ -110,6 +140,7 @@ impl<'b, 'f, A> OverlayChain<'b, 'f, A, Unplaced> { description, behavior, on_dismiss, + presence, declared_at, state: Unplaced, } = self; @@ -120,6 +151,7 @@ impl<'b, 'f, A> OverlayChain<'b, 'f, A, Unplaced> { description, behavior, on_dismiss, + presence, declared_at, state, } @@ -187,6 +219,77 @@ impl OverlayChain<'_, '_, A, State> { self.on_dismiss = Some(Box::new(then)); self } + + /// Declares the overlay every frame, whether it is shown or not, and + /// lets the library keep it on screen while it leaves. Without + /// `shown` the overlay is open exactly in the frames that declare it, + /// and has no motion. + /// + /// `children` is not called while the overlay is fully closed. While it + /// exits it is built as usual, takes no input, still blocks the page, and + /// is not dismissed again. Reopening mid-exit reverses from where the + /// box is. + pub fn shown(mut self, shown: Shown) -> Self { + self.presence.shown = Some(shown); + self + } + + /// How long the overlay takes to enter and to leave. The style's + /// [`motion`](crate::contract::Style::motion) for the kind of overlay + /// unless set. Needs [`shown`](Self::shown). + pub fn transition(mut self, duration: Duration) -> Self { + self.presence.transition = Some(duration); + self + } + + /// How long the overlay takes to leave, if that is not how long it takes + /// to enter. Needs [`shown`](Self::shown). + pub fn exit_transition(mut self, duration: Duration) -> Self { + self.presence.exit = Some(duration); + self + } + + /// The timing function of the enter and the exit. Needs + /// [`shown`](Self::shown). + pub fn easing(mut self, easing: Easing) -> Self { + self.presence.easing = Some(easing); + self + } + + /// [`Easing::Linear`]. + pub fn ease_linear(self) -> Self { + self.easing(Easing::Linear) + } + + /// [`Easing::In`]. + pub fn ease_in(self) -> Self { + self.easing(Easing::In) + } + + /// [`Easing::Out`]. + pub fn ease_out(self) -> Self { + self.easing(Easing::Out) + } + + /// [`Easing::InOut`]. + pub fn ease_in_out(self) -> Self { + self.easing(Easing::InOut) + } + + /// How the overlay arrives and leaves. The style's entry for the kind of + /// overlay unless set. Needs [`shown`](Self::shown). + pub fn entrance(mut self, entrance: Entrance) -> Self { + self.presence.entrance = Some(entrance); + self + } + + /// Runs `then` once, in the frame the overlay has finished leaving and + /// is no longer built: clear what the content needed during the exit. + /// Needs [`shown`](Self::shown). + pub fn on_exited(mut self, then: impl FnOnce(&mut A) + 'static) -> Self { + self.presence.on_exited = Some(Box::new(then)); + self + } } impl OverlayChain<'_, '_, A, Floating> { @@ -214,9 +317,11 @@ impl<'f, A, State> OverlayChain<'_, 'f, A, State> { description, behavior, on_dismiss, + presence, declared_at, state: _, } = self; + let motion = presence.resolve(b.ctx(), &presentation, behavior.nav, declared_at); let decl = OverlayDecl { id: slot.id, presentation, @@ -224,8 +329,9 @@ impl<'f, A, State> OverlayChain<'_, 'f, A, State> { description, behavior, declared_at, + staged: Staged::STEADY, }; - b.overlay_with(&slot, decl, on_dismiss, body); + b.overlay_with(&slot, decl, on_dismiss, (motion, presence.on_exited), body); } } @@ -266,3 +372,44 @@ impl<'f, A> OverlayChain<'_, 'f, A, Modally> { self.declare(Presentation::Modal(modal), body); } } + +impl Presence { + /// The motion the overlay declared, over the style's for its kind. + fn resolve( + &self, + ctx: &egui::Context, + presentation: &Presentation, + nav: Nav, + declared_at: &'static std::panic::Location<'static>, + ) -> Option { + let Some(shown) = self.shown else { + debug_assert!( + self.transition.is_none() + && self.exit.is_none() + && self.easing.is_none() + && self.entrance.is_none() + && self.on_exited.is_none(), + "an overlay declares motion without `shown` (declared at {declared_at})" + ); + return None; + }; + let motion = &crate::Style::of(ctx).motion; + let (kind, edge) = match presentation { + Presentation::Floating { .. } + if matches!(nav, Nav::Menu | Nav::Submenu | Nav::Listbox) => + { + (motion.menu, None) + } + Presentation::Floating { .. } => (motion.popover, None), + Presentation::Modal(Modal::Center) => (motion.dialog, None), + Presentation::Modal(Modal::Edge(side)) => (motion.sheet, Some(*side)), + }; + Some(Motion { + shown, + enter: self.transition.unwrap_or(kind.enter), + exit: self.exit.or(self.transition).unwrap_or(kind.exit), + easing: self.easing.unwrap_or(kind.easing), + entrance: self.entrance.unwrap_or_else(|| kind.entry.entrance(edge)), + }) + } +} diff --git a/src/overlay_input.rs b/src/overlay_input.rs index bbff1fcc..38b9a846 100644 --- a/src/overlay_input.rs +++ b/src/overlay_input.rs @@ -77,15 +77,17 @@ fn is_nested_in(roots: &[PlacedRoot], root: usize, ancestor: usize) -> bool { std::iter::successors(roots[root].parent, |&at| roots[at].parent).any(|at| at == ancestor) } -/// The attached overlays, the one on the bottom first. +/// The attached overlays, the one on the bottom first. An overlay that is +/// leaving is not among them: it takes no key and is not judged again. fn open_overlays(roots: &[PlacedRoot]) -> Vec> { let order: Vec = stacked_top_down(roots) .into_iter() .rev() .filter(|&root| { roots[root].overlay().is_some_and(|overlay| { - overlay.anchored == crate::overlay::Anchored::Attached - || overlay.lookup == AnchorLookup::Missing + !overlay.staged.is_exiting() + && (overlay.anchored == crate::overlay::Anchored::Attached + || overlay.lookup == AnchorLookup::Missing) }) }) .collect(); diff --git a/src/owned/menu.rs b/src/owned/menu.rs index 4dfc6479..5acdf630 100644 --- a/src/owned/menu.rs +++ b/src/owned/menu.rs @@ -16,7 +16,7 @@ use super::{Chevron, Enablement, Mark, OnResponse, describe, paint_check, paint_ use crate::builder::{Scope, Slot}; use crate::contract::{MenuStyle, Style, Variant}; use crate::kept::Handle; -use crate::overlay::{Anchor, Distance, Nav, Outside, Placement}; +use crate::overlay::{Anchor, Distance, Nav, Outside, Placement, Shown}; use crate::overlay_chain::OverlayChain; use crate::{Builder, Icon, NodeUi as _, TextSpec, Tw, nav, tw}; @@ -773,13 +773,11 @@ impl<'a, 'f, A: 'static, K: crate::Key + Clone> DropdownChain<'a, 'f, A, K> { } }) .on_click(move |_| on_click.change(|menus| menus.toggle(trigger))); - if !open { - return; - } let close = shared.clone(); OverlayChain::new(b.reborrow(), list) .anchor(Anchor::Node(trigger)) .placement(Placement::below().gap(Distance::new(4.0))) + .shown(if open { Shown::Open } else { Shown::Closed }) .nav(Nav::Menu) .role(Role::Menu) .named(name.unwrap_or_default()) diff --git a/src/owned/select.rs b/src/owned/select.rs index 1c07b23a..c12be750 100644 --- a/src/owned/select.rs +++ b/src/owned/select.rs @@ -15,7 +15,7 @@ use super::{ Chevron, Enablement, Mark, OnResponse, Tip, describe, paint_check, paint_chevron, tipped, }; use crate::builder::Slot; -use crate::overlay::{Anchor, Distance, Focus, MatchWidth, Nav, Outside, Placement, Wrap}; +use crate::overlay::{Anchor, Distance, Focus, MatchWidth, Nav, Outside, Placement, Shown, Wrap}; use crate::overlay_chain::OverlayChain; use crate::pipeline::Room; use crate::scroll::{Axis, Focusable}; @@ -222,7 +222,11 @@ impl<'a, 'f, A: 'static, T: Copy + PartialEq + 'static> SelectChain<'a, 'f, A, T node.set_has_popup(HasPopup::Listbox); }); }); - if Listing::of(&ctx, trigger) == Listing::Open { + { + let shown = match Listing::of(&ctx, trigger) { + Listing::Open => Shown::Open, + Listing::Closed => Shown::Closed, + }; let options = List { style, options, @@ -235,6 +239,7 @@ impl<'a, 'f, A: 'static, T: Copy + PartialEq + 'static> SelectChain<'a, 'f, A, T OverlayChain::new(b.reborrow(), list) .anchor(Anchor::Node(trigger)) .placement(placement()) + .shown(shown) .match_width(MatchWidth::Anchor) .focus(Focus::Stay) .nav(Nav::Listbox) diff --git a/src/pipeline.rs b/src/pipeline.rs index e9b6fcd2..9e50d018 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -185,6 +185,8 @@ pub(crate) struct Frame<'f, A> { pub roots: Vec, /// What to run when an overlay is dismissed, by the overlay's id. pub dismiss: HashMap>, + /// What to run for the overlays that finished leaving this frame. + pub exited: Vec>, /// The root whose body is being built. pub current: usize, } @@ -358,6 +360,7 @@ impl LayoutState { drag: Decls::default(), roots: vec![RootDecl::base()], dismiss: HashMap::new(), + exited: Vec::new(), current: 0, }; let mut kids = Vec::new(); @@ -436,6 +439,7 @@ impl<'f, A> Built<'f, A> { drag, roots: decls, dismiss, + exited, .. } = frame; st.tree @@ -656,6 +660,7 @@ impl<'f, A> Built<'f, A> { behavior: overlay.behavior, stack_index: 0, description: overlay.description, + staged: overlay.staged, }), }); } @@ -669,6 +674,7 @@ impl<'f, A> Built<'f, A> { } } stack.store(&st.kept); + st.kept.with(|kept| kept.presences.sweep()); drop(measures); let draws = draws.into_iter().map(Some).collect(); Placed { @@ -682,6 +688,7 @@ impl<'f, A> Built<'f, A> { draws, drag, dismiss, + exited, roots, } } @@ -1297,6 +1304,7 @@ pub struct Placed { pub(crate) draws: Vec>>, pub(crate) drag: Decls, pub(crate) dismiss: HashMap>, + pub(crate) exited: Vec>, /// The base root, then the overlays in the order they were declared. pub(crate) roots: Vec, } diff --git a/src/presence.rs b/src/presence.rs new file mode 100644 index 00000000..9b2d0841 --- /dev/null +++ b/src/presence.rs @@ -0,0 +1,449 @@ +//! Presence: an overlay that enters and leaves with motion. +//! +//! The application declares the overlay every frame and says whether it is +//! [`Shown`]. The library keeps the overlay mounted while it leaves, so the +//! application's own state can already say `Closed` while the box is still +//! on screen. The phase is `Closed | Entering | Open | Exiting`; progress is +//! the retargetable eased [`Progress`] of [`transition`](crate::transition), +//! so a reopen mid-exit reverses from where the box is. +//! +//! The motion is paint-only: layout and hit rects are final from the first +//! frame, and the draw moves, fades and scales what the overlay painted. + +use core::time::Duration; +use std::collections::{HashMap, HashSet}; + +use egui::{Context, Id, Vec2, vec2}; + +use crate::kept::Handle; +use crate::overlay::Side; +use crate::pipeline::DismissFn; +use crate::roots::Form; +use crate::transition::Transition; +use crate::tw::{Easing, Opacity, Progress}; + +/// Whether an overlay is shown or being closed, as the application's state +/// says. The overlay is declared either way; the library keeps it on screen +/// until its exit has run. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +pub enum Shown { + /// The overlay is open: it enters, or has entered. + Open, + /// The overlay is closed: it exits, or has exited. + #[default] + Closed, +} + +impl Shown { + /// Whether the state says open. + pub fn is_open(self) -> bool { + self == Self::Open + } +} + +/// How an overlay arrives and leaves. +/// +/// Only the scrim of a modal fades. The box and its contents are never faded: +/// without group opacity (#40) a per-shape fade lets the page show through the +/// box mid-motion. The entrances move the box instead. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum Entrance { + /// No motion of the box; the scrim of a modal fades. + Fade, + /// Scales the box up from 95% about its centre: shadcn's `zoom-in-95`. + Zoom, + /// [`Zoom`](Self::Zoom) with a short slide away from the anchor, for an + /// overlay that floats next to one: shadcn's `zoom-in-95 + /// slide-in-from-top-2`. A modal has no anchor and only zooms. + Pop, + /// Slides in from this side of the screen by the box's own size. + Slide(Side), +} + +impl Entrance { + const ZOOM_FROM: f32 = 0.95; + /// shadcn's `slide-in-from-top-2`, 0.5rem. + const POP_SLIDE: f32 = 8.0; + + fn scale(self, progress: Progress) -> f32 { + match self { + Self::Zoom | Self::Pop => progress.lerp(Self::ZOOM_FROM, 1.0), + _ => 1.0, + } + } + + /// How far the box is painted from its layout. + fn offset(self, progress: Progress, size: Vec2, form: Form) -> Vec2 { + let left = 1.0 - f32::from(progress); + match (self, form) { + (Self::Slide(side), _) => direction(side) * size * left, + (Self::Pop, Form::Floating(side)) => { + direction(side.opposite()) * Self::POP_SLIDE * left + } + _ => Vec2::ZERO, + } + } +} + +/// The unit vector pointing out of the screen's `side`. +fn direction(side: Side) -> Vec2 { + match side { + Side::Top => vec2(0.0, -1.0), + Side::Bottom => vec2(0.0, 1.0), + Side::Left => vec2(-1.0, 0.0), + Side::Right => vec2(1.0, 0.0), + } +} + +/// An [`Entrance`] without a side, as the style names one; the side of a +/// sheet is its own edge. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +pub enum Entry { + /// [`Entrance::Fade`]. + #[default] + Fade, + /// [`Entrance::Zoom`]. + Zoom, + /// [`Entrance::Pop`]. + Pop, + /// [`Entrance::Slide`] from the edge a modal is docked to; an overlay + /// without one has no box motion. + Slide, +} + +impl Entry { + pub(crate) fn entrance(self, edge: Option) -> Entrance { + match (self, edge) { + (Self::Fade, _) => Entrance::Fade, + (Self::Zoom, _) => Entrance::Zoom, + (Self::Pop, _) => Entrance::Pop, + (Self::Slide, Some(side)) => Entrance::Slide(side), + (Self::Slide, None) => Entrance::Fade, + } + } +} + +/// The motion of one kind of overlay. +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct KindMotion { + /// How the overlay arrives and leaves. + pub entry: Entry, + /// How long it takes to enter. Zero is no motion. + pub enter: Duration, + /// How long it takes to leave. Zero is no motion. + pub exit: Duration, + /// The timing function of both. + pub easing: Easing, +} + +impl KindMotion { + /// No motion: the overlay appears and vanishes at once. + pub const INSTANT: Self = Self { + entry: Entry::Fade, + enter: Duration::ZERO, + exit: Duration::ZERO, + easing: Easing::Default, + }; +} + +/// Enter and exit motion per kind of overlay: what an overlay that was +/// given [`shown`](crate::overlay::OverlayChain::shown) and no motion of its +/// own does. +#[derive(Clone, Copy, Debug, PartialEq)] +#[non_exhaustive] +pub struct MotionStyle { + /// Anchored overlays that are not menus. + pub popover: KindMotion, + /// Menus and the lists selects open. + pub menu: KindMotion, + /// Modals centred on the screen. + pub dialog: KindMotion, + /// Modals docked to a screen edge. + pub sheet: KindMotion, +} + +impl MotionStyle { + /// No overlay moves. + pub const INSTANT: Self = Self { + popover: KindMotion::INSTANT, + menu: KindMotion::INSTANT, + dialog: KindMotion::INSTANT, + sheet: KindMotion::INSTANT, + }; +} + +impl Default for MotionStyle { + fn default() -> Self { + Self::INSTANT + } +} + +/// Where in its life an overlay is. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) enum Phase { + Entering, + Open, + Exiting, +} + +/// An overlay's presence in one frame, with the motion it is painted with. +#[derive(Clone, Copy, Debug, PartialEq)] +pub(crate) struct Staged { + pub(crate) phase: Phase, + pub(crate) progress: Progress, + pub(crate) entrance: Entrance, +} + +impl Staged { + /// An overlay that is simply there: declared without presence. + pub(crate) const STEADY: Self = Self { + phase: Phase::Open, + progress: Progress::END, + entrance: Entrance::Fade, + }; + + pub(crate) fn is_steady(&self) -> bool { + self.phase == Phase::Open + } + + /// An exiting overlay takes no input but still blocks it. + pub(crate) fn is_exiting(&self) -> bool { + self.phase == Phase::Exiting + } + + pub(crate) fn scrim(&self) -> Opacity { + Opacity::new(self.progress.into()) + } + + pub(crate) fn scale(&self) -> f32 { + self.entrance.scale(self.progress) + } + + pub(crate) fn offset(&self, size: Vec2, form: Form) -> Vec2 { + self.entrance.offset(self.progress, size, form) + } +} + +/// What the chain declared, with the style's defaults filled in. +pub(crate) struct Motion { + pub(crate) shown: Shown, + pub(crate) enter: Duration, + pub(crate) exit: Duration, + pub(crate) easing: Easing, + pub(crate) entrance: Entrance, +} + +/// What stepping an overlay's presence found. +pub(crate) enum Step { + /// Not on screen: build nothing. `exited` is set in the frame it got + /// there. + Closed { + exited: bool, + }, + Present(Staged), +} + +/// The overlays that have a presence, by id. +#[derive(Default)] +pub(crate) struct Presences { + entries: HashMap, + seen: HashSet, +} + +impl Presences { + /// Moves the presence of `id` to this frame. + pub(crate) fn step(&mut self, ctx: &Context, id: Id, motion: &Motion) -> Step { + let now = ctx.input(|input| input.time); + self.seen.insert(id); + let (target, full) = match motion.shown { + Shown::Open => (Progress::END, motion.enter), + Shown::Closed => (Progress::START, motion.exit), + }; + let known = self.entries.get(&id).copied(); + let transition = known + .unwrap_or_else(|| Transition::settled(Progress::START, now)) + .toward(target, now, motion.easing, full); + let in_flight = transition.in_flight(now); + let progress = transition.value(now, motion.easing); + let phase = match (motion.shown, in_flight) { + (Shown::Open, true) => Phase::Entering, + (Shown::Open, false) => Phase::Open, + (Shown::Closed, true) => Phase::Exiting, + (Shown::Closed, false) => { + self.entries.remove(&id); + return Step::Closed { + exited: known.is_some(), + }; + } + }; + self.entries.insert(id, transition); + if in_flight { + ctx.request_repaint(); + } + Step::Present(Staged { + phase, + progress, + entrance: motion.entrance, + }) + } + + /// Forgets the overlays a frame did not declare, and starts the next + /// frame's accounting. + pub(crate) fn sweep(&mut self) { + let seen = std::mem::take(&mut self.seen); + self.entries.retain(|id, _| seen.contains(id)); + } +} + +/// Steps the presence of `id` in the layout's kept state. +pub(crate) fn step(kept: &Handle, ctx: &Context, id: Id, motion: &Motion) -> Step { + kept.with(|kept| kept.presences.step(ctx, id, motion)) +} + +/// What to run once an overlay has left. +pub(crate) type ExitedFn = DismissFn; + +#[cfg(test)] +mod tests { + use super::*; + + fn motion(shown: Shown) -> Motion { + Motion { + shown, + enter: Duration::from_millis(100), + exit: Duration::from_millis(100), + easing: Easing::Linear, + entrance: Entrance::Fade, + } + } + + fn at(presences: &mut Presences, time: f64, shown: Shown) -> Step { + let ctx = Context::default(); + ctx.begin_pass(egui::RawInput { + time: Some(time), + ..egui::RawInput::default() + }); + let step = presences.step(&ctx, Id::NULL.with("overlay"), &motion(shown)); + ctx.end_pass().textures_delta.clear(); + step + } + + fn phase(step: &Step) -> Option { + match step { + Step::Present(staged) => Some(staged.phase), + Step::Closed { .. } => None, + } + } + + #[test] + fn an_overlay_never_shown_stays_closed_and_does_not_exit() { + let mut presences = Presences::default(); + assert!(matches!( + at(&mut presences, 0.0, Shown::Closed), + Step::Closed { exited: false } + )); + } + + #[test] + fn the_phase_runs_entering_open_exiting_closed() { + let mut presences = Presences::default(); + let phases: Vec<_> = [ + (0.0, Shown::Open), + (0.05, Shown::Open), + (0.2, Shown::Open), + (0.25, Shown::Closed), + (0.3, Shown::Closed), + (0.4, Shown::Closed), + (0.5, Shown::Closed), + ] + .into_iter() + .map(|(time, shown)| phase(&at(&mut presences, time, shown))) + .collect(); + assert_eq!( + phases, + [ + Some(Phase::Entering), + Some(Phase::Entering), + Some(Phase::Open), + Some(Phase::Exiting), + Some(Phase::Exiting), + None, + None, + ] + ); + } + + #[test] + fn exited_is_reported_once() { + let mut presences = Presences::default(); + at(&mut presences, 0.0, Shown::Open); + at(&mut presences, 0.2, Shown::Open); + at(&mut presences, 0.25, Shown::Closed); + assert!(matches!( + at(&mut presences, 0.4, Shown::Closed), + Step::Closed { exited: true } + )); + assert!(matches!( + at(&mut presences, 0.45, Shown::Closed), + Step::Closed { exited: false } + )); + } + + #[test] + fn reopening_mid_exit_reverses_from_where_it_was() { + let mut presences = Presences::default(); + at(&mut presences, 0.0, Shown::Open); + at(&mut presences, 0.2, Shown::Open); + let Step::Present(leaving) = at(&mut presences, 0.25, Shown::Closed) else { + panic!("exiting"); + }; + let Step::Present(deeper) = at(&mut presences, 0.3, Shown::Closed) else { + panic!("exiting"); + }; + let Step::Present(back) = at(&mut presences, 0.31, Shown::Open) else { + panic!("entering"); + }; + assert!(deeper.progress < leaving.progress); + assert_eq!(back.phase, Phase::Entering); + assert!( + (f32::from(back.progress) - f32::from(deeper.progress)).abs() < 0.2, + "continues from {:?}, not from the start: {:?}", + deeper.progress, + back.progress + ); + assert!(f32::from(back.progress) > 0.0); + } + + #[test] + fn zero_durations_are_never_in_flight() { + let mut presences = Presences::default(); + let instant = |shown| Motion { + enter: Duration::ZERO, + exit: Duration::ZERO, + ..motion(shown) + }; + let ctx = Context::default(); + ctx.begin_pass(egui::RawInput::default()); + let opened = presences.step(&ctx, Id::NULL.with("overlay"), &instant(Shown::Open)); + let closed = presences.step(&ctx, Id::NULL.with("overlay"), &instant(Shown::Closed)); + ctx.end_pass().textures_delta.clear(); + assert_eq!(phase(&opened), Some(Phase::Open)); + assert!(matches!(closed, Step::Closed { exited: true })); + } + + #[test] + fn a_slide_is_the_boxs_own_size_from_its_side() { + let staged = Staged { + phase: Phase::Entering, + progress: Progress::START, + entrance: Entrance::Slide(Side::Right), + }; + let form = Form::Modal(crate::overlay::Modal::Edge(Side::Right)); + assert_eq!(staged.offset(vec2(380.0, 600.0), form), vec2(380.0, 0.0)); + let settled = Staged { + progress: Progress::END, + ..staged + }; + assert_eq!(settled.offset(vec2(380.0, 600.0), form), Vec2::ZERO); + } +} diff --git a/src/roots.rs b/src/roots.rs index 0dbb76e0..847eaa21 100644 --- a/src/roots.rs +++ b/src/roots.rs @@ -18,6 +18,7 @@ use crate::overlay::{ Anchor, AnchorLookup, Anchored, Band, Behavior, MatchWidth, Modal, Outside, Placement, Side, }; use crate::pipeline::{Placed, PlacedNode}; +use crate::presence::Staged; use crate::scroll::Description; /// What a root is, and what only that kind of root declares. @@ -46,6 +47,7 @@ pub(crate) struct OverlayDecl { pub(crate) description: Description, pub(crate) behavior: Behavior, pub(crate) declared_at: &'static std::panic::Location<'static>, + pub(crate) staged: Staged, } /// A root, from the moment its body starts to be built. @@ -154,6 +156,7 @@ pub(crate) struct PlacedOverlay { /// opened in. pub(crate) stack_index: usize, pub(crate) description: Description, + pub(crate) staged: Staged, } /// What a laid-out root is. diff --git a/src/stack.rs b/src/stack.rs index 8edcc635..530140e1 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -109,7 +109,7 @@ fn intact_prefix(ranks: &[usize]) -> usize { } /// An overlay shown this frame. -pub(crate) struct Shown { +pub(crate) struct Drawn { pub(crate) id: Id, pub(crate) band: Band, } @@ -129,7 +129,7 @@ pub(crate) struct Shown { /// `pressed` is the overlay a pointer press landed on this frame: egui raises /// that layer by itself, so it and the layers above it are flagged too, which /// keeps their order (a press on a menu must not bring it over its submenu). -pub(crate) fn repair(ctx: &Context, shown: &[Shown], pressed: Option) { +pub(crate) fn repair(ctx: &Context, shown: &[Drawn], pressed: Option) { let order: Vec = ctx.memory(|memory| memory.layer_ids().collect()); for band in [Band::Floating, Band::Popup, Band::Tooltip] { let layers: Vec<(Id, LayerId)> = shown diff --git a/src/transition.rs b/src/transition.rs index f4c1bc86..5bc55289 100644 --- a/src/transition.rs +++ b/src/transition.rs @@ -18,7 +18,7 @@ use crate::tw::{Easing, Progress}; /// One transition in flight, from where the previous one left the value to /// `target`. #[derive(Clone, Copy)] -struct Transition { +pub(crate) struct Transition { from: Progress, target: Progress, start: f64, @@ -26,7 +26,7 @@ struct Transition { } impl Transition { - fn settled(at: Progress, now: f64) -> Self { + pub(crate) fn settled(at: Progress, now: f64) -> Self { Self { from: at, target: at, @@ -44,7 +44,7 @@ impl Transition { } } - fn elapsed(&self, now: f64) -> Progress { + pub(crate) fn elapsed(&self, now: f64) -> Progress { let elapsed = (now - self.start).max(0.0) as f32; let total = self.duration.as_secs_f32(); if total > 0.0 { @@ -54,7 +54,7 @@ impl Transition { } } - fn value(&self, now: f64, easing: Easing) -> Progress { + pub(crate) fn value(&self, now: f64, easing: Easing) -> Progress { Progress::new( easing .ease(self.elapsed(now)) @@ -62,6 +62,19 @@ impl Transition { ) } + /// This transition if it already heads for `target`, else retargeted. + pub(crate) fn toward(self, target: Progress, now: f64, easing: Easing, full: Duration) -> Self { + if self.target == target { + self + } else { + self.retarget(target, now, easing, full) + } + } + + pub(crate) fn in_flight(&self, now: f64) -> bool { + self.elapsed(now) < Progress::END + } + /// Retargets from the current value. As in CSS, a transition reversed /// mid-flight starts from where the value is and lasts only in proportion /// to the distance it has left to travel. @@ -96,13 +109,9 @@ pub(crate) fn animate( let previous = ctx .data(|data| data.get_temp::(id)) .unwrap_or(Transition::settled(target, now)); - let transition = if previous.target == target { - previous - } else { - previous.retarget(target, now, easing, duration) - }; + let transition = previous.toward(target, now, easing, duration); ctx.data_mut(|data| data.insert_temp(id, transition)); - if transition.elapsed(now) < Progress::END { + if transition.in_flight(now) { ctx.request_repaint(); } transition.value(now, easing) diff --git a/tests/it/chat_shell_demo.rs b/tests/it/chat_shell_demo.rs index 49e63ad5..03d7bc58 100644 --- a/tests/it/chat_shell_demo.rs +++ b/tests/it/chat_shell_demo.rs @@ -440,7 +440,7 @@ fn the_model_select_changes_the_model_and_the_details_follow() { click_node(&mut harness, "/Centre/TopBar/Model"); harness.run_steps(3); harness.get_by_label(MODELS[2]).click(); - harness.run_steps(3); + harness.run_steps(12); assert_eq!(harness.state().app.model, 2); assert_eq!(rect(&harness, Part::Centre), before, "nothing moved"); diff --git a/tests/it/main.rs b/tests/it/main.rs index 5b441e0f..5566d6cc 100644 --- a/tests/it/main.rs +++ b/tests/it/main.rs @@ -53,6 +53,7 @@ mod owned_choice; mod owned_number; mod popup_style; mod ports; +mod presence; mod prims; mod progress; mod scroll; diff --git a/tests/it/modal.rs b/tests/it/modal.rs index 857f5230..eb0a45ed 100644 --- a/tests/it/modal.rs +++ b/tests/it/modal.rs @@ -2,7 +2,7 @@ //! by `egui_kittest::Harness`, build, layout, draw and the judgement of the //! frame's input. -use eggshell_ui::overlay::{DismissOn, Modal, Side}; +use eggshell_ui::overlay::{DismissOn, Modal, Shown, Side}; use eggshell_ui::owned::Enablement; use eggshell_ui::prim::text_field::Field; use eggshell_ui::{Builder, TextSpec, TextStyle, tw}; @@ -33,7 +33,7 @@ fn base_text() -> TextStyle { } fn settle(harness: &mut Harness<'_, Rig>) { - harness.run_steps(6); + harness.run_steps(12); } fn click_at(harness: &mut Harness<'_, Rig>, at: Pos2) { @@ -465,7 +465,7 @@ mod example { let mut harness = harness(State::default()); click_node(&mut harness, "/Page/Intro/Actions/OpenDialog"); settle(&mut harness); - assert!(harness.state().app.dialog, "precondition: open"); + assert!(harness.state().app.dialog.is_open(), "precondition: open"); harness } @@ -473,7 +473,10 @@ mod example { let mut harness = dialog(); click_node(&mut harness, "/Dialog/Box/Footer/Delete"); settle(&mut harness); - assert!(harness.state().app.confirm, "precondition: confirm open"); + assert!( + harness.state().app.confirm.is_open(), + "precondition: confirm open" + ); harness } @@ -530,7 +533,7 @@ mod example { click_node(&mut harness, "/Page/Intro/Actions/OpenSheet"); settle(&mut harness); let boxed = rect_of(&harness, "/Sheet/Box"); - assert!(harness.state().app.sheet, "precondition: open"); + assert!(harness.state().app.sheet.is_open(), "precondition: open"); assert_eq!(boxed.max.x, SCREEN.x); assert_eq!((boxed.min.y, boxed.max.y), (0.0, SCREEN.y)); assert!(boxed.width() <= 384.0 + 0.5, "{boxed:?}"); @@ -543,8 +546,8 @@ mod example { .prepare(eggshell_ui_shadcn::Shadcn::apply_both) .layout(&State::default(), |b, _| { let open = State { - dialog: true, - sheet: true, + dialog: Shown::Open, + sheet: Shown::Open, ..State::default() }; layout(b, &open); @@ -585,7 +588,7 @@ mod example { ); wheel(&mut modal, outside_box); assert_eq!(page_offset(&modal), before, "scroll lock"); - modal.state_mut().app.dialog = false; + modal.state_mut().app.dialog = Shown::Closed; settle(&mut modal); wheel(&mut modal, outside_box); assert!( @@ -603,8 +606,14 @@ mod example { "precondition: the page's button is outside the box" ); click_at(&mut harness, sheet_button); - assert!(!harness.state().app.sheet, "it never got the press"); - assert!(!harness.state().app.dialog, "the scrim press dismissed"); + assert!( + !harness.state().app.sheet.is_open(), + "it never got the press" + ); + assert!( + !harness.state().app.dialog.is_open(), + "the scrim press dismissed" + ); } #[test] @@ -638,10 +647,13 @@ mod example { } assert_eq!(support::focused_path(&harness).as_deref(), Some(opener)); press_key(&mut harness, Key::Enter); - assert!(harness.state().app.dialog, "precondition: open"); + assert!(harness.state().app.dialog.is_open(), "precondition: open"); assert!(focus(&harness).starts_with("/Dialog/")); press_key(&mut harness, Key::Escape); - assert!(!harness.state().app.dialog, "precondition: closed"); + assert!( + !harness.state().app.dialog.is_open(), + "precondition: closed" + ); assert_eq!(support::focused_path(&harness).as_deref(), Some(opener)); } @@ -654,11 +666,11 @@ mod example { assert_eq!(harness.state().app.name, "Ada", "precondition: typed"); press_key(&mut harness, Key::Enter); assert_eq!(harness.state().app.saved.as_deref(), Some("Ada")); - assert!(!harness.state().app.dialog); + assert!(!harness.state().app.dialog.is_open()); let mut harness = self::dialog(); press_key(&mut harness, Key::Escape); - assert!(!harness.state().app.dialog); + assert!(!harness.state().app.dialog.is_open()); assert_eq!(harness.state().app.saved, None, "cancel saves nothing"); } @@ -676,7 +688,7 @@ mod example { harness.state().app.saved.is_none(), "Save is under the scrim" ); - assert!(harness.state().app.dialog && harness.state().app.confirm); + assert!(harness.state().app.dialog.is_open() && harness.state().app.confirm.is_open()); let lap = lap(&mut harness); assert!( lap.iter() @@ -690,12 +702,18 @@ mod example { let mut harness = confirm(); click_at(&mut harness, pos2(5.0, 5.0)); assert!( - harness.state().app.confirm && harness.state().app.dialog, + harness.state().app.confirm.is_open() && harness.state().app.dialog.is_open(), "the scrim does nothing to an EscOnly confirmation, nor to the dialog below" ); press_key(&mut harness, Key::Escape); - assert!(!harness.state().app.confirm, "its cancel button ran"); - assert!(harness.state().app.dialog, "the dialog is still open"); + assert!( + !harness.state().app.confirm.is_open(), + "its cancel button ran" + ); + assert!( + harness.state().app.dialog.is_open(), + "the dialog is still open" + ); } #[test] @@ -707,10 +725,10 @@ mod example { focus(&harness) ); press_key(&mut harness, Key::Enter); - assert!(!harness.state().app.confirm, "Cancel ran"); + assert!(!harness.state().app.confirm.is_open(), "Cancel ran"); assert_eq!(harness.state().app.deleted, 0); assert!(harness.state().app.saved.is_none(), "not the dialog's Save"); - assert!(harness.state().app.dialog); + assert!(harness.state().app.dialog.is_open()); } #[test] @@ -740,7 +758,10 @@ mod example { click_at(&mut harness, item.center()); assert_eq!(harness.state().app.role, 1); assert!(!harness.state().app.picker); - assert!(harness.state().app.dialog, "the dialog stays open"); + assert!( + harness.state().app.dialog.is_open(), + "the dialog stays open" + ); } #[test] @@ -750,7 +771,7 @@ mod example { settle(&mut harness); assert!(harness.state().app.picker, "precondition: the menu opened"); click_at(&mut harness, pos2(5.0, 5.0)); - assert!(!harness.state().app.picker && !harness.state().app.dialog); + assert!(!harness.state().app.picker && !harness.state().app.dialog.is_open()); } const ROLES_LAST: usize = 2; @@ -847,7 +868,7 @@ mod example { settle(&mut harness); press_key(&mut harness, Key::Escape); assert!(!harness.state().app.picker); - assert!(harness.state().app.dialog); + assert!(harness.state().app.dialog.is_open()); } } @@ -864,7 +885,7 @@ mod style { eggshell_ui_shadcn::Shadcn::light(), eggshell_ui_shadcn::Shadcn::dark(), ] { - assert_eq!(preset.style().scrim, Color32::from_black_alpha(128)); + assert_eq!(preset.style().scrim, Color32::from_black_alpha(204)); } } } @@ -913,7 +934,7 @@ mod two_frames { frame, ); harness.run_steps(4); - harness.state_mut().app.state.dialog = true; + harness.state_mut().app.state.dialog = Shown::Open; harness.run_steps(8); let name = harness.ctx.memory(|memory| memory.focused()); assert!(name.is_some(), "precondition: focus entered the dialog"); @@ -922,7 +943,7 @@ mod two_frames { let moved = harness.ctx.memory(|memory| memory.focused()); assert_ne!(moved, name, "Tab moved the focus"); assert!(moved.is_some(), "and into the dialog's next control"); - assert!(harness.state().app.state.dialog); + assert!(harness.state().app.state.dialog.is_open()); } } diff --git a/tests/it/overlay.rs b/tests/it/overlay.rs index 33a11217..effeeba3 100644 --- a/tests/it/overlay.rs +++ b/tests/it/overlay.rs @@ -1211,7 +1211,7 @@ mod menu_example { assert_eq!(popover.min.x, button.min.x); assert_eq!(popover.min.y, button.max.y + 4.0); click_node(&mut harness, "/Page/Top/PopoverButton"); - harness.run_steps(3); + harness.run_steps(8); assert!(!has(&harness, "/Page/Top/(PopoverButton, Menu)")); } @@ -1224,7 +1224,7 @@ mod menu_example { &mut harness, "/Page/Top/(PopoverButton, Menu)/Box/Item(Copy)", ); - harness.run_steps(3); + harness.run_steps(8); assert!(!has(&harness, "/Page/Top/(PopoverButton, Menu)")); assert_eq!(harness.state().app.chosen.as_deref(), Some("Copy")); } @@ -1262,7 +1262,7 @@ mod menu_example { &mut harness, "/Page/Top/(PopoverButton, Menu)/Box/(Item(Arrange), Submenu)/Box/Item(Back)", ); - harness.run_steps(3); + harness.run_steps(8); assert_eq!(harness.state().app.chosen.as_deref(), Some("Back")); assert!(!has(&harness, "/Page/Top/(PopoverButton, Menu)")); } @@ -1278,13 +1278,13 @@ mod menu_example { "precondition: away from the menu" ); support::press_and_release(&mut harness, away); - harness.run_steps(3); + harness.run_steps(8); assert!(!has(&harness, "/Page/Top/(PopoverButton, Menu)")); click_node(&mut harness, "/Page/Top/PopoverButton"); harness.run_steps(3); harness.key_press(egui::Key::Escape); - harness.run_steps(3); + harness.run_steps(8); assert!(!has(&harness, "/Page/Top/(PopoverButton, Menu)")); } @@ -1298,7 +1298,7 @@ mod menu_example { harness.run_steps(3); } harness.key_press(egui::Key::Enter); - harness.run_steps(3); + harness.run_steps(8); assert!( harness.state().app.grid, "opened with the pointer, the first Down goes to Copy and the second skips the disabled Paste to Show grid" diff --git a/tests/it/owned_number.rs b/tests/it/owned_number.rs index eb219fc7..0db1cac2 100644 --- a/tests/it/owned_number.rs +++ b/tests/it/owned_number.rs @@ -113,7 +113,7 @@ fn tab_to(harness: &mut Harness<'_, Rig>, path: &str) { fn press(harness: &mut Harness<'_, Rig>, key: Key) { harness.key_press(key); - harness.run_steps(3); + harness.run_steps(8); } const TRACK: &str = "/\"volume\"/Track"; diff --git a/tests/it/popup_style.rs b/tests/it/popup_style.rs index 5f4d78f7..a7ae0293 100644 --- a/tests/it/popup_style.rs +++ b/tests/it/popup_style.rs @@ -73,8 +73,14 @@ fn a_popup_opened_in_a_node_takes_the_global_style_not_the_nodes() { assert_ne!(probe.in_popup, probe.scoped, "and not the node's"); } -#[derive(Default)] -struct Pick(usize); +/// The layout is kept between frames, as presence needs. +struct Pick(usize, LayoutState); + +impl Default for Pick { + fn default() -> Self { + Self(0, LayoutState::new()) + } +} fn open_select_shapes(restyle_global: bool) -> Vec { let mut harness = Harness::builder() @@ -107,8 +113,9 @@ fn open_select_shapes(restyle_global: bool) -> Vec { }, Color32::BLACK, ); - LayoutState::new() - .with_base_text(base) + let mut layout = std::mem::take(&mut pick.1); + layout.set_base_text(Some(base)); + layout .build(&ctx, |b| { b.select("select", pick.0, [(0, "One"), (1, "Two"), (2, "Three")]) .named("pick") @@ -116,12 +123,13 @@ fn open_select_shapes(restyle_global: bool) -> Vec { }) .layout(area) .draw(pick, ui); + pick.1 = layout; }, Pick::default(), ); harness.run_steps(2); harness.get_by_label("pick").click(); - harness.run_steps(4); + harness.run_steps(12); harness .output() .shapes diff --git a/tests/it/presence.rs b/tests/it/presence.rs new file mode 100644 index 00000000..c649a427 --- /dev/null +++ b/tests/it/presence.rs @@ -0,0 +1,645 @@ +//! Overlay presence through the real path: events dispatched by +//! `egui_kittest::Harness`, build, layout, draw and the judgement of the +//! frame's input, with a fixed time step so that a transition lasts a known +//! number of frames. + +use core::time::Duration; +use std::cell::Cell; + +use eggshell_ui::overlay::{Entrance, Modal, Shown, Side}; +use eggshell_ui::testing::{Motion, Timeline, record}; +use eggshell_ui::{Builder, TextSpec, TextStyle, tw}; +use egui::{Color32, FontFamily, Key, Pos2, pos2, vec2}; +use egui_kittest::Harness; + +use crate::support::{self, Rig, focused_node, id_of, rect_of}; + +#[path = "../../examples/common/mod.rs"] +mod common; + +#[allow(dead_code, reason = "the example's main is not run here")] +#[path = "../../examples/dialog.rs"] +mod dialog; + +const SCREEN: egui::Vec2 = vec2(800.0, 600.0); +/// Frames are this far apart. +const STEP: f32 = 0.02; +const BOX_WIDTH: f32 = 200.0; +const BOX_FILL: Color32 = Color32::from_rgb(10, 20, 30); + +#[derive(Clone, Copy, Debug, Hash)] +enum Part { + Page, + Opener, + Sheet, + Box, + Inner, +} + +#[derive(Default)] +struct App { + shown: Shown, + built: Cell, + exited: u32, + dismissed: u32, + page_clicks: u32, + inner_clicks: u32, +} + +#[derive(Clone, Copy)] +struct Enter { + entrance: Entrance, + millis: u64, +} + +const SLIDE: Enter = Enter { + entrance: Entrance::Slide(Side::Right), + millis: 200, +}; + +fn base_text() -> TextStyle { + TextStyle::new( + TextSpec { + size: 14.0, + line_height: 20.0, + family: FontFamily::Proportional, + }, + Color32::BLACK, + ) +} + +fn page(b: &mut Builder<'_, '_, App>) { + b.div_id(Part::Page, tw().w_full().h_full(), |s| { + s.button(Part::Opener, "Open").on_click(|app: &mut App| { + app.page_clicks += 1; + app.shown = Shown::Open; + }); + }); +} + +fn sheet(b: &mut Builder<'_, '_, App>, app: &App, motion: Enter) { + b.overlay(Part::Sheet) + .modal(Modal::Edge(Side::Right)) + .shown(app.shown) + .transition(Duration::from_millis(motion.millis)) + .ease_linear() + .entrance(motion.entrance) + .on_dismiss(|app: &mut App| { + app.dismissed += 1; + app.shown = Shown::Closed; + }) + .on_exited(|app: &mut App| app.exited += 1) + .children(|s| { + app.built.set(app.built.get() + 1); + s.div_id( + Part::Box, + tw().w_px(BOX_WIDTH).h_full().bg(BOX_FILL).p(4.0), + |s| { + s.button(Part::Inner, "Inner") + .on_click(|app: &mut App| app.inner_clicks += 1); + }, + ); + }); +} + +fn slide_view(b: &mut Builder<'_, '_, App>, app: &App) { + page(b); + sheet(b, app, SLIDE); +} + +fn fade_view(b: &mut Builder<'_, '_, App>, app: &App) { + page(b); + sheet( + b, + app, + Enter { + entrance: Entrance::Fade, + millis: 200, + }, + ); +} + +fn zoom_view(b: &mut Builder<'_, '_, App>, app: &App) { + page(b); + sheet( + b, + app, + Enter { + entrance: Entrance::Zoom, + millis: 200, + }, + ); +} + +fn slow_view(b: &mut Builder<'_, '_, App>, app: &App) { + page(b); + sheet( + b, + app, + Enter { + entrance: Entrance::Slide(Side::Right), + millis: 1000, + }, + ); +} + +fn harness(view: support::View) -> Harness<'static, Rig> { + let mut harness = support::harness_stepped(SCREEN, STEP, base_text(), App::default(), view); + harness.run_steps(2); + harness +} + +fn open(harness: &mut Harness<'_, Rig>) { + harness.state_mut().app.shown = Shown::Open; + harness.step(); +} + +fn close(harness: &mut Harness<'_, Rig>) { + harness.state_mut().app.shown = Shown::Closed; + harness.step(); +} + +fn painted_box(harness: &Harness<'_, Rig>) -> Option { + support::shapes(harness) + .into_iter() + .find_map(|shape| match shape { + egui::Shape::Rect(rect) + if rect.fill.to_srgba_unmultiplied()[..3] + == BOX_FILL.to_srgba_unmultiplied()[..3] => + { + Some(rect.clone()) + } + _ => None, + }) +} + +/// How far right of its layout the box is painted. +fn painted_offset(harness: &Harness<'_, Rig>) -> f32 { + let painted = painted_box(harness).expect("the box is painted"); + painted.rect.min.x - rect_of(harness, "/Sheet/Box").min.x +} + +fn built(harness: &Harness<'_, Rig>) -> u32 { + harness.state().app.built.get() +} + +fn page_button_at() -> Pos2 { + pos2(30.0, 20.0) +} + +#[test] +fn children_are_not_built_while_the_overlay_is_closed() { + let mut harness = harness(slide_view); + harness.run_steps(5); + assert_eq!(built(&harness), 0); + assert!( + harness + .state() + .nodes + .iter() + .all(|(path, _)| !path.starts_with("/Sheet")), + "{:?}", + harness.state().nodes + ); +} + +#[test] +fn the_box_slides_in_by_its_own_size_and_arrives() { + let mut harness = harness(slide_view); + open(&mut harness); + let first = painted_offset(&harness); + assert!( + (first - BOX_WIDTH).abs() < 1.0, + "starts a box width off: {first}" + ); + let mut seen = vec![first]; + for _ in 0..12 { + harness.step(); + seen.push(painted_offset(&harness)); + } + assert!( + seen.windows(2).all(|pair| pair[1] <= pair[0]), + "never moves back: {seen:?}" + ); + assert!(seen[5] > 0.0 && seen[5] < BOX_WIDTH, "part-way: {seen:?}"); + assert_eq!(*seen.last().expect("steps ran"), 0.0, "{seen:?}"); +} + +#[test] +fn layout_is_final_on_the_first_frame() { + let mut harness = harness(slide_view); + open(&mut harness); + let first = rect_of(&harness, "/Sheet/Box"); + harness.run_steps(12); + assert_eq!(rect_of(&harness, "/Sheet/Box"), first); + assert_eq!(first.max.x, SCREEN.x); +} + +#[test] +fn the_phase_runs_entering_open_exiting_closed() { + let mut harness = harness(slide_view); + open(&mut harness); + assert!(painted_offset(&harness) > 0.0, "entering"); + harness.run_steps(12); + assert_eq!(painted_offset(&harness), 0.0, "open"); + let open_builds = built(&harness); + close(&mut harness); + harness.step(); + let leaving = painted_offset(&harness); + assert!(leaving > 0.0 && leaving < BOX_WIDTH, "exiting: {leaving}"); + assert!(built(&harness) > open_builds, "still built while it exits"); + harness.run_steps(12); + let after = built(&harness); + harness.run_steps(3); + assert_eq!(built(&harness), after, "not built once closed"); + assert!(painted_box(&harness).is_none(), "closed"); + assert!( + harness + .state() + .nodes + .iter() + .all(|(path, _)| !path.starts_with("/Sheet")), + "gone from the frame" + ); +} + +#[test] +fn on_exited_fires_once_when_the_exit_has_run() { + let mut harness = harness(slide_view); + open(&mut harness); + harness.run_steps(12); + close(&mut harness); + assert_eq!(harness.state().app.exited, 0, "not yet: it is leaving"); + harness.run_steps(4); + assert_eq!(harness.state().app.exited, 0, "still leaving"); + harness.run_steps(12); + assert_eq!(harness.state().app.exited, 1); + harness.run_steps(12); + assert_eq!(harness.state().app.exited, 1, "once"); +} + +#[test] +fn reopening_mid_exit_reverses_from_where_the_box_is() { + let mut harness = harness(slide_view); + open(&mut harness); + harness.run_steps(12); + close(&mut harness); + harness.run_steps(4); + let before = painted_offset(&harness); + assert!(before > 0.0 && before < BOX_WIDTH, "precondition: {before}"); + open(&mut harness); + let after = painted_offset(&harness); + assert!( + (after - before).abs() < BOX_WIDTH / 4.0, + "continues from {before}, not a jump to {after}" + ); + harness.run_steps(12); + assert_eq!(painted_offset(&harness), 0.0, "open again"); + assert_eq!(harness.state().app.exited, 0, "it never left"); +} + +#[test] +fn a_leaving_overlay_takes_no_input_and_still_blocks_the_page() { + let mut harness = harness(slow_view); + open(&mut harness); + harness.run_steps(60); + let inner = rect_of(&harness, "/Sheet/Box/Inner").center(); + close(&mut harness); + harness.run_steps(2); + assert!(painted_offset(&harness) > 0.0, "precondition: leaving"); + let exited = harness.state().app.exited; + assert_eq!(exited, 0, "precondition: not gone"); + + support::press_and_release(&mut harness, page_button_at()); + assert_eq!(harness.state().app.page_clicks, 0, "the page is blocked"); + assert_eq!(harness.state().app.dismissed, 0); + + support::press_and_release(&mut harness, inner); + assert_eq!(harness.state().app.inner_clicks, 0, "the box is inert"); + assert_eq!(harness.state().app.dismissed, 0, "not judged again"); + assert_eq!(harness.state().app.shown, Shown::Closed); +} + +#[test] +fn the_page_takes_the_pointer_again_once_the_overlay_is_gone() { + let mut harness = harness(slide_view); + open(&mut harness); + harness.run_steps(12); + close(&mut harness); + harness.run_steps(14); + support::press_and_release(&mut harness, page_button_at()); + assert_eq!(harness.state().app.page_clicks, 1); +} + +#[test] +fn esc_while_entering_dismisses_and_the_box_turns_round() { + let mut harness = harness(slide_view); + open(&mut harness); + harness.run_steps(3); + let entering = painted_offset(&harness); + assert!( + entering > 0.0 && entering < BOX_WIDTH, + "precondition: {entering}" + ); + harness.key_press(Key::Escape); + harness.step(); + assert_eq!(harness.state().app.dismissed, 1); + assert_eq!(harness.state().app.shown, Shown::Closed); + harness.run_steps(2); + let leaving = painted_offset(&harness); + harness.run_steps(2); + assert!( + painted_offset(&harness) > leaving, + "moving out: {leaving} then {}", + painted_offset(&harness) + ); + harness.run_steps(14); + assert!(painted_box(&harness).is_none()); + assert_eq!(harness.state().app.exited, 1); +} + +#[test] +fn esc_does_not_dismiss_a_leaving_overlay_again() { + let mut harness = harness(slow_view); + open(&mut harness); + harness.run_steps(60); + close(&mut harness); + harness.key_press(Key::Escape); + harness.step(); + assert_eq!(harness.state().app.dismissed, 0); +} + +#[test] +fn focus_returns_to_the_opener_after_an_animated_close() { + let mut harness = harness(slide_view); + let opener = id_of(&harness, "/Page/Opener"); + harness + .ctx + .memory_mut(|memory| memory.request_focus(opener)); + harness.run_steps(2); + assert_eq!(focused_node(&harness).as_deref(), Some("/Page/Opener")); + open(&mut harness); + harness.run_steps(12); + assert_eq!( + focused_node(&harness).as_deref(), + Some("/Sheet/Box/Inner"), + "focus entered the sheet" + ); + harness.key_press(Key::Escape); + harness.run_steps(20); + assert!(painted_box(&harness).is_none(), "precondition: closed"); + assert_eq!(focused_node(&harness).as_deref(), Some("/Page/Opener")); +} + +#[test] +fn nothing_requests_a_repaint_once_the_motion_has_settled() { + let mut harness = harness(slide_view); + assert!(!harness.ctx.has_requested_repaint(), "closed and idle"); + open(&mut harness); + assert!(harness.ctx.has_requested_repaint(), "entering"); + harness.run_steps(12); + harness.step(); + assert!(!harness.ctx.has_requested_repaint(), "open and idle"); + close(&mut harness); + assert!(harness.ctx.has_requested_repaint(), "exiting"); + harness.run_steps(14); + assert!(!harness.ctx.has_requested_repaint(), "closed and idle"); +} + +#[test] +fn a_fade_leaves_the_box_opaque_and_fades_only_the_scrim() { + let mut harness = harness(fade_view); + open(&mut harness); + harness.run_steps(4); + assert_eq!( + painted_box(&harness).expect("painted").fill, + BOX_FILL, + "the box is not faded" + ); + assert_eq!( + painted_offset(&harness), + 0.0, + "a fade does not move the box" + ); + let scrim = support::shapes(&harness) + .into_iter() + .find_map(|shape| match shape { + egui::Shape::Rect(rect) if rect.rect.width() >= SCREEN.x - 1.0 => Some(rect.fill), + _ => None, + }) + .expect("the scrim is painted"); + let full = eggshell_ui::Style::of(&harness.ctx).scrim.a(); + assert!( + scrim.a() > 0 && scrim.a() < full, + "the scrim is part-way: {scrim:?} of {full}" + ); + harness.run_steps(12); + assert_eq!(painted_box(&harness).expect("painted").fill, BOX_FILL); +} + +#[test] +fn a_zoom_scales_the_box_about_its_centre() { + let mut harness = harness(zoom_view); + open(&mut harness); + harness.run_steps(3); + let layout = rect_of(&harness, "/Sheet/Box"); + let part_way = painted_box(&harness).expect("painted").rect; + assert!( + part_way.width() > layout.width() * 0.95 && part_way.width() < layout.width() * 0.99, + "between 95% and full: {part_way:?} of {layout:?}" + ); + assert!( + (part_way.center() - layout.center()).length() < 1.0, + "about the centre" + ); + harness.run_steps(12); + let settled = painted_box(&harness).expect("painted").rect; + assert!((settled.width() - layout.width()).abs() < 0.5); +} + +#[test] +fn an_overlay_without_motion_in_the_style_appears_and_vanishes_at_once() { + fn instant_view(b: &mut Builder<'_, '_, App>, app: &App) { + page(b); + b.overlay(Part::Sheet) + .modal(Modal::Edge(Side::Right)) + .shown(app.shown) + .on_exited(|app: &mut App| app.exited += 1) + .children(|s| { + s.div_id( + Part::Box, + tw().w_px(BOX_WIDTH).h_full().bg(BOX_FILL), + |_| {}, + ); + }); + } + let mut harness = harness(instant_view); + eggshell_ui::Style::default().install_for(&harness.ctx, harness.ctx.theme()); + open(&mut harness); + assert_eq!(painted_offset(&harness), 0.0); + close(&mut harness); + assert!(painted_box(&harness).is_none()); + assert_eq!(harness.state().app.exited, 1); +} + +#[test] +fn the_continuity_checker_accepts_a_sheet_opening_and_closing() { + let mut harness = harness(slide_view); + record(&harness.ctx); + open(&mut harness); + harness.run_steps(14); + close(&mut harness); + harness.run_steps(16); + let timeline = Timeline::recorded(&harness.ctx); + let presenting = (0..timeline.len()) + .filter(|&frame| { + timeline + .frame(frame) + .iter() + .any(|node| node.motion == Motion::Presents) + }) + .count(); + assert!(presenting >= 20, "precondition: {presenting} frames moved"); + timeline.assert_continuous(); +} + +/// The dialog example's sheet and dialog, with the shadcn preset's motion. +mod example { + use super::dialog::State; + use super::*; + + fn harness() -> Harness<'static, Rig> { + let mut harness = support::harness_scaled( + SCREEN, + 1.0, + common::base_text(egui::Theme::Light), + State::default(), + dialog::layout, + common::use_accent, + ); + harness.state_mut().page = support::Page::Themed; + harness.run_steps(4); + harness + } + + #[test] + fn the_sheet_slides_in_over_the_shadcn_duration_and_slides_out() { + let mut harness = harness(); + harness.state_mut().app.sheet = Shown::Open; + harness.step(); + let layout = rect_of(&harness, "/Sheet/Box"); + let painted = |harness: &Harness<'_, Rig>| { + support::shapes(harness) + .into_iter() + .filter_map(|shape| match shape { + egui::Shape::Rect(rect) + if rect.rect.height() >= layout.height() - 1.0 + && rect.rect.width() < layout.width() + 2.0 => + { + Some(rect.rect.min.x) + } + _ => None, + }) + .fold(f32::MAX, f32::min) + }; + assert!( + painted(&harness) > layout.min.x + layout.width() / 2.0, + "starts off to the right" + ); + harness.run_steps(4); + let part_way = painted(&harness); + assert!(part_way > layout.min.x, "still on its way after 0.2 s"); + harness.run_steps(14); + assert!((painted(&harness) - layout.min.x).abs() < 1.0, "arrived"); + harness.state_mut().app.sheet = Shown::Closed; + harness.run_steps(2); + assert!( + harness.state().nodes.iter().any(|(p, _)| p == "/Sheet/Box"), + "still there while it leaves" + ); + harness.run_steps(14); + assert!( + harness + .state() + .nodes + .iter() + .all(|(p, _)| !p.starts_with("/Sheet")), + "gone" + ); + } + + #[test] + fn the_dialog_fades_and_zooms_in() { + let mut harness = harness(); + harness.state_mut().app.dialog = Shown::Open; + harness.step(); + let layout = rect_of(&harness, "/Dialog/Box"); + let width = |harness: &Harness<'_, Rig>| { + support::shapes(harness) + .into_iter() + .filter_map(|shape| match shape { + egui::Shape::Rect(rect) + if (rect.rect.center() - layout.center()).length() < 2.0 + && rect.rect.width() > layout.width() * 0.9 + && rect.rect.width() < layout.width() * 1.1 + && rect.rect.height() > layout.height() * 0.9 => + { + Some(rect.rect.width()) + } + _ => None, + }) + .fold(0.0_f32, f32::max) + }; + let first = width(&harness); + assert!(first < layout.width() * 0.97, "zoomed out: {first}"); + harness.run_steps(14); + assert!(width(&harness) >= layout.width() - 1.0, "settled"); + } + + #[test] + fn the_dialog_box_stays_opaque_while_the_scrim_fades() { + let mut harness = harness(); + harness.state_mut().app.dialog = Shown::Open; + harness.run_steps(2); + let layout = rect_of(&harness, "/Dialog/Box"); + let fills: Vec<_> = support::shapes(&harness) + .into_iter() + .filter_map(|shape| match shape { + egui::Shape::Rect(rect) + if rect.rect.width() > layout.width() * 0.9 + && rect.rect.width() < layout.width() * 1.1 + && rect.rect.height() > layout.height() * 0.9 => + { + Some(rect.fill) + } + _ => None, + }) + .collect(); + assert!( + fills.iter().any(|fill| fill.a() == 255), + "precondition: the box is painted, mid-motion: {fills:?}" + ); + assert!( + fills + .iter() + .filter(|fill| fill.r() > 0) + .all(|fill| fill.a() == 255), + "no translucent box fill: {fills:?}" + ); + let scrim = support::shapes(&harness) + .into_iter() + .find_map(|shape| match shape { + egui::Shape::Rect(rect) + if rect.rect.width() >= SCREEN.x - 1.0 && rect.fill.a() < 255 => + { + Some(rect.fill) + } + _ => None, + }); + let scrim = scrim.expect("the scrim is painted"); + assert!( + scrim.a() > 0 && scrim.a() < 128, + "the scrim is part-way: {scrim:?}" + ); + } +} diff --git a/tests/it/select.rs b/tests/it/select.rs index bc56cf7b..6ed05327 100644 --- a/tests/it/select.rs +++ b/tests/it/select.rs @@ -571,3 +571,48 @@ mod beside_another_frame { assert_eq!(harness.state().app.changes, [2]); } } + +#[test] +fn the_list_pops_in_with_the_styles_menu_motion_and_leaves_the_same_way() { + use eggshell_ui::testing::{Motion, record}; + + let mut harness = support::harness_stepped(SCREEN, 0.02, base_text(), App::default(), view); + harness.run_steps(4); + record(&harness.ctx); + let motion = Style::of(&harness.ctx).motion.menu; + assert!( + !motion.enter.is_zero(), + "precondition: the shadcn preset moves menus" + ); + let moved = |harness: &Harness<'_, Rig>| { + let node = support::last_drawn(&harness.ctx, LIST)?; + Some((node.painted_rect != node.layout_rect, node.motion)) + }; + + click_node(&mut harness, PICK); + harness.step(); + assert_eq!( + moved(&harness), + Some((true, Motion::Presents)), + "scaled and nudged while it enters" + ); + harness.run_steps(20); + assert_eq!(moved(&harness).map(|moved| moved.0), Some(false), "settled"); + + harness.key_press(Key::Escape); + harness.run_steps(3); + assert_eq!( + moved(&harness).map(|moved| moved.0), + Some(true), + "scaled and nudged while it leaves" + ); + harness.run_steps(20); + assert!( + harness + .state() + .nodes + .iter() + .all(|(path, _)| !path.starts_with(LIST)), + "gone once the exit has run" + ); +} diff --git a/tests/it/snapshots.rs b/tests/it/snapshots.rs index e0e845bc..15b804df 100644 --- a/tests/it/snapshots.rs +++ b/tests/it/snapshots.rs @@ -1419,7 +1419,7 @@ fn dialog_in(name: &str, theme: egui::Theme, state: dialog::State) { fn open_dialog() -> dialog::State { dialog::State { - dialog: true, + dialog: eggshell_ui::overlay::Shown::Open, ..dialog::State::default() } } @@ -1436,7 +1436,7 @@ fn dialog_dark() { fn confirming() -> dialog::State { dialog::State { - confirm: true, + confirm: eggshell_ui::overlay::Shown::Open, ..open_dialog() } } @@ -1462,7 +1462,7 @@ fn dialog_role_menu_light() { fn sheet() -> dialog::State { dialog::State { - sheet: true, + sheet: eggshell_ui::overlay::Shown::Open, ..dialog::State::default() } } @@ -1554,3 +1554,135 @@ fn menu_destructive_light() { fn menu_destructive_dark() { menu_destructive("menu_destructive_dark", egui::Theme::Dark); } + +/// Frames of the dialog, the sheet and the menu entering and leaving, for +/// review (the motion is the user's choice): `cargo test --features +/// snapshots --test it motion_strips -- --ignored` with `EGGSHELL_MOTION_DIR` +/// naming where the PNGs go, and `VK_ICD_FILENAMES` the software renderer. +mod motion { + use super::*; + use eggshell_ui::overlay::Shown; + + fn out() -> std::path::PathBuf { + let dir = std::env::var("EGGSHELL_MOTION_DIR") + .expect("EGGSHELL_MOTION_DIR names the output directory"); + std::fs::create_dir_all(&dir).expect("the directory can be made"); + dir.into() + } + + /// Five frames a quarter of `duration` apart, from 0% to 100%. + fn frames(harness: &mut Harness<'static, support::Rig>, name: &str) { + for quarter in 0..5 { + harness.step(); + let image = harness.render().expect("renders"); + image + .save(out().join(format!("{name}_{}.png", quarter * 25))) + .expect("saves"); + } + } + + fn dialog_harness( + theme: egui::Theme, + step_dt: f32, + state: dialog::State, + ) -> Harness<'static, support::Rig> { + let style = ShadcnStyle::Vega; + let mut harness = support::harness_stepped( + SIZE, + step_dt, + TextStyle::new(layouts::BODY, Tokens::for_theme(theme).foreground), + dialog::State { + name: "Pedro Duarte".to_owned(), + ..state + }, + dialog::layout, + ); + common::set_style(&harness.ctx, style); + harness.state_mut().page = support::Page::Themed; + harness.state_mut().companion = support::Companion::Alone; + harness.ctx.set_theme(theme); + harness.run_steps(8); + harness + } + + fn modal_strips( + kind: &str, + open: fn(&mut dialog::State, eggshell_ui::overlay::Shown), + enter: f32, + exit: f32, + ) { + report_renderer(); + for (theme, label) in [(egui::Theme::Light, "light"), (egui::Theme::Dark, "dark")] { + let mut harness = dialog_harness(theme, enter / 4.0, dialog::State::default()); + open(&mut harness.state_mut().app, Shown::Open); + frames(&mut harness, &format!("{kind}_enter_{label}")); + + let mut harness = dialog_harness(theme, exit / 4.0, dialog::State::default()); + open(&mut harness.state_mut().app, Shown::Open); + harness.run_steps(40); + open(&mut harness.state_mut().app, Shown::Closed); + frames(&mut harness, &format!("{kind}_exit_{label}")); + } + } + + #[test] + #[ignore = "writes review images, see the module comment"] + fn motion_strips_dialog() { + modal_strips("dialog", |state, on| state.dialog = on, 0.2, 0.2); + } + + #[test] + #[ignore = "writes review images, see the module comment"] + fn motion_strips_sheet() { + modal_strips("sheet", |state, on| state.sheet = on, 0.5, 0.3); + } + + fn menu_harness(theme: egui::Theme) -> Harness<'static, support::Rig> { + let style = ShadcnStyle::Vega; + let mut harness = support::harness_stepped( + Vec2::new(420.0, 400.0), + 0.0375, + common::base_text_styled(theme, style), + menu::State { + grid: true, + ..menu::State::default() + }, + menu::layout, + ); + common::set_style(&harness.ctx, style); + harness.state_mut().page = support::Page::Themed; + harness.state_mut().companion = support::Companion::Alone; + harness.ctx.set_theme(theme); + harness.run_steps(8); + harness + } + + #[test] + #[ignore = "writes review images, see the module comment"] + fn motion_strips_menu() { + report_renderer(); + for (theme, label) in [(egui::Theme::Light, "light"), (egui::Theme::Dark, "dark")] { + let mut harness = menu_harness(theme); + let at = support::rect_of(&harness, "/Page/Top/PopoverButton").center(); + support::hover_over(&mut harness, at); + harness.event(egui::Event::PointerButton { + pos: at, + button: egui::PointerButton::Primary, + pressed: true, + modifiers: egui::Modifiers::NONE, + }); + harness.step(); + harness.event(egui::Event::PointerButton { + pos: at, + button: egui::PointerButton::Primary, + pressed: false, + modifiers: egui::Modifiers::NONE, + }); + harness.step(); + frames(&mut harness, &format!("menu_enter_{label}")); + harness.run_steps(12); + harness.key_press(egui::Key::Escape); + frames(&mut harness, &format!("menu_exit_{label}")); + } + } +} diff --git a/tests/snapshots/dialog_confirm_dark.png b/tests/snapshots/dialog_confirm_dark.png index ee470cdd..8cafecfc 100644 Binary files a/tests/snapshots/dialog_confirm_dark.png and b/tests/snapshots/dialog_confirm_dark.png differ diff --git a/tests/snapshots/dialog_confirm_light.png b/tests/snapshots/dialog_confirm_light.png index c7a88dc8..acfcbe56 100644 Binary files a/tests/snapshots/dialog_confirm_light.png and b/tests/snapshots/dialog_confirm_light.png differ diff --git a/tests/snapshots/dialog_dark.png b/tests/snapshots/dialog_dark.png index 7a7ebe4e..8fb230e4 100644 Binary files a/tests/snapshots/dialog_dark.png and b/tests/snapshots/dialog_dark.png differ diff --git a/tests/snapshots/dialog_light.png b/tests/snapshots/dialog_light.png index c897f5f0..4e318871 100644 Binary files a/tests/snapshots/dialog_light.png and b/tests/snapshots/dialog_light.png differ diff --git a/tests/snapshots/dialog_role_menu_light.png b/tests/snapshots/dialog_role_menu_light.png index 89ca9a22..e7a883ff 100644 Binary files a/tests/snapshots/dialog_role_menu_light.png and b/tests/snapshots/dialog_role_menu_light.png differ diff --git a/tests/snapshots/sheet_dark.png b/tests/snapshots/sheet_dark.png index de1610c6..d5890080 100644 Binary files a/tests/snapshots/sheet_dark.png and b/tests/snapshots/sheet_dark.png differ diff --git a/tests/snapshots/sheet_light.png b/tests/snapshots/sheet_light.png index 99cef5a4..0e01a75a 100644 Binary files a/tests/snapshots/sheet_light.png and b/tests/snapshots/sheet_light.png differ