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::{RenderNodeType, ffi};
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 { Some(out_opaque) } else { None }
126 }
127 }
128
129 /// Serializes the @self for later deserialization via
130 /// gsk_render_node_deserialize(). No guarantees are made about the format
131 /// used other than that the same version of GTK will be able to deserialize
132 /// the result of a call to gsk_render_node_serialize() and
133 /// gsk_render_node_deserialize() will correctly reject files it cannot open
134 /// that were created with previous versions of GTK.
135 ///
136 /// The intended use of this functions is testing, benchmarking and debugging.
137 /// The format is not meant as a permanent storage format.
138 ///
139 /// # Returns
140 ///
141 /// a `GBytes` representing the node.
142 #[doc(alias = "gsk_render_node_serialize")]
143 pub fn serialize(&self) -> glib::Bytes {
144 unsafe {
145 from_glib_full(ffi::gsk_render_node_serialize(
146 self.as_ref().to_glib_none().0,
147 ))
148 }
149 }
150
151 /// This function is equivalent to calling [`serialize()`][Self::serialize()]
152 /// followed by `file_set_contents()`.
153 ///
154 /// See those two functions for details on the arguments.
155 ///
156 /// It is mostly intended for use inside a debugger to quickly dump a render
157 /// node to a file for later inspection.
158 /// ## `filename`
159 /// the file to save it to
160 ///
161 /// # Returns
162 ///
163 /// true if saving was successful
164 #[doc(alias = "gsk_render_node_write_to_file")]
165 pub fn write_to_file(&self, filename: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
166 unsafe {
167 let mut error = std::ptr::null_mut();
168 let is_ok = ffi::gsk_render_node_write_to_file(
169 self.as_ref().to_glib_none().0,
170 filename.as_ref().to_glib_none().0,
171 &mut error,
172 );
173 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
174 if error.is_null() {
175 Ok(())
176 } else {
177 Err(from_glib_full(error))
178 }
179 }
180 }
181}