24
24
import adafruit_imageload
25
25
import adafruit_usb_host_descriptors
26
26
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
28
28
from adafruit_argv_file import read_argv , write_argv
29
29
30
30
"""
58
58
"bg" : os .getenv ("FRUIT_JAM_OS_BG" , 0x222222 ),
59
59
"fg" : os .getenv ("FRUIT_JAM_OS_FG" , 0xffffff ),
60
60
"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" ),
62
62
}
63
63
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 )
65
73
display = supervisor .runtime .display
66
74
67
75
scale = 1
144
152
145
153
mouse_buf = array .array ("b" , [0 ] * 8 )
146
154
147
- WIDTH = 280
148
- HEIGHT = 182
155
+ WIDTH = int ( 280 / 360 * display . width // scale )
156
+ HEIGHT = int ( 182 / 200 * display . height // scale )
149
157
150
158
config = {
151
159
"menu_title" : "Launcher Menu" ,
186
194
}
187
195
188
196
cell_width = WIDTH // config ["width" ]
197
+ cell_height = HEIGHT // config ["height" ]
189
198
190
199
default_icon_bmp , default_icon_palette = adafruit_imageload .load ("launcher_assets/default_icon.bmp" )
191
200
default_icon_palette .make_transparent (0 )
192
- menu_grid = GridLayout (x = 40 , y = 16 , width = WIDTH , height = HEIGHT , grid_size = (config ["width" ], config ["height" ]),
201
+ menu_grid = GridLayout (x = (display .width // scale - WIDTH ) // 2 ,
202
+ y = (display .height // scale - HEIGHT ) // 2 ,
203
+ width = WIDTH , height = HEIGHT , grid_size = (config ["width" ], config ["height" ]),
193
204
divider_lines = False )
194
205
scaled_group .append (menu_grid )
195
206
@@ -276,8 +287,9 @@ def _create_cell_group(app):
276
287
cell_group .append (icon_tg )
277
288
278
289
icon_tg .x = cell_width // 2 - icon_tg .tile_width // 2
279
- title_txt = TextBox (font , text = app ["title" ], width = WIDTH // config [ "width" ] , height = 18 ,
290
+ title_txt = TextBox (font , text = app ["title" ], width = cell_width , height = 18 ,
280
291
align = TextBox .ALIGN_CENTER , color = color_palette ["fg" ])
292
+ icon_tg .y = (cell_height - icon_tg .tile_height - title_txt .height ) // 2
281
293
cell_group .append (title_txt )
282
294
title_txt .anchor_point = (0 , 0 )
283
295
title_txt .anchored_position = (0 , icon_tg .y + icon_tg .tile_height )
@@ -297,7 +309,7 @@ def _reuse_cell_group(app, cell_group):
297
309
icon_tg .pixel_shader = icon_palette
298
310
299
311
icon_tg .x = cell_width // 2 - icon_tg .tile_width // 2
300
- # title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"] , height=18,
312
+ # title_txt = TextBox(font, text=app["title"], width=cell_width , height=18,
301
313
# align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
302
314
# cell_group.append(title_txt)
303
315
title_txt = cell_group [1 ]
@@ -347,7 +359,7 @@ def display_page(page_index):
347
359
print (f"{ grid_index } | { grid_index % config ["width" ], grid_index // config ["width" ]} " )
348
360
349
361
350
- page_txt = Label (terminalio .FONT , text = "" , scale = 2 , color = color_palette ["fg" ])
362
+ page_txt = Label (terminalio .FONT , text = "" , scale = scale , color = color_palette ["fg" ])
351
363
page_txt .anchor_point = (1.0 , 1.0 )
352
364
page_txt .anchored_position = (display .width - 2 , display .height - 2 )
353
365
main_group .append (page_txt )
@@ -359,7 +371,7 @@ def display_page(page_index):
359
371
left_palette .make_transparent (0 )
360
372
right_bmp , right_palette = adafruit_imageload .load ("launcher_assets/arrow_right.bmp" )
361
373
right_palette .make_transparent (0 )
362
- if color_palette ["arrow" ] >= 0 :
374
+ if color_palette ["arrow" ] is not None :
363
375
left_palette [2 ] = right_palette [2 ] = color_palette ["arrow" ]
364
376
365
377
left_tg = AnchoredTileGrid (bitmap = left_bmp , pixel_shader = left_palette )
0 commit comments