23
23
import adafruit_imageload
24
24
import adafruit_usb_host_descriptors
25
25
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
27
27
from adafruit_argv_file import read_argv , write_argv
28
28
29
29
"""
52
52
print (f"launching: { next_code_file } " )
53
53
supervisor .reload ()
54
54
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 )
56
64
display = supervisor .runtime .display
57
65
58
66
scale = 1
137
145
138
146
mouse_buf = array .array ("b" , [0 ] * 8 )
139
147
140
- WIDTH = 280
141
- HEIGHT = 182
148
+ WIDTH = int ( 280 / 360 * display . width // scale )
149
+ HEIGHT = int ( 182 / 200 * display . height // scale )
142
150
143
151
config = {
144
152
"menu_title" : "Launcher Menu" ,
179
187
}
180
188
181
189
cell_width = WIDTH // config ["width" ]
190
+ cell_height = HEIGHT // config ["height" ]
182
191
183
192
default_icon_bmp , default_icon_palette = adafruit_imageload .load ("launcher_assets/default_icon.bmp" )
184
193
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" ]),
186
197
divider_lines = False )
187
198
scaled_group .append (menu_grid )
188
199
@@ -269,8 +280,9 @@ def _create_cell_group(app):
269
280
cell_group .append (icon_tg )
270
281
271
282
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 ,
273
284
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
274
286
cell_group .append (title_txt )
275
287
title_txt .anchor_point = (0 , 0 )
276
288
title_txt .anchored_position = (0 , icon_tg .y + icon_tg .tile_height )
@@ -290,7 +302,7 @@ def _reuse_cell_group(app, cell_group):
290
302
icon_tg .pixel_shader = icon_palette
291
303
292
304
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,
294
306
# align=TextBox.ALIGN_CENTER, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
295
307
# cell_group.append(title_txt)
296
308
title_txt = cell_group [1 ]
@@ -340,7 +352,7 @@ def display_page(page_index):
340
352
print (f"{ grid_index } | { grid_index % config ["width" ], grid_index // config ["width" ]} " )
341
353
342
354
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 ))
344
356
page_txt .anchor_point = (1.0 , 1.0 )
345
357
page_txt .anchored_position = (display .width - 2 , display .height - 2 )
346
358
main_group .append (page_txt )
0 commit comments