From 154a6a29824cc4502f251d7dde4071a0b3de8869 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak <dos@dosowisko.net> Date: Sat, 30 Sep 2023 04:17:10 +0200 Subject: [PATCH] ViewManager: Don't call .think on the outgoing view unless requested Let's see how that works out. Simplifies input handling in apps, so they don't have to guard things with is_active checks for the common cases. --- python_payload/st3m/ui/view.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/python_payload/st3m/ui/view.py b/python_payload/st3m/ui/view.py index eb042b6790..a0b5f5bbe5 100644 --- a/python_payload/st3m/ui/view.py +++ b/python_payload/st3m/ui/view.py @@ -21,11 +21,13 @@ class View(Responder): """ pass - def on_exit(self) -> None: + def on_exit(self) -> bool: """ Called when the View is about to become inactive. + If it returns True, think calls will continue to happen + until on_exit_done. """ - pass + return False def on_enter_done(self) -> None: """ @@ -199,6 +201,8 @@ class ViewManager(Responder): self._first_think = False self._fully_drawn = 0 + self._outgoing_wants_to_think = False + def _end_transition(self) -> None: if not self._transitioning: return @@ -225,7 +229,7 @@ class ViewManager(Responder): self._incoming = self._pending self._pending = None if self._outgoing is not None: - self._outgoing.on_exit() + self._outgoing_wants_to_think = self._outgoing.on_exit() self._incoming.on_enter(self) if self._outgoing is None: self._end_transition() @@ -251,7 +255,7 @@ class ViewManager(Responder): else: self.pop(ViewTransitionSwipeRight()) - if self._outgoing is not None: + if self._outgoing is not None and self._outgoing_wants_to_think: self._outgoing.think(ins, delta_ms) if self._incoming is not None: self._incoming.think(ins, delta_ms) -- GitLab