Skip to content

Commit a88968f

Browse files
committed
9.X API, anchor positioning, bigger scale, set paddings in example. allow smaller screens.
1 parent 1d5e51b commit a88968f

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

adafruit_display_text/outlined_label.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ def __init__(
100100
)
101101

102102
def _add_outline(self):
103+
"""
104+
Blit the outline into the labels Bitmap. We will stamp self._stamp_source for each
105+
pixel of the foreground color but skip the foreground color when we blit.
106+
:return: None
107+
"""
103108
if hasattr(self, "_stamp_source"):
104109
for y in range(self.bitmap.height):
105110
for x in range(self.bitmap.width):
@@ -119,12 +124,6 @@ def _add_outline(self):
119124
"Try using either larger padding sizes, or smaller outline_size."
120125
) from value_error
121126

122-
# bitmaptools.blit(bitmap, stamp_source, x - size, y - size)
123-
# for y_loc in range(-size, size+1):
124-
# for x_loc in range(-size, size+1):
125-
# if bitmap[x+x_loc, y+y_loc] != target_color_index:
126-
# bitmap[x + x_loc, y + y_loc] = outline_color_index
127-
128127
def _place_text(
129128
self,
130129
bitmap: Bitmap,
@@ -136,6 +135,16 @@ def _place_text(
136135
# when copying glyph bitmaps (this is important for slanted text
137136
# where rectangular glyph boxes overlap)
138137
) -> Tuple[int, int, int, int]:
138+
"""
139+
Copy the glpyphs that represent the value of the string into the labels Bitmap.
140+
:param bitmap: The bitmap to place text into
141+
:param text: The text to render
142+
:param font: The font to render the text in
143+
:param xposition: x location of the starting point within the bitmap
144+
:param yposition: y location of the starting point within the bitmap
145+
:param skip_index: Color index to skip during rendering instead of covering up
146+
:return Tuple bounding_box: tuple with x, y, width, height values of the bitmap
147+
"""
139148
parent_result = super()._place_text(
140149
bitmap, text, font, xposition, yposition, skip_index=skip_index
141150
)

examples/display_text_outlined_label_simpletest.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,25 @@
55
import terminalio
66
from adafruit_display_text import outlined_label
77

8-
text = "Hello world"
8+
if board.DISPLAY.width <= 150:
9+
text = "Hello\nworld"
10+
else:
11+
text = "Hello world"
12+
913
text_area = outlined_label.OutlinedLabel(
1014
terminalio.FONT,
1115
text=text,
1216
color=0xFF00FF,
1317
outline_color=0x00FF00,
1418
outline_size=1,
15-
scale=2,
19+
padding_left=2,
20+
padding_right=2,
21+
padding_top=2,
22+
padding_bottom=2,
23+
scale=3,
1624
)
17-
text_area.x = 10
18-
text_area.y = 14
19-
board.DISPLAY.show(text_area)
25+
text_area.anchor_point = (0,0)
26+
text_area.anchored_position = (10, 10)
27+
board.DISPLAY.root_group = text_area
2028
while True:
2129
pass

0 commit comments

Comments
 (0)