[libadwaita/wip/exalm/browsing-view: 18/18] demo




commit 5e17fd021fa4890d176dcb3574e881d3a08a7ad2
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Oct 14 19:42:56 2022 +0400

    demo

 .../view-switcher/adw-view-switcher-demo-window.c  |  76 +++++++++++
 .../view-switcher/adw-view-switcher-demo-window.ui | 146 +++++++++++----------
 2 files changed, 155 insertions(+), 67 deletions(-)
---
diff --git a/demo/pages/view-switcher/adw-view-switcher-demo-window.c 
b/demo/pages/view-switcher/adw-view-switcher-demo-window.c
index 1832647e..5958635f 100644
--- a/demo/pages/view-switcher/adw-view-switcher-demo-window.c
+++ b/demo/pages/view-switcher/adw-view-switcher-demo-window.c
@@ -5,22 +5,98 @@
 struct _AdwViewSwitcherDemoWindow
 {
   AdwWindow parent_instance;
+
+  AdwBrowsingView *view;
+  GList *forward_stack;
 };
 
 G_DEFINE_TYPE (AdwViewSwitcherDemoWindow, adw_view_switcher_demo_window, ADW_TYPE_WINDOW)
 
+static void
+update_actions (AdwViewSwitcherDemoWindow *self)
+{
+  AdwBrowsingViewChild *child = adw_browsing_view_get_visible_child (self->view);
+  gboolean has_back = child && adw_browsing_view_get_previous_child (self->view, child);
+
+  gtk_widget_action_set_enabled (GTK_WIDGET (self), "example.back", has_back);
+  gtk_widget_action_set_enabled (GTK_WIDGET (self), "example.forward", !!self->forward_stack);
+}
+
+static void
+pushed_cb (AdwViewSwitcherDemoWindow *self)
+{
+  AdwBrowsingViewChild *child = adw_browsing_view_get_visible_child (self->view);
+
+  if (self->forward_stack) {
+    if (self->forward_stack->data == child)
+      self->forward_stack = g_list_remove (self->forward_stack, child);
+    else
+     g_clear_pointer (&self->forward_stack, g_list_free);
+  }
+
+  update_actions (self);
+}
+
+static void
+popped_cb (AdwViewSwitcherDemoWindow *self,
+           AdwBrowsingViewChild      *child)
+{
+  self->forward_stack = g_list_prepend (self->forward_stack, child);
+
+  update_actions (self);
+}
+
+static AdwBrowsingViewChild *
+get_next_child_cb (AdwViewSwitcherDemoWindow *self)
+{
+  if (self->forward_stack)
+    return self->forward_stack->data;
+
+  return NULL;
+}
+
+static void
+back_cb (AdwViewSwitcherDemoWindow *self)
+{
+  adw_browsing_view_pop (self->view, TRUE);
+}
+
+static void
+forward_cb (AdwViewSwitcherDemoWindow *self)
+{
+  AdwBrowsingViewChild *child;
+
+  g_assert (self->forward_stack);
+
+  child = self->forward_stack->data;
+
+  adw_browsing_view_push (self->view, GTK_WIDGET (child), TRUE);
+}
+
 static void
 adw_view_switcher_demo_window_class_init (AdwViewSwitcherDemoWindowClass *klass)
 {
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Adwaita1/Demo/ui/pages/view-switcher/adw-view-switcher-demo-window.ui");
+  gtk_widget_class_bind_template_child (widget_class, AdwViewSwitcherDemoWindow, view);
+
+  gtk_widget_class_install_action (widget_class, "example.back", NULL,
+                                   (GtkWidgetActionActivateFunc) back_cb);
+  gtk_widget_class_install_action (widget_class, "example.forward", NULL,
+                                   (GtkWidgetActionActivateFunc) forward_cb);
 }
 
 static void
 adw_view_switcher_demo_window_init (AdwViewSwitcherDemoWindow *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
+
+  update_actions (self);
+
+  g_signal_connect_swapped (self->view, "pushed", G_CALLBACK (pushed_cb), self);
+  g_signal_connect_swapped (self->view, "popped", G_CALLBACK (popped_cb), self);
+  g_signal_connect_swapped (self->view, "get-next-child", G_CALLBACK (get_next_child_cb), self);
 }
 
 AdwViewSwitcherDemoWindow *
diff --git a/demo/pages/view-switcher/adw-view-switcher-demo-window.ui 
b/demo/pages/view-switcher/adw-view-switcher-demo-window.ui
index 28164f81..c00c939e 100644
--- a/demo/pages/view-switcher/adw-view-switcher-demo-window.ui
+++ b/demo/pages/view-switcher/adw-view-switcher-demo-window.ui
@@ -11,22 +11,44 @@
     <property name="default-height">600</property>
     <property name="title" translatable="yes">AdwBrowsingView Demo</property>
     <property name="content">
-      <object class="AdwBrowsingView">
+      <object class="GtkBox">
+        <property name="orientation">vertical</property>
         <child>
-          <object class="AdwBrowsingViewChild">
-            <property name="title">Page 1</property>
-            <property name="child-name">page-1</property>
-            <property name="child">
-              <object class="GtkBox">
-                <property name="orientation">vertical</property>
-                <child>
-                  <object class="AdwHeaderBar"/>
-                </child>
-                <child>
+          <object class="AdwHeaderBar">
+            <child>
+              <object class="GtkButton">
+                <property name="icon-name">go-previous-symbolic</property>
+                <property name="action-name">example.back</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkButton">
+                <property name="icon-name">go-next-symbolic</property>
+                <property name="action-name">example.forward</property>
+              </object>
+            </child>
+            <property name="title-widget">
+              <object class="AdwWindowTitle">
+                <binding name="title">
+                  <lookup name="title" type="AdwBrowsingViewChild">
+                    <lookup name="visible-child">view</lookup>
+                  </lookup>
+                </binding>
+              </object>
+            </property>
+          </object>
+        </child>
+        <child>
+          <object class="AdwBrowsingView" id="view">
+            <property name="vexpand">True</property>
+            <child>
+              <object class="AdwBrowsingViewChild">
+                <property name="title">Page 1</property>
+                <property name="child-name">page-1</property>
+                <property name="child">
                   <object class="GtkBox">
                     <property name="orientation">vertical</property>
                     <property name="spacing">12</property>
-                    <property name="vexpand">True</property>
                     <property name="valign">center</property>
                     <property name="halign">center</property>
                     <child>
@@ -58,26 +80,17 @@
                       </object>
                     </child>
                   </object>
-                </child>
+                </property>
               </object>
-            </property>
-          </object>
-        </child>
-        <child>
-          <object class="AdwBrowsingViewChild">
-            <property name="title">Page 2</property>
-            <property name="child-name">page-2</property>
-            <property name="child">
-              <object class="GtkBox">
-                <property name="orientation">vertical</property>
-                <child>
-                  <object class="AdwHeaderBar"/>
-                </child>
-                <child>
+            </child>
+            <child>
+              <object class="AdwBrowsingViewChild">
+                <property name="title">Page 2</property>
+                <property name="child-name">page-2</property>
+                <property name="child">
                   <object class="GtkBox">
                     <property name="orientation">vertical</property>
                     <property name="spacing">12</property>
-                    <property name="vexpand">True</property>
                     <property name="valign">center</property>
                     <property name="halign">center</property>
                     <child>
@@ -99,49 +112,48 @@
                       </object>
                     </child>
                   </object>
-                </child>
+                </property>
               </object>
-            </property>
-          </object>
-        </child>
-        <child>
-          <object class="AdwBrowsingViewChild">
-            <property name="title">Page 3</property>
-            <property name="child-name">page-3</property>
-            <property name="child">
-              <object class="GtkBox">
-                <property name="orientation">vertical</property>
-                <child>
-                  <object class="AdwHeaderBar"/>
-                </child>
-                <child>
-                  <object class="GtkLabel">
-                    <property name="vexpand">True</property>
-                    <property name="label" translatable="yes">Page 3</property>
-                    <style>
-                      <class name="title-1"/>
-                    </style>
+            </child>
+            <child>
+              <object class="AdwBrowsingViewChild">
+                <property name="title">Page 3</property>
+                <property name="child-name">page-3</property>
+                <property name="child">
+                  <object class="GtkBox">
+                    <property name="orientation">vertical</property>
+                    <property name="spacing">12</property>
+                    <property name="valign">center</property>
+                    <property name="halign">center</property>
+                    <child>
+                      <object class="GtkLabel">
+                        <property name="label" translatable="yes">Page 3</property>
+                        <style>
+                          <class name="title-1"/>
+                        </style>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkButton">
+                        <property name="label" translatable="yes">Page 3</property>
+                        <property name="action-name">example.pop-all</property>
+                        <style>
+                          <class name="pill"/>
+                        </style>
+                      </object>
+                    </child>
                   </object>
-                </child>
+                </property>
               </object>
-            </property>
-          </object>
-        </child>
-        <child>
-          <object class="AdwBrowsingViewChild">
-            <property name="title">Page 4</property>
-            <property name="child-name">page-4</property>
-            <property name="child">
-              <object class="GtkBox">
-                <property name="orientation">vertical</property>
-                <child>
-                  <object class="AdwHeaderBar"/>
-                </child>
-                <child>
+            </child>
+            <child>
+              <object class="AdwBrowsingViewChild">
+                <property name="title">Page 4</property>
+                <property name="child-name">page-4</property>
+                <property name="child">
                   <object class="GtkBox">
                     <property name="orientation">vertical</property>
                     <property name="spacing">12</property>
-                    <property name="vexpand">True</property>
                     <property name="valign">center</property>
                     <property name="halign">center</property>
                     <child>
@@ -163,9 +175,9 @@
                       </object>
                     </child>
                   </object>
-                </child>
+                </property>
               </object>
-            </property>
+            </child>
           </object>
         </child>
       </object>


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