[gnome-system-monitor] Improve alignment of percentage values/labels for 10 or more CPUs



commit 9d3b5b7aef9c6d6ff0fa631574d2b527a3d95886
Author: Zhao Yongming <ming zym gmail com>
Date:   Tue Oct 26 10:30:59 2021 +1300

    Improve alignment of percentage values/labels for 10 or more CPUs
    
    With 10+ cpu in the system, the cpu label in cpu box will align
    ugly, this patch will make sure we count in cpu numbers to adjust
    the cpu id lebal width.
    
    And we will try to xalign cpu id label to the left while cpu load
    label to the right.
    
    Will produce a better alignment for system with many cpus.
    
    this close #216

 src/interface.cpp | 5 +++++
 1 file changed, 5 insertions(+)
---
diff --git a/src/interface.cpp b/src/interface.cpp
index 04f95715..5b8ac6b5 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -256,6 +256,10 @@ create_sys_view (GsmApplication *app, GtkBuilder * builder)
         }
         title_text = g_strdup_printf(title_template, label_text);
         label = GTK_LABEL (gtk_label_new (label_text));
+        gtk_label_set_xalign(label, 0.0);
+        if(app->config.num_cpus >=10) {
+            gtk_label_set_width_chars(label, log10(app->config.num_cpus)+1+4);
+        }
         gsm_color_button_set_title(color_picker, title_text);
         g_free(title_text);
         gtk_box_pack_start (temp_hbox, GTK_WIDGET (label), FALSE, FALSE, 6);
@@ -266,6 +270,7 @@ create_sys_view (GsmApplication *app, GtkBuilder * builder)
 
         /* Reserve some space to avoid the layout changing with the values. */
         gtk_label_set_width_chars(cpu_label, 6);
+        gtk_label_set_xalign(cpu_label, 1.0);
         gtk_widget_set_valign (GTK_WIDGET (cpu_label), GTK_ALIGN_CENTER);
         gtk_widget_set_halign (GTK_WIDGET (cpu_label), GTK_ALIGN_START);
         gtk_box_pack_start (temp_hbox, GTK_WIDGET (cpu_label), FALSE, FALSE, 0);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]