Immediate-mode GUIs (Dear ImGui, egui, Clay, Nuklear, microui, Gio)
How a GUI that rebuilds its whole description every frame animates without retained widgets: each system keeps a small amount of presentation state in a store keyed by widget identity, advances it with a delta time the host supplies, and either lets the calling code read the animated value back (egui, Dear ImGui, Gio) or interpolates layout output itself between two layout passes (Clay). Nuklear and microui keep almost no animation state at all.
| Field | Value |
|---|---|
| Language | C++ (Dear ImGui) · Rust (egui) · C99 (Clay, Nuklear) · ANSI C (microui) · Go (Gio) |
| License | MIT (Dear ImGui) · MIT OR Apache-2.0 (egui) · zlib (Clay) · MIT or public domain (Nuklear) · MIT (microui) · Unlicense OR MIT (Gio) |
| Repository | ocornut/imgui · emilk/egui · nicbarker/clay · Immediate-Mode-UI/Nuklear · rxi/microui · gioui/gio (mirror of git.sr.ht/~eliasnaur/gio) |
| Documentation | Dear ImGui docs/FAQ.md · egui README.md and the doc comments in context.rs · Clay README.md § Transitions · Nuklear and microui: header comments only · Gio: doc comments (op.InvalidateCmd) |
| Category | immediate mode: the application calls widget functions every frame; per-identity state survives in a library-owned store |
| Versions surveyed | Dear ImGui 1.93.1 WIP at bd4e3b0 (2026-11-23) · egui 0.37.0 at 90431d9 (2026-11-24) · Clay at e6cc369 (2026-05-20) · Nuklear 4.13.4 at c8bfb4d (2026-11-26) · microui at 0850aba (2024-08-13) · Gio at 9816a10 (2026-11-23) |
| Animation state lives in | egui: AnimationManager maps keyed by Id, plus widget state in Memory::data (IdTypeMap) · Dear ImGui: fields of the global ImGuiContext and of each ImGuiWindow/ImGuiTabBar, plus ImGuiStorage · Clay: Clay__TransitionDataInternal records keyed by element id · Gio: the widget struct the caller owns (widget.Clickable press history) · Nuklear/microui: nothing beyond hover timers |
NOTE
This page covers animation only. How these systems measure and place elements is in the layout catalog (Dear ImGui, egui, Clay); how they handle long lists, including egui's CollapsingHeader height cache, is in Immediate-mode large views. The terminal analogues (Bubble Tea, Textual, tachyonfx) are on the sibling page Terminal UIs. Terms such as retarget, stepped integration and presence are defined in Concepts. Every claim was read at the pinned revision.
Overview
What it solves
An immediate-mode GUI has no widget objects to hang an animation on. A button exists only while the frame's code is calling ui.button(...); the next frame's call is a different call that happens to produce the same identity. Animation therefore needs three things the paradigm does not give for free: a place to keep a value between frames (keyed by identity), a clock (the frame's delta time, from the host), and a way to keep the frame loop running while something moves (otherwise a reactive host sleeps). The systems surveyed solve these in different proportions. egui solves all three in the library; Dear ImGui solves the first two for a fixed set of built-in effects; Clay solves the first two for layout output and leaves the third to the host; Gio puts the clock in the context and the state in the caller's widget struct; Nuklear and microui solve almost none of them.
Design philosophy
Dear ImGui's FAQ states the trade the paradigm makes (docs/FAQ.md):
"UI library stores minimal amounts of data. At one point in time, it typically doesn't know or remember which other widgets are displayed and which widgets are coming next."
egui's README names animation as one of the two reasons the frame loop runs at all (README.md):
"
eguionly repaints when there is interaction (e.g. mouse movement) or an animation, so if your app is idle, no CPU is wasted."
Clay's README makes the identity requirement explicit (README.md):
"Note: for transitions to work, elements need a stable ID from one frame to the next - using loop indexes or CLAY_AUTO_ID will not work."
Gio puts the clock into the per-frame value the caller threads through every widget (app/app.go):
"Now is the current animation. Use Now instead of time.Now to synchronize animation and to avoid the time.Now call overhead."
How it works
Dear ImGui
Dear ImGui has no animation API. It animates a handful of its own effects, each with a dedicated field advanced by io.DeltaTime, which the host must set every frame (float DeltaTime; // = 1.0f/60.0f, imgui.h); NewFrame asserts it is positive (imgui.cpp).
| Effect | State | Update rule |
|---|---|---|
| Modal / Ctrl+Tab background dim | g.DimBgRatio (imgui_internal.h) | += DeltaTime * 6 towards 1 while a modal is open, -= DeltaTime * 10 towards 0 otherwise (source) |
| Ctrl+Tab window highlight | g.NavWindowingHighlightAlpha, g.NavWindowingTimer, g.NavWindowingTargetAnim | fades out at DeltaTime * 10 once the target is cleared (source) |
| Flash of an item activated by a shortcut | g.NavHighlightActivatedTimer = NAV_ACTIVATE_HIGHLIGHT_TIMER (0.10 s, source) | counted down by DeltaTime (source) |
| Tab-bar scrolling | ImGuiTabBar::ScrollingAnim, ScrollingTarget, ScrollingSpeed (imgui_internal.h) | ImLinearSweep at a speed chosen to arrive within 0.3 s; teleports if far off (source) |
| Hover delays (separator highlight, menus, tooltips) | g.HoveredIdTimer, g.HoverItemDelayTimer, g.MouseStationaryTimer (imgui_internal.h) | accumulate DeltaTime while the same id stays hovered, reset otherwise (source) |
| Text cursor blink | ImGuiInputTextState::CursorAnim | += DeltaTime; visible while fmod(CursorAnim, 1.20) <= 0.80 (source) |
The comment on LastActiveIdTimer names the intended consumer: "Store the last non-zero ActiveId timer since the beginning of activation, useful for animation." (imgui_internal.h). Custom widgets animate by reading these id-keyed timers or by keeping their own value in ImGuiStorage, the sorted ImGuiID → int/float/void* map each window carries (imgui.h):
"We use it to e.g. store collapse state for a tree (Int 0/1) […] You can use it as custom user storage for temporary values."
Window scrolling does not animate: SetScrollY/ScrollToItem store ScrollTarget, and the next Begin resolves it in one step in CalcNextScrollFromScrollTargetAndClamp (source). Tree nodes, popups and tooltips open and close in one frame.
egui
egui exposes animation as functions on Context that take an Id and a target and return the current value (context.rs):
// crates/egui/src/context.rs
pub fn animate_bool(&self, id: Id, value: bool) -> f32; // Style::animation_time, linear
pub fn animate_bool_responsive(&self, id: Id, value: bool) -> f32; // cubic_out
pub fn animate_bool_with_time_and_easing(&self, id: Id, target_value: bool,
animation_time: f32, easing: fn(f32) -> f32) -> f32;
pub fn animate_value_with_time(&self, id: Id, target_value: f32, animation_time: f32) -> f32;The state behind them is AnimationManager, two IdMaps inside the context (animation_manager.rs):
pub(crate) struct AnimationManager {
bools: IdMap<BoolAnim>, // BoolAnim { last_value: f32, last_tick: f64 }
values: IdMap<ValueAnim>, // ValueAnim { from_value: f32, to_value: f32, toggle_time: f64 }
}The two kinds are integrated differently:
animate_boolis stepped. Each call adds(end - start) * elapsed / animation_timetolast_value, withelapsedclamped toinput.stable_dt, and clamps to[0, 1](source). The first call returns the target immediately (no enter animation for a widget seen for the first time). Easing is applied to the output, flipped for the closing direction:easing(v)when the target istrue,1 - easing(1 - v)when it isfalse(source).animate_value_with_timeis closed form. It remapstime - toggle_time(plus half apredicted_dt, "On the frame we toggle we don't want to return the old value, so we extrapolate forwards by half a frame") linearly fromfrom_valuetoto_value. When the target changes it setsfrom_valueto the value it would have returned and restarts the clock (source).
Both wrappers call request_repaint() only while the value is strictly between its endpoints (0.0 < animated_value && animated_value < 1.0, or animated_value != target_value), so a settled animation costs nothing (source, source). The manager never evicts an entry; clear_animations drops all of them (source).
Time comes from InputState. RawInput::time is optional: "If None is provided, egui will assume a time delta of predicted_dt (default 1/60 seconds)" (raw_input.rs). stable_dt exists because egui sleeps when idle (input_state/mod.rs):
"If
eguirequested a repaint the previous frame, theneguiwill usestable_dt = unstable_dt;, but ifeguidid not not request a repaint last frame, theneguiwill assumeunstable_dtis too large, and will usestable_dt = predicted_dt;."
The global duration is Style::animation_time ("How many seconds a typical animation should last", default 0.2, style.rs). Easing curves live in emath::easing ("Contains most easing functions from https://easings.net/", easing.rs), plus emath::ease_in_ease_out (smoothstep) and emath::interpolation_factor, which turns a (start, end) time span and the frame's dt into the fraction of the remaining distance to cover this frame, so a lerp from the current position stays on the eased curve (emath/src/lib.rs).
Built-in widgets that animate:
CollapsingHeader/CollapsingState.openness()isanimate_bool_responsive(id, open); while0 < openness < 1the body is built every frame inside a childUiwhose clip rect is cut toopenness × open_height, and the parent is told the child took only that much space (force_set_min_rect).open_heightis the body's height from the last fully open frame, stored inMemory::dataasInnerState { open, open_height }; with no stored height the first animated frame usesfallback_height_guess = 10.0(collapsing_header.rs, body).Windowfade-out.Window::showcomputesopacity = animate_bool_with_easing(area.id.with("fade-out"), is_open, cubic_out)and returnsNoneonly onceopacity <= 0.0; until then the window is built normally andmultiply_opacity(opacity)is applied (window.rs, apply). Fade-in isArea's:AreaState::last_became_visible_atis set on the first frame the layer was not visible last frame, and the contentUigetsquadratic_out(age / animation_time)opacity (area.rs, set, apply).ScrollAreaprogrammatic scrolls.scroll_to_*recordsScrollingToTarget { animation_time_span, target_offset }; each frame movesoffsetbyinterpolation_factor(span, time, dt, ease_in_ease_out)towards the target. Duration is distance overScrollAnimation::points_per_second(1000) clamped to0.1..=0.3s (scroll_area.rs, step, start,style.rs).
Other widget state that the animations read sits in Memory::data, an IdTypeMap (id XOR typeid keys, temporary or persisted values) documented as "superficial state for all widgets with custom [Id]s" (memory/mod.rs, id_type_map.rs).
Clay
Clay is a layout engine that returns a flat array of render commands; since the surveyed revision it also has a transition API that interpolates its own layout output (README.md: "Both layout-affecting properties such as width and height, as well as non-layout properties such as backgroundColor are supported."). An element opts in by declaring a handler:
// README.md — Transitions
CLAY(CLAY_IDI("box", colors[index].id), {
.backgroundColor = boxColor,
.transition = {
.handler = Clay_EaseOut,
.duration = 0.5f,
.properties = CLAY_TRANSITION_PROPERTY_WIDTH | CLAY_TRANSITION_PROPERTY_POSITION
| CLAY_TRANSITION_PROPERTY_OVERLAY_COLOR | CLAY_TRANSITION_PROPERTY_BACKGROUND_COLOR,
.enter = { .setInitialState = EnterExitSlideUp },
.exit = { .setFinalState = EnterExitSlideUp },
}
}) { /* children */ }The configuration types are in clay.h: Clay_TransitionData (bounding box, background, overlay and border colour, border width), the state enum IDLE / ENTERING / TRANSITIONING / EXITING, the property bit set, enter and exit triggers relative to the parent, the exiting element's sibling ordering, and whether pointer interaction is disabled while position transitions. The handler is a plain function bool (*handler)(Clay_TransitionCallbackArguments) receiving initial, a pointer to current, target, elapsedTime, duration and the active property set, and returning true when done; Clay_EaseOut is the built-in cubic ease-out lerp (source). Time is the argument to Clay_EndLayout(float deltaTime) (clay.h; the README loop passes deltaTime "the time since the last frame, and is used for transitions", README.md).
Clay_EndLayout runs the engine as follows (source):
- Track. Opening an element that has a handler finds or creates its
Clay__TransitionDataInternal(keyed byelementId, also recordingparentId,siblingIndex, andreparentedif the parent id changed). Re-declaring an element that is mid-exit resets it toIDLE(source). - Prune. Records whose element was not declared this frame and that have no exit state are dropped (source).
- Resurrect exiting elements. A record with
transitionOutwhose element was not declared this frame starts exiting: on the first frame its last frame's size is frozen intoCLAY_SIZING_FIXED, it is reattached to the root as floating at its last bounding box if the parent is also gone, andsetFinalStatecomputes the exit target. On every exiting frame the element's retained subtree — theClay_LayoutElements copied out of the previous frame byClay__CloneElementsWithExitTransition— is cloned back into this frame's tree and reinserted under its old parent at the configured sibling position (source, clone, reattach,Clay__CloneElementsWithExitTransition).Clay_LayoutElement::exitingmarks these "synthetic" elements whose "data was retained from previous frames" (source). - Layout pass 1 without render commands, to get every element's target bounding box:
Clay__CalculateFinalLayout(deltaTime, false, false)(source). - Diff and step. For each record the target is this pass's bounding box and colours. An element that appeared this frame enters from
setInitialState(target)(unless the parent also just appeared and the trigger isSKIP_ON_FIRST_PARENT_FRAME). Otherwise each enabled property whose target differs from last frame's target starts a transition fromcurrentStatewithelapsedTime = 0; a position change counts only if the parent-relative position changed (a moving parent does not animate its children separately) and never on the frame after a root resize (enter, diff). The handler is called, its output written back into the element (width/heightbecomeCLAY_SIZING_FIXEDof the animated size, so children re-lay out inside it), andelapsedTime += deltaTime(source,Clay_ApplyTransitionedPropertiesToElement). - Layout pass 2 with render commands, using the stored animated bounding boxes in place of computed ones for transitioning elements (source, stored boxes), then the exiting subtrees are copied aside for the next frame.
Scroll containers have momentum: Clay_UpdateScrollContainers(enableDragScrolling, scrollDelta, deltaTime) adds scrollMomentum to the position and multiplies it by 0.95 per call (clay.h, momentum). Clay reports nothing to the host about whether a transition is running; the raylib example redraws every frame (while (!WindowShouldClose()), Clay_EndLayout(GetFrameTime()), main.c).
Nuklear and microui
Neither has animation. Nuklear's context carries float delta_time_seconds, set by the platform glue (nuklear.h); it feeds two kinds of timer: the hover-with-delay queries (nk_input_is_mouse_hovering_delay_rect and its _still_ variants accumulate into a caller-supplied float* timer, source; tooltips use them for their delay, source) and auto-hiding scrollbars, which simply stop drawing once scrollbar_hiding_timer passes NK_SCROLLBAR_HIDING_TIMEOUT (4 s) — no fade (source, timeout, default). Per-id state is nk_table, pages of nk_hash → nk_uint pairs owned by a window (used for tree-node open state, source, nk_find_value); windows not touched in a frame are garbage-collected in nk_clear by comparing seq (source).
microui has no time input at all: the context has an integer frame counter and two retained pools, container_pool and treenode_pool, of mu_PoolItem { mu_Id id; int last_update; }, recycled least-recently-updated first (microui.h, mu_PoolItem, mu_pool_init). Its README sells the constraint: "Works within a fixed-sized memory region: no additional memory is allocated" (README.md).
Gio
Gio's per-frame value layout.Context carries Now time.Time ("Now is the animation time", layout/context.go), copied from app.FrameEvent.Now (app/app.go). A widget that wants another frame executes op.InvalidateCmd{At: t} ("requests a redraw at the given time. Use the zero value to request an immediate redraw", op/op.go); the router keeps the earliest requested time (io/input/router.go, WakeupTime) and the window either animates continuously or arms a timer for it (app/window.go). widget.Editor uses the At form for caret blink (source); material.Loader derives its rotation from gtx.Now modulo one second and invalidates every frame (source).
State lives in the widget struct the application keeps. widget.Clickable holds history []Press, each Press { Position, Start, End time.Time, Cancelled bool }; presses are appended on KindPress, stamped with End on click or cancel, and pruned one second after they end (widget/button.go, prune and record). material's drawInk is a pure function of a Press and gtx.Now: it computes fade and expansion fractions from now - Start and now - End, fast-forwards a cancelled press, returns early when the ink is "Too old", and executes op.InvalidateCmd{} only while the press is fading in or has ended (widget/material/button.go).
Fling scrolling is the one physics animation. gesture.Scroll samples pointer velocity with fling.Extrapolation, and on release starts fling.Animation, a closed-form exponential decay x(t) = v0·e^(kt)/k − v0/k with k = −4.2 (−2 on Darwin) that Tick(now) evaluates and that stops below 1 px/s (internal/fling/animation.go, gesture/gesture.go). layout.List scrolls through gesture.Scroll, so it inherits fling; List.ScrollBy/ScrollTo are instantaneous (layout/list.go).
Analysis
Where animation state lives
Every system keys animation state by the widget's identity, never by a widget object:
| System | Store | Key | Lifetime |
|---|---|---|---|
| egui | AnimationManager (IdMap<BoolAnim>, IdMap<ValueAnim>) + Memory::data (IdTypeMap) | Id (caller-chosen, often id.with("…")) | animations: never evicted; Memory::data: until removed, and across restarts with the persistence feature |
| Dear ImGui | ImGuiContext scalars (one hovered/active/nav item at a time), ImGuiTabBar, ImGuiWindow, ImGuiStorage | ImGuiID | context lifetime; windows compacted after ConfigMemoryCompactTimer (imgui.h) |
| Clay | Clay__TransitionDataInternalArray | element id (must be explicit) | until the element is undeclared and its exit completes |
| Gio | the caller's widget value (Clickable.history, gesture.Scroll.flinger) | Go value identity | the caller's |
| Nuklear | nk_table pages per window; caller-owned float* timers | nk_hash | window GC by seq |
| microui | fixed container_pool / treenode_pool | mu_Id | LRU by frame |
Dear ImGui's scalars are notable for what they rule out: HoveredIdTimer and ActiveIdTimer exist once, for the single hovered and single active item (source), so "the button that was hovered a moment ago fades out" is not expressible with them. egui's per-Id maps are what make that fade cheap.
Declaring an animation
All are declarative targets, re-stated every frame: egui's animate_bool(id, open) and Clay's .transition config are called with the current target each frame, and the system decides whether the target changed. The animation is implicit in the sense of Concepts — the caller never names a start value. egui is a read API (the caller gets an f32 and uses it however it likes, typically for opacity, a clip height, or an icon rotation); Clay is a write API (the engine overwrites the element's bounding box and colours, and the caller never sees the animated values). Dear ImGui's effects are hard-coded; Gio's are computed by the caller from timestamps the widget recorded. None has an imperative controller with play/reverse.
Time and the clock
The host owns the clock everywhere; the library never reads the wall clock:
- Dear ImGui and Nuklear take a per-frame delta (
io.DeltaTime,ctx->delta_time_seconds) and integrate it. microui takes none. - egui takes an absolute
time(optional) pluspredicted_dt, and derivesstable_dtto protect stepped animations from the long gap after an idle sleep (source).animate_value_with_timeand the scroll andAreafades are closed-form intime;animate_boolis stepped and therefore frame-rate-sensitive only through thestable_dtclamp. - Clay takes a delta in
Clay_EndLayout(deltaTime)and accumulateselapsedTime; its scroll momentum decays by a per-call factor (*= 0.95), so its speed depends on the frame rate (source). - Gio takes an absolute
Nowand every surveyed animation is a closed-form function ofNowand recorded timestamps — the most deterministic arrangement here.
Interruption and retargeting
None of the immediate-mode systems carries velocity across a retarget:
- egui
animate_boolreverses in place: the steppedlast_valuesimply starts moving the other way at constant rate. Because easing is applied to the output and mirrored for the closing direction, a reversal with an asymmetric curve jumps: forcubic_outatlast_value = 0.5the opening output iseasing(0.5) = 0.875and the closing output is1 − easing(0.5) = 0.125(arithmetic on source).CollapsingHeaderusescubic_out(source). - egui
animate_value_with_timerestarts from the current value with a fresh full duration (restart from current value, zero velocity) (source).ScrollAreakeeps the running time span and moves onlytarget_offsetwhen a new scroll request arrives mid-animation ("the user is continuously callingui.scroll_to_cursor, so we don't want to reset the animation, but perhaps update the target", source). - Clay restarts from
currentStatewithelapsedTime = 0and ORs the newly changed properties into the active set (source); re-declaring an exiting element cancels the exit (source). - Dear ImGui's tab-bar sweep keeps
ScrollingSpeedas a running maximum while moving, so a retarget never slows it (source). Gio's fling restarts from a fresh velocity estimate on each release.
Curves and springs
Duration plus easing throughout; no system has a spring. egui ships the easings.net set (linear, quadratic_*, cubic_*, sin_*, circular_*, exponential_*, back_*, bounce_*) as fn(f32) -> f32 and as the Easing enum, plus smoothstep for scrolling (source). Clay ships one handler (cubic ease-out) and lets the caller write any bool handler(args), which is general enough to host a spring if the caller keeps velocity elsewhere — the handler gets current but no velocity field (source). Dear ImGui's effects are linear ramps. Gio's ink uses smoothstep on two phase fractions; its fling is the only physical model (exponential drag, closed form, source).
Layout animation
Two different strategies, in two different phases:
- egui animates in user code, inside the build pass, with last frame's geometry.
CollapsingHeaderneeds the body's full height to animate it, and the only height it has isopen_heightremembered from the last fully open frame (or a guess of10.0). The body is built in full every animated frame, clipped to the animated height, and the parent is told the reduced size throughforce_set_min_rect— so siblings below move, because the animated value feeds layout before they are placed (source). This is UI-Q9's case (PR #775): the component reads a committed size from the store and that read decides what space it claims. - Clay animates inside the layout phase, with this frame's geometry. It runs layout twice per frame: pass 1 computes targets, the handler interpolates from the previous
currentState, and pass 2 lays out again with animated bounding boxes substituted, so an animatedwidthreflows children inside it (source, stored boxes). It needs the previous frame's animated state (kept in the record) and the previous frame's target (to detect a change), but not a measurement from user code; user code never sees the animated rect.
Dear ImGui and Nuklear do not animate geometry; Gio's ink is paint-only (an offset clip and a colour, computed during the frame's op recording), and its fling changes scroll position, which feeds the next layout of layout.List. None defers animation to a compositor: every system re-records its whole display list each animated frame.
Enter and exit
Three mechanisms, all relevant to UI-Q10 (PR #775):
- Closing state driven by the store, with the caller still building (egui).
Windowstays open-in-code while closing: the application keeps callingWindow::new(…).open(&mut open)withopen == false, andshowbuilds the full window at decreasing opacity untilanimate_boolreaches 0 (source). If the application stops callingshow, the window vanishes the same frame; the library holds no snapshot.CollapsingHeaderis the same: the body closure keeps running whileopenness > 0. - Retained snapshot driven by the engine (Clay). An element not declared this frame but configured with
exit.setFinalStateis resurrected from a copy of its previous frame's layout subtree, frozen at its last size, re-parented (or floated at its last position if the parent is gone), and animated to the final state; nested transitions inside it are removed (source,Clay__CloneElementsWithExitTransition). The clone copiesClay_LayoutElementvalues, so a text element keeps theClay_Stringslice it was declared with (only its wrapped lines are reset and recomputed, source); by inference, the caller's string memory must stay valid for the whole exit. Enter is the symmetricsetInitialState(target)on the first declared frame, with parent-relative triggers (source). - A retained pointer for one effect (Dear ImGui).
NavWindowingTargetAnimis a "Record of last valid NavWindowingTarget until DimBgRatio and NavWindowingHighlightAlpha becomes 0.0f, so the fade-out can stay on it" (source) — the hand-written form of "keep painting the departed thing".
Gio's ink shows a fourth, caller-owned form: a press stays in history for a second after it ends, so the ink keeps painting after the gesture is over (source). Nuklear and microui have no enter or exit.
Scheduling, reduced motion and testing
Frame requests. egui requests a repaint only while an animated value is strictly in flight (source); Gio requests one only while the ink or fling is live, and can request a future frame with InvalidateCmd{At} (source). Clay, Dear ImGui, Nuklear and microui never report "still animating"; their examples redraw continuously (Dear ImGui's GLFW example sleeps only while iconified, main.cpp; Clay's raylib example, main.c).
Reduced motion. No surveyed system reads a reduced-motion preference. egui's equivalent is a style knob: animation_time = 0.0 makes animate_bool jump (division by zero gives a non-finite step, which is replaced by end, source) and animate_value_with_time returns the target (source); ScrollAnimation::none() disables scroll animation (source).
Testing. egui's egui_kittest harness sets exactly those knobs — "The scroll animation is disabled", style.animation_time = 0.0 — and drives frames with a fixed step_dt written into predicted_dt while RawInput::time stays None, so time advances by a constant per frame; Harness::run steps "until all animations are done [and] no more repaints are requested" (egui_kittest/src/lib.rs, style, step, run). Gio's closed-form design makes any frame reproducible by constructing a layout.Context with a chosen Now (the zero Context "returns the zero time from Now", source). Clay and Dear ImGui are deterministic given the delta sequence the test passes.
Lessons for sparkles:ui
- The element store is the right home, and identity must be explicit for anything that animates. Clay refuses auto ids for transitions; egui derives sub-keys such as
area.id.with("fade-out"). sparkles' positional/keyed 64-bit identity can serve, but a positional id that shifts when a sibling is inserted will retarget the wrong element's animation — the same failure Clay warns about. - Reading animated values is pure if the clock is an input. egui's
animate_boolmutates the store from inside the build call, which apurecomponent cannot do. The Gio arrangement fits sparkles better: the store holds timestamps and targets committed by the host; the component reads(now, committed state)and computes the value in closed form; the host decides "still animating" from the same data after commit. egui'sstable_dtproblem disappears when nothing is stepped. - Two layout-animation phases exist and give different answers to UI-Q9. egui's is user-code-reads-last-frame-size (needs a committed
open_height, wrong on the first frame); Clay's is layout-runs-twice (needs no user read, costs a second layout pass only on frames with active transitions, and keeps animated geometry out of component code). A host-side, Clay-style pass fits "components may read but not write the store". - For UI-Q10 the two candidates are both proven. egui's closing state requires the component to keep building the overlay while it closes — at odds with "an overlay is open iff it is built this frame" unless "built" includes "closing". Clay's retained subtree needs no component cooperation but must copy last frame's elements (including borrowed strings) and handle a vanished parent.
- Velocity is absent everywhere here. If sparkles wants springs with retarget continuity, the store must hold velocity alongside value; none of these systems is a template for that (see Bubble Tea and harmonica).
- Avoid output-side easing flips (egui) and per-frame decay factors (Clay momentum); both are frame-rate or reversal artefacts.
Strengths
- Animation state is small, flat, and keyed by the same identity the frame already computes; no widget object or callback is needed.
- egui's API is one function call returning a number; anything (opacity, clip height, rotation) can be animated with it, and it schedules frames itself.
- Clay animates layout output generically — position, size and colour of any element, including enter and exit — without the caller ever handling animated geometry.
- Gio's closed-form timestamp style is deterministic and testable with a synthetic
Now. - Hosts that redraw continuously (games, tools) need nothing beyond a delta time.
Weaknesses
- No velocity, no springs, no retarget continuity in any of the six.
- egui's exit animations need the caller to keep calling the widget; its animation map is never pruned; its eased bool jumps on reversal.
- egui's collapsing animation depends on last frame's measured height and guesses on first open.
- Clay doubles layout work while any transition is active, copies retained subtrees per exiting frame, and does not tell the host when to stop redrawing.
- Dear ImGui's timers are global singletons, not per-item; Nuklear and microui offer nothing.
- No system honours a platform reduced-motion preference.
Key design decisions and trade-offs
| Decision | Rationale | Trade-off |
|---|---|---|
| Animation keyed by widget id in a library map (egui, Clay) | the paradigm has no widget objects; ids are already computed every frame | unstable ids silently retarget or restart animations; maps need eviction policy |
animate_bool(id, target) -> f32 read API (egui) | composable with any visual property; one call | mutates the store from the build call; reversal discontinuity with asymmetric easing |
| Request a repaint only while in flight (egui, Gio) | reactive hosts sleep when idle | the stepped path needs stable_dt to absorb the first frame after a sleep |
| Two layout passes with animated boxes substituted (Clay) | layout-affecting properties animate and children reflow without user code | double layout cost during transitions; animated geometry hidden from the caller |
| Retained subtree resurrected for exit (Clay) | exit works without the caller declaring the departing element | copies last frame's elements; borrowed strings must outlive the exit; parent loss needs floating |
Closing state with the caller still building (egui Window) | no snapshot machinery; the window stays fully live while fading | caller must keep calling show; stopping the call cuts the animation |
| Timestamps in caller state, closed-form evaluation (Gio) | deterministic, frame-rate independent, testable with a synthetic Now | each widget writes its own animation math |
| Global single-item timers (Dear ImGui) | minimal state; enough for hover delays and one highlight | cannot fade an item that is no longer hovered/active |
| No time input at all (microui) | fixed memory, minimal API | no animation is possible inside the library |
Sources
- Dear ImGui
bd4e3b0:docs/FAQ.md,imgui.h,imgui_internal.h,imgui.cpp,imgui_widgets.cpp,examples/example_glfw_opengl3/main.cpp - egui
90431d9:animation_manager.rs,context.rs,input_state/mod.rs,raw_input.rs,style.rs,collapsing_header.rs,window.rs,area.rs,scroll_area.rs,emath/src/easing.rs,emath/src/lib.rs,memory/mod.rs,id_type_map.rs,egui_kittest/src/lib.rs,README.md;Context::animate_boolwas introduced on 2020-08-30 (24003b1) - Clay
e6cc369:clay.h,README.md,examples/raylib-transitions/main.c - Nuklear
c8bfb4d:nuklear.h - microui
0850aba:src/microui.h,src/microui.c,README.md - Gio
9816a10:op/op.go,layout/context.go,app/app.go,app/window.go,io/input/router.go,widget/button.go,widget/material/button.go,internal/fling/animation.go,gesture/gesture.go - Related pages: Dear ImGui layout, egui layout, Clay layout, Immediate-mode large views, Terminal UIs, Concepts, UI authoring