mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
added allow_vertical_scroll and allow_horizontal_scroll
This commit is contained in:
@@ -21,6 +21,8 @@ App > Screen {
|
|||||||
color: $text-background;
|
color: $text-background;
|
||||||
background: $background;
|
background: $background;
|
||||||
layout: vertical;
|
layout: vertical;
|
||||||
|
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from textual.app import App, ComposeResult
|
|||||||
from textual.reactive import Reactive
|
from textual.reactive import Reactive
|
||||||
from textual.widget import Widget
|
from textual.widget import Widget
|
||||||
from textual.widgets import Static, DataTable, DirectoryTree, Header, Footer
|
from textual.widgets import Static, DataTable, DirectoryTree, Header, Footer
|
||||||
from textual.layout import Vertical
|
from textual.layout import Container
|
||||||
|
|
||||||
CODE = '''
|
CODE = '''
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
@@ -120,7 +120,7 @@ class BasicApp(App, css_path="basic.css"):
|
|||||||
table = DataTable()
|
table = DataTable()
|
||||||
self.scroll_to_target = Tweet(TweetBody())
|
self.scroll_to_target = Tweet(TweetBody())
|
||||||
|
|
||||||
yield from (
|
yield Container(
|
||||||
Tweet(TweetBody()),
|
Tweet(TweetBody()),
|
||||||
Widget(
|
Widget(
|
||||||
Static(
|
Static(
|
||||||
@@ -141,15 +141,15 @@ class BasicApp(App, css_path="basic.css"):
|
|||||||
Tweet(TweetBody(), classes="scroll-horizontal"),
|
Tweet(TweetBody(), classes="scroll-horizontal"),
|
||||||
Tweet(TweetBody(), classes="scroll-horizontal"),
|
Tweet(TweetBody(), classes="scroll-horizontal"),
|
||||||
Tweet(TweetBody(), classes="scroll-horizontal"),
|
Tweet(TweetBody(), classes="scroll-horizontal"),
|
||||||
Widget(
|
)
|
||||||
Widget(classes="title"),
|
yield Widget(
|
||||||
Widget(classes="user"),
|
Widget(classes="title"),
|
||||||
OptionItem(),
|
Widget(classes="user"),
|
||||||
OptionItem(),
|
OptionItem(),
|
||||||
OptionItem(),
|
OptionItem(),
|
||||||
Widget(classes="content"),
|
OptionItem(),
|
||||||
id="sidebar",
|
Widget(classes="content"),
|
||||||
),
|
id="sidebar",
|
||||||
)
|
)
|
||||||
yield Footer()
|
yield Footer()
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,16 @@ class Widget(DOMNode):
|
|||||||
show_vertical_scrollbar = Reactive(False, layout=True)
|
show_vertical_scrollbar = Reactive(False, layout=True)
|
||||||
show_horizontal_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:
|
def _arrange(self, size: Size) -> DockArrangeResult:
|
||||||
"""Arrange children.
|
"""Arrange children.
|
||||||
|
|
||||||
@@ -1195,12 +1205,12 @@ class Widget(DOMNode):
|
|||||||
break
|
break
|
||||||
|
|
||||||
def on_mouse_scroll_down(self, event) -> None:
|
def on_mouse_scroll_down(self, event) -> None:
|
||||||
if self.is_scrollable:
|
if self.allow_vertical_scroll:
|
||||||
if self.scroll_down(animate=False):
|
if self.scroll_down(animate=False):
|
||||||
event.stop()
|
event.stop()
|
||||||
|
|
||||||
def on_mouse_scroll_up(self, event) -> None:
|
def on_mouse_scroll_up(self, event) -> None:
|
||||||
if self.is_scrollable:
|
if self.allow_vertical_scroll:
|
||||||
if self.scroll_up(animate=False):
|
if self.scroll_up(animate=False):
|
||||||
event.stop()
|
event.stop()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user