feat(src/shared/window): add animate parameter to control scroll animation
This commit is contained in:
1 file changed
+6
@@ -1,3 +1,4 @@
|
|||||||
|
from fabric.utils import idle_add
|
||||||
from fabric.widgets.scrolledwindow import ScrolledWindow
|
from fabric.widgets.scrolledwindow import ScrolledWindow
|
||||||
|
|
||||||
from shared.widgets.animator import Animator
|
from shared.widgets.animator import Animator
|
||||||
@@ -8,10 +9,12 @@ class AnimatedScrollable(ScrolledWindow):
|
|||||||
self,
|
self,
|
||||||
bezier_curve: tuple[float, float, float, float] = (0.25, 0.1, 0.25, 1.0),
|
bezier_curve: tuple[float, float, float, float] = (0.25, 0.1, 0.25, 1.0),
|
||||||
duration: float = 0.3,
|
duration: float = 0.3,
|
||||||
|
animate: bool = True,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self._last_req = -1
|
self._last_req = -1
|
||||||
|
self.animate = animate
|
||||||
_, min_height = self.min_content_size
|
_, min_height = self.min_content_size
|
||||||
_, max_height = self.max_content_size
|
_, max_height = self.max_content_size
|
||||||
|
|
||||||
@@ -58,6 +61,9 @@ class AnimatedScrollable(ScrolledWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def animate_size(self, height: int = -1):
|
def animate_size(self, height: int = -1):
|
||||||
|
if not self.animate:
|
||||||
|
idle_add(lambda: self.snap_to_size(height))
|
||||||
|
return
|
||||||
self._last_req = height
|
self._last_req = height
|
||||||
current_val = self.height_animator.value
|
current_val = self.height_animator.value
|
||||||
return self.do_animate(current_val, height)
|
return self.do_animate(current_val, height)
|
||||||
|
|||||||
Reference in new issue
Block a user