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:
parent
116c138079
commit
b8ba1a9eba
2 changed files with 20 additions and 75 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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:
|
||||
self.active = False
|
||||
return True
|
||||
elif is_no_button_press:
|
||||
self.active = False
|
||||
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
|
||||
|
||||
return False
|
||||
else:
|
||||
return None
|
||||
|
|
Loading…
Reference in a new issue