added allow_vertical_scroll and allow_horizontal_scroll

This commit is contained in:
Will McGugan
2022-08-13 19:47:41 +01:00
parent 9e7f3d5ec6
commit b741810fce
3 changed files with 25 additions and 13 deletions

View File

@@ -22,6 +22,8 @@ App > Screen {
background: $background;
layout: vertical;
overflow: hidden;
}
#tree-container {

View File

@@ -7,7 +7,7 @@ from textual.app import App, ComposeResult
from textual.reactive import Reactive
from textual.widget import Widget
from textual.widgets import Static, DataTable, DirectoryTree, Header, Footer
from textual.layout import Vertical
from textual.layout import Container
CODE = '''
from __future__ import annotations
@@ -120,7 +120,7 @@ class BasicApp(App, css_path="basic.css"):
table = DataTable()
self.scroll_to_target = Tweet(TweetBody())
yield from (
yield Container(
Tweet(TweetBody()),
Widget(
Static(
@@ -141,7 +141,8 @@ class BasicApp(App, css_path="basic.css"):
Tweet(TweetBody(), classes="scroll-horizontal"),
Tweet(TweetBody(), classes="scroll-horizontal"),
Tweet(TweetBody(), classes="scroll-horizontal"),
Widget(
)
yield Widget(
Widget(classes="title"),
Widget(classes="user"),
OptionItem(),
@@ -149,7 +150,6 @@ class BasicApp(App, css_path="basic.css"):
OptionItem(),
Widget(classes="content"),
id="sidebar",
),
)
yield Footer()

View File

@@ -135,6 +135,16 @@ class Widget(DOMNode):
show_vertical_scrollbar = Reactive(False, layout=True)
show_horizontal_scrollbar = Reactive(False, layout=True)
@property
def allow_vertical_scroll(self) -> bool:
"""Check if vertical scroll is permitted."""
return self.is_scrollable and self.show_vertical_scrollbar
@property
def allow_horizontal_scroll(self) -> bool:
"""Check if horizontal scroll is permitted."""
return self.is_scrollable and self.show_horizontal_scrollbar
def _arrange(self, size: Size) -> DockArrangeResult:
"""Arrange children.
@@ -1195,12 +1205,12 @@ class Widget(DOMNode):
break
def on_mouse_scroll_down(self, event) -> None:
if self.is_scrollable:
if self.allow_vertical_scroll:
if self.scroll_down(animate=False):
event.stop()
def on_mouse_scroll_up(self, event) -> None:
if self.is_scrollable:
if self.allow_vertical_scroll:
if self.scroll_up(animate=False):
event.stop()