add is_scrolling

This commit is contained in:
Will McGugan
2024-11-14 19:06:08 +00:00
parent 201f106055
commit 9f49bc2050
3 changed files with 22 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added several new built-in CSS variables https://github.com/Textualize/textual/pull/5087
- Added support for in-band terminal resize protocol https://github.com/Textualize/textual/pull/5217
- Added TEXTUAL_THEME environment var, which should be a comma separated list of desired themes
- Added `Widget.is_scrolling`
### Changed

View File

@@ -367,6 +367,8 @@ def loop_first_last(values: Iterable[T]) -> Iterable[tuple[bool, bool, T]]:
def update_log(self) -> None:
"""Update the Log with new content."""
log = self.query_one(Log)
if self.is_scrolling:
return
if not self.app.screen.can_view_entire(log) and not log.is_in_maximized_view:
return
self.log_count += 1
@@ -377,6 +379,8 @@ def loop_first_last(values: Iterable[T]) -> Iterable[tuple[bool, bool, T]]:
def update_rich_log(self) -> None:
"""Update the Rich Log with content."""
rich_log = self.query_one(RichLog)
if self.is_scrolling:
return
if (
not self.app.screen.can_view_entire(rich_log)
and not rich_log.is_in_maximized_view
@@ -457,6 +461,8 @@ For detailed graphs, see [textual-plotext](https://github.com/Textualize/textual
def update_sparks(self) -> None:
"""Update the sparks data."""
if self.is_scrolling:
return
if (
not self.app.screen.can_view_partial(self)
and not self.query_one(Sparkline).is_in_maximized_view
@@ -490,6 +496,8 @@ Switches {
yield Markdown(self.SWITCHES_MD)
with containers.ItemGrid(min_column_width=32):
for theme in BUILTIN_THEMES:
if theme.endswith("-ansi"):
continue
with containers.HorizontalGroup():
yield Switch(id=theme)
yield Label(theme, name=theme)

View File

@@ -2208,6 +2208,19 @@ class Widget(DOMNode):
"""Can this widget be scrolled?"""
return self.styles.layout is not None or bool(self._nodes)
@property
def is_scrolling(self) -> bool:
"""Is this widget currently scrolling?"""
for node in self.ancestors:
if not isinstance(node, Widget):
break
if (
node.scroll_x != node.scroll_target_x
or node.scroll_y != node.scroll_target_y
):
return True
return False
@property
def layer(self) -> str:
"""Get the name of this widgets layer.