[gnome-builder/wip/chergert/headerbar: 28/34] headerbar: add hack for center right/left alignment



commit 28d9a9254cfcb198552e3423f0f05e8911e89705
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jun 21 15:30:58 2016 -0700

    headerbar: add hack for center right/left alignment
    
    To implement our designs propertly would require GtkHeaderBar to support
    hexpand for start/end children. Instead, we can work around it for now
    using a center child and opposite packing.
    
    It's not perfect, since it will require even allocation on left/right, but
    it allows us to move forward for now.

 libide/workbench/ide-workbench-header-bar.c  |   42 +++++++++++++++++++++-----
 libide/workbench/ide-workbench-header-bar.ui |   13 +++++++-
 2 files changed, 45 insertions(+), 10 deletions(-)
---
diff --git a/libide/workbench/ide-workbench-header-bar.c b/libide/workbench/ide-workbench-header-bar.c
index 1f48ff6..ca08781 100644
--- a/libide/workbench/ide-workbench-header-bar.c
+++ b/libide/workbench/ide-workbench-header-bar.c
@@ -29,6 +29,7 @@
 typedef struct
 {
   GtkMenuButton  *menu_button;
+  EggPriorityBox *center_box;
   EggPriorityBox *right_box;
   EggPriorityBox *left_box;
 } IdeWorkbenchHeaderBarPrivate;
@@ -51,6 +52,7 @@ ide_workbench_header_bar_class_init (IdeWorkbenchHeaderBarClass *klass)
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/ui/ide-workbench-header-bar.ui");
+  gtk_widget_class_bind_template_child_private (widget_class, IdeWorkbenchHeaderBar, center_box);
   gtk_widget_class_bind_template_child_private (widget_class, IdeWorkbenchHeaderBar, menu_button);
   gtk_widget_class_bind_template_child_private (widget_class, IdeWorkbenchHeaderBar, left_box);
   gtk_widget_class_bind_template_child_private (widget_class, IdeWorkbenchHeaderBar, right_box);
@@ -95,10 +97,22 @@ ide_workbench_header_bar_insert_left (IdeWorkbenchHeaderBar *self,
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (pack_type == GTK_PACK_START || pack_type == GTK_PACK_END);
 
-  gtk_container_add_with_properties (GTK_CONTAINER (priv->left_box), widget,
-                                     "pack-type", pack_type,
-                                     "priority", priority,
-                                     NULL);
+  /*
+   * NOTE: Because GtkHeaderBar does not currently support hexpand, we
+   *       need to check the pack_type requested and possibly insert it
+   *       into our custom center-child (with opposite pack_type).
+   */
+
+  if (pack_type == GTK_PACK_END)
+    gtk_container_add_with_properties (GTK_CONTAINER (priv->center_box), widget,
+                                       "pack-type", GTK_PACK_START,
+                                       "priority", priority,
+                                       NULL);
+  else
+    gtk_container_add_with_properties (GTK_CONTAINER (priv->left_box), widget,
+                                       "pack-type", pack_type,
+                                       "priority", priority,
+                                       NULL);
 }
 
 void
@@ -113,10 +127,22 @@ ide_workbench_header_bar_insert_right (IdeWorkbenchHeaderBar *self,
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (pack_type == GTK_PACK_START || pack_type == GTK_PACK_END);
 
-  gtk_container_add_with_properties (GTK_CONTAINER (priv->right_box), widget,
-                                     "pack-type", pack_type,
-                                     "priority", priority,
-                                     NULL);
+  /*
+   * NOTE: Because GtkHeaderBar does not currently support hexpand, we
+   *       need to check the pack_type requested and possibly insert it
+   *       into our custom center-child (with opposite pack_type).
+   */
+
+  if (pack_type == GTK_PACK_START)
+    gtk_container_add_with_properties (GTK_CONTAINER (priv->center_box), widget,
+                                       "pack-type", GTK_PACK_END,
+                                       "priority", priority,
+                                       NULL);
+  else
+    gtk_container_add_with_properties (GTK_CONTAINER (priv->right_box), widget,
+                                       "pack-type", pack_type,
+                                       "priority", priority,
+                                       NULL);
 }
 
 static GObject *
diff --git a/libide/workbench/ide-workbench-header-bar.ui b/libide/workbench/ide-workbench-header-bar.ui
index 6f5c324..ee76c1a 100644
--- a/libide/workbench/ide-workbench-header-bar.ui
+++ b/libide/workbench/ide-workbench-header-bar.ui
@@ -15,9 +15,18 @@
       </packing>
     </child>
     <child type="title">
-      <object class="IdeOmniBar" id="bar">
-        <property name="valign">center</property>
+      <object class="EggPriorityBox" id="center_box">
+        <property name="spacing">6</property>
         <property name="visible">true</property>
+        <!--
+          We might need separate children for center-right and center-left
+        -->
+        <child type="center">
+          <object class="IdeOmniBar" id="bar">
+            <property name="valign">center</property>
+            <property name="visible">true</property>
+          </object>
+        </child>
       </object>
     </child>
     <child>


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