1
0
Fork 0

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>
This commit is contained in:
Daniel Thompson 2020-12-30 10:29:02 +00:00
parent 116c138079
commit b8ba1a9eba
2 changed files with 20 additions and 75 deletions

View file

@ -106,28 +106,19 @@ class NotificationApp(PagerApp):
return return
else: else:
if event[0] == wasp.EventType.DOWN and self._page == 0: if event[0] == wasp.EventType.DOWN and self._page == 0:
self.confirmation_view.active = True self.confirmation_view.draw('Clear notifications?')
self._draw()
return return
super().swipe(event) super().swipe(event)
def _draw(self):
if self.confirmation_view.active:
self.confirmation_view.draw('Clear notifications?')
else:
super()._draw()
def touch(self, event): def touch(self, event):
if self.confirmation_view.active: if self.confirmation_view.touch(event):
is_confirmed = self.confirmation_view.touch(event) if self.confirmation_view.value:
if is_confirmed:
wasp.system.notifications = {} wasp.system.notifications = {}
wasp.system.navigate(wasp.EventType.BACK) wasp.system.navigate(wasp.EventType.BACK)
elif is_confirmed != None: else:
self._draw() self._draw()
class CrashApp(): class CrashApp():
"""Crash handler application. """Crash handler application.

View file

@ -378,76 +378,30 @@ class Spinner():
return False 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: class ConfirmationView:
"""Confirmation widget allowing user confirmation of a setting.""" """Confirmation widget allowing user confirmation of a setting."""
def __init__(self): def __init__(self):
self.active = False self.active = False
self.value = 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,
)
)
def draw(self, message): 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 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): def touch(self, event):
x_coord = event[1] if not self.active:
y_coord = event[2] return False
is_yes_button_press = (
x_coord > self.yes_button_bounds[0][0] x = event[1]
and y_coord > self.yes_button_bounds[0][1] y = event[2]
and x_coord < self.yes_button_bounds[1][0]
and y_coord < self.yes_button_bounds[1][1] if y >= 80 and y < 180:
) self.active = False
self.value = x < 120
is_no_button_press = ( return True
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:
self.active = False
return True
elif is_no_button_press:
self.active = False
return False return False
else:
return None