Skip to main content

animated

Function animated 

Source
pub fn animated<E>(
    id: impl Into<ElementId>,
    period: Duration,
    build: impl Fn(f32) -> E + 'static,
) -> impl IntoElement
where E: IntoElement + 'static,
Expand description

A decoration that animates, and stops when nobody can see it.

build is handed a 0…1 that loops over period, and returns the element to paint at that point in the loop. The loop runs only while the region is on screen and unclipped, and holds at 0 when the reader has asked for less motion — so an application’s own effect answers to the same preference every animation in this library does, without the application arranging it.

§Example

use gpui_ai::prelude::decoration;
use gpui::{div, prelude::*, px};
use std::time::Duration;

let drifting = decoration::animated("tide", Duration::from_secs(8), |delta| {
    div().absolute().top(px(delta * 40.)).size_full()
});