Gsk.RenderReplay¶
Fields¶
None
Methods¶
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- class Gsk.RenderReplay¶
A facility to replay a [class`Gsk`.RenderNode] and its children, potentially modifying them.
This is a utility tool to walk a rendernode tree. The most powerful way is to provide a function via [method`Gsk`.RenderReplay.set_node_filter] to filter each individual node and then run [method`Gsk`.RenderReplay.filter_node] on the nodes you want to filter.
An easier method exists to just walk the node tree and extract information without any modifications. If you want to do that, the functions [method`Gsk`.RenderReplay.set_node_foreach] exists. You can also call [method`Gsk`.RenderReplay.foreach_node] to run that function. Note that the previously mentioned complex functionality will still be invoked if you have set up a function for it, but its result will not be returned.
Here is an example that combines both approaches to print the whole tree:
```c #include <gtk/gtk.h>
static
Gsk.RenderNode* print_nodes (Gsk.RenderReplay*replay,Gsk.RenderNode*node,objectuser_data) { int *depth = user_data;Gsk.RenderNode*result;g_print (“%*s%s\n”, 2 * *depth, “”,
GObject.type_name_from_instance((GObject.TypeInstance*) node));*depth += 1; result =
Gsk.RenderReplay.default(replay, node); *depth -= 1;return result; }
int main (int argc,
str*argv[]) {Gio.File*file;GLib.Bytes*bytes;Gsk.RenderNode*node;Gsk.RenderReplay*replay; int depth = 0;gtk_init ();
if (argc < 2) { g_print (“usage: %s NODEFILE\n”, argv[0]); return 0; }
file =
Gio.File.new_for_commandline_arg(argv[1]); bytes =Gio.File.load_bytes(file,None,None,None);GObject.Object.unref(file); if (bytes ==None) return 1;node =
Gsk.RenderNode.deserialize(bytes,None,None);GLib.Bytes.unref(bytes); if (node ==None) return 1;replay =
Gsk.RenderReplay.new();Gsk.RenderReplay.set_node_filter(replay, print_nodes, &depth,None); gsk_render_node_foreach_node (replay, node);Gsk.RenderNode.unref(node);return 0; } ```
New in version 4.22.
- classmethod new()¶
- Returns:
A new replay object to replay nodes
- Return type:
Creates a new replay object to replay nodes.
New in version 4.22.
- default(node)¶
- Parameters:
node (
Gsk.RenderNode) – the node to replay- Returns:
The replayed node
- Return type:
Replays the node using the default method.
The default method calls [method`Gsk`.RenderReplay.filter_node] on all its child nodes and the filter functions for all its properties. If none of them are changed, it returns the passed in node. Otherwise it constructs a new node with the changed children and properties.
It may not be possible to construct a new node when any of the callbacks return
None. In that case, this function will returnNone, too.New in version 4.22.
- filter_font(font)¶
- Parameters:
font (
Pango.Font) – The font to filter- Returns:
the filtered font
- Return type:
Filters a font using the current filter function.
New in version 4.22.
- filter_node(node)¶
- Parameters:
node (
Gsk.RenderNode) – the node to replay- Returns:
The replayed node
- Return type:
Replays a node using the replay’s filter function.
After the replay the node may be unchanged, or it may be removed, which will result in
Nonebeing returned.This function calls the registered callback in the following order:
If a foreach function is set, it is called first. If it returns false, this function immediately exits and returns the passed in node.
If a node filter is set, it is called and its result is returned.
[method`Gsk`.RenderReplay.default] is called and its result is returned.
New in version 4.22.
- filter_texture(texture)¶
- Parameters:
texture (
Gdk.Texture) – The texture to filter- Returns:
the filtered texture
- Return type:
Filters a texture using the current filter function.
New in version 4.22.
- foreach_node(node)¶
- Parameters:
node (
Gsk.RenderNode) – the node to replay
Calls the filter and foreach functions for each node.
This function calls [method`Gsk`.RenderReplay.filter_node] internally, but discards the result assuming no changes were made.
New in version 4.22.
- free()¶
Frees a
GskRenderReplay.New in version 4.22.
- set_font_filter(filter, *user_data)¶
- Parameters:
filter (
Gsk.RenderReplayFontFilterorNone) – the font filter function
Sets a filter function to be called by [method`Gsk`.RenderReplay.default] for nodes that contain fonts.
You can call [method`GskRenderReplay`.filter_font] to filter a font yourself.
New in version 4.22.
- set_node_filter(filter, *user_data)¶
- Parameters:
filter (
Gsk.RenderReplayNodeFilterorNone) – the function to call to replay nodes
Sets the function to use as a node filter.
This is the most complex function to use for replaying nodes. It can either:
keep the node and just return it unchanged
create a replacement node and return that
discard the node by returning
NULLcall [method`Gsk`.RenderReplay.default] to have the default handler run for this node, which calls your function on its children
New in version 4.22.
- set_node_foreach(foreach, *user_data)¶
- Parameters:
foreach (
Gsk.RenderReplayNodeForeachorNone) – the function to call for all nodes
Sets the function to call for every node.
This function is called before the node filter, so if it returns false, the node filter will never be called.
New in version 4.22.
- set_texture_filter(filter, *user_data)¶
- Parameters:
filter (
Gsk.RenderReplayTextureFilterorNone) – the texture filter function
Sets a filter function to be called by [method`Gsk`.RenderReplay.default] for nodes that contain textures.
You can call [method`GskRenderReplay`.filter_texture] to filter a texture yourself.
New in version 4.22.