From cf773a90fdbd3cad410426c9fc32bf09686bbcd8 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Thu, 5 Dec 2024 09:56:39 -0800 Subject: [PATCH] anim: smoothly animate delete button from 0 size This is a much cleaner animation Signed-off-by: William Casarin --- src/nav.rs | 7 +++---- src/ui/anim.rs | 5 +++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/nav.rs b/src/nav.rs index e905fa6..85b10b0 100644 --- a/src/nav.rs +++ b/src/nav.rs @@ -377,13 +377,12 @@ fn delete_column_button( let helper = AnimationHelper::new_from_rect(ui, "delete-column-button", button_rect); - let cur_img_size = helper.scale_1d_pos(img_size); + let cur_img_size = helper.scale_1d_pos_min_max(0.0, img_size); let animation_rect = helper.get_animation_rect(); let animation_resp = helper.take_animation_response(); - if allocation_response.union(animation_resp.clone()).hovered() { - img.paint_at(ui, animation_rect.shrink((max_size - cur_img_size) / 2.0)); - } + + img.paint_at(ui, animation_rect.shrink((max_size - cur_img_size) / 2.0)); animation_resp } diff --git a/src/ui/anim.rs b/src/ui/anim.rs index 271ff92..ba47dce 100644 --- a/src/ui/anim.rs +++ b/src/ui/anim.rs @@ -130,4 +130,9 @@ impl AnimationHelper { pub fn scale_pos_from_center(&self, min_pos: Pos2) -> Pos2 { self.scale_from_center(min_pos.x, min_pos.y) } + + /// New method for min/max scaling when needed + pub fn scale_1d_pos_min_max(&self, min_object_size: f32, max_object_size: f32) -> f32 { + min_object_size + ((max_object_size - min_object_size) * self.animation_progress) + } }