Skip to content

Commit 9bfcc84

Browse files
committed
Merge branch 'refs/heads/main' into mouse-click-index
# Conflicts: # src/code.py
2 parents 6ff675b + a69d6c8 commit 9bfcc84

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/code.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import adafruit_imageload
2525
import adafruit_usb_host_descriptors
2626
from adafruit_anchored_group import AnchoredGroup
27-
from adafruit_fruitjam.peripherals import request_display_config
27+
from adafruit_fruitjam.peripherals import request_display_config, VALID_DISPLAY_SIZES
2828
from adafruit_argv_file import read_argv, write_argv
2929

3030
"""
@@ -58,10 +58,18 @@
5858
"bg": os.getenv("FRUIT_JAM_OS_BG", 0x222222),
5959
"fg": os.getenv("FRUIT_JAM_OS_FG", 0xffffff),
6060
"accent": os.getenv("FRUIT_JAM_OS_ACCENT", 0x008800),
61-
"arrow": os.getenv("FRUIT_JAM_OS_ARROW", -1),
61+
"arrow": os.getenv("FRUIT_JAM_OS_ARROW"),
6262
}
6363

64-
request_display_config(720, 400)
64+
if (width_config := os.getenv("CIRCUITPY_DISPLAY_WIDTH")) is not None:
65+
if width_config not in [x[0] for x in VALID_DISPLAY_SIZES]:
66+
raise ValueError(f"Invalid display size. Must be one of: {VALID_DISPLAY_SIZES}")
67+
for display_size in VALID_DISPLAY_SIZES:
68+
if display_size[0] == width_config:
69+
break
70+
else:
71+
display_size = (720, 400)
72+
request_display_config(*display_size)
6573
display = supervisor.runtime.display
6674

6775
scale = 1
@@ -144,8 +152,8 @@
144152

145153
mouse_buf = array.array("b", [0] * 8)
146154

147-
WIDTH = 280
148-
HEIGHT = 182
155+
WIDTH = int(280 / 360 * display.width // scale)
156+
HEIGHT = int(182 / 200 * display.height // scale)
149157

150158
config = {
151159
"menu_title": "Launcher Menu",
@@ -186,11 +194,14 @@
186194
}
187195

188196
cell_width = WIDTH // config["width"]
197+
cell_height = HEIGHT // config["height"]
189198
page_size = config["width"] * config["height"]
190199

191200
default_icon_bmp, default_icon_palette = adafruit_imageload.load("launcher_assets/default_icon.bmp")
192201
default_icon_palette.make_transparent(0)
193-
menu_grid = GridLayout(x=40, y=16, width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]),
202+
menu_grid = GridLayout(x=(display.width // scale - WIDTH) // 2,
203+
y=(display.height // scale - HEIGHT) // 2,
204+
width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]),
194205
divider_lines=False)
195206
scaled_group.append(menu_grid)
196207

@@ -277,8 +288,9 @@ def _create_cell_group(app):
277288
cell_group.append(icon_tg)
278289

279290
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
280-
title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
291+
title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
281292
align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
293+
icon_tg.y = (cell_height - icon_tg.tile_height - title_txt.height) // 2
282294
cell_group.append(title_txt)
283295
title_txt.anchor_point = (0, 0)
284296
title_txt.anchored_position = (0, icon_tg.y + icon_tg.tile_height)
@@ -298,7 +310,7 @@ def _reuse_cell_group(app, cell_group):
298310
icon_tg.pixel_shader = icon_palette
299311

300312
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
301-
# title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
313+
# title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
302314
# align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
303315
# cell_group.append(title_txt)
304316
title_txt = cell_group[1]
@@ -348,7 +360,7 @@ def display_page(page_index):
348360
print(f"{grid_index} | {grid_index % config["width"], grid_index // config["width"]}")
349361

350362

351-
page_txt = Label(terminalio.FONT, text="", scale=2, color=color_palette["fg"])
363+
page_txt = Label(terminalio.FONT, text="", scale=scale, color=color_palette["fg"])
352364
page_txt.anchor_point = (1.0, 1.0)
353365
page_txt.anchored_position = (display.width - 2, display.height - 2)
354366
main_group.append(page_txt)
@@ -360,7 +372,7 @@ def display_page(page_index):
360372
left_palette.make_transparent(0)
361373
right_bmp, right_palette = adafruit_imageload.load("launcher_assets/arrow_right.bmp")
362374
right_palette.make_transparent(0)
363-
if color_palette["arrow"] >= 0:
375+
if color_palette["arrow"] is not None:
364376
left_palette[2] = right_palette[2] = color_palette["arrow"]
365377

366378
left_tg = AnchoredTileGrid(bitmap=left_bmp, pixel_shader=left_palette)

0 commit comments

Comments
 (0)