Skip to main content

gsk4/auto/
radial_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 radial gradient.
10    #[doc(alias = "GskRadialGradientNode")]
11    pub struct RadialGradientNode(Shared<ffi::GskRadialGradientNode>);
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 RadialGradientNode {
20    fn static_type() -> glib::Type {
21        unsafe { from_glib(ffi::gsk_radial_gradient_node_get_type()) }
22    }
23}
24
25impl RadialGradientNode {
26    /// Creates a [`RenderNode`][crate::RenderNode] that draws a radial gradient.
27    ///
28    /// The radial gradient
29    /// starts around @center. The size of the gradient is dictated by @hradius
30    /// in horizontal orientation and by @vradius in vertical orientation.
31    /// ## `bounds`
32    /// the bounds of the node
33    /// ## `center`
34    /// the center of the gradient
35    /// ## `hradius`
36    /// the horizontal radius
37    /// ## `vradius`
38    /// the vertical radius
39    /// ## `start`
40    /// = 0 that defines the start of the gradient around @center
41    /// ## `end`
42    /// = 0 that defines the end of the gradient around @center
43    /// ## `color_stops`
44    /// = 1.
45    ///
46    /// # Returns
47    ///
48    /// A new [`RenderNode`][crate::RenderNode]
49    #[doc(alias = "gsk_radial_gradient_node_new")]
50    pub fn new(
51        bounds: &graphene::Rect,
52        center: &graphene::Point,
53        hradius: f32,
54        vradius: f32,
55        start: f32,
56        end: f32,
57        color_stops: &[ColorStop],
58    ) -> RadialGradientNode {
59        assert_initialized_main_thread!();
60        let n_color_stops = color_stops.len() as _;
61        unsafe {
62            from_glib_full(ffi::gsk_radial_gradient_node_new(
63                bounds.to_glib_none().0,
64                center.to_glib_none().0,
65                hradius,
66                vradius,
67                start,
68                end,
69                color_stops.to_glib_none().0,
70                n_color_stops,
71            ))
72        }
73    }
74
75    /// Retrieves the center pointer for the gradient.
76    ///
77    /// # Returns
78    ///
79    /// the center point for the gradient
80    #[doc(alias = "gsk_radial_gradient_node_get_center")]
81    #[doc(alias = "get_center")]
82    pub fn center(&self) -> graphene::Point {
83        unsafe {
84            from_glib_none(ffi::gsk_radial_gradient_node_get_center(
85                self.to_glib_none().0,
86            ))
87        }
88    }
89
90    /// Retrieves the color stops in the gradient.
91    ///
92    /// # Returns
93    ///
94    /// the color stops in the gradient
95    #[doc(alias = "gsk_radial_gradient_node_get_color_stops")]
96    #[doc(alias = "get_color_stops")]
97    pub fn color_stops(&self) -> Vec<ColorStop> {
98        unsafe {
99            let mut n_stops = std::mem::MaybeUninit::uninit();
100            let ret = FromGlibContainer::from_glib_none_num(
101                ffi::gsk_radial_gradient_node_get_color_stops(
102                    self.to_glib_none().0,
103                    n_stops.as_mut_ptr(),
104                ),
105                n_stops.assume_init() as _,
106            );
107            ret
108        }
109    }
110
111    /// Retrieves the end value for the gradient.
112    ///
113    /// # Returns
114    ///
115    /// the end value for the gradient
116    #[doc(alias = "gsk_radial_gradient_node_get_end")]
117    #[doc(alias = "get_end")]
118    pub fn end(&self) -> f32 {
119        unsafe { ffi::gsk_radial_gradient_node_get_end(self.to_glib_none().0) }
120    }
121
122    /// Retrieves the horizontal radius for the gradient.
123    ///
124    /// # Returns
125    ///
126    /// the horizontal radius for the gradient
127    #[doc(alias = "gsk_radial_gradient_node_get_hradius")]
128    #[doc(alias = "get_hradius")]
129    pub fn hradius(&self) -> f32 {
130        unsafe { ffi::gsk_radial_gradient_node_get_hradius(self.to_glib_none().0) }
131    }
132
133    /// Retrieves the number of color stops in the gradient.
134    ///
135    /// # Returns
136    ///
137    /// the number of color stops
138    #[doc(alias = "gsk_radial_gradient_node_get_n_color_stops")]
139    #[doc(alias = "get_n_color_stops")]
140    pub fn n_color_stops(&self) -> usize {
141        unsafe { ffi::gsk_radial_gradient_node_get_n_color_stops(self.to_glib_none().0) }
142    }
143
144    /// Retrieves the start value for the gradient.
145    ///
146    /// # Returns
147    ///
148    /// the start value for the gradient
149    #[doc(alias = "gsk_radial_gradient_node_get_start")]
150    #[doc(alias = "get_start")]
151    pub fn start(&self) -> f32 {
152        unsafe { ffi::gsk_radial_gradient_node_get_start(self.to_glib_none().0) }
153    }
154
155    /// Retrieves the vertical radius for the gradient.
156    ///
157    /// # Returns
158    ///
159    /// the vertical radius for the gradient
160    #[doc(alias = "gsk_radial_gradient_node_get_vradius")]
161    #[doc(alias = "get_vradius")]
162    pub fn vradius(&self) -> f32 {
163        unsafe { ffi::gsk_radial_gradient_node_get_vradius(self.to_glib_none().0) }
164    }
165}