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

Clue Bug Fixes #327

Merged
merged 3 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
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
Binary file not shown.
1 change: 1 addition & 0 deletions src/base_circuitpython/displayio/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
INCORR_SUBCLASS = "Layer must be a Group or TileGrid subclass."
LAYER_ALREADY_IN_GROUP = "Layer already in a group."
GROUP_FULL = "Group Full"
SCALE_TOO_SMALL = "scale must be >= 1"

SCREEN_HEIGHT_WIDTH = 240

Expand Down
16 changes: 15 additions & 1 deletion src/base_circuitpython/displayio/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import common
import board
import sys

# Group implementation loosely based on the
# displayio.Group class in Adafruit CircuitPython
Expand All @@ -33,12 +34,22 @@ class Group:
"""

def __init__(
self, max_size, scale=1, x=0, y=0, check_active_group_ref=True, auto_write=True
self,
max_size=sys.maxsize,
scale=1,
x=0,
y=0,
check_active_group_ref=True,
auto_write=True,
):
self.__check_active_group_ref = check_active_group_ref
self.__auto_write = auto_write
self.__contents = []
self.__max_size = max_size

if scale < 1:
raise ValueError(CONSTANTS.SCALE_TOO_SMALL)

self.__scale = scale
"""
.. attribute:: scale
Expand Down Expand Up @@ -89,6 +100,9 @@ def scale(self):

@scale.setter
def scale(self, val):
if val < 1:
raise ValueError(CONSTANTS.SCALE_TOO_SMALL)

if self.__scale != val:
self.__scale = val
self.__elem_changed()
Expand Down
5 changes: 5 additions & 0 deletions src/base_circuitpython/displayio/test/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def test_incorr_subclass(self, group_item):
with pytest.raises(ValueError, match=CONSTANTS.INCORR_SUBCLASS):
g1.append(group_item)

@pytest.mark.parametrize("scale", [(0), (-2)])
def test_invalid_scale(self, scale):
with pytest.raises(ValueError, match=CONSTANTS.SCALE_TOO_SMALL):
g1 = Group(scale=scale)

def test_layer_already_in_group(self):
g1 = Group(max_size=4)

Expand Down
8 changes: 4 additions & 4 deletions src/clue/adafruit_clue.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ def __init__(
self._font = terminalio.FONT
if font:
self._font = font
self.text_group = displayio.Group(max_size=20, scale=text_scale)
self.text_scale = text_scale
self.text_group = displayio.Group(max_size=20, scale=self.text_scale)
if title:
# Fail gracefully if title is longer than 60 characters.
if len(title) > 60:
Expand All @@ -130,12 +130,12 @@ def __init__(
scale=title_scale,
)
title.x = 0
title.y = 8
self._y = title.y + 18 * text_scale
title.y = 8 * self.text_scale
self._y = title.y + 18 * self.text_scale

self.text_group.append(title)
else:
self._y = 3
self._y = 3 * self.text_scale

self._lines = []
for num in range(1):
Expand Down