Skip to main content

gpui_kit_material/shapes/
mod.rs

1//! M3 Expressive shapes: the 35-shape library and general morphing.
2//!
3//! - [`ShapeKind`]: the library, in the order of Compose's `MaterialShapes`.
4//! - [`RoundedPolygon`]: any outline of vertices with optional rounding.
5//! - [`Morph`]: an animation between any two polygons, matched corner to
6//!   corner, so the outline neither twists nor needs to be star-shaped.
7//! - [`MaterialShape`]: the element that paints a shape or a morph.
8//!
9//! # Sources
10//!
11//! The Figma kit's pages and md3.io define no shape library, so by the kit's
12//! reference priority the source is the next that does: m3e, which ports
13//! Compose Material3's `MaterialShapes.kt` at `19991f2c` and
14//! `androidx.graphics:graphics-shapes:1.0.1`. This module ports the same files
15//! from Google's source (Apache-2.0: see `LICENSE-androidx` in this directory
16//! and each file's header). `tests/compose_shapes.rs` holds it to a dump those
17//! unmodified sources produced on the JVM.
18//!
19//! Morphing defaults to [`MorphMatching::Current`], current `graphics-shapes`
20//! rather than the pinned 1.0.1 ([`MorphMatching::Compose1_5`]): at the
21//! progress values surveyed, 1.0.1's matching makes 13 of the 1190 ordered
22//! pairs self-intersect, and current matching none. No reference dump exists
23//! for it, so its outlines are held to geometric tests instead.
24//!
25//! # Example
26//!
27//! ```
28//! use gpui_kit_material::shapes::{MaterialShape, ShapeKind};
29//!
30//! // The outline halfway from a circle to a heart. Morphs are built once per
31//! // pair, so asking again costs nothing.
32//! let morph = ShapeKind::Circle.morph_to(ShapeKind::Heart);
33//! assert_eq!(morph.as_cubics(0.5).len(), morph.len());
34//!
35//! // An element that springs to whichever shape it is next given.
36//! let _favorite = MaterialShape::new("favorite", ShapeKind::Heart)
37//!     .label("Favorite")
38//!     .size(96.)
39//!     .animated(true);
40//! ```
41mod catalog;
42mod element;
43mod morph;
44mod polygon;
45
46pub(crate) use element::PathCache;
47
48pub use catalog::ShapeKind;
49pub use element::{MaterialShape, ShapeFrame, morph_path, polygon_path};
50pub use morph::{Morph, MorphMatching};
51pub use polygon::{CornerRounding, Cubic, RoundedPolygon};