libsysprof-ui: use custom cell renderer for progress + .2 precision

This commit is contained in:
Christian Hergert
2019-05-22 10:05:12 -07:00
parent 57064c4dc5
commit eecb3192ec
3 changed files with 22 additions and 19 deletions

View File

@ -35,7 +35,7 @@ enum {
N_PROPS
};
G_DEFINE_TYPE_WITH_PRIVATE (SysprofCellRendererPercent, sysprof_cell_renderer_percent, GTK_TYPE_CELL_RENDERER_TEXT)
G_DEFINE_TYPE_WITH_PRIVATE (SysprofCellRendererPercent, sysprof_cell_renderer_percent, GTK_TYPE_CELL_RENDERER_PROGRESS)
static GParamSpec *properties [N_PROPS];
@ -100,7 +100,7 @@ sysprof_cell_renderer_percent_class_init (SysprofCellRendererPercentClass *klass
static void
sysprof_cell_renderer_percent_init (SysprofCellRendererPercent *self)
{
g_object_set (self, "xalign", 1.0f, NULL);
g_object_set (self, "text-xalign", 1.0f, NULL);
}
gdouble
@ -125,14 +125,17 @@ sysprof_cell_renderer_percent_set_percent (SysprofCellRendererPercent *self,
if (percent != priv->percent)
{
gchar text[128];
gchar text[8];
priv->percent = percent;
g_snprintf (text, sizeof text, "%.2lf<span size='smaller'><span size='smaller'> </span>%%</span>", percent);
g_snprintf (text, sizeof text, "%.2lf%%", percent);
text [sizeof text - 1] = '\0';
g_object_set (self, "markup", text, NULL);
g_object_set (self,
"value", (guint)percent,
"text", text,
NULL);
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PERCENT]);
}

View File

@ -43,12 +43,12 @@ typedef struct _SysprofCellRendererPercentClass SysprofCellRendererPercentClass;
struct _SysprofCellRendererPercent
{
GtkCellRendererText parent;
GtkCellRendererProgress parent;
};
struct _SysprofCellRendererPercentClass
{
GtkCellRendererTextClass parent_class;
GtkCellRendererProgressClass parent_class;
gpointer padding[4];
};

View File

@ -42,11 +42,11 @@
<property name="sort-column-id">1</property>
<property name="title" translatable="yes">Self</property>
<child>
<object class="GtkCellRendererProgress">
<object class="SysprofCellRendererPercent">
<property name="width">65</property>
</object>
<attributes>
<attribute name="value">1</attribute>
<attribute name="percent">1</attribute>
</attributes>
</child>
</object>
@ -58,11 +58,11 @@
<property name="sort-column-id">2</property>
<property name="title" translatable="yes">Total</property>
<child>
<object class="GtkCellRendererProgress">
<object class="SysprofCellRendererPercent">
<property name="width">65</property>
</object>
<attributes>
<attribute name="value">2</attribute>
<attribute name="percent">2</attribute>
</attributes>
</child>
</object>
@ -103,11 +103,11 @@
<property name="sort-column-id">1</property>
<property name="title" translatable="yes">Self</property>
<child>
<object class="GtkCellRendererProgress">
<object class="SysprofCellRendererPercent">
<property name="width">65</property>
</object>
<attributes>
<attribute name="value">1</attribute>
<attribute name="percent">1</attribute>
</attributes>
</child>
</object>
@ -119,11 +119,11 @@
<property name="sort-column-id">2</property>
<property name="title" translatable="yes">Total</property>
<child>
<object class="GtkCellRendererProgress">
<object class="SysprofCellRendererPercent">
<property name="width">65</property>
</object>
<attributes>
<attribute name="value">2</attribute>
<attribute name="percent">2</attribute>
</attributes>
</child>
</object>
@ -158,11 +158,11 @@
<property name="sort-column-id">1</property>
<property name="title" translatable="yes">Self</property>
<child>
<object class="GtkCellRendererProgress">
<object class="SysprofCellRendererPercent">
<property name="width">65</property>
</object>
<attributes>
<attribute name="value">1</attribute>
<attribute name="percent">1</attribute>
</attributes>
</child>
</object>
@ -174,11 +174,11 @@
<property name="sort-column-id">2</property>
<property name="title" translatable="yes">Total</property>
<child>
<object class="GtkCellRendererProgress">
<object class="SysprofCellRendererPercent">
<property name="width">65</property>
</object>
<attributes>
<attribute name="value">2</attribute>
<attribute name="percent">2</attribute>
</attributes>
</child>
</object>