[libadwaita/wip/exalm/demo-cleanups: 14/21] demo: Split styles page into a separate class




commit 3e61e8d6701c3ec4f59e4dd933ed57f060b18981
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Thu Dec 9 18:35:58 2021 +0500

    demo: Split styles page into a separate class

 demo/adw-demo-window.c                           | 14 ++-------
 demo/adw-demo-window.ui                          | 17 +----------
 demo/adwaita-demo.gresources.xml                 |  3 +-
 demo/meson.build                                 |  3 +-
 demo/pages/styles/adw-demo-page-styles.c         | 38 ++++++++++++++++++++++++
 demo/pages/styles/adw-demo-page-styles.h         | 11 +++++++
 demo/pages/styles/adw-demo-page-styles.ui        | 24 +++++++++++++++
 demo/{ => pages/styles}/adw-style-demo-window.c  |  2 +-
 demo/{ => pages/styles}/adw-style-demo-window.h  |  0
 demo/{ => pages/styles}/adw-style-demo-window.ui |  0
 10 files changed, 81 insertions(+), 31 deletions(-)
---
diff --git a/demo/adw-demo-window.c b/demo/adw-demo-window.c
index 7b8519da..ba3a2dcb 100644
--- a/demo/adw-demo-window.c
+++ b/demo/adw-demo-window.c
@@ -8,10 +8,10 @@
 #include "pages/flap/adw-demo-page-flap.h"
 #include "pages/leaflet/adw-demo-page-leaflet.h"
 #include "pages/lists/adw-demo-page-lists.h"
+#include "pages/styles/adw-demo-page-styles.h"
 #include "pages/tab-view/adw-demo-page-tab-view.h"
 #include "pages/view-switcher/adw-demo-page-view-switcher.h"
 #include "pages/welcome/adw-demo-page-welcome.h"
-#include "adw-style-demo-window.h"
 
 struct _AdwDemoWindow
 {
@@ -380,16 +380,6 @@ notify_spring_params_change (AdwDemoWindow *self)
   adw_spring_animation_set_spring_params (ADW_SPRING_ANIMATION (self->spring_animation), spring_params);
 }
 
-static void
-style_classes_demo_clicked_cb (GtkButton     *btn,
-                               AdwDemoWindow *self)
-{
-  AdwStyleDemoWindow *window = adw_style_demo_window_new ();
-
-  gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (self));
-  gtk_window_present (GTK_WINDOW (window));
-}
-
 static void
 add_toast_cb (AdwDemoWindow *self)
 {
@@ -513,7 +503,6 @@ adw_demo_window_class_init (AdwDemoWindowClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, leaflet_next_page_cb);
   gtk_widget_class_bind_template_callback (widget_class, get_color_scheme_icon_name);
   gtk_widget_class_bind_template_callback (widget_class, color_scheme_button_clicked_cb);
-  gtk_widget_class_bind_template_callback (widget_class, style_classes_demo_clicked_cb);
   gtk_widget_class_bind_template_callback (widget_class, add_toast_cb);
   gtk_widget_class_bind_template_callback (widget_class, add_toast_with_button_cb);
   gtk_widget_class_bind_template_callback (widget_class, add_toast_with_long_title_cb);
@@ -617,6 +606,7 @@ adw_demo_window_init (AdwDemoWindow *self)
   g_type_ensure (ADW_TYPE_DEMO_PAGE_FLAP);
   g_type_ensure (ADW_TYPE_DEMO_PAGE_LEAFLET);
   g_type_ensure (ADW_TYPE_DEMO_PAGE_LISTS);
+  g_type_ensure (ADW_TYPE_DEMO_PAGE_STYLES);
   g_type_ensure (ADW_TYPE_DEMO_PAGE_TAB_VIEW);
   g_type_ensure (ADW_TYPE_DEMO_PAGE_VIEW_SWITCHER);
   g_type_ensure (ADW_TYPE_DEMO_PAGE_WELCOME);
diff --git a/demo/adw-demo-window.ui b/demo/adw-demo-window.ui
index 33edc4d5..5ebfc1ec 100644
--- a/demo/adw-demo-window.ui
+++ b/demo/adw-demo-window.ui
@@ -192,24 +192,9 @@
                         </child>
                         <child>
                           <object class="GtkStackPage">
-                            <property name="name">style-classes</property>
                             <property name="title" translatable="yes">Style Classes</property>
                             <property name="child">
-                              <object class="AdwStatusPage">
-                                <property name="icon-name">style-classes-symbolic</property>
-                                <property name="title" translatable="yes">Style Classes</property>
-                                <property name="description" translatable="yes">Various widget styles 
available for use.</property>
-                                <property name="child">
-                                  <object class="GtkButton">
-                                    <property name="label" translatable="yes">Run the Demo</property>
-                                    <property name="halign">center</property>
-                                    <signal name="clicked" handler="style_classes_demo_clicked_cb" 
swapped="no"/>
-                                    <style>
-                                      <class name="pill"/>
-                                    </style>
-                                  </object>
-                                </property>
-                              </object>
+                              <object class="AdwDemoPageStyles"/>
                             </property>
                           </object>
                         </child>
diff --git a/demo/adwaita-demo.gresources.xml b/demo/adwaita-demo.gresources.xml
index 2b264c68..666a1a14 100644
--- a/demo/adwaita-demo.gresources.xml
+++ b/demo/adwaita-demo.gresources.xml
@@ -49,6 +49,8 @@
     <file preprocess="xml-stripblanks">pages/flap/adw-flap-demo-window.ui</file>
     <file preprocess="xml-stripblanks">pages/leaflet/adw-demo-page-leaflet.ui</file>
     <file preprocess="xml-stripblanks">pages/lists/adw-demo-page-lists.ui</file>
+    <file preprocess="xml-stripblanks">pages/styles/adw-demo-page-styles.ui</file>
+    <file preprocess="xml-stripblanks">pages/styles/adw-style-demo-window.ui</file>
     <file preprocess="xml-stripblanks">pages/tab-view/adw-demo-page-tab-view.ui</file>
     <file preprocess="xml-stripblanks">pages/tab-view/adw-tab-view-demo-window.ui</file>
     <file preprocess="xml-stripblanks">pages/view-switcher/adw-demo-page-view-switcher.ui</file>
@@ -56,6 +58,5 @@
     <file preprocess="xml-stripblanks">pages/welcome/adw-demo-page-welcome.ui</file>
     <file preprocess="xml-stripblanks">adw-demo-preferences-window.ui</file>
     <file preprocess="xml-stripblanks">adw-demo-window.ui</file>
-    <file preprocess="xml-stripblanks">adw-style-demo-window.ui</file>
   </gresource>
 </gresources>
diff --git a/demo/meson.build b/demo/meson.build
index 0b30056a..3442fae5 100644
--- a/demo/meson.build
+++ b/demo/meson.build
@@ -20,6 +20,8 @@ adwaita_demo_sources = [
   'pages/flap/adw-flap-demo-window.c',
   'pages/leaflet/adw-demo-page-leaflet.c',
   'pages/lists/adw-demo-page-lists.c',
+  'pages/styles/adw-demo-page-styles.c',
+  'pages/styles/adw-style-demo-window.c',
   'pages/tab-view/adw-demo-page-tab-view.c',
   'pages/tab-view/adw-tab-view-demo-window.c',
   'pages/view-switcher/adw-demo-page-view-switcher.c',
@@ -29,7 +31,6 @@ adwaita_demo_sources = [
   'adwaita-demo.c',
   'adw-demo-preferences-window.c',
   'adw-demo-window.c',
-  'adw-style-demo-window.c',
   libadwaita_generated_headers,
 ]
 
diff --git a/demo/pages/styles/adw-demo-page-styles.c b/demo/pages/styles/adw-demo-page-styles.c
new file mode 100644
index 00000000..cb21ff0f
--- /dev/null
+++ b/demo/pages/styles/adw-demo-page-styles.c
@@ -0,0 +1,38 @@
+#include "adw-demo-page-styles.h"
+
+#include <glib/gi18n.h>
+
+#include "adw-style-demo-window.h"
+
+struct _AdwDemoPageStyles
+{
+  AdwBin parent_instance;
+};
+
+G_DEFINE_TYPE (AdwDemoPageStyles, adw_demo_page_styles, ADW_TYPE_BIN)
+
+static void
+demo_run_cb (AdwDemoPageStyles *self)
+{
+  AdwStyleDemoWindow *window = adw_style_demo_window_new ();
+  GtkRoot *root = gtk_widget_get_root (GTK_WIDGET (self));
+
+  gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (root));
+  gtk_window_present (GTK_WINDOW (window));
+}
+
+static void
+adw_demo_page_styles_class_init (AdwDemoPageStylesClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Adwaita1/Demo/ui/pages/styles/adw-demo-page-styles.ui");
+
+  gtk_widget_class_install_action (widget_class, "demo.run", NULL, (GtkWidgetActionActivateFunc) 
demo_run_cb);
+}
+
+static void
+adw_demo_page_styles_init (AdwDemoPageStyles *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/demo/pages/styles/adw-demo-page-styles.h b/demo/pages/styles/adw-demo-page-styles.h
new file mode 100644
index 00000000..09111663
--- /dev/null
+++ b/demo/pages/styles/adw-demo-page-styles.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include <adwaita.h>
+
+G_BEGIN_DECLS
+
+#define ADW_TYPE_DEMO_PAGE_STYLES (adw_demo_page_styles_get_type())
+
+G_DECLARE_FINAL_TYPE (AdwDemoPageStyles, adw_demo_page_styles, ADW, DEMO_PAGE_STYLES, AdwBin)
+
+G_END_DECLS
diff --git a/demo/pages/styles/adw-demo-page-styles.ui b/demo/pages/styles/adw-demo-page-styles.ui
new file mode 100644
index 00000000..fe031f07
--- /dev/null
+++ b/demo/pages/styles/adw-demo-page-styles.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk" version="4.0"/>
+  <requires lib="libadwaita" version="1.0"/>
+  <template class="AdwDemoPageStyles" parent="AdwBin">
+    <property name="child">
+      <object class="AdwStatusPage">
+        <property name="icon-name">style-classes-symbolic</property>
+        <property name="title" translatable="yes">Style Classes</property>
+        <property name="description" translatable="yes">Various widget styles available for use.</property>
+        <property name="child">
+          <object class="GtkButton">
+            <property name="label" translatable="yes">Run the Demo</property>
+            <property name="halign">center</property>
+            <property name="action-name">demo.run</property>
+            <style>
+              <class name="pill"/>
+            </style>
+          </object>
+        </property>
+      </object>
+    </property>
+  </template>
+</interface>
diff --git a/demo/adw-style-demo-window.c b/demo/pages/styles/adw-style-demo-window.c
similarity index 99%
rename from demo/adw-style-demo-window.c
rename to demo/pages/styles/adw-style-demo-window.c
index 13e1748e..2d7c26d4 100644
--- a/demo/adw-style-demo-window.c
+++ b/demo/pages/styles/adw-style-demo-window.c
@@ -191,7 +191,7 @@ adw_style_demo_window_class_init (AdwStyleDemoWindowClass *klass)
 
   g_object_class_install_properties (object_class, LAST_PROP, props);
 
-  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Adwaita1/Demo/ui/adw-style-demo-window.ui");
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Adwaita1/Demo/ui/pages/styles/adw-style-demo-window.ui");
   gtk_widget_class_bind_template_child (widget_class, AdwStyleDemoWindow, header_bar_window);
   gtk_widget_class_bind_template_child (widget_class, AdwStyleDemoWindow, status_page_window);
   gtk_widget_class_bind_template_child (widget_class, AdwStyleDemoWindow, sidebar_window);
diff --git a/demo/adw-style-demo-window.h b/demo/pages/styles/adw-style-demo-window.h
similarity index 100%
rename from demo/adw-style-demo-window.h
rename to demo/pages/styles/adw-style-demo-window.h
diff --git a/demo/adw-style-demo-window.ui b/demo/pages/styles/adw-style-demo-window.ui
similarity index 100%
rename from demo/adw-style-demo-window.ui
rename to demo/pages/styles/adw-style-demo-window.ui


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