pub struct ThemeAnimator {
pub anim_id: Option<Id>,
pub theme_1: Visuals,
pub theme_2: Visuals,
pub progress: f32,
pub animation_time: f32,
pub theme_1_to_2: bool,
pub animation_done: bool,
}
Expand description
A structure to manage and animate between two different themes in egui.
This allows smooth transitions (interpolations) between two sets of visuals (themes) over a specified period.
Fields§
§anim_id: Option<Id>
egui persistent ID used for animation
theme_1: Visuals
Theme 1 visuals for interpolation
theme_2: Visuals
Theme 2 visuals for interpolation
progress: f32
Value between 0.0 and 1.0 where 1.0 means the animation is completed
animation_time: f32
How long the interpolation should take in seconds. Default is 1.0
theme_1_to_2: bool
Whether we are interpolating from Theme 1 to Theme 2
animation_done: bool
Whether the interpolation is complete. Setting to false
will start the interpolation
Implementations§
Source§impl ThemeAnimator
impl ThemeAnimator
Sourcepub const fn new(theme_1: Visuals, theme_2: Visuals) -> Self
pub const fn new(theme_1: Visuals, theme_2: Visuals) -> Self
Creates a new ThemeAnimator
without an assigned anim_id
.
This constructor initializes the animator with two themes but leaves the anim_id
as None
,
meaning that no animation will take place until the ID is set via set_id
or create_id
.
§Parameters:
theme_1
: The starting theme for the animation.theme_2
: The ending theme for the animation.
§Returns:
A new ThemeAnimator
with the provided themes and default values for other fields.
Sourcepub const fn animation_time(self, time: f32) -> Self
pub const fn animation_time(self, time: f32) -> Self
Sets the duration of the theme animation.
This method allows you to configure the total time (in seconds) that the theme transition
should take. The returned ThemeAnimator
instance will have the updated animation time.
§Parameters:
time
: The new animation duration in seconds.
§Returns:
A new ThemeAnimator
instance with the updated animation time.
Sourcepub const fn update_animation_time(&mut self, new_time: f32)
pub const fn update_animation_time(&mut self, new_time: f32)
Updates the animation time.
This method changes the total duration (in seconds) that the animation will take to complete. Adjust this based on how fast or slow you want the transition between themes.
§Parameters:
new_time
: The new animation time in seconds.
Sourcepub fn set_id(&mut self, ctx: &Context, anim_id: Id)
pub fn set_id(&mut self, ctx: &Context, anim_id: Id)
Assigns a persistent ID to control the animation.
This sets the anim_id
using an existing egui Id
, allowing egui to track and manage
the animation’s state.
§Parameters:
ctx
: The eguiContext
object.anim_id
: The persistentId
used for tracking animation progress.
Sourcepub fn create_id(&mut self, ui: &Ui)
pub fn create_id(&mut self, ui: &Ui)
Creates a new persistent Id
for the animation.
This method generates a new persistent Id
for the animator using the provided Ui
context.
It is useful when an Id
is not manually provided and needs to be created on-the-fly.
§Parameters:
ui
: The eguiUi
object to generate a persistent ID.
Sourcepub const fn start(&mut self)
pub const fn start(&mut self)
Starts the theme animation.
Sets the animation_done
flag to false
, allowing the interpolation to start. Does
nothing if called multiple times while animation is ongoing.
Sourcepub fn animate(&mut self, ctx: &Context)
pub fn animate(&mut self, ctx: &Context)
Performs the animation, interpolating between the two visuals.
This function progresses the animation if animation_done
is set to false
and
an anim_id
is assigned. Once the animation reaches the end (progress
reaches 1.0),
it will automatically switch the animation direction (from theme_1
to theme_2
or
vice versa) for the next time it is started.
§Parameters:
ctx
: The eguiContext
object used for handling the animation.
§Notes:
This method does nothing if the animation is already complete (animation_done = true
)
or if anim_id
is not set.