#egui #themes #interpolation #animation #switch #transition

egui-theme-lerp

An egui lib to animate theme switching between visuals

4 releases

0.1.3 Oct 21, 2024
0.1.2 Sep 27, 2024
0.1.1 Sep 24, 2024
0.1.0 Sep 21, 2024

#233 in GUI

Download history 113/week @ 2024-09-16 332/week @ 2024-09-23 53/week @ 2024-09-30 7/week @ 2024-10-07 10/week @ 2024-10-14 189/week @ 2024-10-21

270 downloads per month
Used in talon-gui

MIT license

20KB
260 lines

egui-theme-lerp

Crates version Downloads Docs

A simple library for egui to smoothly animate theme transitions by interpolating between any two visuals/themes. It works with any set of visuals, allowing transitions between light/dark modes or custom themes.

Installation

Add the following to your Cargo.toml:

[dependencies]
egui-theme-lerp = "0.1.0"

Usage

use egui_theme_lerp::ThemeAnimator;
use egui::Visuals;

pub struct MainWindow {
    theme_animator: ThemeAnimator,
}

impl MainWindow {
    pub fn new() -> Self {
        Self {
            theme_animator: ThemeAnimator::new(Visuals::light(), Visuals::dark()),
        }
    }
}


impl eframe::App for MainWindow {
    fn update(&mut self, ctx: &eframe::egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            if self.theme_animator.anim_id.is_none() {
                self.theme_animator.create_id(ui);
            } else {
                self.theme_animator.animate(ctx);
            }

            ui.vertical_centered(|ui| {
                if ui.button("Switch Theme".to_string()).clicked() {
                    self.theme_animator.start();
                }
            });
        });
    }
}

Run Demo

The demo is accessible online via this link

  • Clone the repository git clone https://github.com/TheRustyPickle/egui-theme-lerp

  • Move into the demo folder cd egui-theme-lerp/demo

    • To run natively cargo run --release

    or

    • To run in wasm locally install the required target with rustup target add wasm32-unknown-unknown
    • Install Trunk with cargo install --locked trunk
    • trunk serve to run and visit http://127.0.0.1:8080/

Contributing

Contributions, issues, and feature requests are welcome! If you'd like to contribute, please open a pull request.

License

This project is licensed under the MIT License.

Dependencies

~4–9MB
~85K SLoC