gsk4/
border_node.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ffi, BorderNode, RenderNodeType, RoundedRect};
6
7define_render_node!(BorderNode, ffi::GskBorderNode, RenderNodeType::BorderNode);
8
9impl BorderNode {
10    #[doc(alias = "gsk_border_node_new")]
11    pub fn new(
12        outline: &RoundedRect,
13        border_width: &[f32; 4],
14        border_color: &[gdk::RGBA; 4],
15    ) -> Self {
16        unsafe {
17            from_glib_full(ffi::gsk_border_node_new(
18                outline.to_glib_none().0,
19                border_width.as_ptr() as *const [f32; 4],
20                border_color.as_ptr() as *const [gdk::ffi::GdkRGBA; 4],
21            ))
22        }
23    }
24
25    #[doc(alias = "gsk_border_node_get_colors")]
26    #[doc(alias = "get_colors")]
27    pub fn colors(&self) -> &[gdk::RGBA; 4] {
28        unsafe {
29            &*(ffi::gsk_border_node_get_colors(self.to_glib_none().0) as *const [gdk::RGBA; 4])
30        }
31    }
32
33    #[doc(alias = "gsk_border_node_get_widths")]
34    #[doc(alias = "get_widths")]
35    pub fn widths(&self) -> &[f32; 4] {
36        unsafe { &*ffi::gsk_border_node_get_widths(self.to_glib_none().0) }
37    }
38}
39
40impl std::fmt::Debug for BorderNode {
41    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
42        f.debug_struct("BorderNode")
43            .field("colors", &self.colors())
44            .field("widths", &self.widths())
45            .field("outline", &self.outline())
46            .finish()
47    }
48}