11import lvgl as lv
22
33class WidgetAnimator :
4- def __init__ (self ):
5- self .animations = {} # Store animations for each widget
64
7- # show_widget and hide_widget could have a (lambda) callback that sets the final state (eg: drawer_open) at the end
5+ # def __init__(self):
6+ # self.animations = {} # Store animations for each widget
7+
8+ # def stop_animation(self, widget):
9+ # """Stop any running animation for the widget."""
10+ # if widget in self.animations:
11+ # self.animations[widget].delete()
12+ # del self.animations[widget]
13+
814
9- def show_widget (self , widget , anim_type = "fade" , duration = 500 , delay = 0 ):
15+ # show_widget and hide_widget could have a (lambda) callback that sets the final state (eg: drawer_open) at the end
16+ @staticmethod
17+ def show_widget (widget , anim_type = "fade" , duration = 500 , delay = 0 ):
1018 """Show a widget with an animation (fade or slide)."""
1119 # Clear HIDDEN flag to make widget visible for animation
1220 widget .remove_flag (lv .obj .FLAG .HIDDEN )
@@ -55,10 +63,11 @@ def show_widget(self, widget, anim_type="fade", duration=500, delay=0):
5563 anim .set_completed_cb (lambda * args : widget .set_y (original_y ))
5664
5765 # Store and start animation
58- self .animations [widget ] = anim
66+ # self.animations[widget] = anim
5967 anim .start ()
6068
61- def hide_widget (self , widget , anim_type = "fade" , duration = 500 , delay = 0 ):
69+ @staticmethod
70+ def hide_widget (widget , anim_type = "fade" , duration = 500 , delay = 0 ):
6271 """Hide a widget with an animation (fade or slide)."""
6372 if anim_type == "fade" :
6473 # Create fade-out animation (opacity from 255 to 0)
@@ -71,7 +80,7 @@ def hide_widget(self, widget, anim_type="fade", duration=500, delay=0):
7180 anim .set_custom_exec_cb (lambda anim , value : widget .set_style_opa (value , 0 ))
7281 anim .set_path_cb (lv .anim_t .path_ease_in_out )
7382 # Set HIDDEN flag after animation
74- anim .set_completed_cb (lambda * args : self .hide_complete_cb (widget ))
83+ anim .set_completed_cb (lambda * args : WidgetAnimator .hide_complete_cb (widget ))
7584 elif anim_type == "slide_down" :
7685 # Create slide-down animation (y from original y to +height)
7786 # Seems to cause scroll bars to be added somehow if done to a keyboard at the bottom of the screen...
@@ -86,7 +95,7 @@ def hide_widget(self, widget, anim_type="fade", duration=500, delay=0):
8695 anim .set_custom_exec_cb (lambda anim , value : widget .set_y (value ))
8796 anim .set_path_cb (lv .anim_t .path_ease_in_out )
8897 # Set HIDDEN flag after animation
89- anim .set_completed_cb (lambda * args : self .hide_complete_cb (widget ))
98+ anim .set_completed_cb (lambda * args : WidgetAnimator .hide_complete_cb (widget ))
9099 elif anim_type == "slide_up" :
91100 print ("hide with slide_up" )
92101 # Create slide-up animation (y from original y to -height)
@@ -101,21 +110,22 @@ def hide_widget(self, widget, anim_type="fade", duration=500, delay=0):
101110 anim .set_custom_exec_cb (lambda anim , value : widget .set_y (value ))
102111 anim .set_path_cb (lv .anim_t .path_ease_in_out )
103112 # Set HIDDEN flag after animation
104- anim .set_completed_cb (lambda * args : self .hide_complete_cb (widget ))
113+ anim .set_completed_cb (lambda * args : WidgetAnimator .hide_complete_cb (widget ))
105114
106115 # Store and start animation
107- self .animations [widget ] = anim
116+ # self.animations[widget] = anim
108117 anim .start ()
109118
110- def hide_complete_cb (self , widget ):
119+ @staticmethod
120+ def hide_complete_cb (widget ):
111121 #print("hide_complete_cb")
112122 widget .add_flag (lv .obj .FLAG .HIDDEN )
113123 #if original_y:
114124 # widget.set_y(original_y) # in case it shifted slightly due to rounding etc
115125
116126
117- def stop_animation ( self , widget ):
118- """Stop any running animation for the widget."""
119- if widget in self . animations :
120- self . animations [ widget ]. delete ()
121- del self . animations [ widget ]
127+ def smooth_show ( widget ):
128+ WidgetAnimator . show_widget ( widget , anim_type = "fade" , duration = 500 , delay = 0 )
129+
130+ def smooth_hide ( widget ):
131+ WidgetAnimator . hide_widget ( widget , anim_type = "fade" , duration = 500 , delay = 0 )
0 commit comments