[libadwaita/wip/exalm/demo-cleanups: 9/21] demo: Split carousel page into a separate class
- From: Christopher Davis <christopherdavis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/demo-cleanups: 9/21] demo: Split carousel page into a separate class
- Date: Thu, 9 Dec 2021 21:44:33 +0000 (UTC)
commit b80181d28348118eff5a95aba240bb8f3b786f3d
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Thu Dec 9 16:59:46 2021 +0500
demo: Split carousel page into a separate class
demo/adw-demo-window.c | 87 +--------------
demo/adw-demo-window.ui | 148 +-----------------------
demo/adwaita-demo.gresources.xml | 1 +
demo/meson.build | 1 +
demo/pages/carousel/adw-demo-page-carousel.c | 101 +++++++++++++++++
demo/pages/carousel/adw-demo-page-carousel.h | 11 ++
demo/pages/carousel/adw-demo-page-carousel.ui | 155 ++++++++++++++++++++++++++
7 files changed, 272 insertions(+), 232 deletions(-)
---
diff --git a/demo/adw-demo-window.c b/demo/adw-demo-window.c
index eb4fbeeb..6d7e2ce4 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/carousel/adw-demo-page-carousel.h"
#include "pages/clamp/adw-demo-page-clamp.h"
#include "pages/leaflet/adw-demo-page-leaflet.h"
#include "pages/lists/adw-demo-page-lists.h"
@@ -21,9 +22,6 @@ struct _AdwDemoWindow
GtkStackSidebar *sidebar;
GtkStack *stack;
AdwLeaflet *subpage_leaflet;
- AdwCarousel *carousel;
- GtkBox *carousel_box;
- GtkStack *carousel_indicators_stack;
AdwAvatar *avatar;
GtkEntry *avatar_text;
GtkLabel *avatar_file_chooser_label;
@@ -163,80 +161,6 @@ leaflet_next_page_cb (AdwDemoWindow *self)
adw_leaflet_navigate (self->subpage_leaflet, ADW_NAVIGATION_DIRECTION_FORWARD);
}
-static char *
-carousel_orientation_name (AdwEnumListItem *item,
- gpointer user_data)
-{
- switch (adw_enum_list_item_get_value (item)) {
- case GTK_ORIENTATION_HORIZONTAL:
- return g_strdup (_("Horizontal"));
- case GTK_ORIENTATION_VERTICAL:
- return g_strdup (_("Vertical"));
- default:
- return NULL;
- }
-}
-
-static void
-notify_carousel_orientation_cb (GObject *sender,
- GParamSpec *pspec,
- AdwDemoWindow *self)
-{
- AdwComboRow *row = ADW_COMBO_ROW (sender);
-
- g_assert (ADW_IS_COMBO_ROW (row));
- g_assert (ADW_IS_DEMO_WINDOW (self));
-
- gtk_orientable_set_orientation (GTK_ORIENTABLE (self->carousel_box),
- 1 - adw_combo_row_get_selected (row));
- gtk_orientable_set_orientation (GTK_ORIENTABLE (self->carousel),
- adw_combo_row_get_selected (row));
-}
-
-static char *
-carousel_indicators_name (GtkStringObject *value)
-{
- const char *style;
-
- g_assert (GTK_IS_STRING_OBJECT (value));
-
- style = gtk_string_object_get_string (value);
-
- if (!g_strcmp0 (style, "dots"))
- return g_strdup (_("Dots"));
-
- if (!g_strcmp0 (style, "lines"))
- return g_strdup (_("Lines"));
-
- return NULL;
-}
-
-static void
-notify_carousel_indicators_cb (GObject *sender,
- GParamSpec *pspec,
- AdwDemoWindow *self)
-{
- AdwComboRow *row = ADW_COMBO_ROW (sender);
- GtkStringObject *obj;
-
- g_assert (ADW_IS_COMBO_ROW (row));
- g_assert (ADW_IS_DEMO_WINDOW (self));
-
- obj = adw_combo_row_get_selected_item (row);
-
- gtk_stack_set_visible_child_name (self->carousel_indicators_stack,
- gtk_string_object_get_string (obj));
-}
-
-static void
-carousel_return_clicked_cb (GtkButton *btn,
- AdwDemoWindow *self)
-{
- adw_carousel_scroll_to (self->carousel,
- adw_carousel_get_nth_page (self->carousel, 0),
- TRUE);
-}
-
AdwDemoWindow *
adw_demo_window_new (GtkApplication *application)
{
@@ -752,9 +676,6 @@ adw_demo_window_class_init (AdwDemoWindowClass *klass)
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, subpage_leaflet);
- gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, carousel);
- gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, carousel_box);
- gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, carousel_indicators_stack);
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, avatar);
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, avatar_text);
gtk_widget_class_bind_template_child (widget_class, AdwDemoWindow, avatar_file_chooser_label);
@@ -781,11 +702,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, notify_carousel_orientation_cb);
- gtk_widget_class_bind_template_callback (widget_class, notify_carousel_indicators_cb);
- gtk_widget_class_bind_template_callback (widget_class, carousel_indicators_name);
- gtk_widget_class_bind_template_callback (widget_class, carousel_orientation_name);
- gtk_widget_class_bind_template_callback (widget_class, carousel_return_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, avatar_file_remove_cb);
gtk_widget_class_bind_template_callback (widget_class, avatar_file_chooser_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, avatar_save_to_file_cb);
@@ -912,6 +828,7 @@ adw_demo_window_init (AdwDemoWindow *self)
{
AdwStyleManager *manager = adw_style_manager_get_default ();
+ g_type_ensure (ADW_TYPE_DEMO_PAGE_CAROUSEL);
g_type_ensure (ADW_TYPE_DEMO_PAGE_CLAMP);
g_type_ensure (ADW_TYPE_DEMO_PAGE_LEAFLET);
g_type_ensure (ADW_TYPE_DEMO_PAGE_LISTS);
diff --git a/demo/adw-demo-window.ui b/demo/adw-demo-window.ui
index 786de7bd..277b199b 100644
--- a/demo/adw-demo-window.ui
+++ b/demo/adw-demo-window.ui
@@ -165,148 +165,9 @@
</child>
<child>
<object class="GtkStackPage">
- <property name="name">carousel</property>
<property name="title" translatable="yes">Carousel</property>
<property name="child">
- <object class="GtkBox" id="carousel_box">
- <property name="orientation">vertical</property>
- <child>
- <object class="GtkBox" id="carousel_empty_box"/>
- </child>
- <child>
- <object class="AdwCarousel" id="carousel">
- <property name="vexpand">True</property>
- <property name="hexpand">True</property>
- <property name="allow-scroll-wheel" bind-source="carousel_scroll_wheel"
bind-property="active" bind-flags="sync-create|bidirectional"/>
- <property name="allow-long-swipes" bind-source="carousel_long_swipes"
bind-property="active" bind-flags="sync-create|bidirectional"/>
- <child>
- <object class="AdwStatusPage">
- <property name="icon-name">widget-carousel-symbolic</property>
- <property name="title" translatable="yes">Carousel</property>
- <property name="description" translatable="yes">A widget for
paginated scrolling.</property>
- <property name="vexpand">True</property>
- </object>
- </child>
- <child>
- <object class="AdwClamp">
- <property name="margin-bottom">32</property>
- <property name="margin-start">12</property>
- <property name="margin-end">12</property>
- <property name="maximum-size">400</property>
- <property name="tightening-threshold">300</property>
- <property name="valign">center</property>
- <child>
- <object class="AdwPreferencesGroup">
- <child>
- <object class="AdwComboRow" id="carousel_orientation_row">
- <property name="title"
translatable="yes">Orientation</property>
- <signal name="notify::selected"
handler="notify_carousel_orientation_cb" swapped="no"/>
- <property name="model">
- <object class="AdwEnumListModel">
- <property name="enum-type">GtkOrientation</property>
- </object>
- </property>
- <property name="expression">
- <closure type="gchararray"
function="carousel_orientation_name"/>
- </property>
- </object>
- </child>
- <child>
- <object class="AdwComboRow" id="carousel_indicators_row">
- <property name="title" translatable="yes">Page
Indicators</property>
- <signal name="notify::selected"
handler="notify_carousel_indicators_cb" swapped="no"/>
- <property name="model">
- <object class="GtkStringList">
- <items>
- <item>dots</item>
- <item>lines</item>
- </items>
- </object>
- </property>
- <property name="expression">
- <closure type="gchararray"
function="carousel_indicators_name"/>
- </property>
- </object>
- </child>
- <child>
- <object class="AdwActionRow">
- <property name="title" translatable="yes">Scroll
Wheel</property>
- <property
name="activatable_widget">carousel_scroll_wheel</property>
- <child>
- <object class="GtkSwitch" id="carousel_scroll_wheel">
- <property name="valign">center</property>
- <property name="active">True</property>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="AdwActionRow">
- <property name="title" translatable="yes">Long
Swipes</property>
- <property
name="activatable_widget">carousel_long_swipes</property>
- <child>
- <object class="GtkSwitch" id="carousel_long_swipes">
- <property name="valign">center</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="AdwStatusPage">
- <property name="title" translatable="yes">Another Page</property>
- <property name="hexpand">True</property>
- <property name="child">
- <object class="GtkButton">
- <property name="label" translatable="yes">_Return to the First
Page</property>
- <property name="use-underline">True</property>
- <property name="halign">center</property>
- <signal name="clicked" handler="carousel_return_clicked_cb"
swapped="no"/>
- <style>
- <class name="suggested-action"/>
- <class name="pill"/>
- </style>
- </object>
- </property>
- </object>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkStack" id="carousel_indicators_stack">
- <property name="vhomogeneous">False</property>
- <property name="margin-top">6</property>
- <property name="margin-bottom">6</property>
- <property name="margin-start">6</property>
- <property name="margin-end">6</property>
- <child>
- <object class="GtkStackPage">
- <property name="name">dots</property>
- <property name="child">
- <object class="AdwCarouselIndicatorDots">
- <property name="carousel">carousel</property>
- <property name="orientation" bind-source="carousel"
bind-property="orientation" bind-flags="sync-create"/>
- </object>
- </property>
- </object>
- </child>
- <child>
- <object class="GtkStackPage">
- <property name="name">lines</property>
- <property name="child">
- <object class="AdwCarouselIndicatorLines">
- <property name="carousel">carousel</property>
- <property name="orientation" bind-source="carousel"
bind-property="orientation" bind-flags="sync-create"/>
- </object>
- </property>
- </object>
- </child>
- </object>
- </child>
- </object>
+ <object class="AdwDemoPageCarousel"/>
</property>
</object>
</child>
@@ -1174,13 +1035,6 @@
</object>
</child>
</template>
- <object class="GtkSizeGroup">
- <property name="mode">both</property>
- <widgets>
- <widget name="carousel_empty_box"/>
- <widget name="carousel_indicators_stack"/>
- </widgets>
- </object>
<object class="GtkAdjustment" id="avatar_adjustment">
<property name="lower">24</property>
<property name="upper">320</property>
diff --git a/demo/adwaita-demo.gresources.xml b/demo/adwaita-demo.gresources.xml
index 8cdbd16c..c9494954 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/carousel/adw-demo-page-carousel.ui</file>
<file preprocess="xml-stripblanks">pages/clamp/adw-demo-page-clamp.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>
diff --git a/demo/meson.build b/demo/meson.build
index 3d51fbfe..7347336d 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/carousel/adw-demo-page-carousel.c',
'pages/clamp/adw-demo-page-clamp.c',
'pages/leaflet/adw-demo-page-leaflet.c',
'pages/lists/adw-demo-page-lists.c',
diff --git a/demo/pages/carousel/adw-demo-page-carousel.c b/demo/pages/carousel/adw-demo-page-carousel.c
new file mode 100644
index 00000000..1c0bf102
--- /dev/null
+++ b/demo/pages/carousel/adw-demo-page-carousel.c
@@ -0,0 +1,101 @@
+#include "adw-demo-page-carousel.h"
+
+#include <glib/gi18n.h>
+
+struct _AdwDemoPageCarousel
+{
+ AdwBin parent_instance;
+
+ GtkBox *box;
+ AdwCarousel *carousel;
+ GtkStack *indicators_stack;
+ AdwComboRow *orientation_row;
+ AdwComboRow *indicators_row;
+};
+
+G_DEFINE_TYPE (AdwDemoPageCarousel, adw_demo_page_carousel, ADW_TYPE_BIN)
+
+static char *
+get_orientation_name (AdwEnumListItem *item,
+ gpointer user_data)
+{
+ switch (adw_enum_list_item_get_value (item)) {
+ case GTK_ORIENTATION_HORIZONTAL:
+ return g_strdup (_("Horizontal"));
+ case GTK_ORIENTATION_VERTICAL:
+ return g_strdup (_("Vertical"));
+ default:
+ return NULL;
+ }
+}
+
+static void
+notify_orientation_cb (AdwDemoPageCarousel *self)
+{
+ GtkOrientation orientation = adw_combo_row_get_selected (self->orientation_row);
+
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (self->box),
+ 1 - orientation);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (self->carousel),
+ orientation);
+}
+
+static char *
+get_indicators_name (GtkStringObject *value)
+{
+ const char *style;
+
+ g_assert (GTK_IS_STRING_OBJECT (value));
+
+ style = gtk_string_object_get_string (value);
+
+ if (!g_strcmp0 (style, "dots"))
+ return g_strdup (_("Dots"));
+
+ if (!g_strcmp0 (style, "lines"))
+ return g_strdup (_("Lines"));
+
+ return NULL;
+}
+
+static void
+notify_indicators_cb (AdwDemoPageCarousel *self)
+{
+ GtkStringObject *obj = adw_combo_row_get_selected_item (self->indicators_row);
+
+ gtk_stack_set_visible_child_name (self->indicators_stack,
+ gtk_string_object_get_string (obj));
+}
+
+static void
+carousel_return_cb (AdwDemoPageCarousel *self)
+{
+ adw_carousel_scroll_to (self->carousel,
+ adw_carousel_get_nth_page (self->carousel, 0),
+ TRUE);
+}
+
+static void
+adw_demo_page_carousel_class_init (AdwDemoPageCarouselClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/Adwaita1/Demo/ui/pages/carousel/adw-demo-page-carousel.ui");
+ gtk_widget_class_bind_template_child (widget_class, AdwDemoPageCarousel, box);
+ gtk_widget_class_bind_template_child (widget_class, AdwDemoPageCarousel, carousel);
+ gtk_widget_class_bind_template_child (widget_class, AdwDemoPageCarousel, indicators_stack);
+ gtk_widget_class_bind_template_child (widget_class, AdwDemoPageCarousel, orientation_row);
+ gtk_widget_class_bind_template_child (widget_class, AdwDemoPageCarousel, indicators_row);
+ gtk_widget_class_bind_template_callback (widget_class, get_orientation_name);
+ gtk_widget_class_bind_template_callback (widget_class, notify_orientation_cb);
+ gtk_widget_class_bind_template_callback (widget_class, get_indicators_name);
+ gtk_widget_class_bind_template_callback (widget_class, notify_indicators_cb);
+
+ gtk_widget_class_install_action (widget_class, "carousel.return", NULL, (GtkWidgetActionActivateFunc)
carousel_return_cb);
+}
+
+static void
+adw_demo_page_carousel_init (AdwDemoPageCarousel *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
diff --git a/demo/pages/carousel/adw-demo-page-carousel.h b/demo/pages/carousel/adw-demo-page-carousel.h
new file mode 100644
index 00000000..574b4ddc
--- /dev/null
+++ b/demo/pages/carousel/adw-demo-page-carousel.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include <adwaita.h>
+
+G_BEGIN_DECLS
+
+#define ADW_TYPE_DEMO_PAGE_CAROUSEL (adw_demo_page_carousel_get_type())
+
+G_DECLARE_FINAL_TYPE (AdwDemoPageCarousel, adw_demo_page_carousel, ADW, DEMO_PAGE_CAROUSEL, AdwBin)
+
+G_END_DECLS
diff --git a/demo/pages/carousel/adw-demo-page-carousel.ui b/demo/pages/carousel/adw-demo-page-carousel.ui
new file mode 100644
index 00000000..eae9c1b9
--- /dev/null
+++ b/demo/pages/carousel/adw-demo-page-carousel.ui
@@ -0,0 +1,155 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk" version="4.0"/>
+ <requires lib="libadwaita" version="1.0"/>
+ <template class="AdwDemoPageCarousel" parent="AdwBin">
+ <property name="child">
+ <object class="GtkBox" id="box">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkBox" id="empty_box"/>
+ </child>
+ <child>
+ <object class="AdwCarousel" id="carousel">
+ <property name="vexpand">True</property>
+ <property name="hexpand">True</property>
+ <property name="allow-scroll-wheel" bind-source="scroll_wheel" bind-property="active"
bind-flags="sync-create|bidirectional"/>
+ <property name="allow-long-swipes" bind-source="long_swipes" bind-property="active"
bind-flags="sync-create|bidirectional"/>
+ <child>
+ <object class="AdwStatusPage">
+ <property name="icon-name">widget-carousel-symbolic</property>
+ <property name="title" translatable="yes">Carousel</property>
+ <property name="description" translatable="yes">A widget for paginated scrolling.</property>
+ <property name="vexpand">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="AdwClamp">
+ <property name="margin-bottom">32</property>
+ <property name="margin-start">12</property>
+ <property name="margin-end">12</property>
+ <property name="maximum-size">400</property>
+ <property name="tightening-threshold">300</property>
+ <property name="valign">center</property>
+ <child>
+ <object class="AdwPreferencesGroup">
+ <child>
+ <object class="AdwComboRow" id="orientation_row">
+ <property name="title" translatable="yes">Orientation</property>
+ <signal name="notify::selected" handler="notify_orientation_cb" swapped="no"/>
+ <property name="model">
+ <object class="AdwEnumListModel">
+ <property name="enum-type">GtkOrientation</property>
+ </object>
+ </property>
+ <property name="expression">
+ <closure type="gchararray" function="get_orientation_name"/>
+ </property>
+ </object>
+ </child>
+ <child>
+ <object class="AdwComboRow" id="indicators_row">
+ <property name="title" translatable="yes">Page Indicators</property>
+ <signal name="notify::selected" handler="notify_indicators_cb" swapped="no"/>
+ <property name="model">
+ <object class="GtkStringList">
+ <items>
+ <item>dots</item>
+ <item>lines</item>
+ </items>
+ </object>
+ </property>
+ <property name="expression">
+ <closure type="gchararray" function="get_indicators_name"/>
+ </property>
+ </object>
+ </child>
+ <child>
+ <object class="AdwActionRow">
+ <property name="title" translatable="yes">Scroll Wheel</property>
+ <property name="activatable_widget">scroll_wheel</property>
+ <child>
+ <object class="GtkSwitch" id="scroll_wheel">
+ <property name="valign">center</property>
+ <property name="active">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="AdwActionRow">
+ <property name="title" translatable="yes">Long Swipes</property>
+ <property name="activatable_widget">long_swipes</property>
+ <child>
+ <object class="GtkSwitch" id="long_swipes">
+ <property name="valign">center</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="AdwStatusPage">
+ <property name="title" translatable="yes">Another Page</property>
+ <property name="hexpand">True</property>
+ <property name="child">
+ <object class="GtkButton">
+ <property name="label" translatable="yes">_Return to the First Page</property>
+ <property name="use-underline">True</property>
+ <property name="halign">center</property>
+ <property name="action-name">carousel.return</property>
+ <style>
+ <class name="suggested-action"/>
+ <class name="pill"/>
+ </style>
+ </object>
+ </property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkStack" id="indicators_stack">
+ <property name="vhomogeneous">False</property>
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="margin-start">6</property>
+ <property name="margin-end">6</property>
+ <child>
+ <object class="GtkStackPage">
+ <property name="name">dots</property>
+ <property name="child">
+ <object class="AdwCarouselIndicatorDots">
+ <property name="carousel">carousel</property>
+ <property name="orientation" bind-source="carousel" bind-property="orientation"
bind-flags="sync-create"/>
+ </object>
+ </property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkStackPage">
+ <property name="name">lines</property>
+ <property name="child">
+ <object class="AdwCarouselIndicatorLines">
+ <property name="carousel">carousel</property>
+ <property name="orientation" bind-source="carousel" bind-property="orientation"
bind-flags="sync-create"/>
+ </object>
+ </property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </property>
+ </template>
+ <object class="GtkSizeGroup">
+ <property name="mode">both</property>
+ <widgets>
+ <widget name="empty_box"/>
+ <widget name="indicators_stack"/>
+ </widgets>
+ </object>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]