Merge branch 'refs/heads/main' into mouse-click-index
# Conflicts: # src/code.py
This commit is contained in:
commit
9bfcc84723
1 changed files with 22 additions and 10 deletions
32
src/code.py
32
src/code.py
|
|
@ -24,7 +24,7 @@ from adafruit_anchored_tilegrid import AnchoredTileGrid
|
||||||
import adafruit_imageload
|
import adafruit_imageload
|
||||||
import adafruit_usb_host_descriptors
|
import adafruit_usb_host_descriptors
|
||||||
from adafruit_anchored_group import AnchoredGroup
|
from adafruit_anchored_group import AnchoredGroup
|
||||||
from adafruit_fruitjam.peripherals import request_display_config
|
from adafruit_fruitjam.peripherals import request_display_config, VALID_DISPLAY_SIZES
|
||||||
from adafruit_argv_file import read_argv, write_argv
|
from adafruit_argv_file import read_argv, write_argv
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -58,10 +58,18 @@ color_palette = {
|
||||||
"bg": os.getenv("FRUIT_JAM_OS_BG", 0x222222),
|
"bg": os.getenv("FRUIT_JAM_OS_BG", 0x222222),
|
||||||
"fg": os.getenv("FRUIT_JAM_OS_FG", 0xffffff),
|
"fg": os.getenv("FRUIT_JAM_OS_FG", 0xffffff),
|
||||||
"accent": os.getenv("FRUIT_JAM_OS_ACCENT", 0x008800),
|
"accent": os.getenv("FRUIT_JAM_OS_ACCENT", 0x008800),
|
||||||
"arrow": os.getenv("FRUIT_JAM_OS_ARROW", -1),
|
"arrow": os.getenv("FRUIT_JAM_OS_ARROW"),
|
||||||
}
|
}
|
||||||
|
|
||||||
request_display_config(720, 400)
|
if (width_config := os.getenv("CIRCUITPY_DISPLAY_WIDTH")) is not None:
|
||||||
|
if width_config not in [x[0] for x in VALID_DISPLAY_SIZES]:
|
||||||
|
raise ValueError(f"Invalid display size. Must be one of: {VALID_DISPLAY_SIZES}")
|
||||||
|
for display_size in VALID_DISPLAY_SIZES:
|
||||||
|
if display_size[0] == width_config:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
display_size = (720, 400)
|
||||||
|
request_display_config(*display_size)
|
||||||
display = supervisor.runtime.display
|
display = supervisor.runtime.display
|
||||||
|
|
||||||
scale = 1
|
scale = 1
|
||||||
|
|
@ -144,8 +152,8 @@ if "use_mouse" in launcher_config and launcher_config["use_mouse"]:
|
||||||
|
|
||||||
mouse_buf = array.array("b", [0] * 8)
|
mouse_buf = array.array("b", [0] * 8)
|
||||||
|
|
||||||
WIDTH = 280
|
WIDTH = int(280 / 360 * display.width // scale)
|
||||||
HEIGHT = 182
|
HEIGHT = int(182 / 200 * display.height // scale)
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
"menu_title": "Launcher Menu",
|
"menu_title": "Launcher Menu",
|
||||||
|
|
@ -186,11 +194,14 @@ config = {
|
||||||
}
|
}
|
||||||
|
|
||||||
cell_width = WIDTH // config["width"]
|
cell_width = WIDTH // config["width"]
|
||||||
|
cell_height = HEIGHT // config["height"]
|
||||||
page_size = config["width"] * config["height"]
|
page_size = config["width"] * config["height"]
|
||||||
|
|
||||||
default_icon_bmp, default_icon_palette = adafruit_imageload.load("launcher_assets/default_icon.bmp")
|
default_icon_bmp, default_icon_palette = adafruit_imageload.load("launcher_assets/default_icon.bmp")
|
||||||
default_icon_palette.make_transparent(0)
|
default_icon_palette.make_transparent(0)
|
||||||
menu_grid = GridLayout(x=40, y=16, width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]),
|
menu_grid = GridLayout(x=(display.width // scale - WIDTH) // 2,
|
||||||
|
y=(display.height // scale - HEIGHT) // 2,
|
||||||
|
width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]),
|
||||||
divider_lines=False)
|
divider_lines=False)
|
||||||
scaled_group.append(menu_grid)
|
scaled_group.append(menu_grid)
|
||||||
|
|
||||||
|
|
@ -277,8 +288,9 @@ def _create_cell_group(app):
|
||||||
cell_group.append(icon_tg)
|
cell_group.append(icon_tg)
|
||||||
|
|
||||||
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
|
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
|
||||||
title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
|
title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
|
||||||
align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
|
align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
|
||||||
|
icon_tg.y = (cell_height - icon_tg.tile_height - title_txt.height) // 2
|
||||||
cell_group.append(title_txt)
|
cell_group.append(title_txt)
|
||||||
title_txt.anchor_point = (0, 0)
|
title_txt.anchor_point = (0, 0)
|
||||||
title_txt.anchored_position = (0, icon_tg.y + icon_tg.tile_height)
|
title_txt.anchored_position = (0, icon_tg.y + icon_tg.tile_height)
|
||||||
|
|
@ -298,7 +310,7 @@ def _reuse_cell_group(app, cell_group):
|
||||||
icon_tg.pixel_shader = icon_palette
|
icon_tg.pixel_shader = icon_palette
|
||||||
|
|
||||||
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
|
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
|
||||||
# title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
|
# title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
|
||||||
# align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
|
# align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
|
||||||
# cell_group.append(title_txt)
|
# cell_group.append(title_txt)
|
||||||
title_txt = cell_group[1]
|
title_txt = cell_group[1]
|
||||||
|
|
@ -348,7 +360,7 @@ def display_page(page_index):
|
||||||
print(f"{grid_index} | {grid_index % config["width"], grid_index // config["width"]}")
|
print(f"{grid_index} | {grid_index % config["width"], grid_index // config["width"]}")
|
||||||
|
|
||||||
|
|
||||||
page_txt = Label(terminalio.FONT, text="", scale=2, color=color_palette["fg"])
|
page_txt = Label(terminalio.FONT, text="", scale=scale, color=color_palette["fg"])
|
||||||
page_txt.anchor_point = (1.0, 1.0)
|
page_txt.anchor_point = (1.0, 1.0)
|
||||||
page_txt.anchored_position = (display.width - 2, display.height - 2)
|
page_txt.anchored_position = (display.width - 2, display.height - 2)
|
||||||
main_group.append(page_txt)
|
main_group.append(page_txt)
|
||||||
|
|
@ -360,7 +372,7 @@ left_bmp, left_palette = adafruit_imageload.load("launcher_assets/arrow_left.bmp
|
||||||
left_palette.make_transparent(0)
|
left_palette.make_transparent(0)
|
||||||
right_bmp, right_palette = adafruit_imageload.load("launcher_assets/arrow_right.bmp")
|
right_bmp, right_palette = adafruit_imageload.load("launcher_assets/arrow_right.bmp")
|
||||||
right_palette.make_transparent(0)
|
right_palette.make_transparent(0)
|
||||||
if color_palette["arrow"] >= 0:
|
if color_palette["arrow"] is not None:
|
||||||
left_palette[2] = right_palette[2] = color_palette["arrow"]
|
left_palette[2] = right_palette[2] = color_palette["arrow"]
|
||||||
|
|
||||||
left_tg = AnchoredTileGrid(bitmap=left_bmp, pixel_shader=left_palette)
|
left_tg = AnchoredTileGrid(bitmap=left_bmp, pixel_shader=left_palette)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue