gsk4/auto/
conic_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 conic gradient.
10    #[doc(alias = "GskConicGradientNode")]
11    pub struct ConicGradientNode(Shared<ffi::GskConicGradientNode>);
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 ConicGradientNode {
20    fn static_type() -> glib::Type {
21        unsafe { from_glib(ffi::gsk_conic_gradient_node_get_type()) }
22    }
23}
24
25impl ConicGradientNode {
26    /// Creates a [`RenderNode`][crate::RenderNode] that draws a conic gradient.
27    ///
28    /// The conic gradient
29    /// starts around @center in the direction of @rotation. A rotation of 0 means
30    /// that the gradient points up. Color stops are then added clockwise.
31    /// ## `bounds`
32    /// the bounds of the node
33    /// ## `center`
34    /// the center of the gradient
35    /// ## `rotation`
36    /// the rotation of the gradient in degrees
37    /// ## `color_stops`
38    /// a pointer to an array of
39    ///   [`ColorStop`][crate::ColorStop] defining the gradient. The offsets of all color stops
40    ///   must be increasing. The first stop's offset must be >= 0 and the last
41    ///   stop's offset must be <= 1.
42    ///
43    /// # Returns
44    ///
45    /// A new [`RenderNode`][crate::RenderNode]
46    #[doc(alias = "gsk_conic_gradient_node_new")]
47    pub fn new(
48        bounds: &graphene::Rect,
49        center: &graphene::Point,
50        rotation: f32,
51        color_stops: &[ColorStop],
52    ) -> ConicGradientNode {
53        assert_initialized_main_thread!();
54        let n_color_stops = color_stops.len() as _;
55        unsafe {
56            from_glib_full(ffi::gsk_conic_gradient_node_new(
57                bounds.to_glib_none().0,
58                center.to_glib_none().0,
59                rotation,
60                color_stops.to_glib_none().0,
61                n_color_stops,
62            ))
63        }
64    }
65
66    /// Retrieves the angle for the gradient in radians, normalized in [0, 2 * PI].
67    ///
68    /// The angle is starting at the top and going clockwise, as expressed
69    /// in the css specification:
70    ///
71    ///     angle = 90 - gsk_conic_gradient_node_get_rotation()
72    ///
73    /// # Returns
74    ///
75    /// the angle for the gradient
76    #[cfg(feature = "v4_2")]
77    #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
78    #[doc(alias = "gsk_conic_gradient_node_get_angle")]
79    #[doc(alias = "get_angle")]
80    pub fn angle(&self) -> f32 {
81        unsafe { ffi::gsk_conic_gradient_node_get_angle(self.to_glib_none().0) }
82    }
83
84    /// Retrieves the center pointer for the gradient.
85    ///
86    /// # Returns
87    ///
88    /// the center point for the gradient
89    #[doc(alias = "gsk_conic_gradient_node_get_center")]
90    #[doc(alias = "get_center")]
91    pub fn center(&self) -> graphene::Point {
92        unsafe {
93            from_glib_none(ffi::gsk_conic_gradient_node_get_center(
94                self.to_glib_none().0,
95            ))
96        }
97    }
98
99    /// Retrieves the color stops in the gradient.
100    ///
101    /// # Returns
102    ///
103    /// the color stops in the gradient
104    #[doc(alias = "gsk_conic_gradient_node_get_color_stops")]
105    #[doc(alias = "get_color_stops")]
106    pub fn color_stops(&self) -> Vec<ColorStop> {
107        unsafe {
108            let mut n_stops = std::mem::MaybeUninit::uninit();
109            let ret = FromGlibContainer::from_glib_none_num(
110                ffi::gsk_conic_gradient_node_get_color_stops(
111                    self.to_glib_none().0,
112                    n_stops.as_mut_ptr(),
113                ),
114                n_stops.assume_init() as _,
115            );
116            ret
117        }
118    }
119
120    /// Retrieves the number of color stops in the gradient.
121    ///
122    /// # Returns
123    ///
124    /// the number of color stops
125    #[doc(alias = "gsk_conic_gradient_node_get_n_color_stops")]
126    #[doc(alias = "get_n_color_stops")]
127    pub fn n_color_stops(&self) -> usize {
128        unsafe { ffi::gsk_conic_gradient_node_get_n_color_stops(self.to_glib_none().0) }
129    }
130
131    /// Retrieves the rotation for the gradient in degrees.
132    ///
133    /// # Returns
134    ///
135    /// the rotation for the gradient
136    #[doc(alias = "gsk_conic_gradient_node_get_rotation")]
137    #[doc(alias = "get_rotation")]
138    pub fn rotation(&self) -> f32 {
139        unsafe { ffi::gsk_conic_gradient_node_get_rotation(self.to_glib_none().0) }
140    }
141}