@@ -51,15 +51,23 @@ class RoundRect(displayio.TileGrid):
5151 ``height``.
5252
5353 """
54+
5455 def __init__ (self , x , y , width , height , r , * , fill = None , outline = None , stroke = 1 ):
5556 self ._palette = displayio .Palette (3 )
5657 self ._palette .make_transparent (0 )
5758 self ._bitmap = displayio .Bitmap (width , height , 3 )
58- for i in range (0 , width ): # draw the center chunk
59- for j in range (r , height - r ): # draw the center chunk
59+ for i in range (0 , width ): # draw the center chunk
60+ for j in range (r , height - r ): # draw the center chunk
6061 self ._bitmap [i , j ] = 2
61- self ._helper (r , r , r , color = 2 , fill = True ,
62- x_offset = width - 2 * r - 1 , y_offset = height - 2 * r - 1 )
62+ self ._helper (
63+ r ,
64+ r ,
65+ r ,
66+ color = 2 ,
67+ fill = True ,
68+ x_offset = width - 2 * r - 1 ,
69+ y_offset = height - 2 * r - 1 ,
70+ )
6371
6472 if fill is not None :
6573 self ._palette [2 ] = fill
@@ -74,19 +82,37 @@ def __init__(self, x, y, width, height, r, *, fill=None, outline=None, stroke=1)
7482 for w in range (r , width - r ):
7583 for line in range (stroke ):
7684 self ._bitmap [w , line ] = 1
77- self ._bitmap [w , height - line - 1 ] = 1
85+ self ._bitmap [w , height - line - 1 ] = 1
7886 for _h in range (r , height - r ):
7987 for line in range (stroke ):
8088 self ._bitmap [line , _h ] = 1
81- self ._bitmap [width - line - 1 , _h ] = 1
89+ self ._bitmap [width - line - 1 , _h ] = 1
8290 # draw round corners
83- self ._helper (r , r , r , color = 1 , stroke = stroke ,
84- x_offset = width - 2 * r - 1 , y_offset = height - 2 * r - 1 )
91+ self ._helper (
92+ r ,
93+ r ,
94+ r ,
95+ color = 1 ,
96+ stroke = stroke ,
97+ x_offset = width - 2 * r - 1 ,
98+ y_offset = height - 2 * r - 1 ,
99+ )
85100 super ().__init__ (self ._bitmap , pixel_shader = self ._palette , x = x , y = y )
86101
87102 # pylint: disable=invalid-name, too-many-locals, too-many-branches
88- def _helper (self , x0 , y0 , r , * , color , x_offset = 0 , y_offset = 0 ,
89- stroke = 1 , corner_flags = 0xF , fill = False ):
103+ def _helper (
104+ self ,
105+ x0 ,
106+ y0 ,
107+ r ,
108+ * ,
109+ color ,
110+ x_offset = 0 ,
111+ y_offset = 0 ,
112+ stroke = 1 ,
113+ corner_flags = 0xF ,
114+ fill = False
115+ ):
90116 f = 1 - r
91117 ddF_x = 1
92118 ddF_y = - 2 * r
@@ -103,32 +129,33 @@ def _helper(self, x0, y0, r, *, color, x_offset=0, y_offset=0,
103129 f += ddF_x
104130 if corner_flags & 0x8 :
105131 if fill :
106- for w in range (x0 - y , x0 + y + x_offset ):
107- self ._bitmap [w , y0 + x + y_offset ] = color
108- for w in range (x0 - x , x0 + x + x_offset ):
109- self ._bitmap [w , y0 + y + y_offset ] = color
132+ for w in range (x0 - y , x0 + y + x_offset ):
133+ self ._bitmap [w , y0 + x + y_offset ] = color
134+ for w in range (x0 - x , x0 + x + x_offset ):
135+ self ._bitmap [w , y0 + y + y_offset ] = color
110136 else :
111137 for line in range (stroke ):
112- self ._bitmap [x0 - y + line , y0 + x + y_offset ] = color
113- self ._bitmap [x0 - x , y0 + y + y_offset - line ] = color
138+ self ._bitmap [x0 - y + line , y0 + x + y_offset ] = color
139+ self ._bitmap [x0 - x , y0 + y + y_offset - line ] = color
114140 if corner_flags & 0x1 :
115141 if fill :
116- for w in range (x0 - y , x0 + y + x_offset ):
117- self ._bitmap [w , y0 - x ] = color
118- for w in range (x0 - x , x0 + x + x_offset ):
119- self ._bitmap [w , y0 - y ] = color
142+ for w in range (x0 - y , x0 + y + x_offset ):
143+ self ._bitmap [w , y0 - x ] = color
144+ for w in range (x0 - x , x0 + x + x_offset ):
145+ self ._bitmap [w , y0 - y ] = color
120146 else :
121147 for line in range (stroke ):
122- self ._bitmap [x0 - y + line , y0 - x ] = color
123- self ._bitmap [x0 - x , y0 - y + line ] = color
148+ self ._bitmap [x0 - y + line , y0 - x ] = color
149+ self ._bitmap [x0 - x , y0 - y + line ] = color
124150 if corner_flags & 0x4 :
125151 for line in range (stroke ):
126- self ._bitmap [x0 + x + x_offset , y0 + y + y_offset - line ] = color
127- self ._bitmap [x0 + y + x_offset - line , y0 + x + y_offset ] = color
152+ self ._bitmap [x0 + x + x_offset , y0 + y + y_offset - line ] = color
153+ self ._bitmap [x0 + y + x_offset - line , y0 + x + y_offset ] = color
128154 if corner_flags & 0x2 :
129155 for line in range (stroke ):
130- self ._bitmap [x0 + x + x_offset , y0 - y + line ] = color
131- self ._bitmap [x0 + y + x_offset - line , y0 - x ] = color
156+ self ._bitmap [x0 + x + x_offset , y0 - y + line ] = color
157+ self ._bitmap [x0 + y + x_offset - line , y0 - x ] = color
158+
132159 # pylint: enable=invalid-name, too-many-locals, too-many-branches
133160
134161 @property
0 commit comments