pub struct RenderReplay(/* private fields */);v4_22 only.Expand description
A facility to replay a 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 set_node_filter()
to filter each individual node and then run
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
set_node_foreach() exists. You can also call
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:
⚠️ The following code is in c ⚠️
#include <gtk/gtk.h>
static GskRenderNode *
print_nodes (GskRenderReplay *replay,
GskRenderNode *node,
gpointer user_data)
{
int *depth = user_data;
GskRenderNode *result;
g_print ("%*s%s\n", 2 * *depth, "", g_type_name_from_instance ((GTypeInstance *) node));
*depth += 1;
result = gsk_render_replay_default (replay, node);
*depth -= 1;
return result;
}
int
main (int argc, char *argv[])
{
GFile *file;
GBytes *bytes;
GskRenderNode *node;
GskRenderReplay *replay;
int depth = 0;
gtk_init ();
if (argc < 2)
{
g_print ("usage: %s NODEFILE\n", argv[0]);
return 0;
}
file = g_file_new_for_commandline_arg (argv[1]);
bytes = g_file_load_bytes (file, NULL, NULL, NULL);
g_object_unref (file);
if (bytes == NULL)
return 1;
node = gsk_render_node_deserialize (bytes, NULL, NULL);
g_bytes_unref (bytes);
if (node == NULL)
return 1;
replay = gsk_render_replay_new ();
gsk_render_replay_set_node_filter (replay, print_nodes, &depth, NULL);
gsk_render_node_foreach_node (replay, node);
gsk_render_node_unref (node);
return 0;
}Implementations§
Source§impl RenderReplay
impl RenderReplay
Sourcepub fn default(&self, node: impl AsRef<RenderNode>) -> Option<RenderNode>
pub fn default(&self, node: impl AsRef<RenderNode>) -> Option<RenderNode>
Replays the node using the default method.
The default method calls filter_node()
on all its child nodes and the filter functions for all its
proeprties. 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 NULL. In that case, this function will return NULL, too.
§node
the node to replay
§Returns
The replayed node
Sourcepub fn filter_font(&self, font: &impl IsA<Font>) -> Font
pub fn filter_font(&self, font: &impl IsA<Font>) -> Font
Sourcepub fn filter_node(&self, node: impl AsRef<RenderNode>) -> Option<RenderNode>
pub fn filter_node(&self, node: impl AsRef<RenderNode>) -> Option<RenderNode>
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 None being 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.
-
default()is called and its result is returned.
§node
the node to replay
§Returns
The replayed node
Sourcepub fn filter_texture(&self, texture: &impl IsA<Texture>) -> Texture
pub fn filter_texture(&self, texture: &impl IsA<Texture>) -> Texture
Sourcepub fn foreach_node(&self, node: impl AsRef<RenderNode>)
pub fn foreach_node(&self, node: impl AsRef<RenderNode>)
Calls the filter and foreach functions for each node.
This function calls filter_node() internally,
but discards the result assuming no changes were made.
§node
the node to replay
Sourcepub fn set_font_filter<P: Fn(&RenderReplay, &Font) -> Font + 'static>(
&mut self,
filter: P,
)
pub fn set_font_filter<P: Fn(&RenderReplay, &Font) -> Font + 'static>( &mut self, filter: P, )
pub fn unset_font_filter(&mut self)
Sourcepub fn set_node_filter<P: Fn(&RenderReplay, &RenderNode) -> Option<RenderNode> + 'static>(
&mut self,
filter: P,
)
pub fn set_node_filter<P: Fn(&RenderReplay, &RenderNode) -> Option<RenderNode> + 'static>( &mut self, filter: P, )
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
None -
call
default()to have the default handler run for this node, which calls your function on its children
§filter
The function to call to replay nodes
pub fn unset_node_filter(&mut self)
Sourcepub fn set_node_foreach<P: Fn(&RenderReplay, &RenderNode) -> ControlFlow + 'static>(
&mut self,
foreach: P,
)
pub fn set_node_foreach<P: Fn(&RenderReplay, &RenderNode) -> ControlFlow + 'static>( &mut self, foreach: P, )
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.
§foreach
the function to call for all nodes