Skip to content

Commit dff278a

Browse files
committed
Updated examples to use a label
1 parent 7d86e1a commit dff278a

File tree

2 files changed

+11
-40
lines changed

2 files changed

+11
-40
lines changed

examples/ili9341_shield_simpletest.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
22
This test will initialize the display using displayio and draw a solid green
3-
background, a smaller purple rectangle, and some yellow text. All drawing is done
4-
using native displayio modules.
3+
background, a smaller purple rectangle, and some yellow text.
54
65
Pinouts are for the 2.8" TFT Shield
76
"""
87
import board
98
import displayio
109
import terminalio
10+
from adafruit_display_text import label
1111
import adafruit_ili9341
1212

1313
spi = board.SPI()
@@ -42,26 +42,11 @@
4242
x=20, y=20)
4343
splash.append(inner_sprite)
4444

45-
# Draw some text the manual way!
46-
font_palette = displayio.Palette(2)
47-
font_palette.make_transparent(0)
48-
font_palette[1] = 0xFFFF00 # Yellow
49-
50-
text_group = displayio.Group(max_size=20, scale=3, x=57, y=120)
45+
# Draw a label
46+
text_group = displayio.Group(max_size=10, scale=3, x=57, y=120)
5147
text = "Hello World!"
52-
x = 0
53-
54-
for character in text:
55-
glyph = terminalio.FONT.get_glyph(ord(character))
56-
position_x = x + glyph.dx
57-
position_y = 0 - round((glyph.height - glyph.dy) / 2) # Center text vertically
58-
face = displayio.TileGrid(glyph.bitmap, pixel_shader=font_palette,
59-
default_tile=glyph.tile_index,
60-
tile_width=glyph.width, tile_height=glyph.height,
61-
x=position_x, y=position_y)
62-
text_group.append(face)
63-
x += glyph.shift_x
64-
48+
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
49+
text_group.append(text_area) # Subgroup gor text scaling
6550
splash.append(text_group)
6651

6752
while True:

examples/ili9341_simpletest.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import board
99
import displayio
1010
import terminalio
11+
from adafruit_display_text import label
1112
import adafruit_ili9341
1213

1314
spi = board.SPI()
@@ -42,26 +43,11 @@
4243
x=20, y=20)
4344
splash.append(inner_sprite)
4445

45-
# Draw some text the manual way!
46-
font_palette = displayio.Palette(2)
47-
font_palette.make_transparent(0)
48-
font_palette[1] = 0xFFFF00 # Yellow
49-
50-
text_group = displayio.Group(max_size=20, scale=3, x=57, y=120)
46+
# Draw a label
47+
text_group = displayio.Group(max_size=10, scale=3, x=57, y=120)
5148
text = "Hello World!"
52-
x = 0
53-
54-
for character in text:
55-
glyph = terminalio.FONT.get_glyph(ord(character))
56-
position_x = x + glyph.dx
57-
position_y = 0 - round((glyph.height - glyph.dy) / 2) # Center text vertically
58-
face = displayio.TileGrid(glyph.bitmap, pixel_shader=font_palette,
59-
default_tile=glyph.tile_index,
60-
tile_width=glyph.width, tile_height=glyph.height,
61-
x=position_x, y=position_y)
62-
text_group.append(face)
63-
x += glyph.shift_x
64-
49+
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
50+
text_group.append(text_area) # Subgroup gor text scaling
6551
splash.append(text_group)
6652

6753
while True:

0 commit comments

Comments
 (0)