animate/legacy/
text_node.rs

1use crate::{Color, InternalColor, PaintNode, RgbaColor};
2use glib::{object::Cast, translate::*};
3use std::fmt;
4
5glib_wrapper! {
6    pub struct TextNode(Object<ffi::ClutterTextNode, ffi::ClutterTextNodeClass, TextNodeClass>) @extends PaintNode;
7
8    match fn {
9        get_type => || ffi::clutter_text_node_get_type(),
10    }
11}
12
13impl TextNode {
14    /// Creates a new `PaintNode` that will paint a `pango::Layout`
15    /// with the given color.
16    ///
17    /// This function takes a reference on the passed `layout`, so it
18    /// is safe to call `gobject::ObjectExt::unref` after it returns.
19    /// ## `layout`
20    /// a `pango::Layout`, or `None`
21    /// ## `color`
22    /// the color used to paint the layout,
23    ///  or `None`
24    ///
25    /// # Returns
26    ///
27    /// the newly created `PaintNode`.
28    ///  Use `PaintNodeExt::unref` when done
29    pub fn new(layout: Option<&pango::Layout>, color: Option<Color>) -> TextNode {
30        let color = match color {
31            Some(value) => {
32                let RgbaColor {
33                    red,
34                    green,
35                    blue,
36                    alpha,
37                } = value.into();
38                Some(InternalColor::new(red, green, blue, alpha))
39            }
40            None => None,
41        };
42        unsafe {
43            PaintNode::from_glib_full(ffi::clutter_text_node_new(
44                layout.to_glib_none().0,
45                color.to_glib_none().0,
46            ))
47            .unsafe_cast()
48        }
49    }
50}
51
52impl fmt::Display for TextNode {
53    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
54        write!(f, "TextNode")
55    }
56}