gtk4/auto/
native.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use 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
32pub trait NativeExt: IsA<Native> + 'static {
33    #[doc(alias = "gtk_native_get_renderer")]
34    #[doc(alias = "get_renderer")]
35    fn renderer(&self) -> Option<gsk::Renderer> {
36        unsafe { from_glib_none(ffi::gtk_native_get_renderer(self.as_ref().to_glib_none().0)) }
37    }
38
39    #[doc(alias = "gtk_native_get_surface")]
40    #[doc(alias = "get_surface")]
41    fn surface(&self) -> Option<gdk::Surface> {
42        unsafe { from_glib_none(ffi::gtk_native_get_surface(self.as_ref().to_glib_none().0)) }
43    }
44
45    #[doc(alias = "gtk_native_get_surface_transform")]
46    #[doc(alias = "get_surface_transform")]
47    fn surface_transform(&self) -> (f64, f64) {
48        unsafe {
49            let mut x = std::mem::MaybeUninit::uninit();
50            let mut y = std::mem::MaybeUninit::uninit();
51            ffi::gtk_native_get_surface_transform(
52                self.as_ref().to_glib_none().0,
53                x.as_mut_ptr(),
54                y.as_mut_ptr(),
55            );
56            (x.assume_init(), y.assume_init())
57        }
58    }
59
60    #[doc(alias = "gtk_native_realize")]
61    fn realize(&self) {
62        unsafe {
63            ffi::gtk_native_realize(self.as_ref().to_glib_none().0);
64        }
65    }
66
67    #[doc(alias = "gtk_native_unrealize")]
68    fn unrealize(&self) {
69        unsafe {
70            ffi::gtk_native_unrealize(self.as_ref().to_glib_none().0);
71        }
72    }
73}
74
75impl<O: IsA<Native>> NativeExt for O {}