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 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
99/// Trait containing all [`struct@Popup`] methods.
100///
101/// # Implementors
102///
103/// [`Popup`][struct@crate::Popup]
104pub trait PopupExt: IsA<Popup> + 'static {
105 /// Returns whether this popup is set to hide on outside clicks.
106 ///
107 /// # Returns
108 ///
109 /// [`true`] if @self will autohide
110 #[doc(alias = "gdk_popup_get_autohide")]
111 #[doc(alias = "get_autohide")]
112 #[doc(alias = "autohide")]
113 fn is_autohide(&self) -> bool {
114 unsafe { from_glib(ffi::gdk_popup_get_autohide(self.as_ref().to_glib_none().0)) }
115 }
116
117 /// Returns the parent surface of a popup.
118 ///
119 /// # Returns
120 ///
121 /// the parent surface
122 #[doc(alias = "gdk_popup_get_parent")]
123 #[doc(alias = "get_parent")]
124 fn parent(&self) -> Option<Surface> {
125 unsafe { from_glib_none(ffi::gdk_popup_get_parent(self.as_ref().to_glib_none().0)) }
126 }
127
128 /// Obtains the position of the popup relative to its parent.
129 ///
130 /// # Returns
131 ///
132 /// the X coordinate of @self position
133 #[doc(alias = "gdk_popup_get_position_x")]
134 #[doc(alias = "get_position_x")]
135 fn position_x(&self) -> i32 {
136 unsafe { ffi::gdk_popup_get_position_x(self.as_ref().to_glib_none().0) }
137 }
138
139 /// Obtains the position of the popup relative to its parent.
140 ///
141 /// # Returns
142 ///
143 /// the Y coordinate of @self position
144 #[doc(alias = "gdk_popup_get_position_y")]
145 #[doc(alias = "get_position_y")]
146 fn position_y(&self) -> i32 {
147 unsafe { ffi::gdk_popup_get_position_y(self.as_ref().to_glib_none().0) }
148 }
149
150 /// Gets the current popup rectangle anchor.
151 ///
152 /// The value returned may change after calling [`present()`][Self::present()],
153 /// or after the [`layout`][struct@crate::Surface#layout] signal is emitted.
154 ///
155 /// # Returns
156 ///
157 /// the current rectangle anchor value of @self
158 #[doc(alias = "gdk_popup_get_rect_anchor")]
159 #[doc(alias = "get_rect_anchor")]
160 fn rect_anchor(&self) -> Gravity {
161 unsafe {
162 from_glib(ffi::gdk_popup_get_rect_anchor(
163 self.as_ref().to_glib_none().0,
164 ))
165 }
166 }
167
168 /// Gets the current popup surface anchor.
169 ///
170 /// The value returned may change after calling [`present()`][Self::present()],
171 /// or after the [`layout`][struct@crate::Surface#layout] signal is emitted.
172 ///
173 /// # Returns
174 ///
175 /// the current surface anchor value of @self
176 #[doc(alias = "gdk_popup_get_surface_anchor")]
177 #[doc(alias = "get_surface_anchor")]
178 fn surface_anchor(&self) -> Gravity {
179 unsafe {
180 from_glib(ffi::gdk_popup_get_surface_anchor(
181 self.as_ref().to_glib_none().0,
182 ))
183 }
184 }
185
186 /// Present @self after having processed the [`PopupLayout`][crate::PopupLayout] rules.
187 ///
188 /// If the popup was previously not showing, it will be shown,
189 /// otherwise it will change position according to @layout.
190 ///
191 /// After calling this function, the result should be handled in response
192 /// to the [`layout`][struct@crate::Surface#layout] signal being emitted. The resulting
193 /// popup position can be queried using [`position_x()`][Self::position_x()],
194 /// [`position_y()`][Self::position_y()], and the resulting size will be sent as
195 /// parameters in the layout signal. Use [`rect_anchor()`][Self::rect_anchor()]
196 /// and [`surface_anchor()`][Self::surface_anchor()] to get the resulting anchors.
197 ///
198 /// Presenting may fail, for example if the @self is set to autohide
199 /// and is immediately hidden upon being presented. If presenting failed,
200 /// the [`layout`][struct@crate::Surface#layout] signal will not me emitted.
201 /// ## `width`
202 /// the unconstrained popup width to layout
203 /// ## `height`
204 /// the unconstrained popup height to layout
205 /// ## `layout`
206 /// the [`PopupLayout`][crate::PopupLayout] object used to layout
207 ///
208 /// # Returns
209 ///
210 /// [`false`] if it failed to be presented, otherwise [`true`].
211 #[doc(alias = "gdk_popup_present")]
212 fn present(&self, width: i32, height: i32, layout: &PopupLayout) -> bool {
213 unsafe {
214 from_glib(ffi::gdk_popup_present(
215 self.as_ref().to_glib_none().0,
216 width,
217 height,
218 layout.to_glib_none().0,
219 ))
220 }
221 }
222}
223
224impl<O: IsA<Popup>> PopupExt for O {}