[gtk+/gtk-3-18] placesview: vertically align path labels



commit 9a0d2366092a35594f07c50b483c697864066bdd
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Oct 29 10:14:57 2015 -0200

    placesview: vertically align path labels
    
    The current situation is somewhat sad, with the path
    label totally misaligned throughout the rows.
    
    This is fixed by using a size group for the path labels,
    so they all have the same allocated size (with the max
    of 15 chars). Also, instead of hiding the eject button,
    set it child-invisible, so it is hidden and yet it's size
    is allocated by GtkBox.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757303

 gtk/gtkplacesview.c           |    6 ++++++
 gtk/gtkplacesviewrow.c        |   18 +++++++++++++++++-
 gtk/gtkplacesviewrowprivate.h |    4 ++++
 gtk/ui/gtkplacesviewrow.ui    |    4 ++--
 4 files changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c
index 7c70e98..77dd938 100644
--- a/gtk/gtkplacesview.c
+++ b/gtk/gtkplacesview.c
@@ -72,6 +72,8 @@ struct _GtkPlacesViewPrivate
   GtkWidget                     *network_placeholder;
   GtkWidget                     *network_placeholder_label;
 
+  GtkSizeGroup                  *path_size_group;
+
   GtkEntryCompletion            *address_entry_completion;
   GtkListStore                  *completion_store;
 
@@ -406,6 +408,7 @@ gtk_places_view_finalize (GObject *object)
   g_clear_object (&priv->volume_monitor);
   g_clear_object (&priv->cancellable);
   g_clear_object (&priv->networks_fetching_cancellable);
+  g_clear_object (&priv->path_size_group);
 
   G_OBJECT_CLASS (gtk_places_view_parent_class)->finalize (object);
 }
@@ -674,6 +677,8 @@ insert_row (GtkPlacesView *view,
                     G_CALLBACK (on_eject_button_clicked),
                     row);
 
+  gtk_places_view_row_set_path_size_group (GTK_PLACES_VIEW_ROW (row), priv->path_size_group);
+
   gtk_container_add (GTK_CONTAINER (priv->listbox), row);
 }
 
@@ -2254,6 +2259,7 @@ gtk_places_view_init (GtkPlacesView *self)
 
   priv->volume_monitor = g_volume_monitor_get ();
   priv->open_flags = GTK_PLACES_OPEN_NORMAL;
+  priv->path_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
   gtk_widget_init_template (GTK_WIDGET (self));
 }
diff --git a/gtk/gtkplacesviewrow.c b/gtk/gtkplacesviewrow.c
index 8c1d1cb..3466053 100644
--- a/gtk/gtkplacesviewrow.c
+++ b/gtk/gtkplacesviewrow.c
@@ -150,7 +150,15 @@ gtk_places_view_row_set_property (GObject      *object,
 
     case PROP_MOUNT:
       g_set_object (&self->mount, g_value_get_object (value));
-      gtk_widget_set_visible (GTK_WIDGET (self->eject_button), self->mount != NULL);
+
+      /*
+       * When we hide the eject button, no size is allocated for it. Since
+       * we want to have alignment between rows, it needs an empty space
+       * when the eject button is not available. So, call then
+       * gtk_widget_set_child_visible(), which makes the button allocate the
+       * size but it stays hidden when needed.
+       */
+      gtk_widget_set_child_visible (GTK_WIDGET (self->eject_button), self->mount != NULL);
       break;
 
     case PROP_FILE:
@@ -323,3 +331,11 @@ gtk_places_view_row_set_is_network (GtkPlacesViewRow *row,
       gtk_widget_set_tooltip_text (GTK_WIDGET (row->eject_button), is_network ? _("Disconnect") : 
_("Unmount"));
     }
 }
+
+void
+gtk_places_view_row_set_path_size_group (GtkPlacesViewRow *row,
+                                         GtkSizeGroup     *group)
+{
+  if (group)
+    gtk_size_group_add_widget (group, GTK_WIDGET (row->path_label));
+}
diff --git a/gtk/gtkplacesviewrowprivate.h b/gtk/gtkplacesviewrowprivate.h
index 3c46d5d..2d5da7e 100644
--- a/gtk/gtkplacesviewrowprivate.h
+++ b/gtk/gtkplacesviewrowprivate.h
@@ -24,6 +24,7 @@
 #endif
 
 #include "gtkwidget.h"
+#include "gtksizegroup.h"
 #include "gtklistbox.h"
 
 G_BEGIN_DECLS
@@ -53,6 +54,9 @@ gboolean           gtk_places_view_row_get_is_network            (GtkPlacesViewR
 void               gtk_places_view_row_set_is_network            (GtkPlacesViewRow   *row,
                                                                   gboolean            is_network);
 
+void               gtk_places_view_row_set_path_size_group       (GtkPlacesViewRow   *row,
+                                                                  GtkSizeGroup       *group);
+
 G_END_DECLS
 
 #endif /* GTK_PLACES_VIEW_ROW_H */
diff --git a/gtk/ui/gtkplacesviewrow.ui b/gtk/ui/gtkplacesviewrow.ui
index 2d06d0d..9ace5b9 100644
--- a/gtk/ui/gtkplacesviewrow.ui
+++ b/gtk/ui/gtkplacesviewrow.ui
@@ -40,8 +40,7 @@
                 <property name="visible">1</property>
                 <property name="justify">right</property>
                 <property name="ellipsize">middle</property>
-                <property name="xalign">1</property>
-                <property name="width_chars">15</property>
+                <property name="xalign">0</property>
                 <property name="max_width_chars">15</property>
                 <style>
                   <class name="dim-label"/>
@@ -53,6 +52,7 @@
             </child>
             <child>
               <object class="GtkButton" id="eject_button">
+                <property name="visible">True</property>
                 <property name="halign">end</property>
                 <property name="valign">center</property>
                 <property name="tooltip-text" translatable="yes">Unmount</property>


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