Add Pico touch routing abstraction
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
NAV_ITEMS = [
|
||||
("dashboard", 0, 64),
|
||||
("battery", 64, 128),
|
||||
("temps", 128, 192),
|
||||
("power", 192, 256),
|
||||
("system", 256, 320),
|
||||
]
|
||||
|
||||
|
||||
class TouchRouter:
|
||||
def __init__(self, screen_manager, width=320, height=480, nav_height=56):
|
||||
self.screen_manager = screen_manager
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.nav_height = nav_height
|
||||
|
||||
def handle_touch(self, event):
|
||||
if not event or not event.pressed:
|
||||
return False
|
||||
|
||||
if self._is_bottom_nav(event.y):
|
||||
screen = self._screen_for_nav_x(event.x)
|
||||
|
||||
if screen:
|
||||
self.screen_manager.go_to(screen)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def _is_bottom_nav(self, y):
|
||||
return y >= self.height - self.nav_height
|
||||
|
||||
def _screen_for_nav_x(self, x):
|
||||
for screen, start_x, end_x in NAV_ITEMS:
|
||||
if start_x <= x < end_x:
|
||||
return screen
|
||||
|
||||
return None
|
||||
Reference in New Issue
Block a user