def on_draw(self, widget: Widget, context: cairo.Context): for b in self._buttons: b.set_shape_from_context(context) shapes = [b.shape for b in self._buttons] context.save() context.select_font_face("", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) xb, yb, w, h, xa, ya = context.text_extents(self.title) width = max(shape.width for shape in shapes) width = max(width, xa) container_width = self.container_size[0] translation = Point(0, self.distance) if container_width > width: translation += Point((container_width)/2, 0) else: translation += Point(width/2, 0) context.move_to(translation.x - xa/2, h + 2 * self.distance) context.show_text(self.title) context.restore() height = h + self.distance * 3 for b in self._buttons: height += b.shape.height + self.distance self.min_size = width + 2 * self.distance, height + self.distance start_point = context.get_current_point() translation += Point(0, h + self.distance * 3) context.translate(translation.x, translation.y) distance_offset = Point(0, self.distance) for b in self._buttons: context.move_to(*start_point) b.set_translate(translation.x, translation.y) context.save() b.on_draw(widget, context) context.restore() to_translate = Point(distance_offset.x, distance_offset.y + b.shape.height) context.translate(to_translate.x, to_translate.y) translation += to_translate
def on_draw(self, widget: Widget, context: cairo.Context): for b in self._buttons: b.set_shape_from_context(context) shapes = [b.shape for b in self._buttons] context.save() context.select_font_face("", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) xb, yb, w, h, xa, ya = context.text_extents(self.title) width = max(shape.width for shape in shapes) width = max(width, xa) container_width = self.container_size[0] translation = Point(0, self.distance) if container_width > width: translation += Point((container_width) / 2, 0) else: translation += Point(width / 2, 0) context.move_to(translation.x - xa / 2, h + 2 * self.distance) context.show_text(self.title) context.restore() height = h + self.distance * 3 for b in self._buttons: height += b.shape.height + self.distance self.min_size = width + 2 * self.distance, height + self.distance start_point = context.get_current_point() translation += Point(0, h + self.distance * 3) context.translate(translation.x, translation.y) distance_offset = Point(0, self.distance) for b in self._buttons: context.move_to(*start_point) b.set_translate(translation.x, translation.y) context.save() b.on_draw(widget, context) context.restore() to_translate = Point(distance_offset.x, distance_offset.y + b.shape.height) context.translate(to_translate.x, to_translate.y) translation += to_translate
def on_draw(self, widget: Widget, context: cairo.Context): start_x, start_y = context.get_current_point() context.set_font_size(self.font_size) context.move_to(0, 0) if not self.is_shape_set: self.set_shape_from_context(context) shape = self.shape start = shape.start padding = self.padding h = shape.height - 2 * padding label = self.label context.set_source_rgb(*self.background_color) shape.draw_on_context(context) context.fill_preserve() context.set_line_width(1) context.set_source_rgb(*self.label_color) context.stroke() if self.disabled: context.set_source_rgba(1, 1, 1, .7) context.move_to(start.x + padding-1, start.y + padding + h+1) context.show_text(label) context.set_source_rgba(*self.label_color, .9) else: context.set_source_rgb(*self.label_color) context.move_to(start.x + padding, start.y + padding + h) context.show_text(label) if self.disabled: context.set_source_rgba(1, 1, 1, .7) context.move_to(0, 0) shape.draw_on_context(context) context.fill()
def on_draw(self, widget: Widget, context: cairo.Context): start_x, start_y = context.get_current_point() context.set_font_size(self.font_size) context.move_to(0, 0) if not self.is_shape_set: self.set_shape_from_context(context) shape = self.shape start = shape.start padding = self.padding h = shape.height - 2 * padding label = self.label context.set_source_rgb(*self.background_color) shape.draw_on_context(context) context.fill_preserve() context.set_line_width(1) context.set_source_rgb(*self.label_color) context.stroke() if self.disabled: context.set_source_rgba(1, 1, 1, .7) context.move_to(start.x + padding - 1, start.y + padding + h + 1) context.show_text(label) context.set_source_rgba(*self.label_color, .9) else: context.set_source_rgb(*self.label_color) context.move_to(start.x + padding, start.y + padding + h) context.show_text(label) if self.disabled: context.set_source_rgba(1, 1, 1, .7) context.move_to(0, 0) shape.draw_on_context(context) context.fill()
def on_draw(self, widget: Widget, context: cairo.Context): self.min_size = 200, 150 super().on_draw(widget, context) context.save() context.set_font_size(self.font_size) if self._table_extents is None: self._update_table_extents(context) skip = max(self.skip, 0) how_many = self.how_many table_extents = self._table_extents title_extents = self._table_extents.title_extents expected_height = title_extents.total_height + self.margin entries = self.entries base = skip up_to = skip over = False while up_to < len(entries) and not over: expected_height += table_extents[up_to].total_height over = expected_height >= self._max_height if not over: up_to += 1 while base > 0 and not over: expected_height += table_extents[base-1].total_height over = expected_height >= self._max_height if not over: base -= 1 how_many = up_to - base skip = base self.base = base entries = self.entries[skip:skip + how_many] def table_extents_iterator(): return table_extents.iter_over( skip, how_many ) start_x, start_y = context.get_current_point() start_y += title_extents.total_height h = title_extents.total_height self.title_height = h for (index, cell), data in zip(enumerate(title_extents), self.title): context.save() offset = title_extents.get_cell_data_left(index) context.rectangle(start_x + offset, start_y - h, cell.width, 2*h) context.clip() context.move_to( start_x + offset, start_y ) context.show_text(data) context.restore() # start_y += self.margin curr_x, curr_y = start_x, start_y# + title_extents.total_height for line_index, (line_extent, entry) in enumerate(zip(table_extents_iterator(), entries)): h = line_extent.total_height curr_y += h if curr_y + self.margin >= self._max_height: break for (cell_index, cell), data in zip(enumerate(line_extent), entry): context.save() offset = line_extent.get_cell_data_left(cell_index) context.rectangle(curr_x + offset, curr_y - h, cell.width, 2*h) context.clip() context.move_to( curr_x + offset, curr_y ) context.show_text(data) context.restore() curr_x = start_x end_x = table_extents.entries_width curr_y = start_y + self.margin end_y = table_extents.get_height_up_to(skip, how_many) + start_y + self.margin + 1 self.table_height = end_y self.table_width = end_x for line in table_extents_iterator(): context.move_to(curr_x, curr_y) context.line_to(end_x, curr_y) context.stroke() curr_y += line.total_height context.move_to(curr_x, curr_y) context.line_to(end_x, curr_y) context.stroke() curr_x = start_x curr_y = start_y - 1 + self.margin if self._how_many > 0: line = table_extents[0] for cell in line: context.move_to(curr_x, curr_y) context.line_to(curr_x, end_y) context.stroke() curr_x += cell.total_width + 2 * self.margin context.move_to(curr_x, curr_y) context.line_to(curr_x, end_y) context.stroke() if self._to_highlight is not None: r, g, b = global_constants.highlight context.set_source_rgba(r, g, b, .6) index = self._to_highlight base = start_y + table_extents.get_height_up_to(skip, index) + self.margin h = table_extents.get_height_of(skip, how_many, index) context.rectangle(start_x, base, table_extents.entries_width, h) context.fill() context.restore() self._shown = how_many