egui-theme-lerp

Crates.ioegui-theme-lerp
lib.rsegui-theme-lerp
version0.1.3
sourcesrc
created_at2024-09-21 22:35:26.354375
updated_at2024-10-21 06:59:37.168302
descriptionAn egui lib to animate theme switching between visuals
homepagehttps://github.com/TheRustyPickle/egui-theme-lerp
repositoryhttps://github.com/TheRustyPickle/egui-theme-lerp
max_upload_size
id1382497
size20,393
Rusty Pickle (TheRustyPickle)

documentation

README

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.

Commit count: 21

cargo fmt