Skip to content

use adafruit_anchored_group instead of sized_group #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@
"""
import array

import board
import displayio
import pathlib
import supervisor
import sys
import usb
from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text.text_box import TextBox
from adafruit_display_text.bitmap_label import Label
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
from adafruit_anchored_tilegrid import AnchoredTileGrid
import adafruit_imageload
import adafruit_usb_host_descriptors
from sized_group import SizedGroup
from adafruit_anchored_group import AnchoredGroup

display = supervisor.runtime.display
font_file = "/fonts/terminal.lvfontbin"
Expand All @@ -36,7 +34,7 @@
main_group.append(bg_tg)

# load the mouse cursor bitmap
mouse_bmp = displayio.OnDiskBitmap("mouse_cursor.bmp")
mouse_bmp = displayio.OnDiskBitmap("launcher_assets/mouse_cursor.bmp")

# make the background pink pixels transparent
mouse_bmp.pixel_shader.make_transparent(0)
Expand All @@ -47,15 +45,15 @@
# move it to the center of the display
mouse_tg.x = display.width // 2
mouse_tg.y = display.height // 2
#046d:c52f
# 046d:c52f


#mouse = usb.core.find(idVendor=0x046d, idProduct=0xc52f)
# mouse = usb.core.find(idVendor=0x046d, idProduct=0xc52f)

DIR_IN = 0x80
mouse_interface_index, mouse_endpoint_address = None, None
mouse = None
#scan for connected USB device and loop over any found
# scan for connected USB device and loop over any found
print("scanning usb")
for device in usb.core.find(find_all=True):
# print device info
Expand Down Expand Up @@ -152,15 +150,15 @@

cell_width = WIDTH // config["width"]

default_icon_bmp, default_icon_palette = adafruit_imageload.load("default_icon_64.bmp")
default_icon_bmp, default_icon_palette = adafruit_imageload.load("launcher_assets/default_icon.bmp")
default_icon_palette.make_transparent(0)
menu_grid = GridLayout(x=10, y=26, width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]),
divider_lines=False)
main_group.append(menu_grid)

menu_title_txt = Label(font, text=config["menu_title"])
menu_title_txt.anchor_point = (0.5, 0.5)
menu_title_txt.anchored_position = (display.width//2, 2)
menu_title_txt.anchored_position = (display.width // 2, 2)
main_group.append(menu_title_txt)

app_titles = []
Expand All @@ -172,7 +170,7 @@
code_file = path / "code.py"
if not code_file.exists():
continue
cell_group = SizedGroup()
cell_group = AnchoredGroup()
icon_file = path / "icon.bmp"
if not icon_file.exists():
icon_file = None
Expand All @@ -189,18 +187,19 @@
icon_tg = displayio.TileGrid(bitmap=icon_bmp, pixel_shader=icon_palette)
cell_group.append(icon_tg)

icon_tg.x = cell_width//2 - icon_tg.tile_width//2
title_txt = TextBox(font, text=apps[-1]["title"], width=WIDTH // config["width"], height=18, align=TextBox.ALIGN_CENTER)
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
title_txt = TextBox(font, text=apps[-1]["title"], width=WIDTH // config["width"], height=18,
align=TextBox.ALIGN_CENTER)
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)
app_titles.append(title_txt)
menu_grid.add_content(cell_group, grid_position=(i % config["width"], i // config["width"]), cell_size=(1, 1))
i += 1

left_bmp, left_palette = adafruit_imageload.load("arrow_left.bmp")
left_bmp, left_palette = adafruit_imageload.load("launcher_assets/arrow_left.bmp")
left_palette.make_transparent(0)
right_bmp, right_palette = adafruit_imageload.load("arrow_right.bmp")
right_bmp, right_palette = adafruit_imageload.load("launcher_assets/arrow_right.bmp")
right_palette.make_transparent(0)

left_tg = AnchoredTileGrid(bitmap=left_bmp, pixel_shader=left_palette)
Expand Down Expand Up @@ -257,9 +256,10 @@
clicked_cell = menu_grid.which_cell_contains((mouse_tg.x, mouse_tg.y))
if clicked_cell is not None:
index = clicked_cell[1] * config["width"] + clicked_cell[0]

if index is not None:
supervisor.set_next_code_file(config["apps"][index]["file"], sticky_on_reload=True, reload_on_error=True, working_directory="/apps/matrix")
supervisor.set_next_code_file(config["apps"][index]["file"], sticky_on_reload=True, reload_on_error=True,
working_directory="/apps/matrix")

if mouse and not mouse.is_kernel_driver_active(0):
mouse.attach_kernel_driver(0)
Expand Down
Binary file added src/launcher_assets/arrow_left.bmp
Binary file not shown.
Binary file added src/launcher_assets/arrow_right.bmp
Binary file not shown.
Binary file added src/launcher_assets/default_icon.bmp
Binary file not shown.
Binary file added src/launcher_assets/mouse_cursor.bmp
Binary file not shown.
49 changes: 0 additions & 49 deletions src/sized_group.py

This file was deleted.