[libadwaita/wip/exalm/tab-overview: 12/16] demo: Hide tab bar when the tab window is narrow




commit b41f299ff062d7162c6bc86e0dfc0e437fa80ee5
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Sep 6 17:55:24 2022 +0400

    demo: Hide tab bar when the tab window is narrow

 demo/pages/tab-view/adw-tab-view-demo-window.c  | 56 +++++++++++++++++++++++++
 demo/pages/tab-view/adw-tab-view-demo-window.ui |  2 +
 2 files changed, 58 insertions(+)
---
diff --git a/demo/pages/tab-view/adw-tab-view-demo-window.c b/demo/pages/tab-view/adw-tab-view-demo-window.c
index 4462e535..65d15861 100644
--- a/demo/pages/tab-view/adw-tab-view-demo-window.c
+++ b/demo/pages/tab-view/adw-tab-view-demo-window.c
@@ -11,10 +11,19 @@ struct _AdwTabViewDemoWindow
   GActionMap *tab_action_group;
 
   AdwTabPage *menu_page;
+  gboolean narrow;
 };
 
 G_DEFINE_TYPE (AdwTabViewDemoWindow, adw_tab_view_demo_window, ADW_TYPE_WINDOW)
 
+enum {
+  PROP_0,
+  PROP_NARROW,
+  LAST_PROP,
+};
+
+static GParamSpec *props[LAST_PROP];
+
 char **icon_names = NULL;
 gsize n_icon_names = 0;
 
@@ -497,6 +506,26 @@ extra_drag_drop_cb (AdwTabViewDemoWindow *self,
   return GDK_EVENT_STOP;
 }
 
+static void
+adw_tab_view_demo_window_size_allocate (GtkWidget *widget,
+                                        int        width,
+                                        int        height,
+                                        int        baseline)
+{
+  AdwTabViewDemoWindow *self = ADW_TAB_VIEW_DEMO_WINDOW (widget);
+  gboolean narrow = width < 600;
+
+  if (self->narrow != narrow) {
+    self->narrow = narrow;
+    g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NARROW]);
+  }
+
+  GTK_WIDGET_CLASS (adw_tab_view_demo_window_parent_class)->size_allocate (widget,
+                                                                           width,
+                                                                           height,
+                                                                           baseline);
+}
+
 static void
 adw_tab_view_demo_window_dispose (GObject *object)
 {
@@ -507,6 +536,23 @@ adw_tab_view_demo_window_dispose (GObject *object)
   G_OBJECT_CLASS (adw_tab_view_demo_window_parent_class)->dispose (object);
 }
 
+static void
+adw_tab_view_demo_window_get_property (GObject    *object,
+                                       guint       prop_id,
+                                       GValue     *value,
+                                       GParamSpec *pspec)
+{
+  AdwTabViewDemoWindow *self = ADW_TAB_VIEW_DEMO_WINDOW (object);
+
+  switch (prop_id) {
+  case PROP_NARROW:
+    g_value_set_boolean (value, self->narrow);
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+  }
+}
+
 static void
 adw_tab_view_demo_window_class_init (AdwTabViewDemoWindowClass *klass)
 {
@@ -514,6 +560,16 @@ adw_tab_view_demo_window_class_init (AdwTabViewDemoWindowClass *klass)
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   object_class->dispose = adw_tab_view_demo_window_dispose;
+  object_class->get_property = adw_tab_view_demo_window_get_property;
+
+  widget_class->size_allocate = adw_tab_view_demo_window_size_allocate;
+
+  props[PROP_NARROW] =
+    g_param_spec_boolean ("narrow", NULL, NULL,
+                          FALSE,
+                          G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, LAST_PROP, props);
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Adwaita1/Demo/ui/pages/tab-view/adw-tab-view-demo-window.ui");
   gtk_widget_class_bind_template_child (widget_class, AdwTabViewDemoWindow, view);
diff --git a/demo/pages/tab-view/adw-tab-view-demo-window.ui b/demo/pages/tab-view/adw-tab-view-demo-window.ui
index 8567e39a..43812a0c 100644
--- a/demo/pages/tab-view/adw-tab-view-demo-window.ui
+++ b/demo/pages/tab-view/adw-tab-view-demo-window.ui
@@ -19,6 +19,7 @@
             </child>
             <child type="end">
               <object class="GtkButton">
+                <property name="visible" bind-source="AdwTabViewDemoWindow" bind-property="narrow" 
bind-flags="invert-boolean"/>
                 <property name="action-name">win.tab-new</property>
                 <property name="icon-name">tab-new-symbolic</property>
               </object>
@@ -27,6 +28,7 @@
         </child>
         <child>
           <object class="AdwTabBar" id="tab_bar">
+            <property name="visible" bind-source="AdwTabViewDemoWindow" bind-property="narrow" 
bind-flags="invert-boolean"/>
             <property name="view">view</property>
             <signal name="extra-drag-drop" handler="extra_drag_drop_cb" swapped="true"/>
           </object>


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