[go: up one dir, main page]

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
9pub trait SnapshotExtManual: IsA<Snapshot> + 'static {
10    #[doc(alias = "gtk_snapshot_append_border")]
11    fn append_border(
12        &self,
13        outline: &gsk::RoundedRect,
14        border_width: &[f32; 4],
15        border_color: &[gdk::RGBA; 4],
16    ) {
17        unsafe {
18            let border_color_ptr: Vec<gdk::ffi::GdkRGBA> =
19                border_color.iter().map(|c| *c.to_glib_none().0).collect();
20            ffi::gtk_snapshot_append_border(
21                self.as_ref().to_glib_none().0,
22                outline.to_glib_none().0,
23                border_width,
24                border_color_ptr.as_ptr() as *const _,
25            )
26        }
27    }
28
29    #[doc(alias = "gtk_snapshot_push_debug")]
30    fn push_debug(&self, message: impl IntoGStr) {
31        unsafe {
32            message.run_with_gstr(|message| {
33                ffi::gtk_snapshot_push_debug(self.as_ref().to_glib_none().0, message.as_ptr())
34            })
35        }
36    }
37}
38
39impl<O: IsA<Snapshot>> SnapshotExtManual for O {}
40
41impl AsRef<Snapshot> for gdk::Snapshot {
42    #[inline]
43    fn as_ref(&self) -> &Snapshot {
44        self.downcast_ref().unwrap()
45    }
46}
47
48impl From<gdk::Snapshot> for Snapshot {
49    #[inline]
50    fn from(e: gdk::Snapshot) -> Snapshot {
51        assert_initialized_main_thread!();
52        e.downcast().unwrap()
53    }
54}
55
56impl Borrow<Snapshot> for gdk::Snapshot {
57    #[inline]
58    fn borrow(&self) -> &Snapshot {
59        self.downcast_ref().unwrap()
60    }
61}
62
63unsafe impl IsA<Snapshot> for gdk::Snapshot {}