Skip to content

Commit 9bcfe9f

Browse files
committed
Support 4:3 aspect ratio with FRUIT_JAM_OS_4x3 environment variable
1 parent 8b5b975 commit 9bcfe9f

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/code.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import json
1010
import math
1111
import displayio
12+
import os
1213
import supervisor
1314
import sys
1415
import terminalio
@@ -52,7 +53,13 @@
5253
print(f"launching: {next_code_file}")
5354
supervisor.reload()
5455

55-
request_display_config(720, 400)
56+
# read environment variables
57+
aspect_ratio_4x3 = os.getenv("FRUIT_JAM_OS_4x3", 0)
58+
59+
if aspect_ratio_4x3:
60+
request_display_config(640, 480)
61+
else:
62+
request_display_config(720, 400)
5663
display = supervisor.runtime.display
5764

5865
scale = 1
@@ -135,8 +142,12 @@
135142

136143
mouse_buf = array.array("b", [0] * 8)
137144

138-
WIDTH = 280
139-
HEIGHT = 182
145+
if aspect_ratio_4x3:
146+
WIDTH = 248
147+
HEIGHT = 218
148+
else:
149+
WIDTH = 280
150+
HEIGHT = 182
140151

141152
config = {
142153
"menu_title": "Launcher Menu",
@@ -177,10 +188,13 @@
177188
}
178189

179190
cell_width = WIDTH // config["width"]
191+
cell_height = HEIGHT // config["height"]
180192

181193
default_icon_bmp, default_icon_palette = adafruit_imageload.load("launcher_assets/default_icon.bmp")
182194
default_icon_palette.make_transparent(0)
183-
menu_grid = GridLayout(x=40, y=16, width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]),
195+
menu_grid = GridLayout(x=(display.width // scale - WIDTH) // 2,
196+
y=(display.height // scale - HEIGHT) // 2,
197+
width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]),
184198
divider_lines=False)
185199
scaled_group.append(menu_grid)
186200

@@ -267,8 +281,9 @@ def _create_cell_group(app):
267281
cell_group.append(icon_tg)
268282

269283
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
270-
title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
284+
title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
271285
align=TextBox.ALIGN_CENTER)
286+
icon_tg.y = (cell_height - icon_tg.tile_height - title_txt.height) // 2
272287
cell_group.append(title_txt)
273288
title_txt.anchor_point = (0, 0)
274289
title_txt.anchored_position = (0, icon_tg.y + icon_tg.tile_height)
@@ -288,7 +303,7 @@ def _reuse_cell_group(app, cell_group):
288303
icon_tg.pixel_shader = icon_palette
289304

290305
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
291-
# title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
306+
# title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
292307
# align=TextBox.ALIGN_CENTER)
293308
# cell_group.append(title_txt)
294309
title_txt = cell_group[1]

src/settings.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
CIRCUITPY_PYSTACK_SIZE=4000
2+
# FRUIT_JAM_OS_4x3=1

0 commit comments

Comments
 (0)