gsk4/auto/
cairo_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;
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// A render node for a Cairo surface.
10    #[doc(alias = "GskCairoNode")]
11    pub struct CairoNode(Shared<ffi::GskCairoNode>);
12
13    match fn {
14        ref => |ptr| ffi::gsk_render_node_ref(ptr as *mut ffi::GskRenderNode),
15        unref => |ptr| ffi::gsk_render_node_unref(ptr as *mut ffi::GskRenderNode),
16    }
17}
18
19impl StaticType for CairoNode {
20    fn static_type() -> glib::Type {
21        unsafe { from_glib(ffi::gsk_cairo_node_get_type()) }
22    }
23}
24
25impl CairoNode {
26    /// Creates a [`RenderNode`][crate::RenderNode] that will render a cairo surface
27    /// into the area given by @bounds.
28    ///
29    /// You can draw to the cairo surface using [`draw_context()`][Self::draw_context()].
30    /// ## `bounds`
31    /// the rectangle to render to
32    ///
33    /// # Returns
34    ///
35    /// A new [`RenderNode`][crate::RenderNode]
36    #[doc(alias = "gsk_cairo_node_new")]
37    pub fn new(bounds: &graphene::Rect) -> CairoNode {
38        assert_initialized_main_thread!();
39        unsafe { from_glib_full(ffi::gsk_cairo_node_new(bounds.to_glib_none().0)) }
40    }
41
42    /// Creates a Cairo context for drawing using the surface associated
43    /// to the render node.
44    ///
45    /// If no surface exists yet, a surface will be created optimized for
46    /// rendering to @renderer.
47    ///
48    /// # Returns
49    ///
50    /// a Cairo context used for drawing; use
51    ///   cairo_destroy() when done drawing
52    #[doc(alias = "gsk_cairo_node_get_draw_context")]
53    #[doc(alias = "get_draw_context")]
54    pub fn draw_context(&self) -> cairo::Context {
55        unsafe { from_glib_full(ffi::gsk_cairo_node_get_draw_context(self.to_glib_none().0)) }
56    }
57
58    /// Retrieves the Cairo surface used by the render node.
59    ///
60    /// # Returns
61    ///
62    /// a Cairo surface
63    #[doc(alias = "gsk_cairo_node_get_surface")]
64    #[doc(alias = "get_surface")]
65    pub fn surface(&self) -> cairo::Surface {
66        unsafe { from_glib_none(ffi::gsk_cairo_node_get_surface(self.to_glib_none().0)) }
67    }
68}