gtk-demo: Add another listbox demo

This is a more typical listbox use.
This commit is contained in:
Matthias Clasen 2020-08-09 12:29:52 -04:00
parent 473ed75ed5
commit 5b41612f28
4 changed files with 400 additions and 0 deletions

View File

@ -219,6 +219,7 @@
<file>infobar.c</file> <file>infobar.c</file>
<file>links.c</file> <file>links.c</file>
<file>listbox.c</file> <file>listbox.c</file>
<file>listbox2.c</file>
<file>listview_applauncher.c</file> <file>listview_applauncher.c</file>
<file>listview_colors.c</file> <file>listview_colors.c</file>
<file>listview_clocks.c</file> <file>listview_clocks.c</file>
@ -278,6 +279,9 @@
<file>messages.txt</file> <file>messages.txt</file>
<file>apple-red.png</file> <file>apple-red.png</file>
</gresource> </gresource>
<gresource prefix="/listbox2">
<file>listbox2.ui</file>
</gresource>
<gresource prefix="/glarea"> <gresource prefix="/glarea">
<file>glarea-gl.fs.glsl</file> <file>glarea-gl.fs.glsl</file>
<file>glarea-gl.vs.glsl</file> <file>glarea-gl.vs.glsl</file>

71
demos/gtk-demo/listbox2.c Normal file
View File

@ -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;
}

324
demos/gtk-demo/listbox2.ui Normal file
View File

@ -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>

View File

@ -40,6 +40,7 @@ demos = files([
'infobar.c', 'infobar.c',
'links.c', 'links.c',
'listbox.c', 'listbox.c',
'listbox2.c',
'flowbox.c', 'flowbox.c',
'list_store.c', 'list_store.c',
'listview_applauncher.c', 'listview_applauncher.c',