[gtk/matthiasc/for-master] gtk-demo: Add another listbox demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master] gtk-demo: Add another listbox demo
- Date: Sun, 9 Aug 2020 16:36:34 +0000 (UTC)
commit 5b41612f28b206df2737a8f16018f910ba21a3ab
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Aug 9 12:29:52 2020 -0400
gtk-demo: Add another listbox demo
This is a more typical listbox use.
demos/gtk-demo/demo.gresource.xml | 4 +
demos/gtk-demo/listbox2.c | 71 +++++++++
demos/gtk-demo/listbox2.ui | 324 ++++++++++++++++++++++++++++++++++++++
demos/gtk-demo/meson.build | 1 +
4 files changed, 400 insertions(+)
---
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index 4cfc704db5..b2712d8dba 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -219,6 +219,7 @@
<file>infobar.c</file>
<file>links.c</file>
<file>listbox.c</file>
+ <file>listbox2.c</file>
<file>listview_applauncher.c</file>
<file>listview_colors.c</file>
<file>listview_clocks.c</file>
@@ -278,6 +279,9 @@
<file>messages.txt</file>
<file>apple-red.png</file>
</gresource>
+ <gresource prefix="/listbox2">
+ <file>listbox2.ui</file>
+ </gresource>
<gresource prefix="/glarea">
<file>glarea-gl.fs.glsl</file>
<file>glarea-gl.vs.glsl</file>
diff --git a/demos/gtk-demo/listbox2.c b/demos/gtk-demo/listbox2.c
new file mode 100644
index 0000000000..6b4aae0009
--- /dev/null
+++ b/demos/gtk-demo/listbox2.c
@@ -0,0 +1,71 @@
+/* List Box/Controls
+ *
+ * GtkListBox is well-suited for creating “button strips” — lists of
+ * controls for use in preference dialogs or settings panels. To create
+ * this style of list, use the .rich-list style class.
+ */
+
+#include <gtk/gtk.h>
+
+static GtkWidget *window;
+static GtkWidget *switch_widget;
+static GtkWidget *check;
+static GtkWidget *image;
+
+static void
+row_activated (GtkListBox *list,
+ GtkListBoxRow *row)
+{
+ if (gtk_widget_is_ancestor (switch_widget, GTK_WIDGET (row)))
+ {
+ gtk_switch_set_active (GTK_SWITCH (switch_widget),
+ !gtk_switch_get_active (GTK_SWITCH (switch_widget)));
+ }
+ else if (gtk_widget_is_ancestor (check, GTK_WIDGET (row)))
+ {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check),
+ !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+ }
+ else if (gtk_widget_is_ancestor (image, GTK_WIDGET (row)))
+ {
+ gtk_widget_set_opacity (image,
+ 1.0 - gtk_widget_get_opacity (image));
+ }
+}
+
+GtkWidget *
+do_listbox2 (GtkWidget *do_widget)
+{
+ if (!window)
+ {
+ GtkBuilderScope *scope;
+ GtkBuilder *builder;
+
+ scope = gtk_builder_cscope_new ();
+ gtk_builder_cscope_add_callback_symbol (GTK_BUILDER_CSCOPE (scope),
+ "row_activated", G_CALLBACK (row_activated));
+ builder = gtk_builder_new ();
+ gtk_builder_set_scope (builder, scope);
+
+ gtk_builder_add_from_resource (builder, "/listbox2/listbox2.ui", NULL);
+
+ window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
+ gtk_window_set_display (GTK_WINDOW (window),
+ gtk_widget_get_display (do_widget));
+ g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
+
+ switch_widget = GTK_WIDGET (gtk_builder_get_object (builder, "switch"));
+ check = GTK_WIDGET (gtk_builder_get_object (builder, "check"));
+ image = GTK_WIDGET (gtk_builder_get_object (builder, "image"));
+
+ g_object_unref (builder);
+ g_object_unref (scope);
+ }
+
+ if (!gtk_widget_get_visible (window))
+ gtk_widget_show (window);
+ else
+ gtk_window_destroy (GTK_WINDOW (window));
+
+ return window;
+}
diff --git a/demos/gtk-demo/listbox2.ui b/demos/gtk-demo/listbox2.ui
new file mode 100644
index 0000000000..54975c887b
--- /dev/null
+++ b/demos/gtk-demo/listbox2.ui
@@ -0,0 +1,324 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkWindow" id="window">
+ <property name="title" translatable="yes">List Box — Controls</property>
+ <property name="default-height">400</property>
+ <child>
+ <object class="GtkScrolledWindow">
+ <property name="hscrollbar-policy">never</property>
+ <property name="min-content-height">200</property>
+ <property name="hexpand">0</property>
+ <property name="vexpand">1</property>
+ <child>
+ <object class="GtkViewport">
+ <property name="scroll-to-focus">1</property>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <property name="margin-start">60</property>
+ <property name="margin-end">60</property>
+ <property name="margin-top">30</property>
+ <property name="margin-bottom">30</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="label">Group 1</property>
+ <property name="xalign">0</property>
+ <property name="margin-bottom">10</property>
+ <style>
+ <class name="title-2"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkFrame">
+ <child>
+ <object class="GtkListBox">
+ <property name="selection-mode">none</property>
+ <property name="show-separators">1</property>
+ <signal name="row-activated" handler="row_activated"/>
+ <child>
+ <object class="GtkListBoxRow">
+ <child>
+ <object class="GtkBox">
+ <property name="margin-start">6</property>
+ <property name="margin-end">6</property>
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="spacing">12</property>
+ <property name="height-request">34</property>
+ <child>
+ <object class="GtkLabel" id="switch_label">
+ <property name="label" translatable="yes">Switch</property>
+ <property name="halign">start</property>
+ <property name="valign">center</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSwitch" id="switch">
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkListBoxRow">
+ <child>
+ <object class="GtkBox">
+ <property name="margin-start">6</property>
+ <property name="margin-end">6</property>
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="spacing">12</property>
+ <property name="height-request">34</property>
+ <child>
+ <object class="GtkLabel" id="check_label">
+ <property name="label" translatable="yes">Check</property>
+ <property name="halign">start</property>
+ <property name="valign">center</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="check">
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ <property name="margin-start">10</property>
+ <property name="margin-end">10</property>
+ <property name="active">1</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkListBoxRow">
+ <child>
+ <object class="GtkBox">
+ <property name="margin-start">6</property>
+ <property name="margin-end">6</property>
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="spacing">12</property>
+ <property name="height-request">34</property>
+ <child>
+ <object class="GtkLabel" id="image_label">
+ <property name="label" translatable="yes">Click here!</property>
+ <property name="halign">start</property>
+ <property name="valign">center</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkImage" id="image">
+ <property name="icon-name">object-select-symbolic</property>
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ <property name="opacity">0</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkLabel">
+ <property name="margin-top">30</property>
+ <property name="margin-bottom">10</property>
+ <property name="label">Group 2</property>
+ <property name="xalign">0</property>
+ <style>
+ <class name="title-2"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkFrame">
+ <child>
+ <object class="GtkListBox">
+ <property name="selection-mode">none</property>
+ <property name="show-separators">1</property>
+
+ <child>
+ <object class="GtkListBoxRow">
+ <property name="activatable">0</property>
+ <child>
+ <object class="GtkBox">
+ <property name="margin-start">6</property>
+ <property name="margin-end">6</property>
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="spacing">12</property>
+ <property name="height-request">34</property>
+ <child>
+ <object class="GtkLabel" id="scale_label">
+ <property name="label" translatable="yes">Scale</property>
+ <property name="halign">start</property>
+ <property name="valign">center</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkScale">
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ <property name="draw-value">0</property>
+ <property name="width-request">150</property>
+ <property name="adjustment">
+ <object class="GtkAdjustment">
+ <property name="upper">100</property>
+ <property name="value">50</property>
+ <property name="step-increment">1</property>
+ <property name="page-increment">10</property>
+ </object>
+ </property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkListBoxRow">
+ <property name="activatable">0</property>
+ <child>
+ <object class="GtkBox">
+ <property name="margin-start">6</property>
+ <property name="margin-end">6</property>
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="spacing">12</property>
+ <property name="height-request">34</property>
+ <child>
+ <object class="GtkLabel" id="spin_label">
+ <property name="label" translatable="yes">Spinbutton</property>
+ <property name="halign">start</property>
+ <property name="valign">center</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSpinButton">
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ <property name="adjustment">
+ <object class="GtkAdjustment">
+ <property name="upper">100</property>
+ <property name="value">50</property>
+ <property name="step-increment">1</property>
+ <property name="page-increment">10</property>
+ </object>
+ </property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkListBoxRow">
+ <property name="activatable">0</property>
+ <child>
+ <object class="GtkBox">
+ <property name="margin-start">6</property>
+ <property name="margin-end">6</property>
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="spacing">12</property>
+ <property name="height-request">34</property>
+ <child>
+ <object class="GtkLabel" id="dropdown_label">
+ <property name="label" translatable="yes">Dropdown</property>
+ <property name="halign">start</property>
+ <property name="valign">center</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkDropDown">
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ <property name="model">
+ <object class="GtkStringList">
+ <items>
+ <item>Choice 1</item>
+ <item>Choice 2</item>
+ <item>Choice 3</item>
+ <item>Choice 4</item>
+ </items>
+ </object>
+ </property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkListBoxRow">
+ <property name="activatable">0</property>
+ <child>
+ <object class="GtkBox">
+ <property name="margin-start">6</property>
+ <property name="margin-end">6</property>
+ <property name="margin-top">6</property>
+ <property name="margin-bottom">6</property>
+ <property name="spacing">12</property>
+ <property name="height-request">34</property>
+ <child>
+ <object class="GtkLabel" id="entry_label">
+ <property name="label" translatable="yes">Entry</property>
+ <property name="halign">start</property>
+ <property name="valign">center</property>
+ <property name="hexpand">1</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkEntry">
+ <property name="halign">end</property>
+ <property name="valign">center</property>
+ <property name="placeholder-text">Type here…</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <object class="GtkSizeGroup">
+ <property name="mode">horizontal</property>
+ <widgets>
+ <widget name="switch_label"/>
+ <widget name="check_label"/>
+ <widget name="image_label"/>
+ <widget name="scale_label"/>
+ <widget name="spin_label"/>
+ <widget name="dropdown_label"/>
+ <widget name="entry_label"/>
+ </widgets>
+ </object>
+</interface>
diff --git a/demos/gtk-demo/meson.build b/demos/gtk-demo/meson.build
index 8eaf7090da..9e0eaf2e9b 100644
--- a/demos/gtk-demo/meson.build
+++ b/demos/gtk-demo/meson.build
@@ -40,6 +40,7 @@ demos = files([
'infobar.c',
'links.c',
'listbox.c',
+ 'listbox2.c',
'flowbox.c',
'list_store.c',
'listview_applauncher.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]