Struct ThemeAnimator

Source
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

Source

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.

Source

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.

Source

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.
Source

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 egui Context object.
  • anim_id: The persistent Id used for tracking animation progress.
Source

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 egui Ui object to generate a persistent ID.
Source

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.

Source

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 egui Context 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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.