clutter/auto/
paint_node.rs

1use crate::ActorBox;
2use glib::{object::IsA, translate::*};
3use std::fmt;
4
5glib_wrapper! {
6    pub struct PaintNode(Object<ffi::ClutterPaintNode, ffi::ClutterPaintNodeClass, PaintNodeClass>);
7
8    match fn {
9        get_type => || ffi::clutter_paint_node_get_type(),
10    }
11}
12
13pub const NONE_PAINT_NODE: Option<&PaintNode> = None;
14
15/// Trait containing all `PaintNode` methods.
16///
17/// # Implementors
18///
19/// [`ClipNode`](struct.ClipNode.html), [`PaintNode`](struct.PaintNode.html), [`PipelineNode`](struct.PipelineNode.html), [`TextNode`](struct.TextNode.html)
20pub trait PaintNodeExt: 'static {
21    /// Adds `child` to the list of children of `self`.
22    ///
23    /// This function will acquire a reference on `child`.
24    /// ## `child`
25    /// the child `PaintNode` to add
26    fn add_child<P: IsA<PaintNode>>(&self, child: &P);
27
28    /// Adds a rectangle region to the `self`, as described by the
29    /// passed `rect`.
30    /// ## `rect`
31    /// a `ActorBox`
32    fn add_rectangle(&self, rect: &ActorBox);
33
34    /// Adds a rectangle region to the `self`, with texture coordinates.
35    /// ## `rect`
36    /// a `ActorBox`
37    /// ## `x_1`
38    /// the left X coordinate of the texture
39    /// ## `y_1`
40    /// the top Y coordinate of the texture
41    /// ## `x_2`
42    /// the right X coordinate of the texture
43    /// ## `y_2`
44    /// the bottom Y coordinate of the texture
45    fn add_texture_rectangle(&self, rect: &ActorBox, x_1: f32, y_1: f32, x_2: f32, y_2: f32);
46
47    /// Sets a user-readable `name` for `self`.
48    ///
49    /// The `name` will be used for debugging purposes.
50    ///
51    /// The `self` will copy the passed string.
52    /// ## `name`
53    /// a string annotating the `self`
54    fn set_name(&self, name: &str);
55}
56
57impl<O: IsA<PaintNode>> PaintNodeExt for O {
58    fn add_child<P: IsA<PaintNode>>(&self, child: &P) {
59        unsafe {
60            ffi::clutter_paint_node_add_child(
61                self.as_ref().to_glib_none().0,
62                child.as_ref().to_glib_none().0,
63            );
64        }
65    }
66
67    fn add_rectangle(&self, rect: &ActorBox) {
68        unsafe {
69            ffi::clutter_paint_node_add_rectangle(
70                self.as_ref().to_glib_none().0,
71                rect.to_glib_none().0,
72            );
73        }
74    }
75
76    fn add_texture_rectangle(&self, rect: &ActorBox, x_1: f32, y_1: f32, x_2: f32, y_2: f32) {
77        unsafe {
78            ffi::clutter_paint_node_add_texture_rectangle(
79                self.as_ref().to_glib_none().0,
80                rect.to_glib_none().0,
81                x_1,
82                y_1,
83                x_2,
84                y_2,
85            );
86        }
87    }
88
89    fn set_name(&self, name: &str) {
90        unsafe {
91            ffi::clutter_paint_node_set_name(self.as_ref().to_glib_none().0, name.to_glib_none().0);
92        }
93    }
94}
95
96impl fmt::Display for PaintNode {
97    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
98        write!(f, "PaintNode")
99    }
100}