[libhandy/tabs: 34/62] Handle action bin visibility and add tabs-revealed prop




commit 95211c66b445f5b9ea2fcdfc3a78f40784ccddd5
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Thu Sep 10 00:24:06 2020 +0500

    Handle action bin visibility and add tabs-revealed prop

 src/hdy-tab-bar.c  | 60 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 src/hdy-tab-bar.h  |  3 +++
 src/hdy-tab-bar.ui |  4 ++--
 3 files changed, 60 insertions(+), 7 deletions(-)
---
diff --git a/src/hdy-tab-bar.c b/src/hdy-tab-bar.c
index 3a9500ec..4b475f96 100644
--- a/src/hdy-tab-bar.c
+++ b/src/hdy-tab-bar.c
@@ -59,11 +59,24 @@ enum {
   PROP_START_ACTION_WIDGET,
   PROP_END_ACTION_WIDGET,
   PROP_POSITION,
+  PROP_TABS_REVEALED,
   LAST_PROP
 };
 
 static GParamSpec *props[LAST_PROP];
 
+static void
+set_tabs_revealed (HdyTabBar *self,
+                   gboolean   tabs_revealed)
+{
+  if (tabs_revealed == hdy_tab_bar_get_tabs_revealed (self))
+    return;
+
+  gtk_revealer_set_reveal_child (self->revealer, tabs_revealed);
+
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TABS_REVEALED]);
+}
+
 static void
 update_autohide_cb (HdyTabBar *self)
 {
@@ -71,7 +84,7 @@ update_autohide_cb (HdyTabBar *self)
   gboolean is_dragging;
 
   if (!self->view) {
-    gtk_revealer_set_reveal_child (self->revealer, FALSE);
+    set_tabs_revealed (self, FALSE);
 
     return;
   }
@@ -80,10 +93,7 @@ update_autohide_cb (HdyTabBar *self)
   n_pinned_tabs = hdy_tab_view_get_n_pinned_pages (self->view);
   is_dragging = hdy_tab_view_get_is_dragging (self->view);
 
-  gtk_revealer_set_reveal_child (self->revealer,
-                                 n_tabs > 1 ||
-                                 n_pinned_tabs >= 1 ||
-                                 is_dragging);
+  set_tabs_revealed (self, n_tabs > 1 || n_pinned_tabs >= 1 || is_dragging);
 }
 
 static void
@@ -313,6 +323,10 @@ hdy_tab_bar_get_property (GObject    *object,
     g_value_set_enum (value, hdy_tab_bar_get_position (self));
     break;
 
+  case PROP_TABS_REVEALED:
+    g_value_set_boolean (value, hdy_tab_bar_get_tabs_revealed (self));
+    break;
+
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   }
@@ -422,6 +436,20 @@ hdy_tab_bar_class_init (HdyTabBarClass *klass)
                        HDY_TAB_BAR_POSITION_TOP,
                        G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * HdyTabBar:tabs-revealed:
+   *
+   * TBD
+   *
+   * Since: 1.2
+   */
+  props[PROP_TABS_REVEALED] =
+    g_param_spec_boolean ("tabs-revealed",
+                          _("Tabs Revealed"),
+                          _("Tabs Revealed"),
+                          FALSE,
+                          G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (object_class, LAST_PROP, props);
 
   gtk_widget_class_set_template_from_resource (widget_class,
@@ -638,6 +666,8 @@ hdy_tab_bar_set_start_action_widget (HdyTabBar *self,
   if (widget)
     gtk_container_add (GTK_CONTAINER (self->start_action_bin), widget);
 
+  gtk_widget_set_visible (GTK_WIDGET (self->start_action_bin), widget != NULL);
+
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_START_ACTION_WIDGET]);
 }
 
@@ -688,6 +718,8 @@ hdy_tab_bar_set_end_action_widget (HdyTabBar *self,
   if (widget)
     gtk_container_add (GTK_CONTAINER (self->end_action_bin), widget);
 
+  gtk_widget_set_visible (GTK_WIDGET (self->end_action_bin), widget != NULL);
+
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_END_ACTION_WIDGET]);
 }
 
@@ -754,3 +786,21 @@ hdy_tab_bar_set_position (HdyTabBar         *self,
 
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_POSITION]);
 }
+
+/**
+ * hdy_tab_bar_get_tabs_revealed:
+ * @self: a #HdyTabBar
+ *
+ * TBD
+ *
+ * Returns: TBD
+ *
+ * Since: 1.2
+ */
+gboolean
+hdy_tab_bar_get_tabs_revealed (HdyTabBar *self)
+{
+  g_return_val_if_fail (HDY_IS_TAB_BAR (self), FALSE);
+
+  return gtk_revealer_get_reveal_child (self->revealer);
+}
diff --git a/src/hdy-tab-bar.h b/src/hdy-tab-bar.h
index b1ec9c19..bc539ed1 100644
--- a/src/hdy-tab-bar.h
+++ b/src/hdy-tab-bar.h
@@ -55,4 +55,7 @@ HDY_AVAILABLE_IN_ALL
 void              hdy_tab_bar_set_position (HdyTabBar         *self,
                                             HdyTabBarPosition  position);
 
+HDY_AVAILABLE_IN_ALL
+gboolean hdy_tab_bar_get_tabs_revealed (HdyTabBar *self);
+
 G_END_DECLS
diff --git a/src/hdy-tab-bar.ui b/src/hdy-tab-bar.ui
index f63b2dc6..fa628f41 100644
--- a/src/hdy-tab-bar.ui
+++ b/src/hdy-tab-bar.ui
@@ -18,7 +18,7 @@
             </style>
             <child>
               <object class="GtkEventBox" id="start_action_bin">
-                <property name="visible">True</property>
+                <property name="visible">False</property>
                 <style>
                   <class name="start-action"/>
                 </style>
@@ -61,7 +61,7 @@
             </child>
             <child>
               <object class="GtkEventBox" id="end_action_bin">
-                <property name="visible">True</property>
+                <property name="visible">False</property>
                 <style>
                   <class name="end-action"/>
                 </style>


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