Skip to main content

Module decoration

Module decoration 

Source
Expand description

Layers an application paints into a component’s frame.

A component owns its structure; what fills the space behind and in front of that structure is the application’s business. This is the slot for it: one element under the content, one over it, both clipped to the frame’s own shape, neither taking any part in layout.

§What can go in one

Anything that is an element. A div with a patterned background, an img — including an animated GIF or WebP — a canvas painting arbitrary geometry, or a webview. This crate ships no effects of its own: a shake, a ripple, a halftone field are an application’s expression, not a library’s.

§Corners

A layer that paints all the way to the edge has to carry the frame’s radius itself, because GPUI cannot clip a subtree to a rounded rectangle - its ContentMask is a Bounds, so overflow_hidden clips to the box and never to a corner. frame_radius is that radius. A layer that does not reach the corners - scattered dots, a ring in the middle - needs nothing.

§Example

use gpui_ai::prelude::{Decoration, decoration};
use gpui::{App, div, prelude::*};

Decoration::behind(div().size_full().rounded(decoration::frame_radius(cx)))
    .and_above(div().size_full())

§Motion

animated drives a decoration from a looping 0…1 and stops it when the frame it sits in scrolls out of view or the reader has asked for less motion. A decoration that animates on its own clock would keep a scrolled away panel paying for itself forever.

Structs§

Decoration
The layers an application paints into one component’s frame.

Functions§

animated
A decoration that animates, and stops when nobody can see it.
frame_radius
The corner radius a decoration must carry to reach a component’s edge.
toward
Drives a decoration from a value the application already has.