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

Commit 824b141

Browse files
authored
Clue Bug Fixes (#327)
Small Clue bug fixes
1 parent 3546119 commit 824b141

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed
Binary file not shown.

src/base_circuitpython/displayio/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
INCORR_SUBCLASS = "Layer must be a Group or TileGrid subclass."
55
LAYER_ALREADY_IN_GROUP = "Layer already in a group."
66
GROUP_FULL = "Group Full"
7+
SCALE_TOO_SMALL = "scale must be >= 1"
78

89
SCREEN_HEIGHT_WIDTH = 240
910

src/base_circuitpython/displayio/group.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import common
1010
import board
11+
import sys
1112

1213
# Group implementation loosely based on the
1314
# displayio.Group class in Adafruit CircuitPython
@@ -33,12 +34,22 @@ class Group:
3334
"""
3435

3536
def __init__(
36-
self, max_size, scale=1, x=0, y=0, check_active_group_ref=True, auto_write=True
37+
self,
38+
max_size=sys.maxsize,
39+
scale=1,
40+
x=0,
41+
y=0,
42+
check_active_group_ref=True,
43+
auto_write=True,
3744
):
3845
self.__check_active_group_ref = check_active_group_ref
3946
self.__auto_write = auto_write
4047
self.__contents = []
4148
self.__max_size = max_size
49+
50+
if scale < 1:
51+
raise ValueError(CONSTANTS.SCALE_TOO_SMALL)
52+
4253
self.__scale = scale
4354
"""
4455
.. attribute:: scale
@@ -89,6 +100,9 @@ def scale(self):
89100

90101
@scale.setter
91102
def scale(self, val):
103+
if val < 1:
104+
raise ValueError(CONSTANTS.SCALE_TOO_SMALL)
105+
92106
if self.__scale != val:
93107
self.__scale = val
94108
self.__elem_changed()

src/base_circuitpython/displayio/test/test_group.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ def test_incorr_subclass(self, group_item):
5353
with pytest.raises(ValueError, match=CONSTANTS.INCORR_SUBCLASS):
5454
g1.append(group_item)
5555

56+
@pytest.mark.parametrize("scale", [(0), (-2)])
57+
def test_invalid_scale(self, scale):
58+
with pytest.raises(ValueError, match=CONSTANTS.SCALE_TOO_SMALL):
59+
g1 = Group(scale=scale)
60+
5661
def test_layer_already_in_group(self):
5762
g1 = Group(max_size=4)
5863

src/clue/adafruit_clue.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def __init__(
115115
self._font = terminalio.FONT
116116
if font:
117117
self._font = font
118-
self.text_group = displayio.Group(max_size=20, scale=text_scale)
119118
self.text_scale = text_scale
119+
self.text_group = displayio.Group(max_size=20, scale=self.text_scale)
120120
if title:
121121
# Fail gracefully if title is longer than 60 characters.
122122
if len(title) > 60:
@@ -130,12 +130,12 @@ def __init__(
130130
scale=title_scale,
131131
)
132132
title.x = 0
133-
title.y = 8
134-
self._y = title.y + 18 * text_scale
133+
title.y = 8 * self.text_scale
134+
self._y = title.y + 18 * self.text_scale
135135

136136
self.text_group.append(title)
137137
else:
138-
self._y = 3
138+
self._y = 3 * self.text_scale
139139

140140
self._lines = []
141141
for num in range(1):

0 commit comments

Comments
 (0)