[gtk+] gtk-demo: Add a model button demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gtk-demo: Add a model button demo
- Date: Thu, 20 Aug 2015 03:18:08 +0000 (UTC)
commit 4d9a94333820edb8dfbd8584605e661d18467e64
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Aug 19 23:17:01 2015 -0400
gtk-demo: Add a model button demo
This shows how to hook model buttons up to various action types,
or how to create them manually.
demos/gtk-demo/Makefile.am | 1 +
demos/gtk-demo/demo.gresource.xml | 4 +
demos/gtk-demo/modelbutton.c | 69 +++++++++++++++
demos/gtk-demo/modelbutton.ui | 168 +++++++++++++++++++++++++++++++++++++
4 files changed, 242 insertions(+), 0 deletions(-)
---
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index d85e7ca..088c251 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -41,6 +41,7 @@ demos_base = \
list_store.c \
markup.c \
menus.c \
+ modelbutton.c \
offscreen_window.c \
offscreen_window2.c \
overlay.c \
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index 70eb3b9..a3a3455 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -147,6 +147,7 @@
<file>list_store.c</file>
<file>markup.c</file>
<file>menus.c</file>
+ <file>modelbutton.c</file>
<file>offscreen_window.c</file>
<file>offscreen_window2.c</file>
<file>overlay.c</file>
@@ -209,4 +210,7 @@
<gresource prefix="/scale">
<file>scale.ui</file>
</gresource>
+ <gresource prefix="/modelbutton">
+ <file>modelbutton.ui</file>
+ </gresource>
</gresources>
diff --git a/demos/gtk-demo/modelbutton.c b/demos/gtk-demo/modelbutton.c
new file mode 100644
index 0000000..8dafda8
--- /dev/null
+++ b/demos/gtk-demo/modelbutton.c
@@ -0,0 +1,69 @@
+/* Model Button
+ *
+ * GtkModelButton is a button widget that is designed to be used with
+ * a GAction as model. The button will adjust its appearance according
+ * to the kind of action it is connected to.
+ *
+ * It is also possible to use GtkModelButton without a GAction. In this
+ * case, you should set the "role" attribute yourself, and connect to the
+ * "clicked" signal as you would for any other button.
+ *
+ * A common use of GtkModelButton is to implement menu-like content
+ * in popovers.
+ */
+
+#include <gtk/gtk.h>
+
+static void
+tool_clicked (GtkButton *button)
+{
+ gboolean active;
+
+ g_object_get (button, "active", &active, NULL);
+ g_object_set (button, "active", !active, NULL);
+}
+
+GtkWidget *
+do_modelbutton (GtkWidget *do_widget)
+{
+ static GtkWidget *window = NULL;
+ static GActionEntry win_entries[] = {
+ { "color", NULL, "s", "'red'", NULL },
+ { "chocolate", NULL, NULL, "true", NULL },
+ { "vanilla", NULL, NULL, "false", NULL },
+ { "sprinkles", NULL, NULL, NULL, NULL }
+ };
+
+ if (!window)
+ {
+ GtkBuilder *builder;
+ GActionGroup *actions;
+
+ builder = gtk_builder_new_from_resource ("/modelbutton/modelbutton.ui");
+ gtk_builder_add_callback_symbol (builder, "tool_clicked", G_CALLBACK (tool_clicked));
+ gtk_builder_connect_signals (builder, NULL);
+ window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
+ gtk_window_set_screen (GTK_WINDOW (window),
+ gtk_widget_get_screen (do_widget));
+ g_signal_connect (window, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &window);
+
+ actions = (GActionGroup*)g_simple_action_group_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (actions),
+ win_entries, G_N_ELEMENTS (win_entries),
+ window);
+ gtk_widget_insert_action_group (window, "win", actions);
+
+
+ g_object_unref (builder);
+ }
+
+ if (!gtk_widget_get_visible (window))
+ gtk_widget_show_all (window);
+ else
+ gtk_widget_destroy (window);
+
+
+ return window;
+}
+
diff --git a/demos/gtk-demo/modelbutton.ui b/demos/gtk-demo/modelbutton.ui
new file mode 100644
index 0000000..39121a3
--- /dev/null
+++ b/demos/gtk-demo/modelbutton.ui
@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.6 -->
+ <object class="GtkWindow" id="window1">
+ <child type="titlebar">
+ <object class="GtkHeaderBar">
+ <property name="visible">True</property>
+ <property name="show-close-button">True</property>
+ <property name="title" translatable="yes">Model Button</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="margin">80</property>
+ <child>
+ <object class="GtkMenuButton">
+ <property name="visible">True</property>
+ <property name="popover">thing_a</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label">Color</property>
+ <property name="hexpand">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuButton">
+ <property name="visible">True</property>
+ <property name="popover">thing_b</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label">Flavors</property>
+ <property name="hexpand">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuButton">
+ <property name="visible">True</property>
+ <property name="popover">thing_c</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="label">Tools</property>
+ <property name="hexpand">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <object class="GtkPopover" id="thing_a">
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="margin">10</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="halign">fill</property>
+ <property name="action-name">win.color</property>
+ <property name="action-target">'red'</property>
+ <property name="text">Red</property>
+ <property name="inverted">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="halign">fill</property>
+ <property name="action-name">win.color</property>
+ <property name="action-target">'green'</property>
+ <property name="text">Green</property>
+ <property name="inverted">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="halign">fill</property>
+ <property name="action-name">win.color</property>
+ <property name="action-target">'blue'</property>
+ <property name="text">Blue</property>
+ <property name="inverted">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <object class="GtkPopover" id="thing_b">
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="margin">10</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="action-name">win.chocolate</property>
+ <property name="text">Chocolate</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="action-name">win.vanilla</property>
+ <property name="text">Vanilla</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="action-name">win.sprinkles</property>
+ <property name="text">Add Sprinkles</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <object class="GtkPopover" id="thing_c">
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="margin">10</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">10</property>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="text">Hammer</property>
+ <property name="role">check</property>
+ <signal name="clicked" handler="tool_clicked"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="text">Screwdriver</property>
+ <property name="role">check</property>
+ <signal name="clicked" handler="tool_clicked"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkModelButton">
+ <property name="visible">True</property>
+ <property name="text">Drill</property>
+ <property name="role">check</property>
+ <signal name="clicked" handler="tool_clicked"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]