[libadwaita/wip/exalm/demo-cleanups: 5/21] demo: Split leaflet page into a separate class
- From: Christopher Davis <christopherdavis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/demo-cleanups: 5/21] demo: Split leaflet page into a separate class
- Date: Thu, 9 Dec 2021 21:44:32 +0000 (UTC)
commit d6e6e861072face0acaa6bee01fee6b901720889
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Thu Dec 9 15:47:01 2021 +0500
demo: Split leaflet page into a separate class
demo/adw-demo-window.c | 41 +---------
demo/adw-demo-window.ui | 46 +----------
demo/adwaita-demo.gresources.xml | 1 +
demo/meson.build | 1 +
demo/pages/leaflet/adw-demo-page-leaflet.c | 121 ++++++++++++++++++++++++++++
demo/pages/leaflet/adw-demo-page-leaflet.h | 11 +++
demo/pages/leaflet/adw-demo-page-leaflet.ui | 50 ++++++++++++
7 files changed, 192 insertions(+), 79 deletions(-)
---
diff --git a/demo/adw-demo-window.c b/demo/adw-demo-window.c
index 19eff01e..f33def5d 100644
--- a/demo/adw-demo-window.c
+++ b/demo/adw-demo-window.c
@@ -1,6 +1,7 @@
#include "adw-demo-window.h"
#include <glib/gi18n.h>
+#include "pages/leaflet/adw-demo-page-leaflet.h"
#include "pages/welcome/adw-demo-page-welcome.h"
#include "adw-flap-demo-window.h"
#include "adw-style-demo-window.h"
@@ -17,7 +18,6 @@ struct _AdwDemoWindow
GtkWidget *color_scheme_button;
GtkStackSidebar *sidebar;
GtkStack *stack;
- AdwComboRow *leaflet_transition_row;
AdwLeaflet *subpage_leaflet;
AdwCarousel *carousel;
GtkBox *carousel_box;
@@ -155,40 +155,9 @@ leaflet_back_clicked_cb (GtkWidget *sender,
adw_leaflet_navigate (self->subpage_leaflet, ADW_NAVIGATION_DIRECTION_BACK);
}
-static char *
-leaflet_transition_name (AdwEnumListItem *item,
- gpointer user_data)
-{
- switch (adw_enum_list_item_get_value (item)) {
- case ADW_LEAFLET_TRANSITION_TYPE_OVER:
- return g_strdup (_("Over"));
- case ADW_LEAFLET_TRANSITION_TYPE_UNDER:
- return g_strdup (_("Under"));
- case ADW_LEAFLET_TRANSITION_TYPE_SLIDE:
- return g_strdup (_("Slide"));
- default:
- return NULL;
- }
-}
-
static void
-notify_leaflet_transition_cb (GObject *sender,
- GParamSpec *pspec,
- AdwDemoWindow *self)
+leaflet_next_page_cb (AdwDemoWindow *self)
{
- AdwComboRow *row = ADW_COMBO_ROW (sender);
-
- g_assert (ADW_IS_COMBO_ROW (row));
- g_assert (ADW_IS_DEMO_WINDOW (self));
-
- adw_leaflet_set_transition_type (ADW_LEAFLET (self->content_box), adw_combo_row_get_selected (row));
-}
-
-static void
-leaflet_go_next_row_activated_cb (AdwDemoWindow *self)
-{
- g_assert (ADW_IS_DEMO_WINDOW (self));
-
adw_leaflet_navigate (self->subpage_leaflet, ADW_NAVIGATION_DIRECTION_FORWARD);
}
@@ -790,7 +759,6 @@ adw_demo_window_class_init (AdwDemoWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, color_scheme_button);
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, sidebar);
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, stack);
- gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, leaflet_transition_row);
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, subpage_leaflet);
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, carousel);
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, carousel_box);
@@ -818,9 +786,7 @@ adw_demo_window_class_init (AdwDemoWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, notify_visible_child_cb);
gtk_widget_class_bind_template_callback (widget_class, back_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, leaflet_back_clicked_cb);
- gtk_widget_class_bind_template_callback (widget_class, leaflet_transition_name);
- gtk_widget_class_bind_template_callback (widget_class, notify_leaflet_transition_cb);
- gtk_widget_class_bind_template_callback (widget_class, leaflet_go_next_row_activated_cb);
+ 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, view_switcher_demo_clicked_cb);
@@ -955,6 +921,7 @@ adw_demo_window_init (AdwDemoWindow *self)
{
AdwStyleManager *manager = adw_style_manager_get_default ();
+ g_type_ensure (ADW_TYPE_DEMO_PAGE_LEAFLET);
g_type_ensure (ADW_TYPE_DEMO_PAGE_WELCOME);
gtk_widget_init_template (GTK_WIDGET (self));
diff --git a/demo/adw-demo-window.ui b/demo/adw-demo-window.ui
index 9a95834f..59c11b0b 100644
--- a/demo/adw-demo-window.ui
+++ b/demo/adw-demo-window.ui
@@ -45,10 +45,11 @@
<property name="can-navigate-back">True</property>
<property name="width-request">360</property>
<property name="can-unfold">False</property>
- <property name="transition-type" bind-source="content_box" bind-property="transition-type"
bind-flags="sync-create"/>
+ <property name="transition-type" bind-source="leaflet_page" bind-property="transition-type"
bind-flags="sync-create|bidirectional"/>
<child>
<object class="AdwLeaflet" id="content_box">
<property name="can-navigate-back">True</property>
+ <property name="transition-type" bind-source="leaflet_page" bind-property="transition-type"
bind-flags="sync-create|bidirectional"/>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
@@ -130,49 +131,10 @@
</child>
<child>
<object class="GtkStackPage">
- <property name="name">leaflet</property>
<property name="title" translatable="yes">Leaflet</property>
<property name="child">
- <object class="AdwStatusPage">
- <property name="icon-name">widget-leaflet-symbolic</property>
- <property name="title" translatable="yes">Leaflet</property>
- <property name="description" translatable="yes">A widget showing either all
its children or only one, depending on the available space. This window is using a leaflet, you can control
it with the settings below.</property>
- <property name="child">
- <object class="AdwClamp">
- <property name="child">
- <object class="AdwPreferencesGroup">
- <child>
- <object class="AdwComboRow" id="leaflet_transition_row">
- <property name="subtitle" translatable="yes">The type of
transition to use when the leaflet adapts its size or when changing the visible child</property>
- <property name="title" translatable="yes">Transition
Type</property>
- <signal name="notify::selected"
handler="notify_leaflet_transition_cb" swapped="no"/>
- <property name="model">
- <object class="AdwEnumListModel">
- <property
name="enum-type">AdwLeafletTransitionType</property>
- </object>
- </property>
- <property name="expression">
- <closure type="gchararray" function="leaflet_transition_name"/>
- </property>
- </object>
- </child>
- <child>
- <object class="AdwActionRow">
- <property name="title" translatable="yes">Go to the next page of
the leaflet</property>
- <property name="use_underline">True</property>
- <property name="activatable">True</property>
- <signal name="activated"
handler="leaflet_go_next_row_activated_cb" swapped="yes"/>
- <child>
- <object class="GtkImage">
- <property name="icon_name">go-next-symbolic</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </property>
- </object>
- </property>
+ <object class="AdwDemoPageLeaflet" id="leaflet_page">
+ <signal name="next-page" handler="leaflet_next_page_cb" swapped="yes"/>
</object>
</property>
</object>
diff --git a/demo/adwaita-demo.gresources.xml b/demo/adwaita-demo.gresources.xml
index 62730f1e..a0eec955 100644
--- a/demo/adwaita-demo.gresources.xml
+++ b/demo/adwaita-demo.gresources.xml
@@ -41,6 +41,7 @@
<file compressed="true">style-dark.css</file>
</gresource>
<gresource prefix="/org/gnome/Adwaita1/Demo/ui">
+ <file preprocess="xml-stripblanks">pages/leaflet/adw-demo-page-leaflet.ui</file>
<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>
diff --git a/demo/meson.build b/demo/meson.build
index e6d89269..99475e99 100644
--- a/demo/meson.build
+++ b/demo/meson.build
@@ -12,6 +12,7 @@ adwaita_demo_resources = gnome.compile_resources(
adwaita_demo_sources = [
adwaita_demo_resources,
+ 'pages/leaflet/adw-demo-page-leaflet.c',
'pages/welcome/adw-demo-page-welcome.c',
'adwaita-demo.c',
diff --git a/demo/pages/leaflet/adw-demo-page-leaflet.c b/demo/pages/leaflet/adw-demo-page-leaflet.c
new file mode 100644
index 00000000..56cd07bd
--- /dev/null
+++ b/demo/pages/leaflet/adw-demo-page-leaflet.c
@@ -0,0 +1,121 @@
+#include "adw-demo-page-leaflet.h"
+
+#include <glib/gi18n.h>
+
+struct _AdwDemoPageLeaflet
+{
+ AdwBin parent_instance;
+
+ AdwLeafletTransitionType transition_type;
+};
+
+enum {
+ PROP_0,
+ PROP_TRANSITION_TYPE,
+ LAST_PROP,
+};
+
+static GParamSpec *props[LAST_PROP];
+
+enum {
+ SIGNAL_NEXT_PAGE,
+ SIGNAL_LAST_SIGNAL,
+};
+
+static guint signals[SIGNAL_LAST_SIGNAL];
+
+G_DEFINE_TYPE (AdwDemoPageLeaflet, adw_demo_page_leaflet, ADW_TYPE_BIN)
+
+static char *
+get_transition_name (AdwEnumListItem *item,
+ gpointer user_data)
+{
+ switch (adw_enum_list_item_get_value (item)) {
+ case ADW_LEAFLET_TRANSITION_TYPE_OVER:
+ return g_strdup (_("Over"));
+ case ADW_LEAFLET_TRANSITION_TYPE_UNDER:
+ return g_strdup (_("Under"));
+ case ADW_LEAFLET_TRANSITION_TYPE_SLIDE:
+ return g_strdup (_("Slide"));
+ default:
+ return NULL;
+ }
+}
+
+static void
+next_row_activated_cb (AdwDemoPageLeaflet *self)
+{
+ g_signal_emit (self, signals[SIGNAL_NEXT_PAGE], 0);
+}
+
+static void
+adw_demo_page_leaflet_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ AdwDemoPageLeaflet *self = ADW_DEMO_PAGE_LEAFLET (object);
+
+ switch (prop_id) {
+ case PROP_TRANSITION_TYPE:
+ g_value_set_enum (value, self->transition_type);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+adw_demo_page_leaflet_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ AdwDemoPageLeaflet *self = ADW_DEMO_PAGE_LEAFLET (object);
+
+ switch (prop_id) {
+ case PROP_TRANSITION_TYPE:
+ self->transition_type = g_value_get_enum (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+adw_demo_page_leaflet_class_init (AdwDemoPageLeafletClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->get_property = adw_demo_page_leaflet_get_property;
+ object_class->set_property = adw_demo_page_leaflet_set_property;
+
+ props[PROP_TRANSITION_TYPE] =
+ g_param_spec_enum ("transition-type",
+ "Transition type",
+ "Transition type",
+ ADW_TYPE_LEAFLET_TRANSITION_TYPE,
+ ADW_LEAFLET_TRANSITION_TYPE_OVER,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_properties (object_class, LAST_PROP, props);
+
+ signals[SIGNAL_NEXT_PAGE] =
+ g_signal_new ("next-page",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/Adwaita1/Demo/ui/pages/leaflet/adw-demo-page-leaflet.ui");
+ gtk_widget_class_bind_template_callback (widget_class, get_transition_name);
+ gtk_widget_class_bind_template_callback (widget_class, next_row_activated_cb);
+}
+
+static void
+adw_demo_page_leaflet_init (AdwDemoPageLeaflet *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/demo/pages/leaflet/adw-demo-page-leaflet.h b/demo/pages/leaflet/adw-demo-page-leaflet.h
new file mode 100644
index 00000000..66e90168
--- /dev/null
+++ b/demo/pages/leaflet/adw-demo-page-leaflet.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include <adwaita.h>
+
+G_BEGIN_DECLS
+
+#define ADW_TYPE_DEMO_PAGE_LEAFLET (adw_demo_page_leaflet_get_type())
+
+G_DECLARE_FINAL_TYPE (AdwDemoPageLeaflet, adw_demo_page_leaflet, ADW, DEMO_PAGE_LEAFLET, AdwBin)
+
+G_END_DECLS
diff --git a/demo/pages/leaflet/adw-demo-page-leaflet.ui b/demo/pages/leaflet/adw-demo-page-leaflet.ui
new file mode 100644
index 00000000..d6a47d16
--- /dev/null
+++ b/demo/pages/leaflet/adw-demo-page-leaflet.ui
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk" version="4.0"/>
+ <requires lib="libadwaita" version="1.0"/>
+ <template class="AdwDemoPageLeaflet" parent="AdwBin">
+ <property name="child">
+ <object class="AdwStatusPage">
+ <property name="icon-name">widget-leaflet-symbolic</property>
+ <property name="title" translatable="yes">Leaflet</property>
+ <property name="description" translatable="yes">A widget showing either all its children or only
one, depending on the available space. This window is using a leaflet, you can control it with the settings
below.</property>
+ <property name="child">
+ <object class="AdwClamp">
+ <property name="child">
+ <object class="AdwPreferencesGroup">
+ <child>
+ <object class="AdwComboRow" id="transition_row">
+ <property name="subtitle" translatable="yes">The type of transition to use when the
leaflet adapts its size or when changing the visible child</property>
+ <property name="title" translatable="yes">Transition Type</property>
+ <property name="selected" bind-source="AdwDemoPageLeaflet"
bind-property="transition-type" bind-flags="bidirectional|sync-create"/>
+ <property name="model">
+ <object class="AdwEnumListModel">
+ <property name="enum-type">AdwLeafletTransitionType</property>
+ </object>
+ </property>
+ <property name="expression">
+ <closure type="gchararray" function="get_transition_name"/>
+ </property>
+ </object>
+ </child>
+ <child>
+ <object class="AdwActionRow">
+ <property name="title" translatable="yes">Go to the next page of the leaflet</property>
+ <property name="use_underline">True</property>
+ <property name="activatable">True</property>
+ <signal name="activated" handler="next_row_activated_cb" swapped="yes"/>
+ <child>
+ <object class="GtkImage">
+ <property name="icon_name">go-next-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </property>
+ </object>
+ </property>
+ </object>
+ </property>
+ </template>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]