1
/* Copyright 2016 Software Freedom Conservancy Inc.
3
* This software is licensed under the GNU Lesser General Public License
4
* (version 2.1 or later). See the COPYING file in this distribution.
8
* Draws the count badge and calculates its dimensions.
10
public class CountBadge : Geary.BaseObject {
11
public const string UNREAD_BG_COLOR = "#888888";
13
private const int FONT_SIZE_MESSAGE_COUNT = 8;
15
public int count { get; set; default = 0; }
20
* Creates a count badge.
21
* @param min Minimum count to draw.
23
public CountBadge(int min) {
27
public int get_width(Gtk.Widget widget) {
29
render_internal(widget, null, 0, 0, false, out width, null);
34
public int get_height(Gtk.Widget widget) {
36
render_internal(widget, null, 0, 0, false, null, out height);
41
public void render(Gtk.Widget widget, Cairo.Context? ctx, int x, int y, bool selected) {
42
render_internal(widget, ctx, x, y, selected, null, null);
45
private void render_internal(Gtk.Widget widget, Cairo.Context? ctx, int x, int y, bool selected,
46
out int? width, out int? height) {
55
"<span foreground='white' font='%d' weight='bold'> %d </span>"
56
.printf(FONT_SIZE_MESSAGE_COUNT, count);
58
Pango.Layout layout_num = widget.create_pango_layout(null);
59
layout_num.set_markup(mails, -1);
60
layout_num.set_alignment(Pango.Alignment.RIGHT);
62
Pango.Rectangle? ink_rect;
63
Pango.Rectangle? logical_rect;
64
layout_num.get_pixel_extents(out ink_rect, out logical_rect);
66
double bg_width = logical_rect.width + FormattedConversationData.LINE_SPACING;
67
double bg_height = logical_rect.height;
68
double radius = bg_height / 2.0;
69
double degrees = Math.PI / 180.0;
71
// Create rounded rect.
73
ctx.arc(x + bg_width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
74
ctx.arc(x + bg_width - radius, y + bg_height - radius, radius, 0 * degrees, 90 * degrees);
75
ctx.arc(x + radius, y + bg_height - radius, radius, 90 * degrees, 180 * degrees);
76
ctx.arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
79
// Colorize our shape.
80
GtkUtil.set_source_color_from_string(ctx, UNREAD_BG_COLOR);
82
ctx.set_line_width(2.0);
86
ctx.move_to(x + (bg_width / 2) - logical_rect.width / 2, y);
87
Pango.cairo_show_layout(ctx, layout_num);
90
width = logical_rect.width + FormattedConversationData.LINE_SPACING;
91
height = logical_rect.height;