Skip to content

Commit 265f5cc

Browse files
committed
rectangle with outline/fill (start)
1 parent 1d8c577 commit 265f5cc

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

adafruit_display_shapes/rect.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import displayio
2+
3+
class Rect(displayio.TileGrid):
4+
def __init__(self, x, y, width, height, *, fill=None, outline=None):
5+
self._bitmap = displayio.Bitmap(width, height, 2)
6+
if outline is not None:
7+
for w in range(width):
8+
self._bitmap[w, 0] = 1
9+
self._bitmap[w, height-1] = 1
10+
for h in range(height):
11+
self._bitmap[0, h] = 1
12+
self._bitmap[width-1, h] = 1
13+
14+
self._palette = displayio.Palette(2)
15+
self._palette[0] = fill
16+
self._palette[1] = outline
17+
super().__init__(self._bitmap, pixel_shader=self._palette, position=(x, y))
18+
19+
20+
@property
21+
def x(self):
22+
return self.position[0]
23+
24+
@x.setter
25+
def x(self, x):
26+
self.position = (x, self.position[1])
27+
28+
@property
29+
def y(self):
30+
return self.position[1]
31+
32+
@x.setter
33+
def y(self, y):
34+
self.position = (self.position[0], y)

0 commit comments

Comments
 (0)