Skip to content

Commit

Permalink
fix layout update
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jul 17, 2021
1 parent 15d81e4 commit 4cb9fe1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ async def on_event(self, event: events.Event) -> None:
else:
await super().on_event(event)

async def on_idle(self, event: events.Idle) -> None:
if self.view.check_layout():
await self.view.refresh_layout()

async def action(
self,
action: str,
Expand Down
4 changes: 4 additions & 0 deletions src/textual/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ def reset_update(self) -> None:

def reset(self) -> None:
self._cuts = None
if self._require_update:
self.renders.clear()
self._layout_map.clear()

def reflow(self, width: int, height: int) -> ReflowResult:
self.reset()

map = self.generate_map(width, height)
self._require_update = False

# Filter out widgets that are off screen or zero area
screen_region = Region(0, 0, width, height)
Expand Down
5 changes: 4 additions & 1 deletion src/textual/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def render(self) -> RenderableType:
def get_offset(self, widget: Widget) -> Point:
return self.layout.get_offset(widget)

def check_layout(self) -> bool:
return super().check_layout() or self.layout.check_update()

async def message_update(self, message: UpdateMessage) -> None:
widget = message.widget
assert isinstance(widget, Widget)
Expand Down Expand Up @@ -142,7 +145,7 @@ async def watch_background(value: str) -> None:
async def on_idle(self, event: events.Idle) -> None:
if self.layout.check_update():
self.layout.reset_update()
self.require_layout()
await self.refresh_layout()

async def _on_mouse_move(self, event: events.MouseMove) -> None:
try:
Expand Down

0 comments on commit 4cb9fe1

Please sign in to comment.