Skip to content

Commit

Permalink
call clear cached dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Feb 26, 2024
1 parent a52115b commit 24d341f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
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)
3 changes: 1 addition & 2 deletions src/textual/widgets/_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def renderable(self, renderable: RenderableType) -> None:
self._renderable = Text(renderable)
else:
self._renderable = renderable
self._content_width_cache = (None, 0)
self._content_height_cache = (None, 0)
self.clear_cached_dimensions()

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

0 comments on commit 24d341f

Please sign in to comment.