Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix content size cache #4211

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Tooltips are now cleared when the related widget is no longer under them https://github.com/Textualize/textual/issues/3045
- Simplified tree-sitter highlight queries for HTML, which also seems to fix segfault issue https://github.com/Textualize/textual/pull/4195
- Fixed `DirectoryTree.path` no longer reacting to new values https://github.com/Textualize/textual/issues/4208
- Fixed content size cache with Pretty widget https://github.com/Textualize/textual/pull/4211

## [0.52.1] - 2024-02-20

Expand Down
16 changes: 14 additions & 2 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,19 @@ def __exit__(
else:
self.app._composed[-1].append(composed)

def clear_cached_dimensions(self) -> None:
"""Clear cached results of `get_content_width` and `get_content_height`.
Call if the widget's renderable changes size after the widget has been created.
!!! note
This is not required if you are extending [`Static`][textual.widgets.Static].
"""
self._content_width_cache = (None, 0)
self._content_height_cache = (None, 0)

def get_loading_widget(self) -> Widget:
"""Get a widget to display a loading indicator.
Expand Down Expand Up @@ -3278,8 +3291,7 @@ def refresh(

if repaint:
self._set_dirty(*regions)
self._content_width_cache = (None, 0)
self._content_height_cache = (None, 0)
self.clear_cached_dimensions()
self._rich_style_cache.clear()
self._repaint_required = True

Expand Down
1 change: 1 addition & 0 deletions src/textual/widgets/_pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ def update(self, object: Any) -> None:
object: The object to pretty-print.
"""
self._renderable = PrettyRenderable(object)
self.clear_cached_dimensions()
self.refresh(layout=True)
1 change: 1 addition & 0 deletions src/textual/widgets/_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def renderable(self, renderable: RenderableType) -> None:
self._renderable = Text(renderable)
else:
self._renderable = renderable
self.clear_cached_dimensions()

def render(self) -> RenderableType:
"""Get a rich renderable for the widget's content.
Expand Down
Loading