diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-12-30 10:29:02 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-12-30 10:29:02 (GMT) |
| commit | b8ba1a9eba84f8bdcb9ca5dd992c64e40a17eabe (patch) | |
| tree | 49b709d4673c426129b36b7d236423dc18c27bab | |
| parent | 116c138079798ab0b4cf2e689b2e842ce4d07927 (diff) | |
widgets: ConfirmationView: Fix hit box problems
The ConfirmationView became broken when we converted it's images over to
2-bit RLE. That happened because the confirmation view relied on the
the 1-bit RLE to dynamically generate hit boxes.
Currently the code pre-calculates the hit box which is a waste of RAM.
Let's rip out the existing hit box logic and replace it with much larger
("fat finger") hit targets.
We make the touch() method more closely adopt the idioms of other UI
components (e.g. don't return the dialog status... just whether or
not we handled the touch).
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
| -rw-r--r-- | wasp/apps/pager.py | 17 | ||||
| -rw-r--r-- | wasp/widgets.py | 76 |
2 files changed, 19 insertions, 74 deletions
diff --git a/wasp/apps/pager.py b/wasp/apps/pager.py index 2f74d0e..4f518eb 100644 --- a/wasp/apps/pager.py +++ b/wasp/apps/pager.py @@ -106,28 +106,19 @@ class NotificationApp(PagerApp): return else: if event[0] == wasp.EventType.DOWN and self._page == 0: - self.confirmation_view.active = True - self._draw() + self.confirmation_view.draw('Clear notifications?') return super().swipe(event) - def _draw(self): - if self.confirmation_view.active: - self.confirmation_view.draw('Clear notifications?') - else: - super()._draw() - def touch(self, event): - if self.confirmation_view.active: - is_confirmed = self.confirmation_view.touch(event) - if is_confirmed: + if self.confirmation_view.touch(event): + if self.confirmation_view.value: wasp.system.notifications = {} wasp.system.navigate(wasp.EventType.BACK) - elif is_confirmed != None: + else: self._draw() - class CrashApp(): """Crash handler application. diff --git a/wasp/widgets.py b/wasp/widgets.py index bed9be5..40523ce 100644 --- a/wasp/widgets.py +++ b/wasp/widgets.py @@ -378,76 +378,30 @@ class Spinner(): return False -_message_string_x_coord = const(0) -_message_string_y_coord = const(60) -_yes_button_x_coord = const(20) -_yes_button_y_coord = const(100) -_no_button_x_coord = const(120) -_no_button_y_coord = const(100) - class ConfirmationView: """Confirmation widget allowing user confirmation of a setting.""" def __init__(self): self.active = False - - self.yes_button_bounds = ( - (_yes_button_x_coord, _yes_button_y_coord), - ( - icons.yes_button[0] + _yes_button_x_coord, - icons.yes_button[1] + _yes_button_y_coord, - ), - ) - self.no_button_bounds = ( - (_no_button_x_coord, _no_button_y_coord), - ( - icons.no_button[0] + _no_button_x_coord, - icons.no_button[1] + _no_button_y_coord, - ) - ) + self.value = False def draw(self, message): - wasp.watch.drawable.fill(1) - wasp.watch.drawable.string( - message, - _message_string_x_coord, - _message_string_y_coord - ) - wasp.watch.drawable.blit( - icons.yes_button, - _yes_button_x_coord, - _yes_button_y_coord, - ) - wasp.watch.drawable.blit( - icons.no_button, - _no_button_x_coord, - _no_button_y_coord, - ) self.active = True - + wasp.watch.drawable.fill(1) + wasp.watch.drawable.string(message, 0, 60) + wasp.watch.drawable.blit(icons.yes_button, 20, 100) + wasp.watch.drawable.blit(icons.no_button, 120, 100) def touch(self, event): - x_coord = event[1] - y_coord = event[2] - is_yes_button_press = ( - x_coord > self.yes_button_bounds[0][0] - and y_coord > self.yes_button_bounds[0][1] - and x_coord < self.yes_button_bounds[1][0] - and y_coord < self.yes_button_bounds[1][1] - ) - - is_no_button_press = ( - x_coord > self.no_button_bounds[0][0] - and y_coord > self.no_button_bounds[0][1] - and x_coord < self.no_button_bounds[1][0] - and y_coord < self.no_button_bounds[1][1] - ) - - if is_yes_button_press: + if not self.active: + return False + + x = event[1] + y = event[2] + + if y >= 80 and y < 180: self.active = False + self.value = x < 120 return True - elif is_no_button_press: - self.active = False - return False - else: - return None + + return False |
