|
@@ -1,5 +1,5 @@
|
|
from dataclasses import fields
|
|
from dataclasses import fields
|
|
-from typing import Optional, Callable, Any, Dict
|
|
|
|
|
|
+from typing import Optional, Callable, Any, Dict, Union, Literal
|
|
|
|
|
|
from ..element import Element
|
|
from ..element import Element
|
|
from ..events import ScrollEventArguments, ScrollInfo
|
|
from ..events import ScrollEventArguments, ScrollInfo
|
|
@@ -27,3 +27,28 @@ class ScrollArea(Element):
|
|
client=self.client,
|
|
client=self.client,
|
|
info=ScrollInfo(**msg['args'])
|
|
info=ScrollInfo(**msg['args'])
|
|
))
|
|
))
|
|
|
|
+
|
|
|
|
+ def set_scroll_position(self, offset: Union[int, float], *,
|
|
|
|
+ axis: Literal['vertical', 'horizontal'] = 'vertical', duration_ms: int = 0
|
|
|
|
+ ) -> None:
|
|
|
|
+ """
|
|
|
|
+
|
|
|
|
+ :param offset: Scroll position offset from top in pixels or percentage (0.0 <= x <= 1.0) of the total scrolling
|
|
|
|
+ size
|
|
|
|
+ :param axis: Scroll axis to set
|
|
|
|
+ :param duration_ms: Duration (in milliseconds) enabling animated scroll
|
|
|
|
+ """
|
|
|
|
+ if offset < 0:
|
|
|
|
+ raise ValueError(f'scroll offset must be positive. Got: {offset}')
|
|
|
|
+
|
|
|
|
+ if type(offset) == int:
|
|
|
|
+ self.run_method('setScrollPosition', axis, offset, duration_ms)
|
|
|
|
+
|
|
|
|
+ elif type(offset) == float and offset > 1.0:
|
|
|
|
+ raise ValueError(f'a percentage scroll offset must be 0.0 <= x <= 1.0. Got: {offset}')
|
|
|
|
+
|
|
|
|
+ elif type(offset) == float and offset <= 1.0:
|
|
|
|
+ self.run_method('setScrollPercentage', axis, offset, duration_ms)
|
|
|
|
+
|
|
|
|
+ else:
|
|
|
|
+ raise ValueError(f'Got unsupported offset: {offset}')
|