widgets: Add a button with a graphical icon
Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
parent
fbc806721e
commit
6e269d5cd7
1 changed files with 28 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue