gtk4/
snapshot.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::borrow::Borrow;
4
5use glib::translate::*;
6
7use crate::{ffi, prelude::*, Snapshot};
8
9mod sealed {
10    pub trait Sealed {}
11    impl<T: super::IsA<super::Snapshot>> Sealed for T {}
12}
13
14pub trait SnapshotExtManual: sealed::Sealed + IsA<Snapshot> + 'static {
15    /// Appends a stroked border rectangle inside the given @outline.
16    ///
17    /// The four sides of the border can have different widths and colors.
18    /// ## `outline`
19    /// the outline of the border
20    /// ## `border_width`
21    /// the stroke width of the border on
22    ///   the top, right, bottom and left side respectively.
23    /// ## `border_color`
24    /// the color used on the top, right,
25    ///   bottom and left side.
26    #[doc(alias = "gtk_snapshot_append_border")]
27    fn append_border(
28        &self,
29        outline: &gsk::RoundedRect,
30        border_width: &[f32; 4],
31        border_color: &[gdk::RGBA; 4],
32    ) {
33        unsafe {
34            let border_color_ptr: Vec<gdk::ffi::GdkRGBA> =
35                border_color.iter().map(|c| *c.to_glib_none().0).collect();
36            ffi::gtk_snapshot_append_border(
37                self.as_ref().to_glib_none().0,
38                outline.to_glib_none().0,
39                border_width,
40                border_color_ptr.as_ptr() as *const _,
41            )
42        }
43    }
44
45    /// Inserts a debug node with a message.
46    ///
47    /// Debug nodes don't affect the rendering at all, but can be
48    /// helpful in identifying parts of a render node tree dump,
49    /// for example in the GTK inspector.
50    /// ## `message`
51    /// a printf-style format string
52    #[doc(alias = "gtk_snapshot_push_debug")]
53    fn push_debug(&self, message: impl IntoGStr) {
54        unsafe {
55            message.run_with_gstr(|message| {
56                ffi::gtk_snapshot_push_debug(self.as_ref().to_glib_none().0, message.as_ptr())
57            })
58        }
59    }
60}
61
62impl<O: IsA<Snapshot>> SnapshotExtManual for O {}
63
64impl AsRef<Snapshot> for gdk::Snapshot {
65    #[inline]
66    fn as_ref(&self) -> &Snapshot {
67        self.downcast_ref().unwrap()
68    }
69}
70
71impl From<gdk::Snapshot> for Snapshot {
72    #[inline]
73    fn from(e: gdk::Snapshot) -> Snapshot {
74        assert_initialized_main_thread!();
75        e.downcast().unwrap()
76    }
77}
78
79impl Borrow<Snapshot> for gdk::Snapshot {
80    #[inline]
81    fn borrow(&self) -> &Snapshot {
82        self.downcast_ref().unwrap()
83    }
84}
85
86unsafe impl IsA<Snapshot> for gdk::Snapshot {}