gsk4/auto/
text_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 drawing a set of glyphs.
10    #[doc(alias = "GskTextNode")]
11    pub struct TextNode(Shared<ffi::GskTextNode>);
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 TextNode {
20    fn static_type() -> glib::Type {
21        unsafe { from_glib(ffi::gsk_text_node_get_type()) }
22    }
23}
24
25impl TextNode {
26    /// Creates a render node that renders the given glyphs.
27    ///
28    /// Note that @color may not be used if the font contains
29    /// color glyphs.
30    /// ## `font`
31    /// the [`pango::Font`][crate::pango::Font] containing the glyphs
32    /// ## `glyphs`
33    /// the [`pango::GlyphString`][crate::pango::GlyphString] to render
34    /// ## `color`
35    /// the foreground color to render with
36    /// ## `offset`
37    /// offset of the baseline
38    ///
39    /// # Returns
40    ///
41    /// a new [`RenderNode`][crate::RenderNode]
42    #[doc(alias = "gsk_text_node_new")]
43    pub fn new(
44        font: &impl IsA<pango::Font>,
45        glyphs: &pango::GlyphString,
46        color: &gdk::RGBA,
47        offset: &graphene::Point,
48    ) -> Option<TextNode> {
49        assert_initialized_main_thread!();
50        unsafe {
51            from_glib_full(ffi::gsk_text_node_new(
52                font.as_ref().to_glib_none().0,
53                mut_override(glyphs.to_glib_none().0),
54                color.to_glib_none().0,
55                offset.to_glib_none().0,
56            ))
57        }
58    }
59
60    /// Retrieves the color used by the text @self.
61    ///
62    /// The value returned by this function will not be correct
63    /// if the render node was created for a non-sRGB color.
64    ///
65    /// # Returns
66    ///
67    /// the text color
68    #[doc(alias = "gsk_text_node_get_color")]
69    #[doc(alias = "get_color")]
70    pub fn color(&self) -> gdk::RGBA {
71        unsafe { from_glib_none(ffi::gsk_text_node_get_color(self.to_glib_none().0)) }
72    }
73
74    /// Returns the font used by the text @self.
75    ///
76    /// # Returns
77    ///
78    /// the font
79    #[doc(alias = "gsk_text_node_get_font")]
80    #[doc(alias = "get_font")]
81    pub fn font(&self) -> pango::Font {
82        unsafe { from_glib_none(ffi::gsk_text_node_get_font(self.to_glib_none().0)) }
83    }
84
85    /// Retrieves the glyph information in the @self.
86    ///
87    /// # Returns
88    ///
89    /// the glyph information
90    #[doc(alias = "gsk_text_node_get_glyphs")]
91    #[doc(alias = "get_glyphs")]
92    pub fn glyphs(&self) -> Vec<pango::GlyphInfo> {
93        unsafe {
94            let mut n_glyphs = std::mem::MaybeUninit::uninit();
95            let ret = FromGlibContainer::from_glib_none_num(
96                ffi::gsk_text_node_get_glyphs(self.to_glib_none().0, n_glyphs.as_mut_ptr()),
97                n_glyphs.assume_init() as _,
98            );
99            ret
100        }
101    }
102
103    /// Retrieves the number of glyphs in the text node.
104    ///
105    /// # Returns
106    ///
107    /// the number of glyphs
108    #[doc(alias = "gsk_text_node_get_num_glyphs")]
109    #[doc(alias = "get_num_glyphs")]
110    pub fn num_glyphs(&self) -> u32 {
111        unsafe { ffi::gsk_text_node_get_num_glyphs(self.to_glib_none().0) }
112    }
113
114    /// Retrieves the offset applied to the text.
115    ///
116    /// # Returns
117    ///
118    /// a point with the horizontal and vertical offsets
119    #[doc(alias = "gsk_text_node_get_offset")]
120    #[doc(alias = "get_offset")]
121    pub fn offset(&self) -> graphene::Point {
122        unsafe { from_glib_none(ffi::gsk_text_node_get_offset(self.to_glib_none().0)) }
123    }
124
125    /// Checks whether the text @self has color glyphs.
126    ///
127    /// # Returns
128    ///
129    /// [`true`] if the text node has color glyphs
130    #[cfg(feature = "v4_2")]
131    #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
132    #[doc(alias = "gsk_text_node_has_color_glyphs")]
133    pub fn has_color_glyphs(&self) -> bool {
134        unsafe { from_glib(ffi::gsk_text_node_has_color_glyphs(self.to_glib_none().0)) }
135    }
136}