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

Matthiasc/for master

Closes #1887

See merge request GNOME/gtk!2167
This commit is contained in:
Matthias Clasen 2020-06-29 12:30:41 +00:00
commit 6ddd9793f3
9 changed files with 512 additions and 17 deletions

View File

@ -133,7 +133,7 @@ gtk_demo_run (GtkDemo *self,
}
return TRUE;
}
static void
activate_about (GSimpleAction *action,
GVariant *parameter,
@ -1155,7 +1155,7 @@ out:
static void
print_version (void)
{
g_print ("gtk3-demo %d.%d.%d\n",
g_print ("gtk4-demo %d.%d.%d\n",
gtk_get_major_version (),
gtk_get_minor_version (),
gtk_get_micro_version ());

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window">
<style>
<class name="devel"/>
</style>
<property name="title" translatable="yes">Help</property>
<property name="default-width">720</property>
<property name="default-height">520</property>
<child>
<object class="GtkScrolledWindow">
<child>
<object class="GtkTextView" id="text_view">
<property name="wrap-mode">word</property>
<property name="left-margin">20</property>
<property name="right-margin">20</property>
<property name="top-margin">20</property>
<property name="bottom-margin">20</property>
<property name="buffer">
<object class="GtkTextBuffer" id="buffer"/>
</property>
</object>
</child>
</object>
</child>
</object>
</interface>

View File

@ -51,21 +51,121 @@ node_editor_application_init (NodeEditorApplication *app)
}
static void
quit_activated (GSimpleAction *action,
activate_about (GSimpleAction *action,
GVariant *parameter,
gpointer data)
gpointer user_data)
{
GtkApplication *app = user_data;
char *version;
GString *s;
GskRenderer *gsk_renderer;
const char *renderer;
s = g_string_new ("");
g_string_append (s, "System libraries\n");
g_string_append_printf (s, "\tGLib\t%d.%d.%d\n",
glib_major_version,
glib_minor_version,
glib_micro_version);
g_string_append_printf (s, "\tPango\t%s\n",
pango_version_string ());
g_string_append_printf (s, "\tGTK\t%d.%d.%d\n",
gtk_get_major_version (),
gtk_get_minor_version (),
gtk_get_micro_version ());
gsk_renderer = gtk_native_get_renderer (GTK_NATIVE (gtk_application_get_active_window (app)));
if (strcmp (G_OBJECT_TYPE_NAME (gsk_renderer), "GskVulkanRenderer") == 0)
renderer = "Vulkan";
else if (strcmp (G_OBJECT_TYPE_NAME (gsk_renderer), "GskGLRenderer") == 0)
renderer = "OpenGL";
else if (strcmp (G_OBJECT_TYPE_NAME (gsk_renderer), "GskCairoRenderer") == 0)
renderer = "Cairo";
else
renderer = "Unknown";
g_string_append_printf (s, "\nRenderer\n\t%s", renderer);
version = g_strdup_printf ("%s\nRunning against GTK %d.%d.%d",
PACKAGE_VERSION,
gtk_get_major_version (),
gtk_get_minor_version (),
gtk_get_micro_version ());
gtk_show_about_dialog (GTK_WINDOW (gtk_application_get_active_window (app)),
"program-name", "GTK Node Editor",
"version", version,
"copyright", "©2019—2020 The GTK Team",
"license-type", GTK_LICENSE_LGPL_2_1,
"website", "http://www.gtk.org",
"comments", "Program to test GTK rendering",
"authors", (const char *[]){ "Benjamin Otte", "Timm Bäder", NULL},
"logo-icon-name", "text-editor-symbolic",
"title", "About GTK Node Editor",
"system-information", s->str,
NULL);
g_string_free (s, TRUE);
g_free (version);
}
static void
activate_quit (GSimpleAction *action,
GVariant *parameter,
gpointer data)
{
g_application_quit (G_APPLICATION (data));
}
static void
activate_inspector (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
gtk_window_set_interactive_debugging (TRUE);
}
static void
activate_help (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GtkBuilder *builder;
GtkWidget *window;
GtkTextBuffer *buffer;
GBytes *bytes;
const char *text;
gsize len;
builder = gtk_builder_new ();
gtk_builder_add_from_resource (builder, "/org/gtk/gtk4/node-editor/help-window.ui", NULL);
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
buffer = GTK_TEXT_BUFFER (gtk_builder_get_object (builder, "buffer"));
bytes = g_resources_lookup_data ("/org/gtk/gtk4/node-editor/node-format.md",
G_RESOURCE_LOOKUP_FLAGS_NONE,
NULL);
text = g_bytes_get_data (bytes, &len);
gtk_text_buffer_set_text (buffer, text, len);
g_bytes_unref (bytes);
gtk_window_present (GTK_WINDOW (window));
g_object_unref (builder);
}
static GActionEntry app_entries[] =
{
{ "quit", quit_activated, NULL, NULL, NULL }
{ "about", activate_about, NULL, NULL, NULL },
{ "quit", activate_quit, NULL, NULL, NULL },
{ "inspector", activate_inspector, NULL, NULL, NULL },
{ "help", activate_help, NULL, NULL, NULL },
};
static void
node_editor_application_startup (GApplication *app)
{
const char *help_accels[2] = { "F1", NULL };
const char *quit_accels[2] = { "<Ctrl>Q", NULL };
const char *open_accels[2] = { "<Ctrl>O", NULL };
GtkCssProvider *provider;
@ -75,6 +175,7 @@ node_editor_application_startup (GApplication *app)
g_action_map_add_action_entries (G_ACTION_MAP (app),
app_entries, G_N_ELEMENTS (app_entries),
app);
gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.help", help_accels);
gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.quit", quit_accels);
gtk_application_set_accels_for_action (GTK_APPLICATION (app), "win.open", open_accels);

View File

@ -825,6 +825,7 @@ node_editor_window_create_renderer_widget (gpointer item,
gtk_widget_set_size_request (box, 120, 90);
label = gtk_label_new (g_object_get_data (G_OBJECT (paintable), "description"));
gtk_widget_add_css_class (label, "title-4");
gtk_box_append (GTK_BOX (box), label);
picture = gtk_picture_new_for_paintable (paintable);

View File

@ -1,5 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="gear_menu">
<section>
<item>
<attribute name="label" translatable="yes">_Help</attribute>
<attribute name="action">app.help</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_Inspector</attribute>
<attribute name="action">app.inspector</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_About Node Editor</attribute>
<attribute name="action">app.about</attribute>
</item>
</section>
</menu>
<object class="GtkPopover" id="testcase_popover">
<child>
<object class="GtkGrid">
@ -119,6 +136,13 @@
<property name="popover">testcase_popover</property>
</object>
</child>
<child type="end">
<object class="GtkMenuButton" id="gear_menu_button">
<property name="valign">center</property>
<property name="menu-model">gear_menu</property>
<property name="icon-name">open-menu-symbolic</property>
</object>
</child>
</object>
</child>
<child>

View File

@ -2,5 +2,7 @@
<gresources>
<gresource prefix="/org/gtk/gtk4/node-editor">
<file preprocess="xml-stripblanks">node-editor-window.ui</file>
<file preprocess="xml-stripblanks">help-window.ui</file>
<file>node-format.md</file>
</gresource>
</gresources>

View File

@ -0,0 +1,213 @@
# The Node file format
GSK render nodes can be serialized and deserialized using APIs such as `gsk_render_node_serialize()` and `gsk_render_node_deserialize()`. The intended use for this is development - primarily the development of GTK - by allowing things such as creating testsuites and benchmarks, exchanging nodes in bug reports. GTK includes the `gtk4-node-editor` application for creating such test files.
The format is a text format that follows the [CSS syntax rules](https://drafts.csswg.org/css-syntax-3/). In particular, this means that every array of bytes will produce a render node when parsed, as there is a defined error recovery method. For more details on error handling, please refer to the documentation of the aprsing APIs.
The grammar of a node text representation using [the CSS value definition syntax](https://drafts.csswg.org/css-values-3/#value-defs) looks like this:
**document**: `<node>\*`
**node**: container { <document> } | `<node-name> { <property>* }`
**property**: `<property-name>: <node> | <value> ;`
Each node has its own `<node-name>` and supports a custom set of properties, each with their own `<property-name>` and syntax. The following paragraphs document each of the nodes and their properties.
When serializing and the value of a property equals the default value, this value will not be serialized. Serialization aims to produce an output as small as possible.
# Nodes
### container
The **container** node is a special node that allows specifying a list of child nodes. Its contents follow the same rules as an empty document.
### blend
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| bottom | `<node>` | color { color: #AF0; } | always |
| mode | `<blend-mode>` | normal | non-default |
| top | `<node>` | color { } | always |
Creates a node like `gsk_blend_node_new()` with the given properties.
### blur
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| blur | `<number>` | 1 | non-default |
| child | `<node>` | color { } | always |
Creates a node like `gsk_blur_node_new()` with the given properties.
### border
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| color | `<color>{1,4}` | black | non-default |
| outline | `<rounded-rect>` | 50 | always |
| width | `<number>{1,4}` | 1 | non-default |
Creates a node like `gsk_border_node_new()` with the given properties.
For the color and width properties, the values follow the typical CSS order of top, right, bottom, left. If the last/left value isn't given, the 2nd/right value is used. If the 3rd/bottom value isn't given, the 1st/top value is used. And if the 2nd/right value also isn't given, the 1st/top value is used for every 4 values.
### clip
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| child | `<node>` | color { } | always |
| clip | `<rounded-rect>` | 50 | always |
Creates a node like `gsk_clip_node_new()` with the given properties.
As an extension, this node allows specifying a rounded rectangle for the clip property. If that rectangle is indeed rounded, a node like `gsk_rounded_clip_node_new()` will be created instead.
### color
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| color | `<color>` | #FF00CC | always |
Creates a node like `gsk_color_node_new()` with the given properties.
The color is chosen as an error pink so it is visible while also reminding people to change it.
### color-matrix
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| child | `<node>` | color { } | always |
| matrix | `<transform>` | none | non-default |
| offset | `<number>{4}` | 0 0 0 0 | non-default |
Creates a node like `gsk_color_matrix_node_new()` with the given properties.
The matrix property accepts a <transform> for compatibility purposes, but you should be aware that the allowed values are meant to be used on 3D transformations, so their naming might appear awkward. However, it is always possible to use the matrix3d() production to specify all 16 values individually.
### cross-fade
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| end | `<node>` | color { } | always |
| mode | `<number>` | 0.5 | non-default |
| start | `<node>` | color { color: #AF0; } | always |
Creates a node like `gsk_cross_fade_node_new()` with the given properties.
### debug
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| child | `<node>` | color { } | always |
| message | `<string>` | "" | non-default |
Creates a node like `gsk_debug_node_new()` with the given properties.
### inset-shadow
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| blur | `<number>` | 0 | non-default |
| color | `<color>` | black | non-default |
| dx | `<number>` | 1 | non-default |
| dy | `<number>` | 1 | non-default |
| outline | `<rounded-rect>` | 50 | always |
| spread | `<number>` | 0 | non-default |
Creates a node like `gsk_inset_shadow_node_new()` with the given properties.
### linear-gradient
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| end | `<point>` | 0 50 | always |
| start | `<point>` | 0 0 | always |
| stops | `<color-stop>` | 0 #AF0, 1 #F0C | always |
Creates a node like `gsk_linear_gradient_node_new()` with the given properties.
### opacity
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| child | `<node>` | color { } | always |
| opacity | `<number>` | 0.5 | non-default |
Creates a node like `gsk_transform_node_new()` with the given properties.
### outset-shadow
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| blur | `<number>` | 0 | non-default |
| color | `<color>` | black | non-default |
| dx | `<number>` | 1 | non-default |
| dy | `<number>` | 1 | non-default |
| outline | `<rounded-rect>` | 50 | always |
| spread | `<number>` | 0 | non-default |
Creates a node like `gsk_outset_shadow_node_new()` with the given properties.
### repeat
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| bounds | `<rect>` | *bounds of child node* | non-default |
| child | `<node>` | color { } | always |
| child-bounds| `<rect>` | *bounds of child node* | non-default |
Creates a node like `gsk_repeat_node_new()` with the given properties.
### rounded-clip
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| child | `<node>` | color { } | always |
| clip | `<rounded-rect>` | 50 | always |
Creates a node like `gsk_rounded_clip_node_new()` with the given properties.
### shadow
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| child | `<node>` | color { } | always |
| shadow | `<shadow>` | black 1 1 | always |
Creates a node like `gsk_shadow_node_new()` with the given properties.
### text
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| color | `<color>` | black | non-default |
| font | `<string>` | "Cantarell 11" | always |
| glyphs | `<glyphs>` | "Hello" | always |
| offset | `<point>` | 0 0 | non-default |
Creates a node like `gsk_text_node_new()` with the given properties.
If the given font does not exist or the given glyphs are invalid for the given font, an error node will be returned.
### texture
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| bounds | `<rect>` | 50 | always |
| texture | `<url>` | *see below* | always |
Creates a node like `gsk_texture_node_new()` with the given properties.
The default texture is a 10x10 checkerboard with the top left and bottom right 5x5 being in the color #FF00CC and the other part being transparent. A possible representation for this texture is `url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABmJLR0QA/wD/AP+gvaeTAAAAKUlEQVQYlWP8z3DmPwMaYGQwYUQXY0IXwAUGUCGGoxkYGBiweXAoeAYAz44F3e3U1xUAAAAASUVORK5CYII=")
`.
### transform
| property | syntax | default | printed |
| -------- | ---------------- | ---------------------- | ----------- |
| child | `<node>` | color { } | always |
| transform| `<transform>` | none | non-default |
Creates a node like `gsk_transform_node_new()` with the given properties.

View File

@ -220,7 +220,7 @@ gtk_bitset_new_empty (void)
*
* Creates a copy of @self.
*
* Returns: (transfer full) A new bitset that contains the same
* Returns: (transfer full): A new bitset that contains the same
* values as @self
**/
GtkBitset *
@ -399,7 +399,7 @@ gtk_bitset_add_rectangle (GtkBitset *self,
guint i;
g_return_if_fail (self != NULL);
g_return_if_fail (width <= stride);
g_return_if_fail ((start % stride) + width <= stride);
g_return_if_fail (G_MAXUINT - start >= height * stride);
if (width == 0 || height == 0)
@ -664,7 +664,7 @@ G_STATIC_ASSERT (sizeof (GtkBitsetIter) >= sizeof (roaring_uint32_iterator_t));
/**
* gtk_bitset_iter_init_first:
* @iter: (out): a pointer to a preallocated #GtkBitsetIter
* @iter: (out): a pointer to an uninitialized #GtkBitsetIter
* @set: a #GtkBitset
* @value: (out) (optional): Set to the first value in @set
*
@ -694,7 +694,7 @@ gtk_bitset_iter_init_first (GtkBitsetIter *iter,
/**
* gtk_bitset_iter_init_last:
* @iter: (out): a pointer to a preallocated #GtkBitsetIter
* @iter: (out): a pointer to an uninitialized #GtkBitsetIter
* @set: a #GtkBitset
* @value: (out) (optional): Set to the last value in @set
*
@ -723,7 +723,7 @@ gtk_bitset_iter_init_last (GtkBitsetIter *iter,
/**
* gtk_bitset_iter_init_at:
* @iter: a #GtkBitsetIter
* @iter: (out): a pointer to an uninitialized #GtkBitsetIter
* @set: a #GtkBitset
* @target: target value to start iterating at
* @value: (out) (optional): Set to the found value in @set
@ -851,7 +851,7 @@ gtk_bitset_iter_get_value (const GtkBitsetIter *iter)
* gtk_bitset_iter_is_valid:
* @iter: a #GtkBitsetIter
*
* Checks if @iter points to a valid value
* Checks if @iter points to a valid value.
*
* Returns: %TRUE if @iter points to a valid value
**/
@ -864,4 +864,3 @@ gtk_bitset_iter_is_valid (const GtkBitsetIter *iter)
return riter->has_value;
}

View File

@ -345,7 +345,7 @@ test_subtract (void)
gtk_bitset_unref (testset);
gtk_bitset_unref (jset);
}
gtk_bitset_unref (iset);
}
}
@ -404,11 +404,7 @@ test_shift_right (void)
for (k = min; k <= max; k++)
{
if (k <= G_MAXUINT - j)
{
if (gtk_bitset_contains (iset, k) != gtk_bitset_contains (testset, k + j))
g_print ("right-shift fail set %u shift %u test %u\n", i, j, k);
g_assert_cmpint (gtk_bitset_contains (iset, k), ==, gtk_bitset_contains (testset, k + j));
}
}
gtk_bitset_unref (testset);
@ -418,6 +414,135 @@ test_shift_right (void)
}
}
static void
test_slice (void)
{
GtkBitset *set;
guint i;
set = gtk_bitset_new_empty ();
gtk_bitset_add_range (set, 10, 30);
gtk_bitset_slice (set, 20, 10, 20);
for (i = 0; i < 60; i++)
g_assert_cmpint (gtk_bitset_contains (set, i), ==, (i >= 10 && i < 20) ||
(i >= 40 && i < 50));
gtk_bitset_slice (set, 25, 10, 0);
for (i = 0; i < 60; i++)
g_assert_cmpint (gtk_bitset_contains (set, i), ==, (i >= 10 && i < 20) ||
(i >= 30 && i < 40));
gtk_bitset_unref (set);
}
static void
test_rectangle (void)
{
GtkBitset *set;
GString *s;
guint i, j;
set = gtk_bitset_new_empty ();
gtk_bitset_add_rectangle (set, 8, 5, 5, 7);
gtk_bitset_remove_rectangle (set, 16, 3, 3, 7);
gtk_bitset_add_rectangle (set, 24, 1, 1, 7);
s = g_string_new ("");
for (i = 0; i < 7; i++)
{
for (j = 0; j < 7; j++)
g_string_append_printf (s, "%c ",
gtk_bitset_contains (set, i * 7 + j) ? '*' : ' ');
g_string_append (s, "\n");
}
g_assert_cmpstr (s->str, ==,
" \n"
" * * * * * \n"
" * * \n"
" * * * \n"
" * * \n"
" * * * * * \n"
" \n");
g_string_free (s, TRUE);
gtk_bitset_unref (set);
}
static void
test_iter (void)
{
GtkBitset *set;
GtkBitsetIter iter;
gboolean ret;
guint value;
set = gtk_bitset_new_empty ();
ret = gtk_bitset_iter_init_first (&iter, set, &value);
g_assert_false (ret);
g_assert_false (gtk_bitset_iter_is_valid (&iter));
g_assert_cmpuint (gtk_bitset_iter_get_value (&iter), ==, 0);
g_assert_false (gtk_bitset_iter_previous (&iter, &value));
g_assert_false (gtk_bitset_iter_next (&iter, &value));
ret = gtk_bitset_iter_init_last (&iter, set, &value);
g_assert_false (ret);
g_assert_false (gtk_bitset_iter_is_valid (&iter));
g_assert_cmpuint (gtk_bitset_iter_get_value (&iter), ==, 0);
g_assert_false (gtk_bitset_iter_previous (&iter, &value));
g_assert_false (gtk_bitset_iter_next (&iter, &value));
ret = gtk_bitset_iter_init_at (&iter, set, 0, &value);
g_assert_false (gtk_bitset_iter_is_valid (&iter));
g_assert_cmpuint (gtk_bitset_iter_get_value (&iter), ==, 0);
g_assert_false (gtk_bitset_iter_previous (&iter, &value));
g_assert_false (gtk_bitset_iter_next (&iter, &value));
gtk_bitset_add_range_closed (set, 10, 20);
ret = gtk_bitset_iter_init_first (&iter, set, &value);
g_assert_true (ret);
g_assert_true (gtk_bitset_iter_is_valid (&iter));
g_assert_cmpuint (value, ==, 10);
g_assert_cmpuint (gtk_bitset_iter_get_value (&iter), ==, 10);
ret = gtk_bitset_iter_next (&iter, &value);
g_assert_true (ret);
g_assert_cmpuint (value, ==, 11);
ret = gtk_bitset_iter_next (&iter, NULL);
g_assert_true (ret);
g_assert_cmpuint (gtk_bitset_iter_get_value (&iter), ==, 12);
ret = gtk_bitset_iter_init_last (&iter, set, &value);
g_assert_true (ret);
g_assert_true (gtk_bitset_iter_is_valid (&iter));
g_assert_cmpuint (value, ==, 20);
ret = gtk_bitset_iter_init_at (&iter, set, 5, NULL);
g_assert_true (ret);
g_assert_true (gtk_bitset_iter_is_valid (&iter));
g_assert_cmpuint (gtk_bitset_iter_get_value (&iter), ==, 10);
ret = gtk_bitset_iter_previous (&iter, NULL);
g_assert_false (ret);
g_assert_false (gtk_bitset_iter_is_valid (&iter));
ret = gtk_bitset_iter_init_at (&iter, set, 100, NULL);
g_assert_false (ret);
gtk_bitset_unref (set);
}
int
main (int argc, char *argv[])
{
@ -434,6 +559,9 @@ main (int argc, char *argv[])
g_test_add_func ("/bitset/subtract", test_subtract);
g_test_add_func ("/bitset/shift-left", test_shift_left);
g_test_add_func ("/bitset/shift-right", test_shift_right);
g_test_add_func ("/bitset/slice", test_slice);
g_test_add_func ("/bitset/rectangle", test_rectangle);
g_test_add_func ("/bitset/iter", test_iter);
return g_test_run ();
}