Skip to content

Commit

Permalink
Merge pull request #36 from emfcamp/hugh/app-store
Browse files Browse the repository at this point in the history
App Store App
  • Loading branch information
hughrawlinson committed May 30, 2024
2 parents 484c6a7 + 320f955 commit f22c91a
Show file tree
Hide file tree
Showing 8 changed files with 458 additions and 51 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Pull the firmware build image:

docker build . -t matthewwilkes/esp_idf:5.2.1

Initialize submodules:

git submodule update --init --recursive

To make the docker container with the right version of the ESP-IDF for the latest micropython.

Before you build the first time, apply any patches to vendored content:
Expand Down
27 changes: 21 additions & 6 deletions modules/app_components/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(
app: App,
menu_items: list[str] = [],
position=0,
select_handler: Union[Callable[[str], Any], None] = None,
select_handler: Union[Callable[[str, int], Any], None] = None,
change_handler: Union[Callable[[str], Any], None] = None,
back_handler: Union[Callable, None] = None,
speed_ms=300,
Expand Down Expand Up @@ -66,18 +66,25 @@ def _handle_buttondown(self, event: ButtonDownEvent):
if BUTTON_TYPES["CONFIRM"] in event.button:
if self.select_handler is not None:
self.select_handler(
self.menu_items[self.position % len(self.menu_items)]
self.menu_items[self.position % len(self.menu_items)],
self.position % len(self.menu_items),
)

def up_handler(self):
self.is_animating = "up"
self.animation_time_ms = 0
self.position = (self.position - 1) % len(self.menu_items)
num_menu_items = len(self.menu_items)
self.position = (
(self.position - 1) % num_menu_items if num_menu_items > 0 else 1
)

def down_handler(self):
self.is_animating = "down"
self.animation_time_ms = 0
self.position = (self.position + 1) % len(self.menu_items)
num_menu_items = len(self.menu_items)
self.position = (
(self.position + 1) % num_menu_items if num_menu_items > 0 else 1
)

def draw(self, ctx):
animation_progress = ease_out_quart(self.animation_time_ms / self.speed_ms)
Expand All @@ -92,14 +99,22 @@ def draw(self, ctx):
ctx.text_baseline = ctx.MIDDLE

set_color(ctx, "label")
num_menu_items = len(self.menu_items)
label = ""
try:
label = self.menu_items[
self.position % num_menu_items if num_menu_items > 0 else 1
]
except IndexError:
label = "Empty Menu"
ctx.move_to(
0, animation_direction * -30 + animation_progress * animation_direction * 30
).text(self.menu_items[self.position % len(self.menu_items)])
).text(label)

# Previous menu items
ctx.font_size = self.item_font_size
for i in range(1, 4):
if (self.position - i) >= 0:
if (self.position - i) >= 0 and len(self.menu_items):
ctx.move_to(
0,
-self.focused_item_margin
Expand Down
2 changes: 2 additions & 0 deletions modules/app_components/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
one_pt = ppi / 72
ten_pt = 10 * one_pt
twelve_pt = 12 * one_pt
fourteen_pt = 14 * one_pt
sixteen_pt = 16 * one_pt
eighteen_pt = 18 * one_pt
twentyfour_pt = 24 * one_pt
label_font_size = ten_pt
Expand Down
Loading

0 comments on commit f22c91a

Please sign in to comment.