def paint_foreground(self, ctx: Context): if self.border_corner: draw_rounded_rectangle(ctx, Rectangle(ZERO_TOP_LEFT, self.size), self.border_corner) ctx.clip() self.paint_scale_background(ctx) if self.values: pos = 0.0 for value in self.values: l_pos = pos pos += value[0] / self._total if value[1]: ctx.set_source_rgba(*value[1]) if self.orientation == BarWidget.Orientation.HORIZONTAL_LEFT_TO_RIGHT: ctx.rectangle(l_pos * self.width, 0, (pos - l_pos) * self.width, self.height) elif self.orientation == BarWidget.Orientation.HORIZONTAL_RIGHT_TO_LEFT: ctx.rectangle(self.width - l_pos * self.width, 0, self.width - (l_pos - pos) * self.width, self.height) elif self.orientation == BarWidget.Orientation.VERTICAL_DOWN: ctx.rectangle(0, l_pos * self.height, self.width, (pos - l_pos) * self.height) elif self.orientation == BarWidget.Orientation.VERTICAL_UP: ctx.rectangle(0, self.height - l_pos * self.height, self.width, (l_pos - pos) * self.height) ctx.fill() self.paint_scale_foreground(ctx) if self.border: ctx.set_source_rgba(*self.border) ctx.set_line_width(self.border_width) draw_rounded_rectangle(ctx, Rectangle(ZERO_TOP_LEFT, self.size), self.border_corner) ctx.stroke()
def paint_children(self, ctx: Context): for child in self.children: ctx.save() ctx.translate(*child.position(Anchor.TOP_LEFT)) ctx.rectangle(0, 0, *child.size) ctx.clip() child.paint(ctx) ctx.restore()
def draw_children(self, g: Graphics) -> None: ui = cast(ContainerUI, self.ui) (cx, cy, cw, ch) = ui.content_bounds(self).tuple g.save() g.rectangle(cx, cy, cw, ch) g.clip() try: # noinspection PyTypeChecker for child in self.children: child.draw(g) except BaseException as e: self.error_handler(e) g.restore()
def draw(self, g: Graphics) -> None: if self.visible: g.save() (dx, dy) = self.parent.map(lambda p: p.location).value_or(Point(0, 0)) (cx, cy, cw, ch) = self.ui.clip_bounds(self).tuple g.translate(dx, dy) g.rectangle(cx, cy, cw, ch) g.clip() try: self.draw_component(g) except BaseException as e: self.error_handler(e) g.restore()