Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit 2495de3

Browse files
authored
Displayio Positioning Bug Fix (#306)
Fixed group positioning
1 parent d7d924a commit 2495de3

File tree

1 file changed

+40
-9
lines changed
  • src/base_circuitpython/displayio

1 file changed

+40
-9
lines changed

src/base_circuitpython/displayio/group.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ def __init__(
3939
self.__auto_write = auto_write
4040
self.__contents = []
4141
self.__max_size = max_size
42-
self.scale = scale
42+
self.__scale = scale
4343
"""
4444
.. attribute:: scale
4545
4646
Scales each pixel within the Group in both directions. For example, when scale=2 each pixel
4747
will be represented by 2x2 pixels.
4848
4949
"""
50-
self.x = x
50+
self.__x = x
5151
"""
5252
.. attribute:: x
5353
5454
X position of the Group in the parent.
5555
5656
"""
57-
self.y = y
57+
self.__y = y
5858
"""
5959
.. attribute:: y
6060
@@ -63,6 +63,36 @@ def __init__(
6363
self.__parent = None
6464
self.__hidden = False
6565

66+
@property
67+
def x(self):
68+
return self.__x
69+
70+
@x.setter
71+
def x(self, val):
72+
if self.__x != val:
73+
self.__x = val
74+
self.__elem_changed()
75+
76+
@property
77+
def y(self):
78+
return self.__y
79+
80+
@y.setter
81+
def y(self, val):
82+
if self.__y != val:
83+
self.__y = val
84+
self.__elem_changed()
85+
86+
@property
87+
def scale(self):
88+
return self.__scale
89+
90+
@scale.setter
91+
def scale(self, val):
92+
if self.__scale != val:
93+
self.__scale = val
94+
self.__elem_changed()
95+
6696
@property
6797
def hidden(self):
6898
"""
@@ -255,23 +285,24 @@ def __draw(self, img=None, x=0, y=0, scale=None, show=True):
255285
# 1 unit (1 unit * scale = scale)
256286
y -= scale
257287

258-
# Group is positioned against anchored_position (default (0,0)),
288+
# Group is positioned against anchored_position (already incorporated into self.x and self.y),
259289
# which is positioned against anchor_point
260290

261291
x += self._anchor_point[0]
262292
y += self._anchor_point[1]
263-
if self._boundingbox is not None and self.anchored_position is not None:
264-
x += self.anchored_position[0]
265-
y += self.anchored_position[1]
266293
except AttributeError:
267294
pass
268295

269296
for elem in self.__contents:
270297
if not elem.hidden:
271298
if isinstance(elem, Group):
272-
img = elem._Group__draw(img=img, x=x, y=y, scale=scale, show=False,)
299+
img = elem._Group__draw(
300+
img=img, x=x + self.x, y=y + self.y, scale=scale, show=False,
301+
)
273302
else:
274-
img = elem._TileGrid__draw(img=img, x=x, y=y, scale=scale)
303+
img = elem._TileGrid__draw(
304+
img=img, x=x + self.x, y=y + self.y, scale=scale
305+
)
275306

276307
# show should only be true to the highest parent group
277308
if show:

0 commit comments

Comments
 (0)