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 /// [`Native`][crate::Native] is the interface implemented by all widgets that have
10 /// their own [`gdk::Surface`][crate::gdk::Surface].
11 ///
12 /// The obvious example of a [`Native`][crate::Native] is [`Window`][crate::Window].
13 ///
14 /// Every widget that is not itself a [`Native`][crate::Native] is contained in one,
15 /// and you can get it with [`WidgetExt::native()`][crate::prelude::WidgetExt::native()].
16 ///
17 /// To get the surface of a [`Native`][crate::Native], use [`NativeExt::surface()`][crate::prelude::NativeExt::surface()].
18 /// It is also possible to find the [`Native`][crate::Native] to which a surface
19 /// belongs, with [`for_surface()`][Self::for_surface()].
20 ///
21 /// In addition to a [`gdk::Surface`][crate::gdk::Surface], a [`Native`][crate::Native] also provides
22 /// a [`gsk::Renderer`][crate::gsk::Renderer] for rendering on that surface. To get the
23 /// renderer, use [`NativeExt::renderer()`][crate::prelude::NativeExt::renderer()].
24 ///
25 /// # Implements
26 ///
27 /// [`NativeExt`][trait@crate::prelude::NativeExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
28 #[doc(alias = "GtkNative")]
29 pub struct Native(Interface<ffi::GtkNative, ffi::GtkNativeInterface>) @requires Widget, Accessible, Buildable, ConstraintTarget;
30
31 match fn {
32 type_ => || ffi::gtk_native_get_type(),
33 }
34}
35
36impl Native {
37 pub const NONE: Option<&'static Native> = None;
38
39 /// Finds the [`Native`][crate::Native] associated with the surface.
40 /// ## `surface`
41 /// a [`gdk::Surface`][crate::gdk::Surface]
42 ///
43 /// # Returns
44 ///
45 /// the [`Native`][crate::Native] that is associated with @surface
46 #[doc(alias = "gtk_native_get_for_surface")]
47 #[doc(alias = "get_for_surface")]
48 pub fn for_surface(surface: &impl IsA<gdk::Surface>) -> Option<Native> {
49 assert_initialized_main_thread!();
50 unsafe {
51 from_glib_none(ffi::gtk_native_get_for_surface(
52 surface.as_ref().to_glib_none().0,
53 ))
54 }
55 }
56}
57
58mod sealed {
59 pub trait Sealed {}
60 impl<T: super::IsA<super::Native>> Sealed for T {}
61}
62
63/// Trait containing all [`struct@Native`] methods.
64///
65/// # Implementors
66///
67/// [`AboutDialog`][struct@crate::AboutDialog], [`AppChooserDialog`][struct@crate::AppChooserDialog], [`ApplicationWindow`][struct@crate::ApplicationWindow], [`Assistant`][struct@crate::Assistant], [`ColorChooserDialog`][struct@crate::ColorChooserDialog], [`Dialog`][struct@crate::Dialog], [`DragIcon`][struct@crate::DragIcon], [`EmojiChooser`][struct@crate::EmojiChooser], [`FileChooserDialog`][struct@crate::FileChooserDialog], [`FontChooserDialog`][struct@crate::FontChooserDialog], [`MessageDialog`][struct@crate::MessageDialog], [`Native`][struct@crate::Native], [`PageSetupUnixDialog`][struct@crate::PageSetupUnixDialog], [`PopoverMenu`][struct@crate::PopoverMenu], [`Popover`][struct@crate::Popover], [`PrintUnixDialog`][struct@crate::PrintUnixDialog], [`Root`][struct@crate::Root], [`ShortcutsWindow`][struct@crate::ShortcutsWindow], [`Window`][struct@crate::Window]
68pub trait NativeExt: IsA<Native> + sealed::Sealed + 'static {
69 /// Returns the renderer that is used for this [`Native`][crate::Native].
70 ///
71 /// # Returns
72 ///
73 /// the renderer for @self
74 #[doc(alias = "gtk_native_get_renderer")]
75 #[doc(alias = "get_renderer")]
76 fn renderer(&self) -> Option<gsk::Renderer> {
77 unsafe { from_glib_none(ffi::gtk_native_get_renderer(self.as_ref().to_glib_none().0)) }
78 }
79
80 /// Returns the surface of this [`Native`][crate::Native].
81 ///
82 /// # Returns
83 ///
84 /// the surface of @self
85 #[doc(alias = "gtk_native_get_surface")]
86 #[doc(alias = "get_surface")]
87 fn surface(&self) -> Option<gdk::Surface> {
88 unsafe { from_glib_none(ffi::gtk_native_get_surface(self.as_ref().to_glib_none().0)) }
89 }
90
91 /// Retrieves the surface transform of @self.
92 ///
93 /// This is the translation from @self's surface coordinates into
94 /// @self's widget coordinates.
95 ///
96 /// # Returns
97 ///
98 ///
99 /// ## `x`
100 /// return location for the x coordinate
101 ///
102 /// ## `y`
103 /// return location for the y coordinate
104 #[doc(alias = "gtk_native_get_surface_transform")]
105 #[doc(alias = "get_surface_transform")]
106 fn surface_transform(&self) -> (f64, f64) {
107 unsafe {
108 let mut x = std::mem::MaybeUninit::uninit();
109 let mut y = std::mem::MaybeUninit::uninit();
110 ffi::gtk_native_get_surface_transform(
111 self.as_ref().to_glib_none().0,
112 x.as_mut_ptr(),
113 y.as_mut_ptr(),
114 );
115 (x.assume_init(), y.assume_init())
116 }
117 }
118
119 /// Realizes a [`Native`][crate::Native].
120 ///
121 /// This should only be used by subclasses.
122 #[doc(alias = "gtk_native_realize")]
123 fn realize(&self) {
124 unsafe {
125 ffi::gtk_native_realize(self.as_ref().to_glib_none().0);
126 }
127 }
128
129 /// Unrealizes a [`Native`][crate::Native].
130 ///
131 /// This should only be used by subclasses.
132 #[doc(alias = "gtk_native_unrealize")]
133 fn unrealize(&self) {
134 unsafe {
135 ffi::gtk_native_unrealize(self.as_ref().to_glib_none().0);
136 }
137 }
138}
139
140impl<O: IsA<Native>> NativeExt for O {}