Egui Animate
Custom animations and transitions.
Features
- Out/in
egui::Uielement or variable transitioning. - Out animations for hiding
egui::Uielements or variables. - In animations for presenting
egui::Uielements or variables. - Individual durations for out/in animation segments.
- Direct access to a scoped
&mut egui::Uifor custom animations.
Functionality
egui_animate offers simple, customizable animations based on state variables.
Define transitioning or individual out/in animations for entire ui interfaces,
and/or individual variables. Animations can be customized by providing your own
fn(&mut egui::Ui, f32) definitions that mutate a scoped egui::Ui. See the
example project for common animations/transitions.
Animations
Animations define function(s) that mutate the egui::Ui given the normalized
progression of the animation (segment) between 0.0 and 1.0 (named normal in
examples). Calling [animate] will scope all egui::Ui mutations within. Animations
are triggered by mutations of the value passed to the animate function. Any variable
implementing Default, PartialEq and Clone is supported.
In the example below, an egui::Label is displayed by linearly mutating opacity
from 0.0 to 1.0 over a duration of 0.5 seconds. Animation begins when show_ui
is set to true.
# use egui;
# use eframe;
# use *;
// A animation that sets the (scoped) ui opacity from 0.0 to 1.0 over 0.5 seconds.
const FADE_IN: Animation = new_in;
// Ui state.
let mut show_ui = false;
# let ctx = default;
# ctx.run;
The following animation transitions between interfaces, dynamically setting the animation on input.
# use egui;
# use eframe;
# use *;
# const SLIDE_FADE_LEFT: Animation = EMPTY;
# const SLIDE_FADE_RIGHT: Animation = EMPTY;
// Left and right slide animations. See the example project for definitions.
// const SLIDE_FADE_LEFT: Animation = ..;
// const SLIDE_FADE_RIGHT: Animation = ..;
// Store the menu state and the animation to dynamically change it on input.
let mut menu_state = MainMenu;
let mut menu_anim_state = SLIDE_FADE_LEFT;
# let ctx = default;
# ctx.run;
Animation Run State
The animation [RunState] provides insight into the current animation segment and
normal. Calling run_state will retrieve the state outside of the animations scoped
context. In the example below, RunState is used to disable an egui::Button for
the duration of an animation.
# use egui;
# use eframe;
# use *;
# const MY_ANIM: Animation = EMPTY;
# let mut my_state = 0u32;
# let ctx = default;
# ctx.run;
Examples
| Name | Description |
|---|---|
showcase |
Various example animations. |
menu |
A minimal dynamic "Main Menu" example. |
variable |
Dynamic increment/decrement animations. |
Compatibility
| egui | egui_animate |
|---|---|
| 0.32 | 0.2 |