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 /// Creates a [`RenderNode`][crate::RenderNode] that will stroke a border rectangle inside the
11 /// given @outline.
12 ///
13 /// The 4 sides of the border can have different widths and colors.
14 /// ## `outline`
15 /// a [`RoundedRect`][crate::RoundedRect] describing the outline of the border
16 /// ## `border_width`
17 /// the stroke width of the border on
18 /// the top, right, bottom and left side respectively.
19 /// ## `border_color`
20 /// the color used on the top, right,
21 /// bottom and left side.
22 ///
23 /// # Returns
24 ///
25 /// A new [`RenderNode`][crate::RenderNode]
26 #[doc(alias = "gsk_border_node_new")]
27 pub fn new(
28 outline: &RoundedRect,
29 border_width: &[f32; 4],
30 border_color: &[gdk::RGBA; 4],
31 ) -> Self {
32 unsafe {
33 from_glib_full(ffi::gsk_border_node_new(
34 outline.to_glib_none().0,
35 border_width.as_ptr() as *const [f32; 4],
36 border_color.as_ptr() as *const [gdk::ffi::GdkRGBA; 4],
37 ))
38 }
39 }
40
41 /// Retrieves the colors of the border.
42 ///
43 /// # Returns
44 ///
45 /// an array of 4 [`gdk::RGBA`][crate::gdk::RGBA]
46 /// structs for the top, right, bottom and left color of the border
47 #[doc(alias = "gsk_border_node_get_colors")]
48 #[doc(alias = "get_colors")]
49 pub fn colors(&self) -> &[gdk::RGBA; 4] {
50 unsafe {
51 &*(ffi::gsk_border_node_get_colors(self.to_glib_none().0) as *const [gdk::RGBA; 4])
52 }
53 }
54
55 /// Retrieves the stroke widths of the border.
56 ///
57 /// # Returns
58 ///
59 /// an array of 4 floats
60 /// for the top, right, bottom and left stroke width of the border,
61 /// respectively
62 #[doc(alias = "gsk_border_node_get_widths")]
63 #[doc(alias = "get_widths")]
64 pub fn widths(&self) -> &[f32; 4] {
65 unsafe { &*ffi::gsk_border_node_get_widths(self.to_glib_none().0) }
66 }
67}
68
69impl std::fmt::Debug for BorderNode {
70 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
71 f.debug_struct("BorderNode")
72 .field("colors", &self.colors())
73 .field("widths", &self.widths())
74 .field("outline", &self.outline())
75 .finish()
76 }
77}