anim.rs (795B)
1 pub fn hover_expand( 2 ui: &mut egui::Ui, 3 id: egui::Id, 4 size: f32, 5 expand_size: f32, 6 anim_speed: f32, 7 ) -> (egui::Rect, f32, egui::Response) { 8 // Allocate space for the profile picture with a fixed size 9 let default_size = size + expand_size; 10 let (rect, response) = 11 ui.allocate_exact_size(egui::vec2(default_size, default_size), egui::Sense::click()); 12 13 let val = ui 14 .ctx() 15 .animate_bool_with_time(id, response.hovered(), anim_speed); 16 17 let size = size + val * expand_size; 18 (rect, size, response) 19 } 20 21 pub fn hover_expand_small(ui: &mut egui::Ui, id: egui::Id) -> (egui::Rect, f32, egui::Response) { 22 let size = 10.0; 23 let expand_size = 5.0; 24 let anim_speed = 0.05; 25 26 hover_expand(ui, id, size, expand_size, anim_speed) 27 }