From 95822a273d3769d396d3ad6bd4316191e901491a Mon Sep 17 00:00:00 2001 From: June Tate-Gans Date: Sun, 2 May 2021 15:00:02 -0500 Subject: [PATCH] g13gui: bitwidgets: Adding a Rectangle class So we can draw nice looking rects with curvy corners. --- g13gui/g13gui/bitwidgets/rectangle.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 g13gui/g13gui/bitwidgets/rectangle.py diff --git a/g13gui/g13gui/bitwidgets/rectangle.py b/g13gui/g13gui/bitwidgets/rectangle.py new file mode 100644 index 0000000..bf2bde5 --- /dev/null +++ b/g13gui/g13gui/bitwidgets/rectangle.py @@ -0,0 +1,27 @@ +from g13gui.bitwidgets.widget import Widget + + +class Rectangle(Widget): + def __init__(self, x, y, w, h, radius=0, fill=True): + Widget.__init__(self) + self.position = (x, y) + self.bounds = (w, h) + self.radius = radius + self.fill = fill + + def draw(self, ctx): + if self._visible: + points = (self._position[0], self._position[1], + self._position[0] + self._bounds[0], + self._position[1] + self._bounds[1]) + ctx.rounded_rectangle(*points, + radius=self._radius, + fill=self._fill) + + @property + def radius(self): + return self._radius + + @radius.setter + def radius(self, radius): + self._setProperty('radius', radius)