[libdazzle] dzl-suggestion: Add compact mode



commit 3b3578db9183e6459d8fa8833cfb1cef0e8ee8a3
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Thu Apr 25 21:45:52 2019 +0200

    dzl-suggestion: Add compact mode
    
    If compact mode for a DzlSuggestionEntry is activated the layout for title/subtitle changes from 
horizontal to vertical.
    This improves readability for small screen factors.

 data/themes/shared/shared-suggestions.css |  4 ++
 src/suggestions/dzl-suggestion-entry.c    |  9 ++++
 src/suggestions/dzl-suggestion-entry.h    |  4 ++
 src/suggestions/dzl-suggestion-popover.c  |  9 ++++
 src/suggestions/dzl-suggestion-popover.h  |  3 ++
 src/suggestions/dzl-suggestion-row.c      | 42 +++++++++++++--
 src/suggestions/dzl-suggestion-row.ui     | 85 +++++++++++++++++++------------
 7 files changed, 121 insertions(+), 35 deletions(-)
---
diff --git a/data/themes/shared/shared-suggestions.css b/data/themes/shared/shared-suggestions.css
index edc47e8..49569ad 100644
--- a/data/themes/shared/shared-suggestions.css
+++ b/data/themes/shared/shared-suggestions.css
@@ -37,6 +37,10 @@ dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > li
   color: @theme_fg_color;
 }
 
+dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row box.vertical 
.subtitle {
+  margin-left: 12px;
+}
+
 dzlsuggestionpopover > revealer > box > elastic > scrolledwindow > viewport > list > row .separator {
   margin-left: 12px;
   margin-right: 12px;
diff --git a/src/suggestions/dzl-suggestion-entry.c b/src/suggestions/dzl-suggestion-entry.c
index 62034cf..d1b1f90 100644
--- a/src/suggestions/dzl-suggestion-entry.c
+++ b/src/suggestions/dzl-suggestion-entry.c
@@ -1050,3 +1050,12 @@ dzl_suggestion_entry_get_popover (DzlSuggestionEntry *self)
 
   return GTK_WIDGET (priv->popover);
 }
+
+void
+dzl_suggestion_entry_set_compact (DzlSuggestionEntry *self,
+                                  gboolean            compact)
+{
+  DzlSuggestionEntryPrivate *priv = dzl_suggestion_entry_get_instance_private (self);
+
+  dzl_suggestion_popover_set_compact (priv->popover, compact);
+}
diff --git a/src/suggestions/dzl-suggestion-entry.h b/src/suggestions/dzl-suggestion-entry.h
index a6d1f76..24f5f20 100644
--- a/src/suggestions/dzl-suggestion-entry.h
+++ b/src/suggestions/dzl-suggestion-entry.h
@@ -108,6 +108,10 @@ void dzl_suggestion_entry_window_position_func  (DzlSuggestionEntry *self,
                                                  gboolean           *is_absolute,
                                                  gpointer            user_data);
 
+DZL_AVAILABLE_IN_3_34
+void dzl_suggestion_entry_set_compact           (DzlSuggestionEntry *self,
+                                                 gboolean            compact);
+
 G_END_DECLS
 
 #endif /* DZL_SUGGESTION_ENTRY_H */
diff --git a/src/suggestions/dzl-suggestion-popover.c b/src/suggestions/dzl-suggestion-popover.c
index b8988c8..2a58455 100644
--- a/src/suggestions/dzl-suggestion-popover.c
+++ b/src/suggestions/dzl-suggestion-popover.c
@@ -75,6 +75,7 @@ struct _DzlSuggestionPopover
   guint               popup_requested : 1;
   guint               entry_focused : 1;
   guint               has_grab : 1;
+  guint               compact : 1;
 };
 
 enum {
@@ -500,6 +501,7 @@ attach_cb (DzlListBox    *list_box,
   _dzl_suggestion_row_set_ellipsize (DZL_SUGGESTION_ROW (row),
                                      self->title_ellipsize,
                                      self->subtitle_ellipsize);
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (row), self->compact ? GTK_ORIENTATION_VERTICAL : 
GTK_ORIENTATION_HORIZONTAL);
 }
 
 static gboolean
@@ -1340,3 +1342,10 @@ _dzl_suggestion_popover_set_device (DzlSuggestionPopover *self,
       g_set_object (&self->grab_device, device);
     }
 }
+
+void
+dzl_suggestion_popover_set_compact (DzlSuggestionPopover *self,
+                                    gboolean              compact)
+{
+  self->compact = compact;
+}
diff --git a/src/suggestions/dzl-suggestion-popover.h b/src/suggestions/dzl-suggestion-popover.h
index 62591b1..d423899 100644
--- a/src/suggestions/dzl-suggestion-popover.h
+++ b/src/suggestions/dzl-suggestion-popover.h
@@ -58,6 +58,9 @@ void           dzl_suggestion_popover_set_selected      (DzlSuggestionPopover *s
 DZL_AVAILABLE_IN_ALL
 void           dzl_suggestion_popover_activate_selected (DzlSuggestionPopover *self);
 
+void           dzl_suggestion_popover_set_compact       (DzlSuggestionPopover *self,
+                                                         gboolean              compact);
+
 G_END_DECLS
 
 #endif /* DZL_SUGGESTION_POPOVER_H */
diff --git a/src/suggestions/dzl-suggestion-row.c b/src/suggestions/dzl-suggestion-row.c
index 14448cb..264bfb1 100644
--- a/src/suggestions/dzl-suggestion-row.c
+++ b/src/suggestions/dzl-suggestion-row.c
@@ -27,21 +27,28 @@ typedef struct
 {
   DzlSuggestion *suggestion;
 
+  GtkOrientation orientation;
+
   gulong         notify_icon_handler;
 
   GtkImage      *image;
   GtkLabel      *title;
   GtkLabel      *separator;
   GtkLabel      *subtitle;
+  GtkLabel      *box;
 } DzlSuggestionRowPrivate;
 
 enum {
   PROP_0,
   PROP_SUGGESTION,
+  PROP_ORIENTATION,
   N_PROPS
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (DzlSuggestionRow, dzl_suggestion_row, DZL_TYPE_LIST_BOX_ROW)
+G_DEFINE_TYPE_EXTENDED (DzlSuggestionRow, dzl_suggestion_row, DZL_TYPE_LIST_BOX_ROW, 0,
+                        G_ADD_PRIVATE (DzlSuggestionRow)
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
+
 
 static GParamSpec *properties [N_PROPS];
 
@@ -107,7 +114,13 @@ dzl_suggestion_row_connect (DzlSuggestionRow *self)
 
   subtitle = dzl_suggestion_get_subtitle (priv->suggestion);
   gtk_label_set_label (priv->subtitle, subtitle);
-  gtk_widget_set_visible (GTK_WIDGET (priv->separator), !!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);
 }
 
 static void
@@ -132,6 +145,7 @@ dzl_suggestion_row_get_property (GObject    *object,
                                  GParamSpec *pspec)
 {
   DzlSuggestionRow *self = DZL_SUGGESTION_ROW (object);
+  DzlSuggestionRowPrivate *priv = dzl_suggestion_row_get_instance_private (self);
 
   switch (prop_id)
     {
@@ -139,6 +153,10 @@ dzl_suggestion_row_get_property (GObject    *object,
       g_value_set_object (value, dzl_suggestion_row_get_suggestion (self));
       break;
 
+    case PROP_ORIENTATION:
+      g_value_set_enum (value, priv->orientation);
+      break;
+ 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -151,6 +169,7 @@ dzl_suggestion_row_set_property (GObject      *object,
                                  GParamSpec   *pspec)
 {
   DzlSuggestionRow *self = DZL_SUGGESTION_ROW (object);
+  DzlSuggestionRowPrivate *priv = dzl_suggestion_row_get_instance_private (self);
 
   switch (prop_id)
     {
@@ -158,6 +177,14 @@ dzl_suggestion_row_set_property (GObject      *object,
       dzl_suggestion_row_set_suggestion (self, g_value_get_object (value));
       break;
 
+    case PROP_ORIENTATION:
+      priv->orientation = g_value_get_enum (value);
+      if (priv->orientation == GTK_ORIENTATION_VERTICAL)
+        gtk_widget_set_visible (GTK_WIDGET (priv->separator), FALSE);
+
+      gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), priv->orientation);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -180,13 +207,22 @@ dzl_suggestion_row_class_init (DzlSuggestionRowClass *klass)
                          DZL_TYPE_SUGGESTION,
                          (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
 
-  g_object_class_install_properties (object_class, N_PROPS, properties);
+  properties [PROP_ORIENTATION] =
+    g_param_spec_enum ("orientation",
+                       "Orientation",
+                       "Orientation",
+                       GTK_TYPE_ORIENTATION,
+                       GTK_ORIENTATION_VERTICAL,
+                       (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ 
+   g_object_class_install_properties (object_class, N_PROPS, properties);
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/dazzle/ui/dzl-suggestion-row.ui");
   gtk_widget_class_bind_template_child_private (widget_class, DzlSuggestionRow, image);
   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);
 }
 
 static void
diff --git a/src/suggestions/dzl-suggestion-row.ui b/src/suggestions/dzl-suggestion-row.ui
index 5dbe7dc..f976adb 100644
--- a/src/suggestions/dzl-suggestion-row.ui
+++ b/src/suggestions/dzl-suggestion-row.ui
@@ -13,39 +13,60 @@
           </object>
         </child>
         <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>
-        </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>
-        </child>
-        <child>
-          <object class="GtkLabel" id="subtitle">
-            <property name="hexpand">true</property>
+          <object class="GtkBox" id="box">
+            <property name="orientation">horizontal</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>
+            <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>
         </child>
       </object>


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