summaryrefslogtreecommitdiff
path: root/wasp/widgets.py
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2021-01-18 21:52:55 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2021-01-18 21:52:55 (GMT)
commit6e269d5cd75c5ce869c6de4190c2edf4d899c32f (patch)
treee93eb0c5b1609f35145b80a2ce0c30e2f6ccbedf /wasp/widgets.py
parentfbc806721e346e5c5727e7233c5c8f5e08270eac (diff)
widgets: Add a button with a graphical icon
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
Diffstat (limited to 'wasp/widgets.py')
-rw-r--r--wasp/widgets.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/wasp/widgets.py b/wasp/widgets.py
index 4d17c02..970ab74 100644
--- a/wasp/widgets.py
+++ b/wasp/widgets.py
@@ -302,6 +302,34 @@ class Checkbox():
return True
return False
+class GfxButton():
+ """A button with a graphical icon."""
+ def __init__(self, x, y, gfx):
+ self._im = (x, y)
+ self.gfx = gfx
+
+ def draw(self):
+ """Draw the button."""
+ im = self._im
+ wasp.watch.drawable.blit(self.gfx, im[0], im[1])
+
+ def touch(self, event):
+ x = event[1]
+ y = event[2]
+
+ # Adopt a slightly oversized hit box
+ im = self._im
+ gfx = self.gfx
+ x1 = im[0] - 10
+ x2 = x1 + gfx[1] + 20
+ y1 = im[1] - 10
+ y2 = y1 + gfx[2] + 20
+
+ if x >= x1 and x < x2 and y >= y1 and y < y2:
+ return True
+
+ return False
+
_SLIDER_KNOB_DIAMETER = const(40)
_SLIDER_KNOB_RADIUS = const(_SLIDER_KNOB_DIAMETER // 2)
_SLIDER_WIDTH = const(220)