Commit 12256992 authored by Zander Brown's avatar Zander Brown 🇬🇧 Committed by Robert Roth

general: enable tabular numbers font feature

Use the tnum font feature to ensure numbers line up and reduce movement
in the process, resource, filesystems & memory map views
parent a992121d
......@@ -345,6 +345,7 @@ create_disk_view(GsmApplication *app, GtkBuilder *builder)
GtkListStore *model;
GtkTreeViewColumn *col;
GtkCellRenderer *cell;
PangoAttrList *attrs = NULL;
guint i;
init_volume_monitor (app);
......@@ -418,11 +419,18 @@ create_disk_view(GsmApplication *app, GtkBuilder *builder)
case DISK_TOTAL:
case DISK_FREE:
case DISK_AVAIL:
g_object_set(cell, "xalign", 1.0f, NULL);
gtk_tree_view_column_set_cell_data_func(col, cell,
&procman::size_si_cell_data_func,
GUINT_TO_POINTER(i),
NULL);
attrs = make_tnum_attr_list ();
g_object_set (cell,
"attributes", attrs,
"xalign", 1.0f,
NULL);
g_clear_pointer (&attrs, pango_attr_list_unref);
break;
default:
......@@ -437,7 +445,14 @@ create_disk_view(GsmApplication *app, GtkBuilder *builder)
col = gtk_tree_view_column_new();
cell = gtk_cell_renderer_text_new();
g_object_set(cell, "xalign", 1.0f, NULL);
attrs = make_tnum_attr_list ();
g_object_set (cell,
"attributes", attrs,
"xalign", 1.0f,
NULL);
g_clear_pointer (&attrs, pango_attr_list_unref);
gtk_tree_view_column_set_min_width(col, 72);
gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_pack_start(col, cell, FALSE);
......
......@@ -242,7 +242,7 @@ create_sys_view (GsmApplication *app, GtkBuilder * builder)
gtk_widget_show (GTK_WIDGET (label));
g_free (label_text);
cpu_label = GTK_LABEL (gtk_label_new (NULL));
cpu_label = make_tnum_label ();
/* Reserve some space to avoid the layout changing with the values. */
gtk_label_set_width_chars(cpu_label, 6);
......
......@@ -60,6 +60,7 @@ static void draw_background(LoadGraph *graph) {
unsigned num_bars;
char *caption;
PangoLayout* layout;
PangoAttrList *attrs = NULL;
PangoFontDescription* font_desc;
PangoRectangle extents;
cairo_surface_t *surface;
......@@ -87,6 +88,11 @@ static void draw_background(LoadGraph *graph) {
cairo_paint_with_alpha (cr, 0.0);
layout = pango_cairo_create_layout (cr);
attrs = make_tnum_attr_list ();
pango_layout_set_attributes (layout, attrs);
g_clear_pointer (&attrs, pango_attr_list_unref);
gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL, GTK_STYLE_PROPERTY_FONT, &font_desc, NULL);
pango_font_description_set_size (font_desc, 0.8 * graph->fontsize * PANGO_SCALE);
pango_layout_set_font_description (layout, font_desc);
......@@ -785,17 +791,17 @@ LoadGraph::LoadGraph(guint type)
n = GsmApplication::get()->config.num_cpus;
for(guint i = 0; i < G_N_ELEMENTS(labels.cpu); ++i)
labels.cpu[i] = GTK_LABEL (gtk_label_new(NULL));
labels.cpu[i] = make_tnum_label ();
break;
case LOAD_GRAPH_MEM:
n = 2;
labels.memory = GTK_LABEL (gtk_label_new(NULL));
labels.memory = make_tnum_label ();
gtk_widget_set_valign (GTK_WIDGET (labels.memory), GTK_ALIGN_CENTER);
gtk_widget_set_halign (GTK_WIDGET (labels.memory), GTK_ALIGN_START);
gtk_widget_show (GTK_WIDGET (labels.memory));
labels.swap = GTK_LABEL (gtk_label_new(NULL));
labels.swap = make_tnum_label ();
gtk_widget_set_valign (GTK_WIDGET (labels.swap), GTK_ALIGN_CENTER);
gtk_widget_set_halign (GTK_WIDGET (labels.swap), GTK_ALIGN_START);
gtk_widget_show (GTK_WIDGET (labels.swap));
......@@ -805,25 +811,25 @@ LoadGraph::LoadGraph(guint type)
memset(&net, 0, sizeof net);
n = 2;
net.max = 1;
labels.net_in = GTK_LABEL (gtk_label_new(NULL));
labels.net_in = make_tnum_label ();
gtk_label_set_width_chars(labels.net_in, 10);
gtk_widget_set_valign (GTK_WIDGET (labels.net_in), GTK_ALIGN_CENTER);
gtk_widget_set_halign (GTK_WIDGET (labels.net_in), GTK_ALIGN_END);
gtk_widget_show (GTK_WIDGET (labels.net_in));
labels.net_in_total = GTK_LABEL (gtk_label_new(NULL));
labels.net_in_total = make_tnum_label ();
gtk_widget_set_valign (GTK_WIDGET (labels.net_in_total), GTK_ALIGN_CENTER);
gtk_widget_set_halign (GTK_WIDGET (labels.net_in_total), GTK_ALIGN_END);
gtk_label_set_width_chars(labels.net_in_total, 10);
gtk_widget_show (GTK_WIDGET (labels.net_in_total));
labels.net_out = GTK_LABEL (gtk_label_new(NULL));
labels.net_out = make_tnum_label ();
gtk_widget_set_valign (GTK_WIDGET (labels.net_out), GTK_ALIGN_CENTER);
gtk_widget_set_halign (GTK_WIDGET (labels.net_out), GTK_ALIGN_END);
gtk_label_set_width_chars(labels.net_out, 10);
gtk_widget_show (GTK_WIDGET (labels.net_out));
labels.net_out_total = GTK_LABEL (gtk_label_new(NULL));
labels.net_out_total = make_tnum_label ();
gtk_widget_set_valign (GTK_WIDGET (labels.net_out_total), GTK_ALIGN_CENTER);
gtk_widget_set_halign (GTK_WIDGET (labels.net_out), GTK_ALIGN_END);
gtk_label_set_width_chars(labels.net_out_total, 10);
......
......@@ -356,6 +356,7 @@ create_memmapsdata (GsmApplication *app)
for (i = 0; i < MMAP_COL_MAX; i++) {
GtkCellRenderer *cell;
GtkTreeViewColumn *col;
PangoAttrList *attrs;
cell = gtk_cell_renderer_text_new();
col = gtk_tree_view_column_new();
......@@ -366,6 +367,10 @@ create_memmapsdata (GsmApplication *app)
gtk_tree_view_column_set_reorderable(col, TRUE);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), col);
attrs = make_tnum_attr_list ();
g_object_set (cell, "attributes", attrs, NULL);
g_clear_pointer (&attrs, pango_attr_list_unref);
switch (i) {
case MMAP_COL_PRIVATE_CLEAN:
case MMAP_COL_PRIVATE_DIRTY:
......
......@@ -442,6 +442,7 @@ proctable_new (GsmApplication * const app)
for (i = COL_USER; i <= COL_PRIORITY; i++) {
GtkTreeViewColumn *col;
GtkCellRenderer *cell;
PangoAttrList *attrs = NULL;
#ifndef HAVE_WNCK
if (i == COL_MEMXSERVER)
......@@ -526,6 +527,33 @@ proctable_new (GsmApplication * const app)
break;
}
// Tabular Numbers
switch (i) {
#ifdef HAVE_WNCK
case COL_MEMXSERVER:
#endif
case COL_PID:
case COL_VMSIZE:
case COL_MEMRES:
case COL_MEMSHARED:
case COL_MEM:
case COL_CPU:
case COL_CPU_TIME:
case COL_DISK_READ_TOTAL:
case COL_DISK_WRITE_TOTAL:
case COL_DISK_READ_CURRENT:
case COL_DISK_WRITE_CURRENT:
case COL_START_TIME:
case COL_NICE:
case COL_WCHAN:
attrs = make_tnum_attr_list ();
g_object_set (cell, "attributes", attrs, NULL);
g_clear_pointer (&attrs, pango_attr_list_unref);
break;
default:
break;
}
// sorting
switch (i) {
#ifdef HAVE_WNCK
......
......@@ -373,13 +373,17 @@ namespace procman
g_value_unset(&value);
if (size == 0) {
char *str = g_strdup_printf ("<i>%s</i>", _("N/A"));
g_object_set(renderer, "markup", str, NULL);
g_free(str);
g_object_set (renderer,
"text", _("N/A"),
"style", PANGO_STYLE_ITALIC,
NULL);
}
else {
char *str = g_format_size_full(size, G_FORMAT_SIZE_IEC_UNITS);
g_object_set(renderer, "text", str, NULL);
g_object_set (renderer,
"text", str,
"style", PANGO_STYLE_NORMAL,
NULL);
g_free(str);
}
......@@ -412,12 +416,16 @@ namespace procman
g_value_unset(&value);
if (size == 0) {
char *str = g_strdup_printf ("<i>%s</i>", _("N/A"));
g_object_set(renderer, "markup", str, NULL);
g_free(str);
g_object_set (renderer,
"text", _("N/A"),
"style", PANGO_STYLE_ITALIC,
NULL);
}
else {
g_object_set(renderer, "text", procman::format_rate(size, FALSE).c_str(), NULL);
g_object_set (renderer,
"text", procman::format_rate(size, FALSE).c_str(),
"style", PANGO_STYLE_NORMAL,
NULL);
}
}
......@@ -635,3 +643,29 @@ get_monospace_system_font_name ()
{
return Gio::Settings::create ("org.gnome.desktop.interface")->get_string ("monospace-font-name");
}
GtkLabel *
make_tnum_label (void)
{
PangoAttrList *attrs = make_tnum_attr_list ();
GtkWidget *label = gtk_label_new (NULL);
gtk_label_set_attributes (GTK_LABEL (label), attrs);
g_clear_pointer (&attrs, pango_attr_list_unref);
return GTK_LABEL (label);
}
PangoAttrList *
make_tnum_attr_list (void)
{
PangoAttrList *attrs = NULL;
attrs = pango_attr_list_new ();
pango_attr_list_insert (attrs, pango_attr_font_features_new ("tnum=1"));
return attrs;
}
......@@ -25,6 +25,8 @@ procman_debug_real(const char *file, int line, const char *func,
#define procman_debug(FMT, ...) procman_debug_real(__FILE__, __LINE__, __func__, FMT, ##__VA_ARGS__)
Glib::ustring get_monospace_system_font_name (void);
GtkLabel *make_tnum_label (void);
PangoAttrList *make_tnum_attr_list (void);
inline string make_string(char *c_str)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment