diff --git a/src/textual/widget.py b/src/textual/widget.py index b4723487c..b5fa4f28d 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -1136,6 +1136,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", ) -> bool: """Scroll to a given (absolute) coordinate, optionally animating. @@ -1145,6 +1146,7 @@ class Widget(DOMNode): animate (bool, optional): Animate to new scroll position. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". Returns: bool: True if the scroll position changed, otherwise False. @@ -1162,7 +1164,7 @@ class Widget(DOMNode): self.scroll_target_x, speed=speed, duration=duration, - easing="out_cubic", + easing=easing, ) scrolled_x = True if y is not None: @@ -1173,7 +1175,7 @@ class Widget(DOMNode): self.scroll_target_y, speed=speed, duration=duration, - easing="out_cubic", + easing=easing, ) scrolled_y = True @@ -1197,6 +1199,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", ) -> bool: """Scroll relative to current position. @@ -1206,6 +1209,7 @@ class Widget(DOMNode): animate (bool, optional): Animate to new scroll position. Defaults to False. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". Returns: bool: True if the scroll position changed, otherwise False. @@ -1216,6 +1220,7 @@ class Widget(DOMNode): animate=animate, speed=speed, duration=duration, + easing=easing, ) def scroll_home( @@ -1224,6 +1229,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", ) -> bool: """Scroll to home position. @@ -1231,13 +1237,16 @@ class Widget(DOMNode): animate (bool, optional): Animate scroll. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". Returns: bool: True if any scrolling was done. """ if speed is None and duration is None: duration = 1.0 - return self.scroll_to(0, 0, animate=animate, speed=speed, duration=duration) + return self.scroll_to( + 0, 0, animate=animate, speed=speed, duration=duration, easing=easing + ) def scroll_end( self, @@ -1245,6 +1254,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", ) -> bool: """Scroll to the end of the container. @@ -1252,6 +1262,7 @@ class Widget(DOMNode): animate (bool, optional): Animate scroll. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". Returns: bool: True if any scrolling was done. @@ -1260,7 +1271,12 @@ class Widget(DOMNode): if speed is None and duration is None: duration = 1.0 return self.scroll_to( - 0, self.max_scroll_y, animate=animate, speed=speed, duration=duration + 0, + self.max_scroll_y, + animate=animate, + speed=speed, + duration=duration, + easing=easing, ) def scroll_left( @@ -1269,6 +1285,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", ) -> bool: """Scroll one cell left. @@ -1276,13 +1293,18 @@ class Widget(DOMNode): animate (bool, optional): Animate scroll. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". Returns: bool: True if any scrolling was done. """ return self.scroll_to( - x=self.scroll_target_x - 1, animate=animate, speed=speed, duration=duration + x=self.scroll_target_x - 1, + animate=animate, + speed=speed, + duration=duration, + easing=easing, ) def scroll_right( @@ -1291,6 +1313,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", ) -> bool: """Scroll on cell right. @@ -1298,13 +1321,18 @@ class Widget(DOMNode): animate (bool, optional): Animate scroll. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". Returns: bool: True if any scrolling was done. """ return self.scroll_to( - x=self.scroll_target_x + 1, animate=animate, speed=speed, duration=duration + x=self.scroll_target_x + 1, + animate=animate, + speed=speed, + duration=duration, + easing=easing, ) def scroll_down( @@ -1313,6 +1341,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", ) -> bool: """Scroll one line down. @@ -1320,13 +1349,18 @@ class Widget(DOMNode): animate (bool, optional): Animate scroll. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". Returns: bool: True if any scrolling was done. """ return self.scroll_to( - y=self.scroll_target_y + 1, animate=animate, speed=speed, duration=duration + y=self.scroll_target_y + 1, + animate=animate, + speed=speed, + duration=duration, + easing=easing, ) def scroll_up( @@ -1335,6 +1369,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", ) -> bool: """Scroll one line up. @@ -1342,13 +1377,18 @@ class Widget(DOMNode): animate (bool, optional): Animate scroll. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". Returns: bool: True if any scrolling was done. """ return self.scroll_to( - y=self.scroll_target_y - 1, animate=animate, speed=speed, duration=duration + y=self.scroll_target_y - 1, + animate=animate, + speed=speed, + duration=duration, + easing=easing, ) def scroll_page_up( @@ -1357,6 +1397,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", ) -> bool: """Scroll one page up. @@ -1364,6 +1405,7 @@ class Widget(DOMNode): animate (bool, optional): Animate scroll. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". Returns: bool: True if any scrolling was done. @@ -1374,6 +1416,7 @@ class Widget(DOMNode): animate=animate, speed=speed, duration=duration, + easing=easing, ) def scroll_page_down( @@ -1382,6 +1425,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", ) -> bool: """Scroll one page down. @@ -1389,6 +1433,7 @@ class Widget(DOMNode): animate (bool, optional): Animate scroll. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". Returns: bool: True if any scrolling was done. @@ -1399,6 +1444,7 @@ class Widget(DOMNode): animate=animate, speed=speed, duration=duration, + easing=easing, ) def scroll_page_left( @@ -1407,6 +1453,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", ) -> bool: """Scroll one page left. @@ -1414,6 +1461,7 @@ class Widget(DOMNode): animate (bool, optional): Animate scroll. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". Returns: bool: True if any scrolling was done. @@ -1426,6 +1474,7 @@ class Widget(DOMNode): animate=animate, speed=speed, duration=duration, + easing=easing, ) def scroll_page_right( @@ -1434,6 +1483,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", ) -> bool: """Scroll one page right. @@ -1441,6 +1491,7 @@ class Widget(DOMNode): animate (bool, optional): Animate scroll. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". Returns: bool: True if any scrolling was done. @@ -1453,6 +1504,7 @@ class Widget(DOMNode): animate=animate, speed=speed, duration=duration, + easing=easing, ) def scroll_to_widget( @@ -1462,6 +1514,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", top: bool = False, ) -> bool: """Scroll scrolling to bring a widget in to view. @@ -1471,6 +1524,8 @@ class Widget(DOMNode): animate (bool, optional): True to animate, or False to jump. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". + top (bool, optional): Scroll widget to top of container. Defaults to False. Returns: bool: True if any scrolling has occurred in any descendant, otherwise False. @@ -1489,6 +1544,7 @@ class Widget(DOMNode): speed=speed, duration=duration, top=top, + easing=easing, ) if scroll_offset: scrolled = True @@ -1515,6 +1571,7 @@ class Widget(DOMNode): animate: bool = True, speed: float | None = None, duration: float | None = None, + easing: EasingFunction | str = "out_cubic", top: bool = False, ) -> Offset: """Scrolls a given region in to view, if required. @@ -1528,6 +1585,7 @@ class Widget(DOMNode): animate (bool, optional): True to animate, or False to jump. Defaults to True. speed (float | None, optional): Speed of scroll if animate is True. Or None to use duration. duration (float | None, optional): Duration of animation, if animate is True and speed is None. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". top (bool, optional): Scroll region to top of container. Defaults to False. Returns: @@ -1555,6 +1613,7 @@ class Widget(DOMNode): animate=animate if (abs(delta_y) > 1 or delta_x) else False, speed=speed, duration=duration, + easing=easing, ) return delta @@ -1565,6 +1624,7 @@ class Widget(DOMNode): speed: float | None = None, duration: float | None = None, top: bool = False, + easing: EasingFunction | str = "out_cubic", ) -> None: """Scroll the container to make this widget visible. @@ -1573,6 +1633,7 @@ class Widget(DOMNode): speed (float | None, optional): _description_. Defaults to None. duration (float | None, optional): _description_. Defaults to None. top (bool, optional): Scroll to top of container. Defaults to False. + easing (EasingFunction | str, optional): An easing method for the scrolling animation. Defaults to "out_cubic". """ parent = self.parent if isinstance(parent, Widget): @@ -1583,6 +1644,7 @@ class Widget(DOMNode): speed=speed, duration=duration, top=top, + easing=easing, ) def __init_subclass__(