Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions crates/eggshell-ui-shadcn/src/preset.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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
}

Expand Down
17 changes: 16 additions & 1 deletion docs/overlays.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<bool>`: 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.
51 changes: 24 additions & 27 deletions examples/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<String>,
Expand Down Expand Up @@ -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),
Expand All @@ -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| {
Expand Down Expand Up @@ -229,28 +226,26 @@ 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")
.variant(variant::PRIMARY)
.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);
});
});
}
Expand Down Expand Up @@ -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(
Expand All @@ -314,28 +310,29 @@ 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;
});
});
});
});
}

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(
Expand All @@ -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);
});
});
});
Expand Down
14 changes: 14 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -305,8 +306,21 @@ impl<'b, 'f, A> Builder<'b, 'f, A> {
slot: &Slot,
decl: OverlayDecl,
on_dismiss: Option<DismissFn<A>>,
(motion, on_exited): (Option<Motion>, Option<DismissFn<A>>),
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),
Expand Down
12 changes: 10 additions & 2 deletions src/continuity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
});
Expand Down
4 changes: 4 additions & 0 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -1248,6 +1251,7 @@ impl Style {
},
scroll: ScrollStyle::from_egui(egui),
scrim: Color32::from_black_alpha(100),
motion: MotionStyle::INSTANT,
}
}

Expand Down
Loading
Loading