[libadwaita/ebassi/tagged-entry: 16/20] Add AdwTaggedEntry to the demo application
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/ebassi/tagged-entry: 16/20] Add AdwTaggedEntry to the demo application
- Date: Mon, 14 Mar 2022 18:46:42 +0000 (UTC)
commit 132ce2fc18bfc671aabfb704454f65c317c2217a
Author: Emmanuele Bassi <ebassi gnome org>
Date: Fri Feb 4 14:11:59 2022 +0000
Add AdwTaggedEntry to the demo application
A page for demonstrating the capabilities of the newly added
AdwTaggedEntry widget.
demo/adw-demo-window.c | 2 +
demo/adw-demo-window.ui | 8 ++
demo/adwaita-demo.gresources.xml | 1 +
demo/meson.build | 1 +
.../tagged-entry/adw-demo-page-tagged-entry.c | 97 +++++++++++++++++
.../tagged-entry/adw-demo-page-tagged-entry.h | 11 ++
.../tagged-entry/adw-demo-page-tagged-entry.ui | 117 +++++++++++++++++++++
7 files changed, 237 insertions(+)
---
diff --git a/demo/adw-demo-window.c b/demo/adw-demo-window.c
index befb473e..acce97be 100644
--- a/demo/adw-demo-window.c
+++ b/demo/adw-demo-window.c
@@ -12,6 +12,7 @@
#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/tagged-entry/adw-demo-page-tagged-entry.h"
#include "pages/toasts/adw-demo-page-toasts.h"
#include "pages/view-switcher/adw-demo-page-view-switcher.h"
#include "pages/welcome/adw-demo-page-welcome.h"
@@ -125,6 +126,7 @@ adw_demo_window_init (AdwDemoWindow *self)
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_TAGGED_ENTRY);
g_type_ensure (ADW_TYPE_DEMO_PAGE_TOASTS);
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 f2b4339c..287d5d91 100644
--- a/demo/adw-demo-window.ui
+++ b/demo/adw-demo-window.ui
@@ -216,6 +216,14 @@
</property>
</object>
</child>
+ <child>
+ <object class="GtkStackPage">
+ <property name="title" translatable="yes">Tagged Entries</property>
+ <property name="child">
+ <object class="AdwDemoPageTaggedEntry"/>
+ </property>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/demo/adwaita-demo.gresources.xml b/demo/adwaita-demo.gresources.xml
index 80f528b9..4652edae 100644
--- a/demo/adwaita-demo.gresources.xml
+++ b/demo/adwaita-demo.gresources.xml
@@ -55,6 +55,7 @@
<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/tagged-entry/adw-demo-page-tagged-entry.ui</file>
<file preprocess="xml-stripblanks">pages/toasts/adw-demo-page-toasts.ui</file>
<file preprocess="xml-stripblanks">pages/view-switcher/adw-demo-page-view-switcher.ui</file>
<file preprocess="xml-stripblanks">pages/view-switcher/adw-view-switcher-demo-window.ui</file>
diff --git a/demo/meson.build b/demo/meson.build
index 6af941fe..6c56872e 100644
--- a/demo/meson.build
+++ b/demo/meson.build
@@ -25,6 +25,7 @@ adwaita_demo_sources = [
'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/tagged-entry/adw-demo-page-tagged-entry.c',
'pages/toasts/adw-demo-page-toasts.c',
'pages/view-switcher/adw-demo-page-view-switcher.c',
'pages/view-switcher/adw-view-switcher-demo-window.c',
diff --git a/demo/pages/tagged-entry/adw-demo-page-tagged-entry.c
b/demo/pages/tagged-entry/adw-demo-page-tagged-entry.c
new file mode 100644
index 00000000..54143aed
--- /dev/null
+++ b/demo/pages/tagged-entry/adw-demo-page-tagged-entry.c
@@ -0,0 +1,97 @@
+#include "adw-demo-page-tagged-entry.h"
+
+#include <glib/gi18n.h>
+
+struct _AdwDemoPageTaggedEntry
+{
+ AdwBin parent_instance;
+
+ AdwTaggedEntry *manual_tagged_entry;
+ GtkWidget *add_tag_button;
+ GtkWidget *remove_all_button;
+
+ AdwTaggedEntry *automatic_tagged_entry;
+
+ AdwTaggedEntry *completion_tagged_entry;
+};
+
+G_DEFINE_TYPE (AdwDemoPageTaggedEntry, adw_demo_page_tagged_entry, ADW_TYPE_BIN)
+
+static guint last_tag = 0;
+
+static void
+on_add_tag_clicked (GtkButton *button,
+ AdwDemoPageTaggedEntry *self)
+{
+ char *tag_label = g_strdup_printf ("Tag: %d", last_tag);
+
+ AdwTag *tag = adw_tag_new ();
+ adw_tag_set_label (tag, tag_label);
+ adw_tag_set_action_name (tag, "tags.removable");
+ adw_tag_set_action_target (tag, "i", last_tag);
+
+ adw_tagged_entry_add_tag (self->manual_tagged_entry, tag);
+
+ last_tag += 1;
+}
+
+static void
+on_remove_all_clicked (GtkButton *button,
+ AdwDemoPageTaggedEntry *self)
+{
+ adw_tagged_entry_remove_all_tags (self->manual_tagged_entry);
+}
+
+static void
+on_tag_clicked_activate (GAction *action,
+ GVariant *parameter G_GNUC_UNUSED,
+ AdwDemoPageTaggedEntry *self)
+{
+ g_print ("Tag activated\n");
+}
+
+static void
+on_tag_removable_activate (GAction *action,
+ GVariant *parameter,
+ AdwDemoPageTaggedEntry *self)
+{
+ g_print ("Removable tag %d activated\n",
+ g_variant_get_int32 (parameter));
+}
+
+static void
+adw_demo_page_tagged_entry_class_init (AdwDemoPageTaggedEntryClass *klass)
+{
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/Adwaita1/Demo/ui/pages/tagged-entry/adw-demo-page-tagged-entry.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, AdwDemoPageTaggedEntry, manual_tagged_entry);
+ gtk_widget_class_bind_template_child (widget_class, AdwDemoPageTaggedEntry, add_tag_button);
+ gtk_widget_class_bind_template_child (widget_class, AdwDemoPageTaggedEntry, remove_all_button);
+ gtk_widget_class_bind_template_child (widget_class, AdwDemoPageTaggedEntry, automatic_tagged_entry);
+ gtk_widget_class_bind_template_child (widget_class, AdwDemoPageTaggedEntry, completion_tagged_entry);
+
+ gtk_widget_class_bind_template_callback (widget_class, on_add_tag_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_remove_all_clicked);
+}
+
+static void
+adw_demo_page_tagged_entry_init (AdwDemoPageTaggedEntry *self)
+{
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ GSimpleActionGroup *group = g_simple_action_group_new ();
+ gtk_widget_insert_action_group (GTK_WIDGET (self), "tags", G_ACTION_GROUP (group));
+ g_object_unref (group);
+
+ GSimpleAction *tag_action = g_simple_action_new ("clicked", NULL);
+ g_signal_connect (tag_action, "activate", G_CALLBACK (on_tag_clicked_activate), self);
+ g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (tag_action));
+ g_object_unref (tag_action);
+
+ GSimpleAction *removable_action = g_simple_action_new ("removable", G_VARIANT_TYPE ("i"));
+ g_signal_connect (removable_action, "activate", G_CALLBACK (on_tag_removable_activate), self);
+ g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (removable_action));
+ g_object_unref (removable_action);
+}
diff --git a/demo/pages/tagged-entry/adw-demo-page-tagged-entry.h
b/demo/pages/tagged-entry/adw-demo-page-tagged-entry.h
new file mode 100644
index 00000000..6d62fd96
--- /dev/null
+++ b/demo/pages/tagged-entry/adw-demo-page-tagged-entry.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include <adwaita.h>
+
+G_BEGIN_DECLS
+
+#define ADW_TYPE_DEMO_PAGE_TAGGED_ENTRY (adw_demo_page_tagged_entry_get_type())
+
+G_DECLARE_FINAL_TYPE (AdwDemoPageTaggedEntry, adw_demo_page_tagged_entry, ADW,
ADW_TYPE_DEMO_PAGE_TAGGED_ENTRY, AdwBin)
+
+G_END_DECLS
diff --git a/demo/pages/tagged-entry/adw-demo-page-tagged-entry.ui
b/demo/pages/tagged-entry/adw-demo-page-tagged-entry.ui
new file mode 100644
index 00000000..daad621b
--- /dev/null
+++ b/demo/pages/tagged-entry/adw-demo-page-tagged-entry.ui
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk" version="4.0"/>
+ <requires lib="libadwaita" version="1.0"/>
+ <template class="AdwDemoPageTaggedEntry" parent="AdwBin">
+ <property name="child">
+ <object class="AdwStatusPage">
+ <property name="title" translatable="yes">Tagged Entries</property>
+ <property name="description" translatable="yes">Entries with tags.</property>
+ <property name="child">
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="spacing">18</property>
+ <child>
+
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="label">Manual Tags</property>
+ <style>
+ <class name="heading"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="AdwTaggedEntry" id="manual_tagged_entry">
+ <property name="placeholder-text" translatable="yes">Enter text here...</property>
+ <property name="delimiter-chars"></property>
+ <child>
+ <object class="AdwTag">
+ <property name="gicon">
+ <object class="GThemedIcon">
+ <property name="names">emoji-body-symbolic</property>
+ </object>
+ </property>
+ <property name="label">First</property>
+ <property name="show-close">0</property>
+ <property name="action-name">tags.clicked</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="add_tag_button">
+ <property name="label" translatable="yes">Add tag</property>
+ <signal name="clicked" handler="on_add_tag_clicked" object="AdwDemoPageTaggedEntry"
swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="remove_all_button">
+ <property name="label" translatable="yes">Remove all tags</property>
+ <signal name="clicked" handler="on_remove_all_clicked" object="AdwDemoPageTaggedEntry"
swapped="no"/>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="label">Automatic Tags</property>
+ <style>
+ <class name="heading"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="AdwTaggedEntry" id="automatic_tagged_entry">
+ <property name="placeholder-text" translatable="yes">Enter a comma after each
tag</property>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="label">Tag Completion</property>
+ <style>
+ <class name="heading"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="AdwTaggedEntry" id="completion_tagged_entry">
+ <property name="placeholder-text" translatable="yes">Enter text here...</property>
+ <property name="match-model">
+ <object class="GtkStringList">
+ <items>
+ <item>foo</item>
+ <item>bar</item>
+ <item>baz</item>
+ <item>quux</item>
+ <item>GNOME</item>
+ <item>GTK</item>
+ </items>
+ </object>
+ </property>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ </object>
+ </property>
+ </object>
+ </property>
+ </template>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]