gdk4/auto/popup.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, Gravity, PopupLayout, Surface};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// A [`Popup`][crate::Popup] is a surface that is attached to another surface.
10 ///
11 /// The [`Popup`][crate::Popup] is positioned relative to its parent surface.
12 ///
13 /// [`Popup`][crate::Popup]s are typically used to implement menus and similar popups.
14 /// They can be modal, which is indicated by the [`autohide`][struct@crate::Popup#autohide]
15 /// property.
16 ///
17 /// ## Properties
18 ///
19 ///
20 /// #### `autohide`
21 /// Whether to hide on outside clicks.
22 ///
23 /// Readable | Writeable | Construct Only
24 ///
25 ///
26 /// #### `parent`
27 /// The parent surface.
28 ///
29 /// Readable | Writeable | Construct Only
30 /// <details><summary><h4>Surface</h4></summary>
31 ///
32 ///
33 /// #### `cursor`
34 /// The mouse pointer for the [`Surface`][crate::Surface].
35 ///
36 /// Readable | Writeable
37 ///
38 ///
39 /// #### `display`
40 /// The [`Display`][crate::Display] connection of the surface.
41 ///
42 /// Readable | Writeable | Construct Only
43 ///
44 ///
45 /// #### `frame-clock`
46 /// The [`FrameClock`][crate::FrameClock] of the surface.
47 ///
48 /// Readable | Writeable | Construct Only
49 ///
50 ///
51 /// #### `height`
52 /// The height of the surface, in pixels.
53 ///
54 /// Readable
55 ///
56 ///
57 /// #### `mapped`
58 /// Whether the surface is mapped.
59 ///
60 /// Readable
61 ///
62 ///
63 /// #### `scale`
64 /// The scale of the surface.
65 ///
66 /// Readable
67 ///
68 ///
69 /// #### `scale-factor`
70 /// The scale factor of the surface.
71 ///
72 /// The scale factor is the next larger integer,
73 /// compared to [`scale`][struct@crate::Surface#scale].
74 ///
75 /// Readable
76 ///
77 ///
78 /// #### `width`
79 /// The width of the surface in pixels.
80 ///
81 /// Readable
82 /// </details>
83 ///
84 /// # Implements
85 ///
86 /// [`PopupExt`][trait@crate::prelude::PopupExt], [`SurfaceExt`][trait@crate::prelude::SurfaceExt], [`SurfaceExtManual`][trait@crate::prelude::SurfaceExtManual]
87 #[doc(alias = "GdkPopup")]
88 pub struct Popup(Interface<ffi::GdkPopup, ffi::GdkPopupInterface>) @requires Surface;
89
90 match fn {
91 type_ => || ffi::gdk_popup_get_type(),
92 }
93}
94
95impl Popup {
96 pub const NONE: Option<&'static Popup> = None;
97}
98
99mod sealed {
100 pub trait Sealed {}
101 impl<T: super::IsA<super::Popup>> Sealed for T {}
102}
103
104/// Trait containing all [`struct@Popup`] methods.
105///
106/// # Implementors
107///
108/// [`Popup`][struct@crate::Popup]
109pub trait PopupExt: IsA<Popup> + sealed::Sealed + 'static {
110 /// Returns whether this popup is set to hide on outside clicks.
111 ///
112 /// # Returns
113 ///
114 /// [`true`] if @self will autohide
115 #[doc(alias = "gdk_popup_get_autohide")]
116 #[doc(alias = "get_autohide")]
117 #[doc(alias = "autohide")]
118 fn is_autohide(&self) -> bool {
119 unsafe { from_glib(ffi::gdk_popup_get_autohide(self.as_ref().to_glib_none().0)) }
120 }
121
122 /// Returns the parent surface of a popup.
123 ///
124 /// # Returns
125 ///
126 /// the parent surface
127 #[doc(alias = "gdk_popup_get_parent")]
128 #[doc(alias = "get_parent")]
129 fn parent(&self) -> Option<Surface> {
130 unsafe { from_glib_none(ffi::gdk_popup_get_parent(self.as_ref().to_glib_none().0)) }
131 }
132
133 /// Obtains the position of the popup relative to its parent.
134 ///
135 /// # Returns
136 ///
137 /// the X coordinate of @self position
138 #[doc(alias = "gdk_popup_get_position_x")]
139 #[doc(alias = "get_position_x")]
140 fn position_x(&self) -> i32 {
141 unsafe { ffi::gdk_popup_get_position_x(self.as_ref().to_glib_none().0) }
142 }
143
144 /// Obtains the position of the popup relative to its parent.
145 ///
146 /// # Returns
147 ///
148 /// the Y coordinate of @self position
149 #[doc(alias = "gdk_popup_get_position_y")]
150 #[doc(alias = "get_position_y")]
151 fn position_y(&self) -> i32 {
152 unsafe { ffi::gdk_popup_get_position_y(self.as_ref().to_glib_none().0) }
153 }
154
155 /// Gets the current popup rectangle anchor.
156 ///
157 /// The value returned may change after calling [`present()`][Self::present()],
158 /// or after the [`layout`][struct@crate::Surface#layout] signal is emitted.
159 ///
160 /// # Returns
161 ///
162 /// the current rectangle anchor value of @self
163 #[doc(alias = "gdk_popup_get_rect_anchor")]
164 #[doc(alias = "get_rect_anchor")]
165 fn rect_anchor(&self) -> Gravity {
166 unsafe {
167 from_glib(ffi::gdk_popup_get_rect_anchor(
168 self.as_ref().to_glib_none().0,
169 ))
170 }
171 }
172
173 /// Gets the current popup surface anchor.
174 ///
175 /// The value returned may change after calling [`present()`][Self::present()],
176 /// or after the [`layout`][struct@crate::Surface#layout] signal is emitted.
177 ///
178 /// # Returns
179 ///
180 /// the current surface anchor value of @self
181 #[doc(alias = "gdk_popup_get_surface_anchor")]
182 #[doc(alias = "get_surface_anchor")]
183 fn surface_anchor(&self) -> Gravity {
184 unsafe {
185 from_glib(ffi::gdk_popup_get_surface_anchor(
186 self.as_ref().to_glib_none().0,
187 ))
188 }
189 }
190
191 /// Present @self after having processed the [`PopupLayout`][crate::PopupLayout] rules.
192 ///
193 /// If the popup was previously not showing, it will be shown,
194 /// otherwise it will change position according to @layout.
195 ///
196 /// After calling this function, the result should be handled in response
197 /// to the [`layout`][struct@crate::Surface#layout] signal being emitted. The resulting
198 /// popup position can be queried using [`position_x()`][Self::position_x()],
199 /// [`position_y()`][Self::position_y()], and the resulting size will be sent as
200 /// parameters in the layout signal. Use [`rect_anchor()`][Self::rect_anchor()]
201 /// and [`surface_anchor()`][Self::surface_anchor()] to get the resulting anchors.
202 ///
203 /// Presenting may fail, for example if the @self is set to autohide
204 /// and is immediately hidden upon being presented. If presenting failed,
205 /// the [`layout`][struct@crate::Surface#layout] signal will not me emitted.
206 /// ## `width`
207 /// the unconstrained popup width to layout
208 /// ## `height`
209 /// the unconstrained popup height to layout
210 /// ## `layout`
211 /// the [`PopupLayout`][crate::PopupLayout] object used to layout
212 ///
213 /// # Returns
214 ///
215 /// [`false`] if it failed to be presented, otherwise [`true`].
216 #[doc(alias = "gdk_popup_present")]
217 fn present(&self, width: i32, height: i32, layout: &PopupLayout) -> bool {
218 unsafe {
219 from_glib(ffi::gdk_popup_present(
220 self.as_ref().to_glib_none().0,
221 width,
222 height,
223 layout.to_glib_none().0,
224 ))
225 }
226 }
227}
228
229impl<O: IsA<Popup>> PopupExt for O {}