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

Displayio Positioning Bug Fix #306

Merged
merged 5 commits into from
Apr 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions src/base_circuitpython/displayio/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ def __init__(
self.__auto_write = auto_write
self.__contents = []
self.__max_size = max_size
self.scale = scale
self.__scale = scale
"""
.. attribute:: scale

Scales each pixel within the Group in both directions. For example, when scale=2 each pixel
will be represented by 2x2 pixels.

"""
self.x = x
self.__x = x
"""
.. attribute:: x

X position of the Group in the parent.

"""
self.y = y
self.__y = y
"""
.. attribute:: y

Expand All @@ -63,6 +63,36 @@ def __init__(
self.__parent = None
self.__hidden = False

@property
def x(self):
return self.__x

@x.setter
def x(self, val):
if self.__x != val:
self.__x = val
self.__elem_changed()

@property
def y(self):
return self.__y

@y.setter
def y(self, val):
if self.__y != val:
self.__y = val
self.__elem_changed()

@property
def scale(self):
return self.__scale

@scale.setter
def scale(self, val):
if self.__scale != val:
self.__scale = val
self.__elem_changed()

@property
def hidden(self):
"""
Expand Down Expand Up @@ -255,23 +285,24 @@ def __draw(self, img=None, x=0, y=0, scale=None, show=True):
# 1 unit (1 unit * scale = scale)
y -= scale

# Group is positioned against anchored_position (default (0,0)),
# Group is positioned against anchored_position (already incorporated into self.x and self.y),
# which is positioned against anchor_point

x += self._anchor_point[0]
y += self._anchor_point[1]
if self._boundingbox is not None and self.anchored_position is not None:
x += self.anchored_position[0]
y += self.anchored_position[1]
except AttributeError:
pass

for elem in self.__contents:
if not elem.hidden:
if isinstance(elem, Group):
img = elem._Group__draw(img=img, x=x, y=y, scale=scale, show=False,)
img = elem._Group__draw(
img=img, x=x + self.x, y=y + self.y, scale=scale, show=False,
)
else:
img = elem._TileGrid__draw(img=img, x=x, y=y, scale=scale)
img = elem._TileGrid__draw(
img=img, x=x + self.x, y=y + self.y, scale=scale
)

# show should only be true to the highest parent group
if show:
Expand Down