guise/anim/prop.rs
1//! What a motion is allowed to move.
2//!
3//! gpui has no transform matrix on a `div`, so there is no `translate` or
4//! `scale` to animate — motion is expressed through the properties that do
5//! exist: opacity, the relative inset (which shifts an element at paint time
6//! without disturbing its siblings, the closest thing to a translate), the
7//! box, and colours. Naming them in a `Copy` enum instead of strings is what
8//! makes [`Frame::apply`](super::Frame::apply) exhaustive and a typo a
9//! compile error.
10
11/// One animatable property.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13pub enum Prop {
14 Opacity,
15 /// Horizontal offset in px, applied as a relative inset — the element
16 /// moves, the layout does not.
17 X,
18 /// Vertical offset in px, same mechanism as [`Prop::X`].
19 Y,
20 Width,
21 Height,
22 MarginTop,
23 MarginRight,
24 MarginBottom,
25 MarginLeft,
26 PadTop,
27 PadRight,
28 PadBottom,
29 PadLeft,
30 Radius,
31 BorderWidth,
32 Gap,
33 FontSize,
34 Background,
35 BorderColor,
36 TextColor,
37 /// Turns in degrees. gpui can only rotate an `Image`/`Svg` (through its
38 /// own `Transformation`), so this is carried for you to read out of the
39 /// [`Frame`](super::Frame) — `apply` skips it.
40 Rotate,
41 /// A multiplier. Same story as [`Prop::Rotate`]: yours to apply.
42 Scale,
43 /// Anything else you want tweened. The value never touches a style — you
44 /// read it back out of the frame and do what you like with it.
45 Custom(&'static str),
46}
47
48impl Prop {
49 /// Whether the property expects an [`AnimValue::Color`](super::AnimValue).
50 pub fn is_color(self) -> bool {
51 matches!(self, Prop::Background | Prop::BorderColor | Prop::TextColor)
52 }
53}