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::{ffi, ColorStop};
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    /// a percentage >= 0 that defines the start of the gradient around @center
41    /// ## `end`
42    /// a percentage >= 0 that defines the end of the gradient around @center
43    /// ## `color_stops`
44    /// a pointer to an array of
45    ///   [`ColorStop`][crate::ColorStop] defining the gradient. The offsets of all color stops
46    ///   must be increasing. The first stop's offset must be >= 0 and the last
47    ///   stop's offset must be <= 1.
48    ///
49    /// # Returns
50    ///
51    /// A new [`RenderNode`][crate::RenderNode]
52    #[doc(alias = "gsk_radial_gradient_node_new")]
53    pub fn new(
54        bounds: &graphene::Rect,
55        center: &graphene::Point,
56        hradius: f32,
57        vradius: f32,
58        start: f32,
59        end: f32,
60        color_stops: &[ColorStop],
61    ) -> RadialGradientNode {
62        assert_initialized_main_thread!();
63        let n_color_stops = color_stops.len() as _;
64        unsafe {
65            from_glib_full(ffi::gsk_radial_gradient_node_new(
66                bounds.to_glib_none().0,
67                center.to_glib_none().0,
68                hradius,
69                vradius,
70                start,
71                end,
72                color_stops.to_glib_none().0,
73                n_color_stops,
74            ))
75        }
76    }
77
78    /// Retrieves the center pointer for the gradient.
79    ///
80    /// # Returns
81    ///
82    /// the center point for the gradient
83    #[doc(alias = "gsk_radial_gradient_node_get_center")]
84    #[doc(alias = "get_center")]
85    pub fn center(&self) -> graphene::Point {
86        unsafe {
87            from_glib_none(ffi::gsk_radial_gradient_node_get_center(
88                self.to_glib_none().0,
89            ))
90        }
91    }
92
93    /// Retrieves the color stops in the gradient.
94    ///
95    /// # Returns
96    ///
97    /// the color stops in the gradient
98    #[doc(alias = "gsk_radial_gradient_node_get_color_stops")]
99    #[doc(alias = "get_color_stops")]
100    pub fn color_stops(&self) -> Vec<ColorStop> {
101        unsafe {
102            let mut n_stops = std::mem::MaybeUninit::uninit();
103            let ret = FromGlibContainer::from_glib_none_num(
104                ffi::gsk_radial_gradient_node_get_color_stops(
105                    self.to_glib_none().0,
106                    n_stops.as_mut_ptr(),
107                ),
108                n_stops.assume_init() as _,
109            );
110            ret
111        }
112    }
113
114    /// Retrieves the end value for the gradient.
115    ///
116    /// # Returns
117    ///
118    /// the end value for the gradient
119    #[doc(alias = "gsk_radial_gradient_node_get_end")]
120    #[doc(alias = "get_end")]
121    pub fn end(&self) -> f32 {
122        unsafe { ffi::gsk_radial_gradient_node_get_end(self.to_glib_none().0) }
123    }
124
125    /// Retrieves the horizontal radius for the gradient.
126    ///
127    /// # Returns
128    ///
129    /// the horizontal radius for the gradient
130    #[doc(alias = "gsk_radial_gradient_node_get_hradius")]
131    #[doc(alias = "get_hradius")]
132    pub fn hradius(&self) -> f32 {
133        unsafe { ffi::gsk_radial_gradient_node_get_hradius(self.to_glib_none().0) }
134    }
135
136    /// Retrieves the number of color stops in the gradient.
137    ///
138    /// # Returns
139    ///
140    /// the number of color stops
141    #[doc(alias = "gsk_radial_gradient_node_get_n_color_stops")]
142    #[doc(alias = "get_n_color_stops")]
143    pub fn n_color_stops(&self) -> usize {
144        unsafe { ffi::gsk_radial_gradient_node_get_n_color_stops(self.to_glib_none().0) }
145    }
146
147    /// Retrieves the start value for the gradient.
148    ///
149    /// # Returns
150    ///
151    /// the start value for the gradient
152    #[doc(alias = "gsk_radial_gradient_node_get_start")]
153    #[doc(alias = "get_start")]
154    pub fn start(&self) -> f32 {
155        unsafe { ffi::gsk_radial_gradient_node_get_start(self.to_glib_none().0) }
156    }
157
158    /// Retrieves the vertical radius for the gradient.
159    ///
160    /// # Returns
161    ///
162    /// the vertical radius for the gradient
163    #[doc(alias = "gsk_radial_gradient_node_get_vradius")]
164    #[doc(alias = "get_vradius")]
165    pub fn vradius(&self) -> f32 {
166        unsafe { ffi::gsk_radial_gradient_node_get_vradius(self.to_glib_none().0) }
167    }
168}