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 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]; static GParamSpec *properties [N_PROPS];
@ -100,7 +100,7 @@ sysprof_cell_renderer_percent_class_init (SysprofCellRendererPercentClass *klass
static void static void
sysprof_cell_renderer_percent_init (SysprofCellRendererPercent *self) 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 gdouble
@ -125,14 +125,17 @@ sysprof_cell_renderer_percent_set_percent (SysprofCellRendererPercent *self,
if (percent != priv->percent) if (percent != priv->percent)
{ {
gchar text[128]; gchar text[8];
priv->percent = percent; 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'; 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]); g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PERCENT]);
} }

View File

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

View File

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