[libdazzle] menu-button: use size-group for button labels



commit 5dc2001fd689ab428be0982f6c68d681570aa8fc
Author: Christian Hergert <chergert redhat com>
Date:   Sun Jul 9 17:33:12 2017 -0700

    menu-button: use size-group for button labels
    
    This allows us to align all the text labels, including that
    of the shortcut label.

 src/menus/dzl-menu-button-item.c    |   31 ++++++++++++++++++++++---------
 src/menus/dzl-menu-button-section.c |   13 +++++++++++++
 src/menus/dzl-menu-button.c         |    3 +++
 src/menus/dzl-menu-button.ui        |    3 +++
 4 files changed, 41 insertions(+), 9 deletions(-)
---
diff --git a/src/menus/dzl-menu-button-item.c b/src/menus/dzl-menu-button-item.c
index fdefca1..62ff751 100644
--- a/src/menus/dzl-menu-button-item.c
+++ b/src/menus/dzl-menu-button-item.c
@@ -20,21 +20,22 @@
 
 #include "menus/dzl-menu-button-item.h"
 #include "shortcuts/dzl-shortcut-label.h"
+#include "shortcuts/dzl-shortcut-simple-label.h"
 #include "util/dzl-gtk.h"
 
 struct _DzlMenuButtonItem
 {
-  GtkCheckButton    parent_instance;
+  GtkCheckButton          parent_instance;
 
-  const gchar      *action_name;
+  const gchar            *action_name;
 
   /* Template references */
-  GtkLabel         *text;
-  DzlShortcutLabel *accel;
-  GtkImage         *image;
+  GtkLabel               *text;
+  DzlShortcutSimpleLabel *accel;
+  GtkImage               *image;
 
-  guint             has_icon : 1;
-  guint             show_image : 1;
+  guint                   has_icon : 1;
+  guint                   show_image : 1;
 };
 
 enum {
@@ -43,6 +44,7 @@ enum {
   PROP_ICON_NAME,
   PROP_SHOW_ACCEL,
   PROP_SHOW_IMAGE,
+  PROP_TEXT_SIZE_GROUP,
   PROP_TEXT,
   N_PROPS,
 };
@@ -128,7 +130,7 @@ dzl_menu_button_item_set_property (GObject      *object,
   switch (prop_id)
     {
     case PROP_ACCEL:
-      dzl_shortcut_label_set_accelerator (self->accel, g_value_get_string (value));
+      dzl_shortcut_simple_label_set_accel (self->accel, g_value_get_string (value));
       break;
 
     case PROP_ICON_NAME:
@@ -150,6 +152,11 @@ dzl_menu_button_item_set_property (GObject      *object,
       gtk_label_set_label (self->text, g_value_get_string (value));
       break;
 
+    case PROP_TEXT_SIZE_GROUP:
+      if (g_value_get_object (value))
+        gtk_size_group_add_widget (g_value_get_object (value), GTK_WIDGET (self->text));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -200,6 +207,11 @@ dzl_menu_button_item_class_init (DzlMenuButtonItemClass *klass)
                          NULL,
                          (G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_TEXT_SIZE_GROUP] =
+    g_param_spec_object ("text-size-group", NULL, NULL,
+                         GTK_TYPE_SIZE_GROUP,
+                         (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, N_PROPS, properties);
 }
 
@@ -255,7 +267,8 @@ dzl_menu_button_item_init (DzlMenuButtonItem *self)
                                      "position", 1,
                                      NULL);
 
-  self->accel = g_object_new (DZL_TYPE_SHORTCUT_LABEL,
+  self->accel = g_object_new (DZL_TYPE_SHORTCUT_SIMPLE_LABEL,
+                              "margin-start", 12,
                               "hexpand", FALSE,
                               NULL);
   gtk_container_add_with_properties (GTK_CONTAINER (box), GTK_WIDGET (self->accel),
diff --git a/src/menus/dzl-menu-button-section.c b/src/menus/dzl-menu-button-section.c
index 80c370b..9278508 100644
--- a/src/menus/dzl-menu-button-section.c
+++ b/src/menus/dzl-menu-button-section.c
@@ -30,6 +30,7 @@ struct _DzlMenuButtonSection
 
   /* Owned references */
   DzlSignalGroup *menu_signals;
+  GtkSizeGroup   *text_size_group;
 
   /* Template references */
   GtkLabel       *label;
@@ -40,6 +41,7 @@ enum {
   PROP_0,
   PROP_LABEL,
   PROP_MODEL,
+  PROP_TEXT_SIZE_GROUP,
   N_PROPS
 };
 
@@ -85,6 +87,7 @@ dzl_menu_button_section_items_changed (DzlMenuButtonSection *self,
                            "show-accel", TRUE,
                            "icon-name", verb_icon_name,
                            "text", label,
+                           "text-size-group", self->text_size_group,
                            "accel", accel,
                            "visible", TRUE,
                            NULL);
@@ -128,6 +131,7 @@ dzl_menu_button_section_destroy (GtkWidget *widget)
   DzlMenuButtonSection *self = (DzlMenuButtonSection *)widget;
 
   g_clear_object (&self->menu_signals);
+  g_clear_object (&self->text_size_group);
 
   GTK_WIDGET_CLASS (dzl_menu_button_section_parent_class)->destroy (widget);
 }
@@ -175,6 +179,10 @@ dzl_menu_button_section_set_property (GObject      *object,
                               !dzl_str_empty0 (g_value_get_string (value)));
       break;
 
+    case PROP_TEXT_SIZE_GROUP:
+      self->text_size_group = g_value_dup_object (value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -200,6 +208,11 @@ dzl_menu_button_section_class_init (DzlMenuButtonSectionClass *klass)
     g_param_spec_string ("label", NULL, NULL, NULL,
                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_TEXT_SIZE_GROUP] =
+    g_param_spec_object ("text-size-group", NULL, NULL,
+                         GTK_TYPE_SIZE_GROUP,
+                         (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
   g_object_class_install_properties (object_class, N_PROPS, properties);
 
   gtk_widget_class_set_css_name (widget_class, "dzlmenubuttonsection");
diff --git a/src/menus/dzl-menu-button.c b/src/menus/dzl-menu-button.c
index 138e864..6912fb5 100644
--- a/src/menus/dzl-menu-button.c
+++ b/src/menus/dzl-menu-button.c
@@ -36,6 +36,7 @@ typedef struct
   GtkImage       *image;
   GtkImage       *pan_down_image;
   DzlBox         *popover_box;
+  GtkSizeGroup   *text_size_group;
 
   guint           show_accels : 1;
   guint           show_icons : 1;
@@ -107,6 +108,7 @@ dzl_menu_button_add_linked_model (DzlMenuButton *self,
   section = g_object_new (DZL_TYPE_MENU_BUTTON_SECTION,
                           "label", label,
                           "model", model,
+                          "text-size-group", priv->text_size_group,
                           "visible", TRUE,
                           NULL);
   dzl_box_insert (priv->popover_box, GTK_WIDGET (section), position);
@@ -352,6 +354,7 @@ dzl_menu_button_class_init (DzlMenuButtonClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, DzlMenuButton, pan_down_image);
   gtk_widget_class_bind_template_child_private (widget_class, DzlMenuButton, popover);
   gtk_widget_class_bind_template_child_private (widget_class, DzlMenuButton, popover_box);
+  gtk_widget_class_bind_template_child_private (widget_class, DzlMenuButton, text_size_group);
 }
 
 static void
diff --git a/src/menus/dzl-menu-button.ui b/src/menus/dzl-menu-button.ui
index f28ce92..a159ff5 100644
--- a/src/menus/dzl-menu-button.ui
+++ b/src/menus/dzl-menu-button.ui
@@ -35,4 +35,7 @@
       </object>
     </child>
   </template>
+  <object class="GtkSizeGroup" id="text_size_group">
+    <property name="mode">horizontal</property>
+  </object>
 </interface>


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