Skip to main content

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::{ColorStop, ffi};
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    /// = 1.
39    ///
40    /// # Returns
41    ///
42    /// A new [`RenderNode`][crate::RenderNode]
43    #[doc(alias = "gsk_conic_gradient_node_new")]
44    pub fn new(
45        bounds: &graphene::Rect,
46        center: &graphene::Point,
47        rotation: f32,
48        color_stops: &[ColorStop],
49    ) -> ConicGradientNode {
50        assert_initialized_main_thread!();
51        let n_color_stops = color_stops.len() as _;
52        unsafe {
53            from_glib_full(ffi::gsk_conic_gradient_node_new(
54                bounds.to_glib_none().0,
55                center.to_glib_none().0,
56                rotation,
57                color_stops.to_glib_none().0,
58                n_color_stops,
59            ))
60        }
61    }
62
63    /// Retrieves the angle for the gradient in radians, normalized in [0, 2 * PI].
64    ///
65    /// The angle is starting at the top and going clockwise, as expressed
66    /// in the css specification:
67    ///
68    ///     angle = 90 - gsk_conic_gradient_node_get_rotation()
69    ///
70    /// # Returns
71    ///
72    /// the angle for the gradient
73    #[cfg(feature = "v4_2")]
74    #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
75    #[doc(alias = "gsk_conic_gradient_node_get_angle")]
76    #[doc(alias = "get_angle")]
77    pub fn angle(&self) -> f32 {
78        unsafe { ffi::gsk_conic_gradient_node_get_angle(self.to_glib_none().0) }
79    }
80
81    /// Retrieves the center pointer for the gradient.
82    ///
83    /// # Returns
84    ///
85    /// the center point for the gradient
86    #[doc(alias = "gsk_conic_gradient_node_get_center")]
87    #[doc(alias = "get_center")]
88    pub fn center(&self) -> graphene::Point {
89        unsafe {
90            from_glib_none(ffi::gsk_conic_gradient_node_get_center(
91                self.to_glib_none().0,
92            ))
93        }
94    }
95
96    /// Retrieves the color stops in the gradient.
97    ///
98    /// # Returns
99    ///
100    /// the color stops in the gradient
101    #[doc(alias = "gsk_conic_gradient_node_get_color_stops")]
102    #[doc(alias = "get_color_stops")]
103    pub fn color_stops(&self) -> Vec<ColorStop> {
104        unsafe {
105            let mut n_stops = std::mem::MaybeUninit::uninit();
106            let ret = FromGlibContainer::from_glib_none_num(
107                ffi::gsk_conic_gradient_node_get_color_stops(
108                    self.to_glib_none().0,
109                    n_stops.as_mut_ptr(),
110                ),
111                n_stops.assume_init() as _,
112            );
113            ret
114        }
115    }
116
117    /// Retrieves the number of color stops in the gradient.
118    ///
119    /// # Returns
120    ///
121    /// the number of color stops
122    #[doc(alias = "gsk_conic_gradient_node_get_n_color_stops")]
123    #[doc(alias = "get_n_color_stops")]
124    pub fn n_color_stops(&self) -> usize {
125        unsafe { ffi::gsk_conic_gradient_node_get_n_color_stops(self.to_glib_none().0) }
126    }
127
128    /// Retrieves the rotation for the gradient in degrees.
129    ///
130    /// # Returns
131    ///
132    /// the rotation for the gradient
133    #[doc(alias = "gsk_conic_gradient_node_get_rotation")]
134    #[doc(alias = "get_rotation")]
135    pub fn rotation(&self) -> f32 {
136        unsafe { ffi::gsk_conic_gradient_node_get_rotation(self.to_glib_none().0) }
137    }
138}