gsk4/auto/render_node.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, RenderNodeType};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// The basic block in a scene graph to be rendered using [`Renderer`][crate::Renderer].
10 ///
11 /// Each node has a parent, except the top-level node; each node may have
12 /// children nodes.
13 ///
14 /// Each node has an associated drawing surface, which has the size of
15 /// the rectangle set when creating it.
16 ///
17 /// Render nodes are meant to be transient; once they have been associated
18 /// to a [`Renderer`][crate::Renderer] it's safe to release any reference you have on
19 /// them. All [`RenderNode`][crate::RenderNode]s are immutable, you can only specify their
20 /// properties during construction.
21 ///
22 /// This is an Abstract Base Class, you cannot instantiate it.
23 #[doc(alias = "GskRenderNode")]
24 pub struct RenderNode(Shared<ffi::GskRenderNode>);
25
26 match fn {
27 ref => |ptr| ffi::gsk_render_node_ref(ptr),
28 unref => |ptr| ffi::gsk_render_node_unref(ptr),
29 }
30}
31
32impl StaticType for RenderNode {
33 fn static_type() -> glib::Type {
34 unsafe { from_glib(ffi::gsk_render_node_get_type()) }
35 }
36}
37
38impl RenderNode {
39 pub const NONE: Option<&'static RenderNode> = None;
40
41 /// Draws the contents of a render node on a cairo context.
42 ///
43 /// Typically, you'll use this function to implement fallback rendering
44 /// of render nodes on an intermediate Cairo context, instead of using
45 /// the drawing context associated to a [`gdk::Surface`][crate::gdk::Surface]'s rendering buffer.
46 ///
47 /// For advanced nodes that cannot be supported using Cairo, in particular
48 /// for nodes doing 3D operations, this function may fail.
49 /// ## `cr`
50 /// cairo context to draw to
51 #[doc(alias = "gsk_render_node_draw")]
52 pub fn draw(&self, cr: &cairo::Context) {
53 unsafe {
54 ffi::gsk_render_node_draw(
55 self.as_ref().to_glib_none().0,
56 mut_override(cr.to_glib_none().0),
57 );
58 }
59 }
60
61 /// Retrieves the boundaries of the @self.
62 ///
63 /// The node will not draw outside of its boundaries.
64 ///
65 /// # Returns
66 ///
67 ///
68 /// ## `bounds`
69 /// return location for the boundaries
70 #[doc(alias = "gsk_render_node_get_bounds")]
71 #[doc(alias = "get_bounds")]
72 pub fn bounds(&self) -> graphene::Rect {
73 unsafe {
74 let mut bounds = graphene::Rect::uninitialized();
75 ffi::gsk_render_node_get_bounds(
76 self.as_ref().to_glib_none().0,
77 bounds.to_glib_none_mut().0,
78 );
79 bounds
80 }
81 }
82
83 /// Returns the type of the render node.
84 ///
85 /// # Returns
86 ///
87 /// the type of @self
88 #[doc(alias = "gsk_render_node_get_node_type")]
89 #[doc(alias = "get_node_type")]
90 pub fn node_type(&self) -> RenderNodeType {
91 unsafe {
92 from_glib(ffi::gsk_render_node_get_node_type(const_override(
93 self.as_ref().to_glib_none().0,
94 )))
95 }
96 }
97
98 /// Gets an opaque rectangle inside the node that GTK can determine to
99 /// be fully opaque.
100 ///
101 /// There is no guarantee that this is indeed the largest opaque rectangle or
102 /// that regions outside the rectangle are not opaque. This function is a best
103 /// effort with that goal.
104 ///
105 /// The rectangle will be fully contained in the bounds of the node.
106 ///
107 /// # Returns
108 ///
109 /// true if part or all of the rendernode is opaque, false if no
110 /// opaque region could be found.
111 ///
112 /// ## `out_opaque`
113 /// return location for the opaque rect
114 #[cfg(feature = "v4_16")]
115 #[cfg_attr(docsrs, doc(cfg(feature = "v4_16")))]
116 #[doc(alias = "gsk_render_node_get_opaque_rect")]
117 #[doc(alias = "get_opaque_rect")]
118 pub fn opaque_rect(&self) -> Option<graphene::Rect> {
119 unsafe {
120 let mut out_opaque = graphene::Rect::uninitialized();
121 let ret = from_glib(ffi::gsk_render_node_get_opaque_rect(
122 self.as_ref().to_glib_none().0,
123 out_opaque.to_glib_none_mut().0,
124 ));
125 if ret {
126 Some(out_opaque)
127 } else {
128 None
129 }
130 }
131 }
132
133 /// Serializes the @self for later deserialization via
134 /// gsk_render_node_deserialize(). No guarantees are made about the format
135 /// used other than that the same version of GTK will be able to deserialize
136 /// the result of a call to gsk_render_node_serialize() and
137 /// gsk_render_node_deserialize() will correctly reject files it cannot open
138 /// that were created with previous versions of GTK.
139 ///
140 /// The intended use of this functions is testing, benchmarking and debugging.
141 /// The format is not meant as a permanent storage format.
142 ///
143 /// # Returns
144 ///
145 /// a `GBytes` representing the node.
146 #[doc(alias = "gsk_render_node_serialize")]
147 pub fn serialize(&self) -> glib::Bytes {
148 unsafe {
149 from_glib_full(ffi::gsk_render_node_serialize(
150 self.as_ref().to_glib_none().0,
151 ))
152 }
153 }
154
155 /// This function is equivalent to calling [`serialize()`][Self::serialize()]
156 /// followed by `file_set_contents()`.
157 ///
158 /// See those two functions for details on the arguments.
159 ///
160 /// It is mostly intended for use inside a debugger to quickly dump a render
161 /// node to a file for later inspection.
162 /// ## `filename`
163 /// the file to save it to
164 ///
165 /// # Returns
166 ///
167 /// true if saving was successful
168 #[doc(alias = "gsk_render_node_write_to_file")]
169 pub fn write_to_file(&self, filename: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
170 unsafe {
171 let mut error = std::ptr::null_mut();
172 let is_ok = ffi::gsk_render_node_write_to_file(
173 self.as_ref().to_glib_none().0,
174 filename.as_ref().to_glib_none().0,
175 &mut error,
176 );
177 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
178 if error.is_null() {
179 Ok(())
180 } else {
181 Err(from_glib_full(error))
182 }
183 }
184 }
185}