Crate gpui_transitions

Crate gpui_transitions 

Source
Expand description

A library for creating smooth, animated transitions in GPUI applications.

This crate provides an API for interpolating between values over time with customizable easing functions. It integrates seamlessly with GPUI’s rendering lifecycle and state management.

§Core Concepts

  • Lerp - A trait that defines how values can be linearly interpolated. Implementations are provided for common numeric types and GPUI primitives.

  • Transition - The main type for managing animated transitions. It tracks a goal value and interpolates toward it over a specified duration.

  • TransitionState - Internal state container used by Transition.

  • BoolLerp - A wrapper type for animating boolean-like values with smooth intermediate states.

  • WindowUseTransition - An extension trait for GPUI’s Window that provides convenient methods for creating transitions.

§Example

use gpui_transitions::WindowUseTransition;
use std::time::Duration;

// Create a transition that animates a color
let color_transition = window.use_keyed_transition(
    "my_color",
    cx,
    Duration::from_millis(400),
    |_window, _cx| rgb(0xFF0000),
);

// Evaluate the current interpolated value
let current_color = color_transition.evaluate(window, cx);

// Update the goal to trigger an animation
color_transition.update(cx, |color, cx| {
    *color = rgb(0x00FF00);
    cx.notify();
});

Structs§

BoolLerp
A wrapper type for animating boolean-like values.
Transition
An animated transition between values of type T.
TransitionState
Internal state container for a Transition.

Traits§

Lerp
A trait for types that can be linearly interpolated.
WindowUseTransition
Extension trait for GPUI’s Window that provides convenient methods for creating transitions.