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