Created
November 27, 2021 16:43
-
-
Save FoamyGuy/98a4e32db27f71a279dea03170b4e03c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-FileCopyrightText: 2020 Tim C | |
# | |
# SPDX-License-Identifier: Unlicense | |
""" | |
Make green and purple rectangles and a | |
"Hello World" label. | |
""" | |
import displayio | |
import terminalio | |
from adafruit_display_text import label | |
from blinka_displayio_pygamedisplay import PyGameDisplay | |
from adafruit_bitmap_font import bitmap_font | |
import bitmap_font_forkawesome_icons as icons | |
from adafruit_displayio_layout.layouts.grid_layout import GridLayout | |
# Make the display context. Change size if you want | |
display = PyGameDisplay(width=320, height=240) | |
icons = [ | |
icons.building, | |
icons.address_card, | |
icons.bitbucket, | |
icons.archlinux, | |
icons.cogs, | |
icons.envelope_open, | |
] | |
# Make the display context | |
main_group = displayio.Group() | |
display.show(main_group) | |
DISPLAY_WIDTH = display.width | |
DISPLAY_HEIGHT = display.height | |
font_file = "fonts/forkawesome-42.pcf" | |
fontawesome = bitmap_font.load_font(font_file) | |
GRID_SIZE_X = 3 | |
GRID_SIZE_Y = 2 | |
CELL_SIZE = (DISPLAY_WIDTH // GRID_SIZE_X, DISPLAY_HEIGHT // GRID_SIZE_Y) | |
layout = GridLayout( | |
x=0, | |
y=0, | |
width=DISPLAY_WIDTH, | |
height=DISPLAY_HEIGHT, | |
grid_size=(GRID_SIZE_X, GRID_SIZE_Y), | |
cell_padding=0, | |
divider_lines=True, | |
) | |
_grid_contents = [] | |
main_group.append(layout) | |
for icon in icons: | |
_group = displayio.Group() | |
_cur_label = label.Label( | |
fontawesome, | |
text=icon, | |
color=0xCCCCCC, | |
) | |
_cur_label.anchor_point = (0.5, 0.5) | |
_cur_label.anchored_position = (CELL_SIZE[0] // 2, CELL_SIZE[1] // 2) | |
_group.append(_cur_label) | |
_grid_contents.append(_group) | |
layout.add_content(_grid_contents[0], grid_position=(0, 0), cell_size=(1, 1)) | |
layout.add_content(_grid_contents[1], grid_position=(1, 0), cell_size=(1, 1)) | |
layout.add_content(_grid_contents[2], grid_position=(2, 0), cell_size=(1, 1)) | |
layout.add_content(_grid_contents[3], grid_position=(0, 1), cell_size=(1, 1)) | |
layout.add_content(_grid_contents[4], grid_position=(1, 1), cell_size=(1, 1)) | |
layout.add_content(_grid_contents[5], grid_position=(2, 1), cell_size=(1, 1)) | |
while display.running: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment