Skip to content

Commit 5426413

Browse files
committed
gridlayout examples
1 parent 208a25e commit 5426413

3 files changed

+108
-3
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# SPDX-FileCopyrightText: 2020 Tim C, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
Make green and purple rectangles and a
6+
"Hello World" label. Displayed with Blinka_Displayio_PyGameDisplay
7+
"""
8+
import displayio
9+
import terminalio
10+
from adafruit_display_text import label
11+
from blinka_displayio_pygamedisplay import PyGameDisplay
12+
13+
14+
# Make the display context. Change size if you want
15+
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
16+
17+
display = PyGameDisplay(width=320, height=240)
18+
19+
# Make the display context
20+
main_group = displayio.Group(max_size=10)
21+
display.show(main_group)
22+
23+
layout = GridLayout(
24+
x=10,
25+
y=10,
26+
width=320,
27+
height=100,
28+
grid_size=(2, 2),
29+
child_padding=8,
30+
max_children=10,
31+
)
32+
_labels = []
33+
34+
_labels.append(
35+
label.Label(
36+
terminalio.FONT, scale=2, x=0, y=0, text="Hello", background_color=0x770077
37+
)
38+
)
39+
layout.add_sub_view(_labels[0], grid_position=(0, 0), view_grid_size=(1, 1))
40+
_labels.append(
41+
label.Label(
42+
terminalio.FONT, scale=2, x=0, y=0, text="World", background_color=0x007700
43+
)
44+
)
45+
layout.add_sub_view(_labels[1], grid_position=(1, 0), view_grid_size=(1, 1))
46+
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Hello"))
47+
layout.add_sub_view(_labels[2], grid_position=(0, 1), view_grid_size=(1, 1))
48+
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Grid"))
49+
layout.add_sub_view(_labels[3], grid_position=(1, 1), view_grid_size=(1, 1))
50+
51+
main_group.append(layout)
52+
while display.running:
53+
pass
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: 2020 Tim C, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
Make green and purple rectangles and a
6+
"Hello World" label.
7+
"""
8+
import board
9+
import displayio
10+
import terminalio
11+
from adafruit_display_text import label
12+
13+
# Make the display context. Change size if you want
14+
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
15+
16+
# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
17+
# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.)
18+
# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus
19+
display = board.DISPLAY
20+
21+
# Make the display context
22+
main_group = displayio.Group(max_size=10)
23+
display.show(main_group)
24+
25+
layout = GridLayout(
26+
x=10,
27+
y=10,
28+
width=200,
29+
height=100,
30+
grid_size=(2, 2),
31+
child_padding=8,
32+
max_children=10,
33+
)
34+
_labels = []
35+
36+
_labels.append(
37+
label.Label(
38+
terminalio.FONT, scale=2, x=0, y=0, text="Hello", background_color=0x770077
39+
)
40+
)
41+
layout.add_sub_view(_labels[0], grid_position=(0, 0), view_grid_size=(1, 1))
42+
_labels.append(
43+
label.Label(
44+
terminalio.FONT, scale=2, x=0, y=0, text="World", background_color=0x007700
45+
)
46+
)
47+
layout.add_sub_view(_labels[1], grid_position=(1, 0), view_grid_size=(1, 1))
48+
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Hello"))
49+
layout.add_sub_view(_labels[2], grid_position=(0, 1), view_grid_size=(1, 1))
50+
_labels.append(label.Label(terminalio.FONT, scale=2, x=0, y=0, text="Grid"))
51+
layout.add_sub_view(_labels[3], grid_position=(1, 1), view_grid_size=(1, 1))
52+
53+
main_group.append(layout)
54+
while True:
55+
pass

examples/displayio_layout_simpletest.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)