ui: add profile picture hover animation
I wanted to practice doing animation in egui, so here is a simple profile picture hover affect. When you mouse over a profile picture, it get slightly bigger. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
19
src/ui/anim.rs
Normal file
19
src/ui/anim.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
pub fn hover_expand(
|
||||
ui: &mut egui::Ui,
|
||||
id: egui::Id,
|
||||
size: f32,
|
||||
expand_size: f32,
|
||||
anim_speed: f32,
|
||||
) -> (egui::Rect, f32) {
|
||||
// Allocate space for the profile picture with a fixed size
|
||||
let default_size = size + expand_size;
|
||||
let (rect, response) =
|
||||
ui.allocate_exact_size(egui::vec2(default_size, default_size), egui::Sense::hover());
|
||||
|
||||
let val = ui
|
||||
.ctx()
|
||||
.animate_bool_with_time(id, response.hovered(), anim_speed);
|
||||
|
||||
let size = size + val * expand_size;
|
||||
(rect, size)
|
||||
}
|
||||
Reference in New Issue
Block a user