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