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::{ffi, ColorStop};
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    /// a pointer to an array of
36    ///   [`ColorStop`][crate::ColorStop] defining the gradient. The offsets of all color stops
37    ///   must be increasing. The first stop's offset must be >= 0 and the last
38    ///   stop's offset must be <= 1.
39    ///
40    /// # Returns
41    ///
42    /// A new [`RenderNode`][crate::RenderNode]
43    #[doc(alias = "gsk_linear_gradient_node_new")]
44    pub fn new(
45        bounds: &graphene::Rect,
46        start: &graphene::Point,
47        end: &graphene::Point,
48        color_stops: &[ColorStop],
49    ) -> LinearGradientNode {
50        assert_initialized_main_thread!();
51        let n_color_stops = color_stops.len() as _;
52        unsafe {
53            from_glib_full(ffi::gsk_linear_gradient_node_new(
54                bounds.to_glib_none().0,
55                start.to_glib_none().0,
56                end.to_glib_none().0,
57                color_stops.to_glib_none().0,
58                n_color_stops,
59            ))
60        }
61    }
62
63    /// Retrieves the color stops in the gradient.
64    ///
65    /// # Returns
66    ///
67    /// the color stops in the gradient
68    #[doc(alias = "gsk_linear_gradient_node_get_color_stops")]
69    #[doc(alias = "get_color_stops")]
70    pub fn color_stops(&self) -> Vec<ColorStop> {
71        unsafe {
72            let mut n_stops = std::mem::MaybeUninit::uninit();
73            let ret = FromGlibContainer::from_glib_none_num(
74                ffi::gsk_linear_gradient_node_get_color_stops(
75                    self.to_glib_none().0,
76                    n_stops.as_mut_ptr(),
77                ),
78                n_stops.assume_init() as _,
79            );
80            ret
81        }
82    }
83
84    /// Retrieves the final point of the linear gradient.
85    ///
86    /// # Returns
87    ///
88    /// the final point
89    #[doc(alias = "gsk_linear_gradient_node_get_end")]
90    #[doc(alias = "get_end")]
91    pub fn end(&self) -> graphene::Point {
92        unsafe { from_glib_none(ffi::gsk_linear_gradient_node_get_end(self.to_glib_none().0)) }
93    }
94
95    /// Retrieves the number of color stops in the gradient.
96    ///
97    /// # Returns
98    ///
99    /// the number of color stops
100    #[doc(alias = "gsk_linear_gradient_node_get_n_color_stops")]
101    #[doc(alias = "get_n_color_stops")]
102    pub fn n_color_stops(&self) -> usize {
103        unsafe { ffi::gsk_linear_gradient_node_get_n_color_stops(self.to_glib_none().0) }
104    }
105
106    /// Retrieves the initial point of the linear gradient.
107    ///
108    /// # Returns
109    ///
110    /// the initial point
111    #[doc(alias = "gsk_linear_gradient_node_get_start")]
112    #[doc(alias = "get_start")]
113    pub fn start(&self) -> graphene::Point {
114        unsafe {
115            from_glib_none(ffi::gsk_linear_gradient_node_get_start(
116                self.to_glib_none().0,
117            ))
118        }
119    }
120}