From 5b41612f28b206df2737a8f16018f910ba21a3ab Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 9 Aug 2020 12:29:52 -0400 Subject: [PATCH] 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(+) create mode 100644 demos/gtk-demo/listbox2.c create mode 100644 demos/gtk-demo/listbox2.ui 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 @@ infobar.c links.c listbox.c + listbox2.c listview_applauncher.c listview_colors.c listview_clocks.c @@ -278,6 +279,9 @@ messages.txt apple-red.png + + listbox2.ui + glarea-gl.fs.glsl glarea-gl.vs.glsl 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 + +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 @@ + + + + List Box — Controls + 400 + + + never + 200 + 0 + 1 + + + 1 + + + vertical + 60 + 60 + 30 + 30 + + + Group 1 + 0 + 10 + + + + + + + + none + 1 + + + + + + 6 + 6 + 6 + 6 + 12 + 34 + + + Switch + start + center + 1 + + + + + end + center + + + + + + + + + + + + 6 + 6 + 6 + 6 + 12 + 34 + + + Check + start + center + 1 + + + + + end + center + 10 + 10 + 1 + + + + + + + + + + + + 6 + 6 + 6 + 6 + 12 + 34 + + + Click here! + start + center + 1 + + + + + object-select-symbolic + end + center + 0 + + + + + + + + + + + + + + 30 + 10 + Group 2 + 0 + + + + + + + + none + 1 + + + + 0 + + + 6 + 6 + 6 + 6 + 12 + 34 + + + Scale + start + center + 1 + + + + + end + center + 0 + 150 + + + 100 + 50 + 1 + 10 + + + + + + + + + + + + 0 + + + 6 + 6 + 6 + 6 + 12 + 34 + + + Spinbutton + start + center + 1 + + + + + end + center + + + 100 + 50 + 1 + 10 + + + + + + + + + + + 0 + + + 6 + 6 + 6 + 6 + 12 + 34 + + + Dropdown + start + center + 1 + + + + + end + center + + + + Choice 1 + Choice 2 + Choice 3 + Choice 4 + + + + + + + + + + + + + 0 + + + 6 + 6 + 6 + 6 + 12 + 34 + + + Entry + start + center + 1 + + + + + end + center + Type here… + + + + + + + + + + + + + + + + + + + + horizontal + + + + + + + + + + + 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',