Skip to content

Commit 091b193

Browse files
authored
Merge branch 'main' into color-palette-json
2 parents 876e5e1 + a69d6c8 commit 091b193

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/code.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import adafruit_imageload
2424
import adafruit_usb_host_descriptors
2525
from adafruit_anchored_group import AnchoredGroup
26-
from adafruit_fruitjam.peripherals import request_display_config
26+
from adafruit_fruitjam.peripherals import request_display_config, VALID_DISPLAY_SIZES
2727
from adafruit_argv_file import read_argv, write_argv
2828

2929
"""
@@ -52,7 +52,15 @@
5252
print(f"launching: {next_code_file}")
5353
supervisor.reload()
5454

55-
request_display_config(720, 400)
55+
if (width_config := os.getenv("CIRCUITPY_DISPLAY_WIDTH")) is not None:
56+
if width_config not in [x[0] for x in VALID_DISPLAY_SIZES]:
57+
raise ValueError(f"Invalid display size. Must be one of: {VALID_DISPLAY_SIZES}")
58+
for display_size in VALID_DISPLAY_SIZES:
59+
if display_size[0] == width_config:
60+
break
61+
else:
62+
display_size = (720, 400)
63+
request_display_config(*display_size)
5664
display = supervisor.runtime.display
5765

5866
scale = 1
@@ -137,8 +145,8 @@
137145

138146
mouse_buf = array.array("b", [0] * 8)
139147

140-
WIDTH = 280
141-
HEIGHT = 182
148+
WIDTH = int(280 / 360 * display.width // scale)
149+
HEIGHT = int(182 / 200 * display.height // scale)
142150

143151
config = {
144152
"menu_title": "Launcher Menu",
@@ -179,10 +187,13 @@
179187
}
180188

181189
cell_width = WIDTH // config["width"]
190+
cell_height = HEIGHT // config["height"]
182191

183192
default_icon_bmp, default_icon_palette = adafruit_imageload.load("launcher_assets/default_icon.bmp")
184193
default_icon_palette.make_transparent(0)
185-
menu_grid = GridLayout(x=40, y=16, width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]),
194+
menu_grid = GridLayout(x=(display.width // scale - WIDTH) // 2,
195+
y=(display.height // scale - HEIGHT) // 2,
196+
width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]),
186197
divider_lines=False)
187198
scaled_group.append(menu_grid)
188199

@@ -269,8 +280,9 @@ def _create_cell_group(app):
269280
cell_group.append(icon_tg)
270281

271282
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
272-
title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
283+
title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
273284
align=TextBox.ALIGN_CENTER, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
285+
icon_tg.y = (cell_height - icon_tg.tile_height - title_txt.height) // 2
274286
cell_group.append(title_txt)
275287
title_txt.anchor_point = (0, 0)
276288
title_txt.anchored_position = (0, icon_tg.y + icon_tg.tile_height)
@@ -290,7 +302,7 @@ def _reuse_cell_group(app, cell_group):
290302
icon_tg.pixel_shader = icon_palette
291303

292304
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
293-
# title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
305+
# title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
294306
# align=TextBox.ALIGN_CENTER, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
295307
# cell_group.append(title_txt)
296308
title_txt = cell_group[1]
@@ -340,7 +352,7 @@ def display_page(page_index):
340352
print(f"{grid_index} | {grid_index % config["width"], grid_index // config["width"]}")
341353

342354

343-
page_txt = Label(terminalio.FONT, text="", scale=2, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
355+
page_txt = Label(terminalio.FONT, text="", scale=scale, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
344356
page_txt.anchor_point = (1.0, 1.0)
345357
page_txt.anchored_position = (display.width - 2, display.height - 2)
346358
main_group.append(page_txt)

0 commit comments

Comments
 (0)