[libhandy/tabs: 46/62] Autohide




commit ef2acf8b9340c719a952689249b326533bd49b81
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Thu Sep 10 23:30:14 2020 +0500

    Autohide

 src/hdy-tab-bar.c                  | 98 ++++++++++++++++++++++++++++++++++++--
 src/hdy-tab-bar.h                  | 11 ++---
 src/hdy-tab-bar.ui                 |  3 --
 src/hdy-tab-view.c                 |  3 +-
 src/themes/Adwaita-dark.css        |  6 +--
 src/themes/Adwaita.css             |  6 +--
 src/themes/HighContrast.css        |  6 +--
 src/themes/HighContrastInverse.css |  6 +--
 src/themes/_Adwaita-base.scss      | 11 +----
 9 files changed, 103 insertions(+), 47 deletions(-)
---
diff --git a/src/hdy-tab-bar.c b/src/hdy-tab-bar.c
index 3dd2d0ce..33dc5599 100644
--- a/src/hdy-tab-bar.c
+++ b/src/hdy-tab-bar.c
@@ -12,11 +12,16 @@
 
 /**
  * SECTION:hdy-tab-bar
- * @short_description: TBD
+ * @short_description: A tab bar for #HdyTabView
  * @title: HdyTabBar
  * @See_also: #HdyTabView
  *
- * TBD
+ * The #HdyTabBar widget is a tab bar that can be used with conjunction with
+ * #HdyTabView.
+ *
+ * # CSS nodes
+ *
+ * #HdyKeypad has a single CSS node with name keypad.
  *
  * Since: 1.2
  */
@@ -34,6 +39,7 @@ struct _HdyTabBar
   GtkBin *end_action_bin;
 
   HdyTabView *view;
+  gboolean autohide;
 };
 
 static void hdy_tab_bar_buildable_init (GtkBuildableIface *iface);
@@ -47,6 +53,7 @@ enum {
   PROP_VIEW,
   PROP_START_ACTION_WIDGET,
   PROP_END_ACTION_WIDGET,
+  PROP_AUTOHIDE,
   PROP_TABS_REVEALED,
   LAST_PROP
 };
@@ -77,6 +84,12 @@ update_autohide_cb (HdyTabBar *self)
     return;
   }
 
+  if (!self->autohide) {
+    set_tabs_revealed (self, TRUE);
+
+    return;
+  }
+
   n_tabs = hdy_tab_view_get_n_pages (self->view);
   n_pinned_tabs = hdy_tab_view_get_n_pinned_pages (self->view);
   is_transferring_tab = hdy_tab_view_get_is_transferring_tab (self->view);
@@ -322,6 +335,10 @@ hdy_tab_bar_get_property (GObject    *object,
     g_value_set_object (value, hdy_tab_bar_get_end_action_widget (self));
     break;
 
+  case PROP_AUTOHIDE:
+    g_value_set_boolean (value, hdy_tab_bar_get_autohide (self));
+    break;
+
   case PROP_TABS_REVEALED:
     g_value_set_boolean (value, hdy_tab_bar_get_tabs_revealed (self));
     break;
@@ -352,6 +369,9 @@ hdy_tab_bar_set_property (GObject      *object,
     hdy_tab_bar_set_end_action_widget (self, g_value_get_object (value));
     break;
 
+  case PROP_AUTOHIDE:
+    hdy_tab_bar_set_autohide (self, g_value_get_boolean (value));
+    break;
   default:
     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   }
@@ -416,13 +436,31 @@ hdy_tab_bar_class_init (HdyTabBarClass *klass)
                          GTK_TYPE_WIDGET,
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * HdyTabBar:autohide:
+   *
+   * Whether the tabs automatically hide.
+   *
+   * If set to %TRUE, the tab bar disappears when the associated #HdyTabView
+   * has 0 or 1 tab, no pinned tabs, and no tab is being transferred.
+   *
+   * See #HdyTabBar:tabs-revealed.
+   *
+   * Since: 1.2
+   */
+  props[PROP_AUTOHIDE] =
+    g_param_spec_boolean ("autohide",
+                          _("Autohide"),
+                          _("Whether the tabs automatically hide"),
+                          TRUE,
+                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
   /**
    * HdyTabBar:tabs-revealed:
    *
    * Whether the tabs are currently revealed.
    *
-   * TODO have policies and then we can link to the policy prop here and describe
-   * the specific behavior there
+   * See HdyTabBar:autohide.
    *
    * Since: 1.2
    */
@@ -457,6 +495,8 @@ hdy_tab_bar_init (HdyTabBar *self)
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  self->autohide = TRUE;
+
   hdy_tab_box_set_adjustment (self->scroll_box,
                               gtk_scrolled_window_get_hadjustment (self->scrolled_window));
 
@@ -704,6 +744,56 @@ hdy_tab_bar_set_end_action_widget (HdyTabBar *self,
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_END_ACTION_WIDGET]);
 }
 
+/**
+ * hdy_tab_bar_get_autohide:
+ * @self: a #HdyTabBar
+ *
+ * Gets whether the tabs automatically hide, see hdy_tab_bar_set_autohide().
+ *
+ * Returns: whether the tabs automatically hide
+ *
+ * Since: 1.2
+ */
+gboolean
+hdy_tab_bar_get_autohide (HdyTabBar *self)
+{
+  g_return_val_if_fail (HDY_IS_TAB_BAR (self), FALSE);
+
+  return self->autohide;
+}
+
+/**
+ * hdy_tab_bar_set_autohide:
+ * @self: a #HdyTabBar
+ * @autohide: whether the tabs automatically hide
+ *
+ * Sets whether the tabs automatically hide.
+ *
+ * If @autohide is %TRUE, the tab bar disappears when the associated #HdyTabView
+ * has 0 or 1 tab, no pinned tabs, and no tab is being transferred.
+ *
+ * See #HdyTabBar:tabs-revealed.
+ *
+ * Since: 1.2
+ */
+void
+hdy_tab_bar_set_autohide (HdyTabBar *self,
+                          gboolean   autohide)
+{
+  g_return_if_fail (HDY_IS_TAB_BAR (self));
+
+  autohide = !!autohide;
+
+  if (autohide == self->autohide)
+    return;
+
+  self->autohide = autohide;
+
+  update_autohide_cb (self);
+
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_AUTOHIDE]);
+}
+
 /**
  * hdy_tab_bar_get_tabs_revealed:
  * @self: a #HdyTabBar
diff --git a/src/hdy-tab-bar.h b/src/hdy-tab-bar.h
index bc539ed1..97da8e7d 100644
--- a/src/hdy-tab-bar.h
+++ b/src/hdy-tab-bar.h
@@ -23,11 +23,6 @@ G_BEGIN_DECLS
 HDY_AVAILABLE_IN_ALL
 G_DECLARE_FINAL_TYPE (HdyTabBar, hdy_tab_bar, HDY, TAB_BAR, GtkBin)
 
-typedef enum {
-  HDY_TAB_BAR_POSITION_TOP,
-  HDY_TAB_BAR_POSITION_BOTTOM,
-} HdyTabBarPosition;
-
 HDY_AVAILABLE_IN_ALL
 HdyTabBar *hdy_tab_bar_new (void);
 
@@ -50,10 +45,10 @@ void       hdy_tab_bar_set_end_action_widget (HdyTabBar *self,
                                               GtkWidget *widget);
 
 HDY_AVAILABLE_IN_ALL
-HdyTabBarPosition hdy_tab_bar_get_position (HdyTabBar *self);
+gboolean hdy_tab_bar_get_autohide (HdyTabBar *self);
 HDY_AVAILABLE_IN_ALL
-void              hdy_tab_bar_set_position (HdyTabBar         *self,
-                                            HdyTabBarPosition  position);
+void     hdy_tab_bar_set_autohide (HdyTabBar *self,
+                                   gboolean   autohide);
 
 HDY_AVAILABLE_IN_ALL
 gboolean hdy_tab_bar_get_tabs_revealed (HdyTabBar *self);
diff --git a/src/hdy-tab-bar.ui b/src/hdy-tab-bar.ui
index fa628f41..deef9b45 100644
--- a/src/hdy-tab-bar.ui
+++ b/src/hdy-tab-bar.ui
@@ -2,9 +2,6 @@
 <interface>
   <requires lib="gtk+" version="3.24"/>
   <template class="HdyTabBar" parent="GtkBin">
-    <style>
-      <class name="top"/>
-    </style>
     <child>
       <object class="GtkRevealer" id="revealer">
         <property name="visible">True</property>
diff --git a/src/hdy-tab-view.c b/src/hdy-tab-view.c
index 2357fdc3..74abc8a6 100644
--- a/src/hdy-tab-view.c
+++ b/src/hdy-tab-view.c
@@ -2712,9 +2712,8 @@ hdy_tab_view_transfer_page (HdyTabView *self,
 
   pinned = hdy_tab_page_get_pinned (page);
 
-  g_return_if_fail (!pinned || position < other_view->n_pinned_pages);
+  g_return_if_fail (!pinned || position <= other_view->n_pinned_pages);
   g_return_if_fail (pinned || position >= other_view->n_pinned_pages);
-  g_return_if_fail (pinned || position < other_view->n_pages);
 
   hdy_tab_view_detach_page (self, page);
   hdy_tab_view_attach_page (other_view, page, position);
diff --git a/src/themes/Adwaita-dark.css b/src/themes/Adwaita-dark.css
index eebfa90f..a930991a 100644
--- a/src/themes/Adwaita-dark.css
+++ b/src/themes/Adwaita-dark.css
@@ -199,14 +199,10 @@ window.csd.unified:not(.solid-csd):not(.fullscreen) > decoration-overlay { box-s
 
window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized),
 
window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized)
decoration, 
window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized)
decoration-overlay { border-radius: 8px; }
 
 /* FIXME this should be inlined after we finalize the colors */
-tabbar .box { min-height: 38px; background: #161616; border-color: #070707; border-style: solid; }
+tabbar .box { min-height: 38px; background: #161616; border-bottom: 1px solid #070707; }
 
 tabbar .box:backdrop { background-color: #262626; border-color: #202020; }
 
-tabbar.top .box { border-bottom-width: 1px; }
-
-tabbar.bottom .box { border-top-width: 1px; }
-
 tabbar tabbox.pinned:dir(ltr) { padding-right: 1px; box-shadow: inset -1px 0 #070707; }
 
 tabbar tabbox.pinned:dir(ltr):backdrop { box-shadow: inset -1px 0 #202020; }
diff --git a/src/themes/Adwaita.css b/src/themes/Adwaita.css
index 89b2af49..f3dd2c7e 100644
--- a/src/themes/Adwaita.css
+++ b/src/themes/Adwaita.css
@@ -199,14 +199,10 @@ window.csd.unified:not(.solid-csd):not(.fullscreen) > decoration-overlay { box-s
 
window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized),
 
window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized)
decoration, 
window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized)
decoration-overlay { border-radius: 8px; }
 
 /* FIXME this should be inlined after we finalize the colors */
-tabbar .box { min-height: 38px; background: #d4cfca; border-color: #bfb8b1; border-style: solid; }
+tabbar .box { min-height: 38px; background: #d4cfca; border-bottom: 1px solid #bfb8b1; }
 
 tabbar .box:backdrop { background-color: #e1dedb; border-color: #d5d0cc; }
 
-tabbar.top .box { border-bottom-width: 1px; }
-
-tabbar.bottom .box { border-top-width: 1px; }
-
 tabbar tabbox.pinned:dir(ltr) { padding-right: 1px; box-shadow: inset -1px 0 #bfb8b1; }
 
 tabbar tabbox.pinned:dir(ltr):backdrop { box-shadow: inset -1px 0 #d5d0cc; }
diff --git a/src/themes/HighContrast.css b/src/themes/HighContrast.css
index 63e109ea..e46bfa01 100644
--- a/src/themes/HighContrast.css
+++ b/src/themes/HighContrast.css
@@ -199,14 +199,10 @@ window.csd.unified:not(.solid-csd):not(.fullscreen) > decoration-overlay { box-s
 
window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized),
 
window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized)
decoration, 
window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized)
decoration-overlay { border-radius: 8px; }
 
 /* FIXME this should be inlined after we finalize the colors */
-tabbar .box { min-height: 38px; background: #dad6d2; border-color: #6e645a; border-style: solid; }
+tabbar .box { min-height: 38px; background: #dad6d2; border-bottom: 1px solid #6e645a; }
 
 tabbar .box:backdrop { background-color: #e8e6e3; border-color: #d5d0cc; }
 
-tabbar.top .box { border-bottom-width: 1px; }
-
-tabbar.bottom .box { border-top-width: 1px; }
-
 tabbar tabbox.pinned:dir(ltr) { padding-right: 1px; box-shadow: inset -1px 0 #6e645a; }
 
 tabbar tabbox.pinned:dir(ltr):backdrop { box-shadow: inset -1px 0 #d5d0cc; }
diff --git a/src/themes/HighContrastInverse.css b/src/themes/HighContrastInverse.css
index 73450c23..61ab1ecf 100644
--- a/src/themes/HighContrastInverse.css
+++ b/src/themes/HighContrastInverse.css
@@ -199,14 +199,10 @@ window.csd.unified:not(.solid-csd):not(.fullscreen) > decoration-overlay { box-s
 
window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized),
 
window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized)
decoration, 
window.csd.unified:not(.solid-csd):not(.fullscreen):not(.tiled):not(.tiled-top):not(.tiled-bottom):not(.tiled-left):not(.tiled-right):not(.maximized)
decoration-overlay { border-radius: 8px; }
 
 /* FIXME this should be inlined after we finalize the colors */
-tabbar .box { min-height: 38px; background: #111111; border-color: #4e4e4e; border-style: solid; }
+tabbar .box { min-height: 38px; background: #111111; border-bottom: 1px solid #4e4e4e; }
 
 tabbar .box:backdrop { background-color: #202020; border-color: #202020; }
 
-tabbar.top .box { border-bottom-width: 1px; }
-
-tabbar.bottom .box { border-top-width: 1px; }
-
 tabbar tabbox.pinned:dir(ltr) { padding-right: 1px; box-shadow: inset -1px 0 #4e4e4e; }
 
 tabbar tabbox.pinned:dir(ltr):backdrop { box-shadow: inset -1px 0 #202020; }
diff --git a/src/themes/_Adwaita-base.scss b/src/themes/_Adwaita-base.scss
index 0e88ffb8..0da78e74 100644
--- a/src/themes/_Adwaita-base.scss
+++ b/src/themes/_Adwaita-base.scss
@@ -406,8 +406,7 @@ tabbar {
   .box {
     min-height: 38px;
     background: $tab_bar_bg;
-    border-color: $alt_borders_color;
-    border-style: solid;
+    border-bottom: 1px solid $alt_borders_color;
 
     &:backdrop {
       background-color: $tab_bar_bg_backdrop;
@@ -415,14 +414,6 @@ tabbar {
     }
   }
 
-  &.top .box {
-    border-bottom-width: 1px;
-  }
-
-  &.bottom .box {
-    border-top-width: 1px;
-  }
-
   tabbox.pinned {
     &:dir(ltr) {
       padding-right: 1px;


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