1use crate::{ffi, Accessible, Buildable, ConstraintTarget, Widget};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 #[doc(alias = "GtkNative")]
10 pub struct Native(Interface<ffi::GtkNative, ffi::GtkNativeInterface>) @requires Widget, Accessible, Buildable, ConstraintTarget;
11
12 match fn {
13 type_ => || ffi::gtk_native_get_type(),
14 }
15}
16
17impl Native {
18 pub const NONE: Option<&'static Native> = None;
19
20 #[doc(alias = "gtk_native_get_for_surface")]
21 #[doc(alias = "get_for_surface")]
22 pub fn for_surface(surface: &impl IsA<gdk::Surface>) -> Option<Native> {
23 assert_initialized_main_thread!();
24 unsafe {
25 from_glib_none(ffi::gtk_native_get_for_surface(
26 surface.as_ref().to_glib_none().0,
27 ))
28 }
29 }
30}
31
32mod sealed {
33 pub trait Sealed {}
34 impl<T: super::IsA<super::Native>> Sealed for T {}
35}
36
37pub trait NativeExt: IsA<Native> + sealed::Sealed + 'static {
38 #[doc(alias = "gtk_native_get_renderer")]
39 #[doc(alias = "get_renderer")]
40 fn renderer(&self) -> Option<gsk::Renderer> {
41 unsafe { from_glib_none(ffi::gtk_native_get_renderer(self.as_ref().to_glib_none().0)) }
42 }
43
44 #[doc(alias = "gtk_native_get_surface")]
45 #[doc(alias = "get_surface")]
46 fn surface(&self) -> Option<gdk::Surface> {
47 unsafe { from_glib_none(ffi::gtk_native_get_surface(self.as_ref().to_glib_none().0)) }
48 }
49
50 #[doc(alias = "gtk_native_get_surface_transform")]
51 #[doc(alias = "get_surface_transform")]
52 fn surface_transform(&self) -> (f64, f64) {
53 unsafe {
54 let mut x = std::mem::MaybeUninit::uninit();
55 let mut y = std::mem::MaybeUninit::uninit();
56 ffi::gtk_native_get_surface_transform(
57 self.as_ref().to_glib_none().0,
58 x.as_mut_ptr(),
59 y.as_mut_ptr(),
60 );
61 (x.assume_init(), y.assume_init())
62 }
63 }
64
65 #[doc(alias = "gtk_native_realize")]
66 fn realize(&self) {
67 unsafe {
68 ffi::gtk_native_realize(self.as_ref().to_glib_none().0);
69 }
70 }
71
72 #[doc(alias = "gtk_native_unrealize")]
73 fn unrealize(&self) {
74 unsafe {
75 ffi::gtk_native_unrealize(self.as_ref().to_glib_none().0);
76 }
77 }
78}
79
80impl<O: IsA<Native>> NativeExt for O {}