Merge branch 'matthiasc/for-master' into 'master'

Matthiasc/for master

See merge request GNOME/gtk!2422
This commit is contained in:
Matthias Clasen 2020-08-09 17:11:18 +00:00
commit ce1cd67fa4
10 changed files with 461 additions and 256 deletions

View File

@ -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>
@ -229,7 +230,6 @@
<file>listview_words.c</file>
<file>list_store.c</file>
<file>markup.c</file>
<file>modelbutton.c</file>
<file>overlay.c</file>
<file>overlay2.c</file>
<file>paint.c</file>
@ -279,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>
@ -310,9 +313,6 @@
<gresource prefix="/scale">
<file>scale.ui</file>
</gresource>
<gresource prefix="/modelbutton">
<file>modelbutton.ui</file>
</gresource>
<gresource prefix="/tagged_entry">
<file>demotaggedentry.c</file>
<file>demotaggedentry.h</file>

View File

@ -1,4 +1,4 @@
/* List Box
/* List Box/Complex list
*
* GtkListBox allows lists with complicated layouts, using
* regular widgets supporting sorting and filtering.

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

@ -766,6 +766,7 @@ demo_filter_by_name (GtkTreeListRow *row,
GListModel *children;
GtkDemo *demo;
guint i, n;
GtkTreeListRow *parent;
/* Show all items if search is empty */
if (!search_needle || !search_needle[0] || !*search_needle[0])
@ -774,6 +775,17 @@ demo_filter_by_name (GtkTreeListRow *row,
g_assert (GTK_IS_TREE_LIST_ROW (row));
g_assert (GTK_IS_FILTER_LIST_MODEL (model));
/* Show a row if itself of any parent matches */
for (parent = row; parent; parent = gtk_tree_list_row_get_parent (parent))
{
demo = gtk_tree_list_row_get_item (parent);
g_assert (GTK_IS_DEMO (demo));
if (filter_demo (demo))
return TRUE;
}
/* Show a row if any child matches */
children = gtk_tree_list_row_get_children (row);
if (children)
{
@ -792,10 +804,7 @@ demo_filter_by_name (GtkTreeListRow *row,
}
}
demo = gtk_tree_list_row_get_item (row);
g_assert (GTK_IS_DEMO (demo));
return filter_demo (demo);
return FALSE;
}
static void

View File

@ -40,6 +40,7 @@ demos = files([
'infobar.c',
'links.c',
'listbox.c',
'listbox2.c',
'flowbox.c',
'list_store.c',
'listview_applauncher.c',
@ -51,7 +52,6 @@ demos = files([
'listview_weather.c',
'listview_words.c',
'markup.c',
'modelbutton.c',
'overlay.c',
'overlay2.c',
'paint.c',

View File

@ -1,66 +0,0 @@
/* 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>
void
modelbutton_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");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&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 (window);
else
gtk_window_destroy (GTK_WINDOW (window));
return window;
}

View File

@ -1,133 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window1">
<property name="title" translatable="yes">Model Button</property>
<property name="resizable">0</property>
<child type="titlebar">
<object class="GtkHeaderBar"/>
</child>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="margin-start">80</property>
<property name="margin-end">80</property>
<property name="margin-top">80</property>
<property name="margin-bottom">80</property>
<child>
<object class="GtkMenuButton">
<property name="popover">thing_a</property>
<property name="label">_Color</property>
<property name="use-underline">1</property>
</object>
</child>
<child>
<object class="GtkMenuButton">
<property name="popover">thing_b</property>
<property name="label">_Flavors</property>
<property name="use-underline">1</property>
</object>
</child>
<child>
<object class="GtkMenuButton">
<property name="popover">thing_c</property>
<property name="label">_Tools</property>
<property name="use-underline">1</property>
</object>
</child>
</object>
</child>
</object>
<object class="GtkPopover" id="thing_a">
<style>
<class name="menu"/>
</style>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkModelButton">
<property name="action-name">win.color</property>
<property name="action-target">&apos;red&apos;</property>
<property name="text">Red</property>
</object>
</child>
<child>
<object class="GtkModelButton">
<property name="action-name">win.color</property>
<property name="action-target">&apos;green&apos;</property>
<property name="text">Green</property>
</object>
</child>
<child>
<object class="GtkModelButton">
<property name="action-name">win.color</property>
<property name="action-target">&apos;blue&apos;</property>
<property name="text">Blue</property>
</object>
</child>
</object>
</child>
</object>
<object class="GtkPopover" id="thing_b">
<style>
<class name="menu"/>
</style>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkModelButton">
<property name="action-name">win.chocolate</property>
<property name="text">Chocolate</property>
</object>
</child>
<child>
<object class="GtkModelButton">
<property name="action-name">win.vanilla</property>
<property name="text">Vanilla</property>
</object>
</child>
<child>
<object class="GtkSeparator"/>
</child>
<child>
<object class="GtkModelButton">
<property name="action-name">win.sprinkles</property>
<property name="text">Add Sprinkles</property>
</object>
</child>
</object>
</child>
</object>
<object class="GtkPopover" id="thing_c">
<style>
<class name="menu"/>
</style>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkModelButton">
<property name="text">Hammer</property>
<property name="role">check</property>
<signal name="clicked" handler="modelbutton_tool_clicked"/>
</object>
</child>
<child>
<object class="GtkModelButton">
<property name="text">Screwdriver</property>
<property name="role">check</property>
<signal name="clicked" handler="modelbutton_tool_clicked"/>
</object>
</child>
<child>
<object class="GtkModelButton">
<property name="text">Drill</property>
<property name="role">check</property>
<signal name="clicked" handler="modelbutton_tool_clicked"/>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@ -185,54 +185,54 @@ do_spinbutton (GtkWidget *do_widget)
static GtkWidget *window;
if (!window)
{
GtkBuilder *builder;
GtkAdjustment *adj;
GtkWidget *label;
{
GtkBuilder *builder;
GtkAdjustment *adj;
GtkWidget *label;
builder = gtk_builder_new_from_resource ("/spinbutton/spinbutton.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Spin Buttons");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
builder = gtk_builder_new_from_resource ("/spinbutton/spinbutton.ui");
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
gtk_window_set_display (GTK_WINDOW (window),
gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Spin Buttons");
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
adj = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "basic_adjustment"));
label = GTK_WIDGET (gtk_builder_get_object (builder, "basic_label"));
g_object_bind_property_full (adj, "value",
label, "label",
G_BINDING_SYNC_CREATE,
value_to_label,
NULL,
NULL, NULL);
adj = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "hex_adjustment"));
label = GTK_WIDGET (gtk_builder_get_object (builder, "hex_label"));
g_object_bind_property_full (adj, "value",
label, "label",
G_BINDING_SYNC_CREATE,
value_to_label,
NULL,
NULL, NULL);
adj = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "time_adjustment"));
label = GTK_WIDGET (gtk_builder_get_object (builder, "time_label"));
g_object_bind_property_full (adj, "value",
label, "label",
G_BINDING_SYNC_CREATE,
value_to_label,
NULL,
NULL, NULL);
adj = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "month_adjustment"));
label = GTK_WIDGET (gtk_builder_get_object (builder, "month_label"));
g_object_bind_property_full (adj, "value",
label, "label",
G_BINDING_SYNC_CREATE,
value_to_label,
NULL,
NULL, NULL);
adj = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "basic_adjustment"));
label = GTK_WIDGET (gtk_builder_get_object (builder, "basic_label"));
g_object_bind_property_full (adj, "value",
label, "label",
G_BINDING_SYNC_CREATE,
value_to_label,
NULL,
NULL, NULL);
adj = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "hex_adjustment"));
label = GTK_WIDGET (gtk_builder_get_object (builder, "hex_label"));
g_object_bind_property_full (adj, "value",
label, "label",
G_BINDING_SYNC_CREATE,
value_to_label,
NULL,
NULL, NULL);
adj = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "time_adjustment"));
label = GTK_WIDGET (gtk_builder_get_object (builder, "time_label"));
g_object_bind_property_full (adj, "value",
label, "label",
G_BINDING_SYNC_CREATE,
value_to_label,
NULL,
NULL, NULL);
adj = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "month_adjustment"));
label = GTK_WIDGET (gtk_builder_get_object (builder, "month_label"));
g_object_bind_property_full (adj, "value",
label, "label",
G_BINDING_SYNC_CREATE,
value_to_label,
NULL,
NULL, NULL);
g_object_unref (builder);
}
g_object_unref (builder);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);

View File

@ -3078,11 +3078,11 @@ list {
> row.expander .row-header { padding: 2px; }
&.horizontal row.separator:not(:first-child),
&.separators.horizontal row:not(:first-child) {
&.separators.horizontal > row:not(:first-child) {
border-left: 1px solid $borders_color;
}
&:not(.horizontal) row.separator:not(:first-child),
&.separators:not(.horizontal) row:not(:first-child) {
&.separators:not(.horizontal) > row:not(:first-child) {
border-top: 1px solid $borders_color;
}
}