gdk4/auto/
popup.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{ffi, Gravity, PopupLayout, Surface};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// A [`Popup`][crate::Popup] is a surface that is attached to another surface.
    ///
    /// The [`Popup`][crate::Popup] is positioned relative to its parent surface.
    ///
    /// [`Popup`][crate::Popup]s are typically used to implement menus and similar popups.
    /// They can be modal, which is indicated by the [`autohide`][struct@crate::Popup#autohide]
    /// property.
    ///
    /// ## Properties
    ///
    ///
    /// #### `autohide`
    ///  Whether to hide on outside clicks.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `parent`
    ///  The parent surface.
    ///
    /// Readable | Writeable | Construct Only
    /// <details><summary><h4>Surface</h4></summary>
    ///
    ///
    /// #### `cursor`
    ///  The mouse pointer for the [`Surface`][crate::Surface].
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `display`
    ///  The [`Display`][crate::Display] connection of the surface.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `frame-clock`
    ///  The [`FrameClock`][crate::FrameClock] of the surface.
    ///
    /// Readable | Writeable | Construct Only
    ///
    ///
    /// #### `height`
    ///  The height of the surface, in pixels.
    ///
    /// Readable
    ///
    ///
    /// #### `mapped`
    ///  Whether the surface is mapped.
    ///
    /// Readable
    ///
    ///
    /// #### `scale`
    ///  The scale of the surface.
    ///
    /// Readable
    ///
    ///
    /// #### `scale-factor`
    ///  The scale factor of the surface.
    ///
    /// The scale factor is the next larger integer,
    /// compared to [`scale`][struct@crate::Surface#scale].
    ///
    /// Readable
    ///
    ///
    /// #### `width`
    ///  The width of the surface in pixels.
    ///
    /// Readable
    /// </details>
    ///
    /// # Implements
    ///
    /// [`PopupExt`][trait@crate::prelude::PopupExt], [`SurfaceExt`][trait@crate::prelude::SurfaceExt], [`SurfaceExtManual`][trait@crate::prelude::SurfaceExtManual]
    #[doc(alias = "GdkPopup")]
    pub struct Popup(Interface<ffi::GdkPopup, ffi::GdkPopupInterface>) @requires Surface;

    match fn {
        type_ => || ffi::gdk_popup_get_type(),
    }
}

impl Popup {
    pub const NONE: Option<&'static Popup> = None;
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Popup>> Sealed for T {}
}

/// Trait containing all [`struct@Popup`] methods.
///
/// # Implementors
///
/// [`Popup`][struct@crate::Popup]
pub trait PopupExt: IsA<Popup> + sealed::Sealed + 'static {
    /// Returns whether this popup is set to hide on outside clicks.
    ///
    /// # Returns
    ///
    /// [`true`] if @self will autohide
    #[doc(alias = "gdk_popup_get_autohide")]
    #[doc(alias = "get_autohide")]
    #[doc(alias = "autohide")]
    fn is_autohide(&self) -> bool {
        unsafe { from_glib(ffi::gdk_popup_get_autohide(self.as_ref().to_glib_none().0)) }
    }

    /// Returns the parent surface of a popup.
    ///
    /// # Returns
    ///
    /// the parent surface
    #[doc(alias = "gdk_popup_get_parent")]
    #[doc(alias = "get_parent")]
    fn parent(&self) -> Option<Surface> {
        unsafe { from_glib_none(ffi::gdk_popup_get_parent(self.as_ref().to_glib_none().0)) }
    }

    /// Obtains the position of the popup relative to its parent.
    ///
    /// # Returns
    ///
    /// the X coordinate of @self position
    #[doc(alias = "gdk_popup_get_position_x")]
    #[doc(alias = "get_position_x")]
    fn position_x(&self) -> i32 {
        unsafe { ffi::gdk_popup_get_position_x(self.as_ref().to_glib_none().0) }
    }

    /// Obtains the position of the popup relative to its parent.
    ///
    /// # Returns
    ///
    /// the Y coordinate of @self position
    #[doc(alias = "gdk_popup_get_position_y")]
    #[doc(alias = "get_position_y")]
    fn position_y(&self) -> i32 {
        unsafe { ffi::gdk_popup_get_position_y(self.as_ref().to_glib_none().0) }
    }

    /// Gets the current popup rectangle anchor.
    ///
    /// The value returned may change after calling [`present()`][Self::present()],
    /// or after the [`layout`][struct@crate::Surface#layout] signal is emitted.
    ///
    /// # Returns
    ///
    /// the current rectangle anchor value of @self
    #[doc(alias = "gdk_popup_get_rect_anchor")]
    #[doc(alias = "get_rect_anchor")]
    fn rect_anchor(&self) -> Gravity {
        unsafe {
            from_glib(ffi::gdk_popup_get_rect_anchor(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Gets the current popup surface anchor.
    ///
    /// The value returned may change after calling [`present()`][Self::present()],
    /// or after the [`layout`][struct@crate::Surface#layout] signal is emitted.
    ///
    /// # Returns
    ///
    /// the current surface anchor value of @self
    #[doc(alias = "gdk_popup_get_surface_anchor")]
    #[doc(alias = "get_surface_anchor")]
    fn surface_anchor(&self) -> Gravity {
        unsafe {
            from_glib(ffi::gdk_popup_get_surface_anchor(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Present @self after having processed the [`PopupLayout`][crate::PopupLayout] rules.
    ///
    /// If the popup was previously not showing, it will be shown,
    /// otherwise it will change position according to @layout.
    ///
    /// After calling this function, the result should be handled in response
    /// to the [`layout`][struct@crate::Surface#layout] signal being emitted. The resulting
    /// popup position can be queried using [`position_x()`][Self::position_x()],
    /// [`position_y()`][Self::position_y()], and the resulting size will be sent as
    /// parameters in the layout signal. Use [`rect_anchor()`][Self::rect_anchor()]
    /// and [`surface_anchor()`][Self::surface_anchor()] to get the resulting anchors.
    ///
    /// Presenting may fail, for example if the @self is set to autohide
    /// and is immediately hidden upon being presented. If presenting failed,
    /// the [`layout`][struct@crate::Surface#layout] signal will not me emitted.
    /// ## `width`
    /// the unconstrained popup width to layout
    /// ## `height`
    /// the unconstrained popup height to layout
    /// ## `layout`
    /// the [`PopupLayout`][crate::PopupLayout] object used to layout
    ///
    /// # Returns
    ///
    /// [`false`] if it failed to be presented, otherwise [`true`].
    #[doc(alias = "gdk_popup_present")]
    fn present(&self, width: i32, height: i32, layout: &PopupLayout) -> bool {
        unsafe {
            from_glib(ffi::gdk_popup_present(
                self.as_ref().to_glib_none().0,
                width,
                height,
                layout.to_glib_none().0,
            ))
        }
    }
}

impl<O: IsA<Popup>> PopupExt for O {}