Skip to main content

gsk4/auto/
linear_gradient_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::{ColorStop, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// A render node for a linear gradient.
10    #[doc(alias = "GskLinearGradientNode")]
11    pub struct LinearGradientNode(Shared<ffi::GskLinearGradientNode>);
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 LinearGradientNode {
20    fn static_type() -> glib::Type {
21        unsafe { from_glib(ffi::gsk_linear_gradient_node_get_type()) }
22    }
23}
24
25impl LinearGradientNode {
26    /// Creates a [`RenderNode`][crate::RenderNode] that will create a linear gradient from the given
27    /// points and color stops, and render that into the area given by @bounds.
28    /// ## `bounds`
29    /// the rectangle to render the linear gradient into
30    /// ## `start`
31    /// the point at which the linear gradient will begin
32    /// ## `end`
33    /// the point at which the linear gradient will finish
34    /// ## `color_stops`
35    /// = 1.
36    ///
37    /// # Returns
38    ///
39    /// A new [`RenderNode`][crate::RenderNode]
40    #[doc(alias = "gsk_linear_gradient_node_new")]
41    pub fn new(
42        bounds: &graphene::Rect,
43        start: &graphene::Point,
44        end: &graphene::Point,
45        color_stops: &[ColorStop],
46    ) -> LinearGradientNode {
47        assert_initialized_main_thread!();
48        let n_color_stops = color_stops.len() as _;
49        unsafe {
50            from_glib_full(ffi::gsk_linear_gradient_node_new(
51                bounds.to_glib_none().0,
52                start.to_glib_none().0,
53                end.to_glib_none().0,
54                color_stops.to_glib_none().0,
55                n_color_stops,
56            ))
57        }
58    }
59
60    /// Retrieves the color stops in the gradient.
61    ///
62    /// # Returns
63    ///
64    /// the color stops in the gradient
65    #[doc(alias = "gsk_linear_gradient_node_get_color_stops")]
66    #[doc(alias = "get_color_stops")]
67    pub fn color_stops(&self) -> Vec<ColorStop> {
68        unsafe {
69            let mut n_stops = std::mem::MaybeUninit::uninit();
70            let ret = FromGlibContainer::from_glib_none_num(
71                ffi::gsk_linear_gradient_node_get_color_stops(
72                    self.to_glib_none().0,
73                    n_stops.as_mut_ptr(),
74                ),
75                n_stops.assume_init() as _,
76            );
77            ret
78        }
79    }
80
81    /// Retrieves the final point of the linear gradient.
82    ///
83    /// # Returns
84    ///
85    /// the final point
86    #[doc(alias = "gsk_linear_gradient_node_get_end")]
87    #[doc(alias = "get_end")]
88    pub fn end(&self) -> graphene::Point {
89        unsafe { from_glib_none(ffi::gsk_linear_gradient_node_get_end(self.to_glib_none().0)) }
90    }
91
92    /// Retrieves the number of color stops in the gradient.
93    ///
94    /// # Returns
95    ///
96    /// the number of color stops
97    #[doc(alias = "gsk_linear_gradient_node_get_n_color_stops")]
98    #[doc(alias = "get_n_color_stops")]
99    pub fn n_color_stops(&self) -> usize {
100        unsafe { ffi::gsk_linear_gradient_node_get_n_color_stops(self.to_glib_none().0) }
101    }
102
103    /// Retrieves the initial point of the linear gradient.
104    ///
105    /// # Returns
106    ///
107    /// the initial point
108    #[doc(alias = "gsk_linear_gradient_node_get_start")]
109    #[doc(alias = "get_start")]
110    pub fn start(&self) -> graphene::Point {
111        unsafe {
112            from_glib_none(ffi::gsk_linear_gradient_node_get_start(
113                self.to_glib_none().0,
114            ))
115        }
116    }
117}