4545
4646
4747class RoundRect (displayio .TileGrid ):
48- """A round-corner rectangle, top left corner is (x, y) and size of width, height.
49- r is the radius of the rounded corner. Stroke is used for the outline, and will
50- not change outer bound size set by width and height. Fill can be a hex value
51- for the color or None for transparent. Outline can be a hex value for the color
52- or None for no outline."""
53- def __init__ (self , x , y , width , height , r , * , fill = None , outline = None , stroke = 1 ): # pylint: disable=too-many-arguments
48+ # pylint: disable=too-many-arguments
49+ """A round-corner rectangle.
50+
51+ :param x: The x-position of the top left corner.
52+ :param y: The y-position of the top left corner.
53+ :param width: The width of the rounded-corner rectangle.
54+ :param height: The height of the rounded-corner rectangle.
55+ :param r: The radius of the rounded corner.
56+ :param fill: The color to fill the rounded-corner rectangle. Can be a hex value for a color or
57+ ``None`` for transparent.
58+ :param outline: The outline of the rounded-corner rectangle. Can be a hex value for a color or
59+ ``None`` for no outline.
60+ :param stroke: Used for the outline. Will not change the outer bound size set by ``width`` and
61+ ``height``.
62+
63+ """
64+ def __init__ (self , x , y , width , height , r , * , fill = None , outline = None , stroke = 1 ):
5465 self ._palette = displayio .Palette (3 )
5566 self ._palette .make_transparent (0 )
5667 self ._bitmap = displayio .Bitmap (width , height , 3 )
5768
5869 if fill is not None :
5970 for i in range (0 , width ): # draw the center chunk
60- for j in range (r , height - r ): # draw the center chunk
71+ for j in range (r , height - r ): # draw the center chunk
6172 self ._bitmap [i , j ] = 2
6273 self ._helper (r , r , r , color = 2 , fill = True ,
6374 x_offset = width - 2 * r - 1 , y_offset = height - 2 * r - 1 )
@@ -68,24 +79,22 @@ def __init__(self, x, y, width, height, r, *, fill=None, outline=None, stroke=1)
6879 if outline is not None :
6980 self ._palette [1 ] = outline
7081 # draw flat sides
71- for w in range (r , width - r ):
82+ for w in range (r , width - r ):
7283 for line in range (stroke ):
7384 self ._bitmap [w , line ] = 1
7485 self ._bitmap [w , height - line - 1 ] = 1
75- for _h in range (r , height - r ):
86+ for _h in range (r , height - r ):
7687 for line in range (stroke ):
7788 self ._bitmap [line , _h ] = 1
7889 self ._bitmap [width - line - 1 , _h ] = 1
7990 # draw round corners
8091 self ._helper (r , r , r , color = 1 , stroke = stroke ,
8192 x_offset = width - 2 * r - 1 , y_offset = height - 2 * r - 1 )
82-
8393 super ().__init__ (self ._bitmap , pixel_shader = self ._palette , position = (x , y ))
8494
85-
8695 # pylint: disable=invalid-name, too-many-locals, too-many-branches
8796 def _helper (self , x0 , y0 , r , * , color , x_offset = 0 , y_offset = 0 ,
88- stroke = 1 , cornerflags = 0xF , fill = False ):
97+ stroke = 1 , corner_flags = 0xF , fill = False ):
8998 f = 1 - r
9099 ddF_x = 1
91100 ddF_y = - 2 * r
@@ -100,7 +109,7 @@ def _helper(self, x0, y0, r, *, color, x_offset=0, y_offset=0,
100109 x += 1
101110 ddF_x += 2
102111 f += ddF_x
103- if cornerflags & 0x8 :
112+ if corner_flags & 0x8 :
104113 if fill :
105114 for w in range (x0 - y , x0 + y + x_offset ):
106115 self ._bitmap [w , y0 + x + y_offset ] = color
@@ -110,7 +119,7 @@ def _helper(self, x0, y0, r, *, color, x_offset=0, y_offset=0,
110119 for line in range (stroke ):
111120 self ._bitmap [x0 - y + line , y0 + x + y_offset ] = color
112121 self ._bitmap [x0 - x , y0 + y + y_offset - line ] = color
113- if cornerflags & 0x1 :
122+ if corner_flags & 0x1 :
114123 if fill :
115124 for w in range (x0 - y , x0 + y + x_offset ):
116125 self ._bitmap [w , y0 - x ] = color
@@ -120,18 +129,20 @@ def _helper(self, x0, y0, r, *, color, x_offset=0, y_offset=0,
120129 for line in range (stroke ):
121130 self ._bitmap [x0 - y + line , y0 - x ] = color
122131 self ._bitmap [x0 - x , y0 - y + line ] = color
123- if cornerflags & 0x4 :
132+ if corner_flags & 0x4 :
124133 for line in range (stroke ):
125134 self ._bitmap [x0 + x + x_offset , y0 + y + y_offset - line ] = color
126135 self ._bitmap [x0 + y + x_offset - line , y0 + x + y_offset ] = color
127- if cornerflags & 0x2 :
136+ if corner_flags & 0x2 :
128137 for line in range (stroke ):
129138 self ._bitmap [x0 + x + x_offset , y0 - y + line ] = color
130139 self ._bitmap [x0 + y + x_offset - line , y0 - x ] = color
131140 # pylint: enable=invalid-name, too-many-locals, too-many-branches
132141
133142 @property
134143 def fill (self ):
144+ """The fill of the rounded-corner rectangle. Can be a hex value for a color or ``None`` for
145+ transparent."""
135146 return self ._palette [2 ]
136147
137148 @fill .setter
@@ -143,6 +154,8 @@ def fill(self, color):
143154
144155 @property
145156 def outline (self ):
157+ """The outline of the rounded-corner rectangle. Can be a hex value for a color or ``None``
158+ for no outline."""
146159 return self ._palette [1 ]
147160
148161 @outline .setter
@@ -160,6 +173,7 @@ def x(self):
160173
161174 @x .setter
162175 def x (self , x ):
176+ # pylint: disable=attribute-defined-outside-init
163177 self .position = (x , self .position [1 ])
164178
165179 @property
@@ -169,4 +183,5 @@ def y(self):
169183
170184 @y .setter
171185 def y (self , y ):
186+ # pylint: disable=attribute-defined-outside-init
172187 self .position = (self .position [0 ], y )
0 commit comments