diff options
| author | Adam Blair <adampblair@protonmail.com> | 2021-06-23 21:31:42 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2021-07-25 07:56:14 (GMT) |
| commit | e09b951017761236f75137498cc3495a12a91f49 (patch) | |
| tree | 0174dd4e83f8b58166b7dc75692b74ef2de11469 /wasp/widgets.py | |
| parent | 0831f79a105329f0dd7cd252b9fcd327415e4f82 (diff) | |
Advanced alarm app
Features:
* Multiple alarms (up to 4)
* Day of the week support
* One time alarms
* Snooze
Changes to wasp-os for app support:
* Added + and - to the 28pt and 36pt fonts
* Checkboxes now require a click on the body of the checkbox if there is no label
* Added a Toggle Button class that extends Button and stores a state like checkbox
Signed-off-by: Adam Blair <adampblair@protonmail.com>
Diffstat (limited to 'wasp/widgets.py')
| -rw-r--r-- | wasp/widgets.py | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/wasp/widgets.py b/wasp/widgets.py index 01d20a8..4e63d95 100644 --- a/wasp/widgets.py +++ b/wasp/widgets.py @@ -222,11 +222,14 @@ class Button(): def draw(self): """Draw the button.""" - draw = wasp.watch.drawable - im = self._im - bg = draw.darken(wasp.system.theme('ui')) + bg = wasp.watch.drawable.darken(wasp.system.theme('ui')) frame = wasp.system.theme('mid') txt = wasp.system.theme('bright') + self.update(bg, frame, txt) + + def update(self, bg, frame, txt): + draw = wasp.watch.drawable + im = self._im draw.fill(bg, im[0], im[1], im[2], im[3]) draw.set_color(txt, bg) @@ -255,6 +258,31 @@ class Button(): return False +class ToggleButton(Button): + """A button with a text label that can be toggled on and off.""" + def __init__(self, x, y, w, h, label): + super().__init__(x, y, w, h, label) + self.state = False + + def draw(self): + """Draw the button.""" + draw = wasp.watch.drawable + + if self.state: + bg = draw.darken(wasp.system.theme('ui')) + else: + bg = draw.darken(wasp.system.theme('mid')) + frame = wasp.system.theme('mid') + txt = wasp.system.theme('bright') + + self.update(bg, frame, txt) + + def touch(self, event): + """Handle touch events.""" + if super().touch(event): + self.state = not self.state + self.draw() + class Checkbox(): """A simple (labelled) checkbox.""" def __init__(self, x, y, label=None): @@ -294,9 +322,10 @@ class Checkbox(): def touch(self, event): """Handle touch events.""" + x = event[1] y = event[2] im = self._im - if y >= im[1] and y < im[1]+40: + if (self.label or im[0] <= x < im[0]+40) and im[1] <= y < im[1]+40: self.state = not self.state self.update() return True |
