|
Gin
|
Duration and easing of an animated change, CSS transition style. More...
#include <gin_animated.h>
Public Types | |
| using | Easing = float (*) (float) |
| An easing function, mapping linear progress 0..1 to eased progress. | |
Public Member Functions | |
| Transition ()=default | |
| Creates an instant transition. | |
| Transition (double durationMs, Easing easing) | |
| Creates a transition of the given duration in milliseconds and easing. | |
| bool | isInstant () const |
| True for "none", a duration of 0 and a default constructed Transition. | |
| float | getProgress (double elapsedMs) const |
| Returns the eased progress 0..1 at a time since the start; 1 from durationMs on and always for an instant transition. | |
Static Public Member Functions | |
| static std::optional< Transition > | fromSpec (const juce::String &spec) |
| Parses a spec string, "<ms> <easing>", "<ms>" or "none". | |
| static Easing | findEasing (const juce::String &name) |
| Returns the easing function for a name like "inOutQuad", nullptr for an unknown name. | |
| static Transition | resolve (const juce::Component &c, const juce::String &nameOrSpec) |
| Resolves a preset name, an inline spec or "none". | |
| static Transition | forProperty (const juce::Component &c, const juce::String &property) |
| Returns the transition a property of the component animates with, following the inheritance rules above: the nearest "transition" from the component up through its parents that covers the property, else the preset "default", else instant. | |
| static void | setPresets (juce::Component &c, const juce::var &presets) |
| Sets a component's presets, exactly as a layout json's top-level "transitions" does for the component its LayoutSupport lays out: an object of name -> spec, or a JSON string of one. | |
| static juce::var | getPresets (const juce::Component &c) |
| The presets setPresets() or a layout set on exactly this component, void if none. | |
| static void | set (juce::Component &c, const juce::var &transition) |
| Sets a component's "transition", exactly as the layout entry of that name does: a string (preset name, inline spec or "none") or a per-property object, "descendants" included. | |
| static juce::var | get (const juce::Component &c) |
| The "transition" set on exactly this component, void if none. | |
| static void | setGlobalEnabled (bool enabled) |
| Switches every transition in the app on or off, e.g. | |
| static bool | isGlobalEnabled () |
Public Attributes | |
| double | durationMs = 0.0 |
| Easing | easing = nullptr |
Static Public Attributes | |
| static const juce::Identifier | componentProperty { "layoutTransition" } |
| Component property holding a layout entry's "transition". | |
| static const juce::Identifier | presetsProperty { "layoutTransitions" } |
| Component property holding the presets of the layout that positions its children. | |
Duration and easing of an animated change, CSS transition style.
Transitions are opt-in: a layout or a component without transition definitions behaves exactly as without this class, every change applies at once.
A spec string is "<ms> <easing>", e.g. "250 inOutQuad": the duration in milliseconds (digits and an optional decimal point), whitespace, the easing name. Also valid:
Easing names (case sensitive, implemented by the functions in gin_easing.h):
A layout json's top-level "transitions" object names specs. Several layout files of one LayoutSupport merge their presets in load order. Presets are looked up from the animated component up through its parents, so nested layouts can define their own and still use their ancestors'. The preset name "default" is special: it applies to every animated property under that layout that no "transition" entry covers.
A component entry's "transition" is either
Property names: "bounds" (the layout moving and resizing the component), "alpha" and "scale" (the layout's entries of that name and States' values; "scale" is also AnimatedScale's default), "imageFilter" (AnimatedImageFilter's default), and any name an Animated or Crossfade value in code was given.
The transition for a property of a component is the first match walking from the component up through its parents:
An object may set what the descendants inherit instead with the key "descendants" (a string or a per-property object, same rules). It doesn't apply to the component itself, e.g. a page that slides in while the rows inside it keep jumping when they relayout: { "bounds": "glide", "alpha": "glide", "descendants": "none" }
| using Transition::Easing = float (*) (float) |
An easing function, mapping linear progress 0..1 to eased progress.
|
default |
Creates an instant transition.
Referenced by forProperty(), and resolve().
| Transition::Transition | ( | double | durationMs, |
| Easing | easing ) |
Creates a transition of the given duration in milliseconds and easing.
References durationMs, and easing.
|
static |
Parses a spec string, "<ms> <easing>", "<ms>" or "none".
|
static |
Returns the easing function for a name like "inOutQuad", nullptr for an unknown name.
|
static |
Resolves a preset name, an inline spec or "none".
Presets are searched from the component up through its parents (the presets of each LayoutSupport live on the component it lays out). An unknown name asserts and is instant.
References Transition().
Referenced by Animated< T >::followTarget(), Animated< T >::setTarget(), and Crossfade< T >::setTarget().
|
static |
Returns the transition a property of the component animates with, following the inheritance rules above: the nearest "transition" from the component up through its parents that covers the property, else the preset "default", else instant.
References Transition().
| bool Transition::isInstant | ( | ) | const |
True for "none", a duration of 0 and a default constructed Transition.
References durationMs, and easing.
| float Transition::getProgress | ( | double | elapsedMs | ) | const |
Returns the eased progress 0..1 at a time since the start; 1 from durationMs on and always for an instant transition.
|
static |
Sets a component's presets, exactly as a layout json's top-level "transitions" does for the component its LayoutSupport lays out: an object of name -> spec, or a JSON string of one.
They apply to the component and everything inside it, also children added later. A void var clears them. Invalid specs assert. A LayoutSupport replaces the presets of the component it lays out on every pass, so set them on another component.
For code-built UIs without a layout json above them:
|
static |
The presets setPresets() or a layout set on exactly this component, void if none.
|
static |
Sets a component's "transition", exactly as the layout entry of that name does: a string (preset name, inline spec or "none") or a per-property object, "descendants" included.
Inherited by everything inside it as described above. A void var clears it. A layout pass that positions the component replaces it with the entry's own.
|
static |
The "transition" set on exactly this component, void if none.
|
static |
Switches every transition in the app on or off, e.g.
off for software renderers or slow machines. Off, everything that would animate (Animated, Crossfade, AnimatedScale, AnimatedImageFilter, the layout's bounds, alpha and scale, States, box shadows) jumps straight to its target, its owner repainting once per change, and the vertical blank driver doesn't tick at all. Switching off makes running transitions jump to their targets at once. The initial value is GIN_TRANSITIONS_ENABLED_BY_DEFAULT: off on Linux (JUCE's software renderer only), on elsewhere, unless the app defines it.
|
static |
| double Transition::durationMs = 0.0 |
Referenced by isInstant(), and Transition().
| Easing Transition::easing = nullptr |
Referenced by isInstant(), and Transition().
|
static |
Component property holding a layout entry's "transition".
|
static |
Component property holding the presets of the layout that positions its children.