def do_render(self, cr, widget, background_area, cell_area, flags): Gtk.CellRendererPixbuf.do_render(self, cr, widget, background_area, cell_area, flags) if not self.toggle_visible: return xpad, ypad = self.get_padding() direction = widget.get_direction() # FIXME: currently broken with g-i # icon_size = widget.style_get_property("check-icon-size") icon_size = 40 if direction == Gtk.TextDirection.RTL: x_offset = xpad else: x_offset = cell_area.width - icon_size - xpad check_x = cell_area.x + x_offset check_y = cell_area.y + cell_area.height - icon_size - ypad context = widget.get_style_context() context.save() context.add_class(Gtk.STYLE_CLASS_CHECK) if self.active: context.set_state(Gtk.StateFlags.ACTIVE) Gtk.render_check(context, cr, check_x, check_y, icon_size, icon_size) context.restore()
def do_render(self, cr, widget, background_area, cell_area, flags): context = widget.get_style_context() context.save() context.add_class("clocks-digital-renderer") context.add_class(self.css_class) cr.save() Gdk.cairo_rectangle(cr, cell_area) cr.clip() # draw background if self.props.pixbuf: Gtk.CellRendererPixbuf.do_render(self, cr, widget, background_area, cell_area, flags) else: Gtk.render_frame(context, cr, cell_area.x, cell_area.y, cell_area.width, cell_area.height) Gtk.render_background(context, cr, cell_area.x, cell_area.y, cell_area.width, cell_area.height) cr.translate(cell_area.x, cell_area.y) # for now the space around the digital clock is hardcoded and # relative to the image width (not the width of the cell which # may be larger in case of long city names). # We need to know the width to create the pango layouts if self.props.pixbuf: pixbuf_margin = (cell_area.width - self.props.pixbuf.get_width()) // 2 else: pixbuf_margin = 0 margin = 12 + pixbuf_margin padding = 12 w = cell_area.width - 2 * margin # create the layouts so that we can measure them layout = widget.create_pango_layout("") layout.set_markup( "<span size='xx-large'><b>%s</b></span>" % self.text, -1) layout.set_width(w * Pango.SCALE) layout.set_alignment(Pango.Alignment.CENTER) text_w, text_h = layout.get_pixel_size() if self.subtext: layout_subtext = widget.create_pango_layout("") layout_subtext.set_markup( "<span size='medium'>%s</span>" % self.subtext, -1) layout_subtext.set_width(w * Pango.SCALE) layout_subtext.set_alignment(Pango.Alignment.CENTER) subtext_w, subtext_h = layout_subtext.get_pixel_size() subtext_pad = 6 # We just assume the first line is the longest line = layout_subtext.get_line(0) ink_rect, log_rect = line.get_pixel_extents() subtext_w = log_rect.width else: subtext_w, subtext_h, subtext_pad = 0, 0, 0 # measure the actual height and coordinates (xpad is ignored for now) h = 2 * padding + text_h + subtext_h + subtext_pad x = margin y = (cell_area.height - h) / 2 context.add_class("inner") # draw inner rectangle background Gtk.render_frame(context, cr, x, y, w, h) Gtk.render_background(context, cr, x, y, w, h) # draw text Gtk.render_layout(context, cr, x, y + padding, layout) if self.subtext: Gtk.render_layout(context, cr, x, y + padding + text_h + subtext_pad, layout_subtext) context.restore() # draw the overlayed checkbox if self.toggle_visible: context.save() context.add_class(Gtk.STYLE_CLASS_CHECK) xpad, ypad = self.get_padding() direction = widget.get_direction() if direction == Gtk.TextDirection.RTL: x_offset = xpad else: x_offset = cell_area.width - self.icon_size - xpad check_x = x_offset check_y = cell_area.height - self.icon_size - ypad if self.active: context.set_state(Gtk.StateFlags.ACTIVE) Gtk.render_check(context, cr, check_x, check_y, self.icon_size, self.icon_size) context.restore() cr.restore()