[libadwaita/wip/exalm/adaptive-states: 5/7] demo: Port tab bar window to adaptive states




commit 55ddeeb437a7e9502006c65cd00be53f87490d15
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Oct 3 18:51:10 2022 +0400

    demo: Port tab bar window to adaptive states

 demo/pages/tab-view/adw-tab-view-demo-window.c  | 56 -------------------------
 demo/pages/tab-view/adw-tab-view-demo-window.ui | 23 ++++++----
 2 files changed, 16 insertions(+), 63 deletions(-)
---
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 9b67a77a..55d93063 100644
--- a/demo/pages/tab-view/adw-tab-view-demo-window.c
+++ b/demo/pages/tab-view/adw-tab-view-demo-window.c
@@ -14,20 +14,11 @@ struct _AdwTabViewDemoWindow
   GActionMap *tab_action_group;
 
   AdwTabPage *menu_page;
-  gboolean narrow;
   gboolean in_dispose;
 };
 
 G_DEFINE_TYPE (AdwTabViewDemoWindow, adw_tab_view_demo_window, ADW_TYPE_WINDOW)
 
-enum {
-  PROP_0,
-  PROP_NARROW,
-  LAST_PROP,
-};
-
-static GParamSpec *props[LAST_PROP];
-
 static void
 window_new (GSimpleAction *action,
             GVariant      *parameter,
@@ -485,26 +476,6 @@ 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)
 {
@@ -517,23 +488,6 @@ 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)
 {
@@ -541,16 +495,6 @@ 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 11784b0f..98a9ac62 100644
--- a/demo/pages/tab-view/adw-tab-view-demo-window.ui
+++ b/demo/pages/tab-view/adw-tab-view-demo-window.ui
@@ -7,6 +7,7 @@
     <property name="default-width">800</property>
     <property name="default-height">600</property>
     <property name="width-request">360</property>
+    <property name="height-request">150</property>
     <property name="content">
       <object class="AdwTabOverview" id="tab_overview">
         <property name="view">view</property>
@@ -25,23 +26,21 @@
                   </object>
                 </child>
                 <child type="end">
-                  <object class="AdwTabButton">
-                    <property name="visible" bind-source="AdwTabViewDemoWindow" bind-property="narrow" 
bind-flags="sync-create"/>
+                  <object class="AdwTabButton" id="narrow_overview_btn">
+                    <property name="visible">False</property>
                     <property name="view">view</property>
                     <property name="action-name">overview.open</property>
                   </object>
                 </child>
                 <child type="end">
-                  <object class="GtkButton">
-                    <property name="visible" bind-source="AdwTabViewDemoWindow" bind-property="narrow" 
bind-flags="invert-boolean"/>
+                  <object class="GtkButton" id="overview_btn">
                     <property name="icon-name">view-grid-symbolic</property>
                     <property name="tooltip-text" translatable="yes">View Open Tabs</property>
                     <property name="action-name">overview.open</property>
                   </object>
                 </child>
                 <child type="end">
-                  <object class="GtkButton">
-                    <property name="visible" bind-source="AdwTabViewDemoWindow" bind-property="narrow" 
bind-flags="invert-boolean"/>
+                  <object class="GtkButton" id="new_tab_btn">
                     <property name="action-name">win.tab-new</property>
                     <property name="icon-name">tab-new-symbolic</property>
                   </object>
@@ -50,7 +49,6 @@
             </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>
@@ -69,6 +67,17 @@
         </property>
       </object>
     </property>
+    <child>
+      <object class="AdwAdaptiveState">
+        <conditions>
+          <condition type="max-width">600</condition>
+        </conditions>
+        <setter object="narrow_overview_btn" property="visible">True</setter>
+        <setter object="overview_btn" property="visible">False</setter>
+        <setter object="new_tab_btn" property="visible">False</setter>
+        <setter object="tab_bar" property="visible">False</setter>
+      </object>
+    </child>
   </template>
   <menu id="tab_menu">
     <section>


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