[libdazzle: 1/2] dzl-suggestion-row: Move from box to grid layout



commit cd910d71a63fca7120cef61ac0383fe44123536a
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Thu Oct 24 00:39:00 2019 +0000

    dzl-suggestion-row: Move from box to grid layout

 data/themes/shared/shared-suggestions.css |   6 +-
 src/suggestions/dzl-suggestion-row.c      |  55 ++++++++++---
 src/suggestions/dzl-suggestion-row.ui     | 123 +++++++++++++++---------------
 3 files changed, 110 insertions(+), 74 deletions(-)
---
diff --git a/data/themes/shared/shared-suggestions.css b/data/themes/shared/shared-suggestions.css
index 49569ad..76b9ded 100644
--- a/data/themes/shared/shared-suggestions.css
+++ b/data/themes/shared/shared-suggestions.css
@@ -37,7 +37,7 @@ dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > li
   color: @theme_fg_color;
 }
 
-dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row box.vertical 
.subtitle {
+dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row.vertical .subtitle {
   margin-left: 12px;
 }
 
@@ -46,7 +46,7 @@ dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > li
   margin-right: 12px;
 }
 
-dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row > box {
+dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row > grid {
   margin: 4px 8px;
 }
 
@@ -55,7 +55,7 @@ dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > li
   margin-bottom: 3px;
 }
 
-dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row > box > 
image:first-child {
+dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row > grid > 
image:first-child {
   min-width: 16px;
 }
 
diff --git a/src/suggestions/dzl-suggestion-row.c b/src/suggestions/dzl-suggestion-row.c
index be2b021..4d643cf 100644
--- a/src/suggestions/dzl-suggestion-row.c
+++ b/src/suggestions/dzl-suggestion-row.c
@@ -35,7 +35,7 @@ typedef struct
   GtkLabel      *title;
   GtkLabel      *separator;
   GtkLabel      *subtitle;
-  GtkLabel      *box;
+  GtkGrid       *grid;
 } DzlSuggestionRowPrivate;
 
 enum {
@@ -92,6 +92,46 @@ on_notify_icon_cb (DzlSuggestionRow *self,
     }
 }
 
+static void
+dzl_suggestion_set_orientation (DzlSuggestionRowPrivate *priv)
+{
+  const gchar *subtitle;
+
+  subtitle = dzl_suggestion_get_subtitle (priv->suggestion);
+
+  gtk_widget_set_visible (GTK_WIDGET (priv->separator),
+                          priv->orientation != GTK_ORIENTATION_VERTICAL);
+
+  g_object_ref (priv->image);
+  g_object_ref (priv->title);
+  g_object_ref (priv->subtitle);
+
+  gtk_container_remove (GTK_CONTAINER (priv->grid), GTK_WIDGET (priv->image));
+  gtk_container_remove (GTK_CONTAINER (priv->grid), GTK_WIDGET (priv->title));
+  gtk_container_remove (GTK_CONTAINER (priv->grid), GTK_WIDGET (priv->subtitle));
+
+  if (priv->orientation == GTK_ORIENTATION_VERTICAL)
+    {
+      gtk_grid_attach (priv->grid, GTK_WIDGET (priv->image), 0, 0, 1, 1);
+      gtk_grid_attach (priv->grid, GTK_WIDGET (priv->title), 1, 0, 1, 1);
+      gtk_grid_attach (priv->grid, GTK_WIDGET (priv->subtitle), 1, 1, 1, 1);
+
+      gtk_widget_set_visible (GTK_WIDGET (priv->separator), FALSE);
+    }
+  else
+    {
+      gtk_grid_attach (priv->grid, GTK_WIDGET (priv->image), 0, 0, 1, 2);
+      gtk_grid_attach (priv->grid, GTK_WIDGET (priv->title), 1, 0, 1, 1);
+      gtk_grid_attach (priv->grid, GTK_WIDGET (priv->subtitle), 3, 0, 1, 1);
+
+      gtk_widget_set_visible (GTK_WIDGET (priv->separator), !!subtitle);
+    }
+
+  g_object_unref (priv->subtitle);
+  g_object_unref (priv->title);
+  g_object_unref (priv->image);
+}
+
 static void
 dzl_suggestion_row_connect (DzlSuggestionRow *self)
 {
@@ -115,12 +155,7 @@ dzl_suggestion_row_connect (DzlSuggestionRow *self)
   subtitle = dzl_suggestion_get_subtitle (priv->suggestion);
   gtk_label_set_label (priv->subtitle, subtitle);
 
-  if (priv->orientation == GTK_ORIENTATION_VERTICAL)
-    gtk_widget_set_visible (GTK_WIDGET (priv->separator), FALSE);
-  else
-    gtk_widget_set_visible (GTK_WIDGET (priv->separator), !!subtitle);
-
-  gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), priv->orientation);
+  dzl_suggestion_set_orientation (priv);
 }
 
 static void
@@ -181,9 +216,7 @@ dzl_suggestion_row_set_property (GObject      *object,
       if (priv->orientation != g_value_get_enum (value))
         {
           priv->orientation = g_value_get_enum (value);
-          gtk_widget_set_visible (GTK_WIDGET (priv->separator),
-                                  priv->orientation != GTK_ORIENTATION_VERTICAL);
-          gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), priv->orientation);
+          dzl_suggestion_set_orientation (priv);
         }
       break;
 
@@ -224,7 +257,7 @@ dzl_suggestion_row_class_init (DzlSuggestionRowClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, DzlSuggestionRow, title);
   gtk_widget_class_bind_template_child_private (widget_class, DzlSuggestionRow, subtitle);
   gtk_widget_class_bind_template_child_private (widget_class, DzlSuggestionRow, separator);
-  gtk_widget_class_bind_template_child_private (widget_class, DzlSuggestionRow, box);
+  gtk_widget_class_bind_template_child_private (widget_class, DzlSuggestionRow, grid);
 }
 
 static void
diff --git a/src/suggestions/dzl-suggestion-row.ui b/src/suggestions/dzl-suggestion-row.ui
index f976adb..57e24f1 100644
--- a/src/suggestions/dzl-suggestion-row.ui
+++ b/src/suggestions/dzl-suggestion-row.ui
@@ -1,73 +1,76 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
 <interface>
+  <requires lib="gtk+" version="3.0"/>
   <template class="DzlSuggestionRow" parent="DzlListBoxRow">
+    <property name="can_focus">False</property>
     <child>
-      <object class="GtkBox">
-        <property name="orientation">horizontal</property>
-        <property name="visible">true</property>
+      <object class="GtkGrid" id="grid">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
         <child>
           <object class="GtkImage" id="image">
-            <property name="pixel-size">16</property>
-            <property name="hexpand">false</property>
-            <property name="visible">true</property>
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="valign">center</property>
+            <property name="hexpand">False</property>
+            <property name="pixel_size">16</property>
           </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+          </packing>
         </child>
         <child>
-          <object class="GtkBox" id="box">
-            <property name="orientation">horizontal</property>
-            <property name="visible">true</property>
-            <child>
-              <object class="GtkLabel" id="title">
-                <property name="hexpand">false</property>
-                <property name="visible">true</property>
-                <property name="xalign">0.0</property>
-                <property name="use-markup">true</property>
-                <property name="ellipsize">end</property>
-                <style>
-                  <class name="title"/>
-                </style>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="separator">
-                <property name="hexpand">false</property>
-                <property name="label">—</property>
-                <property name="visible">true</property>
-                <style>
-                  <class name="separator"/>
-                  <class name="dim-label"/>
-                </style>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLabel" id="subtitle">
-                <property name="hexpand">true</property>
-                <property name="visible">true</property>
-                <property name="xalign">0.0</property>
-                <property name="use-markup">true</property>
-                <property name="ellipsize">end</property>
-                <style>
-                  <class name="dim-label"/>
-                  <class name="subtitle"/>
-                </style>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
+          <object class="GtkLabel" id="subtitle">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">True</property>
+            <property name="use_markup">True</property>
+            <property name="ellipsize">end</property>
+            <property name="xalign">0</property>
+            <style>
+              <class name="dim-label"/>
+              <class name="subtitle"/>
+            </style>
           </object>
+          <packing>
+            <property name="left_attach">3</property>
+            <property name="top_attach">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="separator">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">False</property>
+            <property name="label">—</property>
+            <style>
+              <class name="separator"/>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left_attach">2</property>
+            <property name="top_attach">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="title">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">False</property>
+            <property name="use_markup">True</property>
+            <property name="ellipsize">end</property>
+            <property name="xalign">0</property>
+            <style>
+              <class name="title"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">0</property>
+          </packing>
         </child>
       </object>
     </child>


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