Skip to content

Commit 741e995

Browse files
committed
Fix y and add x
1 parent 5c41913 commit 741e995

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

adafruit_display_text/text_area.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(self, font, *, text=None, width=None, height=1):
6666

6767
self.sprites = [None] * (width * height)
6868

69+
self._x = 0
6970
self._y = 0
7071

7172
if text:
@@ -80,7 +81,7 @@ def _update_text(self):
8081
if not glyph:
8182
continue
8283
face = displayio.Sprite(glyph["bitmap"], pixel_shader=self.p,
83-
position=(x, self._y + self.height - glyph["bounds"][1] - glyph["bounds"][3]))
84+
position=(self._x + x, self._y + self.height - glyph["bounds"][1] - glyph["bounds"][3]))
8485
x += glyph["shift"][0]
8586
self.group.append(face)
8687
self.sprites[i] = face
@@ -105,9 +106,22 @@ def y(self):
105106

106107
@y.setter
107108
def y(self, new_y):
109+
for sprite in self.sprites:
110+
if not sprite:
111+
continue
112+
pos = sprite.position
113+
sprite.position = (pos[0], (pos[1] - self._y) + new_y)
108114
self._y = new_y
115+
116+
@property
117+
def x(self):
118+
return self._x
119+
120+
@x.setter
121+
def x(self, new_x):
109122
for sprite in self.sprites:
110123
if not sprite:
111124
continue
112125
pos = sprite.position
113-
sprite.position = (pos[0], new_y)
126+
sprite.position = ((pos[0] - self._x) + new_x, pos[1])
127+
self._x = new_x

0 commit comments

Comments
 (0)