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