zed/crates/gpui/examples
David Barsky 8b1497dbd2
gpui: Add spring animations; examples (#62778)
# Objective

I wanted spring animations in GPUI for an application built atop of
GPUI.

## Solution

I texted @mikayla-maki about wanting spring animations; we collaborated
in Delta; this change is the co-authored result. We built atop of GPUI's
existing APIs, but this *is* new API surface. The verbiage is borrowed
from SwiftUI's approach.

First, what _are_ spring animations? If you're unfamiliar, they're the
bouncy, physical animations that you'd often see in mobile applications.
As Claude put it to me, "keyframe animation is a recording; a spring is
a simulation". There's a few consequences:
1. The animation API needs to support interrupts/cancelation, or the
application using spring animations will feel broken. You need to cancel
the momentum in a physically realistic way!
2. The API is more complex! GPUI's existing animations are, roughly,
`Fn(progress: f32) -> eased_progress: f32`, but a spring animation is
closer to `Fn(state: SpringState, target: f32, delta_time: f32) ->
SpringState`. Concretely, GPUI landed on the following:

```
pub fn step(
    &self,
    state: SpringState,
    target: f32,
    delta_time: f32,
) -> SpringState;
```

...where `&self` is:
```
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SpringConfig {
    /// The spring stiffness, conventionally written as $k$.
    pub stiffness: f32,
    /// The viscous damping coefficient, conventionally written as $c$.
    pub damping: f32,
    /// The moving mass, conventionally written as $m$.
    pub mass: f32,
}
```

Conceptually, at each frame, GPUI does `let state = spring.step(state,
target, delta_time);`, or as an other LLM summarized:

```
// Ordinary animation:
progress: f32 -> phase: f32

// GPUI spring:
(state: { position, velocity }, target, dt)
    -> new { position, velocity }
    -> typed presentation value
```

---

Release Notes:

- gpui: Added spring animations
2026-08-17 21:43:46 +00:00
..
image gpui_web: Support Fetch requests from background workers (#61782) 2026-07-28 13:32:52 +00:00
svg
view_example Unify Render and RenderOnce into View (#58087) 2026-07-08 15:52:48 +00:00
a11y.rs gpui: Fix web examples build (#59470) 2026-06-22 00:19:08 +00:00
active_state_bug.rs
anchor.rs
animation.rs gpui: Add spring animations; examples (#62778) 2026-08-17 21:43:46 +00:00
data_table.rs
drag_drop.rs
focus_visible.rs
gif_viewer.rs
gradient.rs
grid_layout.rs gpui: Add container_query element (#60774) 2026-07-12 03:38:24 +00:00
hello_world.rs Bump rustc to 1.97 (#62395) 2026-08-09 22:29:52 +00:00
image_gallery.rs gpui_web: Support Fetch requests from background workers (#61782) 2026-07-28 13:32:52 +00:00
image_loading.rs
input.rs
layer_shell.rs
list_example.rs
mouse_pressure.rs Bump rustc to 1.97 (#62395) 2026-08-09 22:29:52 +00:00
move_entity_between_windows.rs Bump rustc to 1.97 (#62395) 2026-08-09 22:29:52 +00:00
on_window_close_quit.rs
opacity.rs gpui: Add builder API for BoxShadow (#57743) 2026-06-11 21:28:12 +00:00
ownership_post.rs
painting.rs gpui: Add alpha method to Rgba (#52125) 2026-06-11 17:27:25 +00:00
paths_bench.rs
pattern.rs
popover.rs
README.md gpui: Add system notification platform APIs (#61189) 2026-07-17 18:52:23 +00:00
scrollable.rs
set_menus.rs
shadow.rs gpui: Add builder API for BoxShadow (#57743) 2026-06-11 21:28:12 +00:00
system_notifications.rs gpui: Add system notification platform APIs (#61189) 2026-07-17 18:52:23 +00:00
tab_stop.rs
testing.rs
text.rs
text_layout.rs
text_wrapper.rs
tree.rs
uniform_list.rs
window.rs Change "Ok" to "OK" in UI (#58744) 2026-06-08 14:48:37 +00:00
window_movable.rs macos: Fix window move controls are disabled (#60620) 2026-07-12 22:46:47 +00:00
window_positioning.rs
window_shadow.rs gpui: Add builder API for BoxShadow (#57743) 2026-06-11 21:28:12 +00:00

GPUI Examples

Examples can be run from the Zed repository root:

cargo run -p gpui --example hello_world

Where to start

  • hello_world shows the basic shape of a GPUI application: create an Application, open a window, create a root view, and render a div.
  • input demonstrates text input, focus, selections, clipboard actions, and keyboard bindings.
  • uniform_list shows how to render a simple virtualized list.
  • testing demonstrates #[gpui::test], TestAppContext, actions, focus, and window-based tests.

Layout and styling

  • grid_layout demonstrates CSS-grid-style layout.
  • opacity demonstrates opacity styling.
  • pattern shows patterned backgrounds.
  • shadow demonstrates box shadows.
  • text shows styled text rendering.
  • text_layout demonstrates text alignment, decoration, weights, and wrapping.
  • text_wrapper shows wrapping text content.

Interaction

  • anchor demonstrates anchored positioning.
  • data_table combines virtualized list rendering with table-style rows and a custom scrollbar.
  • drag_drop shows draggable elements and drop targets.
  • focus_visible demonstrates keyboard-visible focus styling.
  • mouse_pressure demonstrates pressure-sensitive pointer input where supported.
  • popover shows floating layers with deferred and anchored.
  • scrollable demonstrates scrollable content.
  • tab_stop shows keyboard tab navigation.

Images, drawing, and animation

  • animation demonstrates GPUI animations and animated SVG transforms.
  • gif_viewer shows GIF rendering.
  • gradient demonstrates linear gradients and color spaces.
  • image shows local and remote image loading, image sizing, and asset setup.
  • image_gallery demonstrates image caching and loading remote images.
  • image_loading shows image loading states and asset loading.
  • painting demonstrates custom drawing with paths and canvas.
  • svg shows SVG rendering.

Windows and application behavior

  • move_entity_between_windows shows moving an entity between windows.
  • on_window_close_quit demonstrates quitting when a window closes.
  • set_menus shows application menu setup.
  • system_notifications demonstrates posting, replacing, dismissing, and responding to operating-system notifications.
  • window demonstrates creating normal, dialog, popup, and floating windows.
  • window_positioning demonstrates window bounds and placement.
  • window_shadow demonstrates window shadow styling.

Specialized examples

These examples are useful when working on GPUI itself, but they may not be the best starting point for new applications:

  • active_state_bug is a focused active-state reproduction.
  • layer_shell demonstrates Linux layer-shell windows.
  • list_example demonstrates bottom-aligned list state and scrollbar behavior.
  • ownership_post supports the ownership and data-flow documentation.
  • paths_bench is a path rendering benchmark.
  • tree renders a deep tree of nested elements.