Crates.io | egui-theme-lerp |
lib.rs | egui-theme-lerp |
version | 0.1.3 |
source | src |
created_at | 2024-09-21 22:35:26.354375 |
updated_at | 2024-10-21 06:59:37.168302 |
description | An egui lib to animate theme switching between visuals |
homepage | https://github.com/TheRustyPickle/egui-theme-lerp |
repository | https://github.com/TheRustyPickle/egui-theme-lerp |
max_upload_size | |
id | 1382497 |
size | 20,393 |
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.
Add the following to your Cargo.toml
:
[dependencies]
egui-theme-lerp = "0.1.0"
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();
}
});
});
}
}
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
cargo run --release
or
rustup target add wasm32-unknown-unknown
cargo install --locked trunk
trunk serve
to run and visit http://127.0.0.1:8080/
Contributions, issues, and feature requests are welcome! If you'd like to contribute, please open a pull request.
This project is licensed under the MIT License.