scroll sensitivity

This commit is contained in:
Will McGugan
2023-01-30 12:36:49 +01:00
parent 36188ae0dc
commit b585f25d7b
3 changed files with 26 additions and 12 deletions

View File

@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added the coroutines `Animator.wait_until_complete` and `pilot.wait_for_scheduled_animations` that allow waiting for all current and scheduled animations https://github.com/Textualize/textual/issues/1658
- Added the method `Animator.is_being_animated` that checks if an attribute of an object is being animated or is scheduled for animation
- Added App.scroll_sensitivity to adjust how many lines the scroll wheel moves the scroll position https://github.com/orgs/Textualize/projects/5?pane=issue&itemId=12998591
- Added Shift+scroll wheel and ctrl+scroll wheen to scroll horizontally
### Changed

View File

@@ -369,6 +369,8 @@ class App(Generic[ReturnType], DOMNode):
self.css_path = css_paths
self._registry: WeakSet[DOMNode] = WeakSet()
self.scroll_sensitivity: float = 3
self._installed_screens: WeakValueDictionary[
str, Screen | Callable[[], Screen]
] = WeakValueDictionary()

View File

@@ -1575,7 +1575,7 @@ class Widget(DOMNode):
"""
return self.scroll_to(
x=self.scroll_target_x - 1,
x=self.scroll_target_x - self.app.scroll_sensitivity,
animate=animate,
speed=speed,
duration=duration,
@@ -1607,7 +1607,7 @@ class Widget(DOMNode):
"""
return self.scroll_to(
x=self.scroll_target_x + 1,
x=self.scroll_target_x + self.app.scroll_sensitivity,
animate=animate,
speed=speed,
duration=duration,
@@ -1639,7 +1639,7 @@ class Widget(DOMNode):
"""
return self.scroll_to(
y=self.scroll_target_y + 1,
y=self.scroll_target_y + self.app.scroll_sensitivity,
animate=animate,
speed=speed,
duration=duration,
@@ -1671,7 +1671,7 @@ class Widget(DOMNode):
"""
return self.scroll_to(
y=self.scroll_target_y - 1,
y=self.scroll_target_y - +self.app.scroll_sensitivity,
animate=animate,
speed=speed,
duration=duration,
@@ -2478,15 +2478,25 @@ class Widget(DOMNode):
if self._has_focus_within:
self.app.update_styles(self)
def _on_mouse_scroll_down(self, event) -> None:
if self.allow_vertical_scroll:
if self.scroll_down(animate=False):
event.stop()
def _on_mouse_scroll_down(self, event: events.MouseScrollDown) -> None:
if event.ctrl or event.shift:
if self.allow_horizontal_scroll:
if self.scroll_right(animate=False):
event.stop()
else:
if self.allow_vertical_scroll:
if self.scroll_down(animate=False):
event.stop()
def _on_mouse_scroll_up(self, event) -> None:
if self.allow_vertical_scroll:
if self.scroll_up(animate=False):
event.stop()
def _on_mouse_scroll_up(self, event: events.MouseScrollUp) -> None:
if event.ctrl or event.shift:
if self.allow_horizontal_scroll:
if self.scroll_left(animate=False):
event.stop()
else:
if self.allow_vertical_scroll:
if self.scroll_up(animate=False):
event.stop()
def _on_scroll_to(self, message: ScrollTo) -> None:
if self._allow_scroll: