gdk4/auto/popup_layout.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, AnchorHints, Gravity, Rectangle};
6use glib::translate::*;
7
8glib::wrapper! {
9 /// The [`PopupLayout`][crate::PopupLayout] struct contains information that is
10 /// necessary position a [`Popup`][crate::Popup] relative to its parent.
11 ///
12 /// The positioning requires a negotiation with the windowing system,
13 /// since it depends on external constraints, such as the position of
14 /// the parent surface, and the screen dimensions.
15 ///
16 /// The basic ingredients are a rectangle on the parent surface,
17 /// and the anchor on both that rectangle and the popup. The anchors
18 /// specify a side or corner to place next to each other.
19 ///
20 /// 
21 ///
22 /// For cases where placing the anchors next to each other would make
23 /// the popup extend offscreen, the layout includes some hints for how
24 /// to resolve this problem. The hints may suggest to flip the anchor
25 /// position to the other side, or to 'slide' the popup along a side,
26 /// or to resize it.
27 ///
28 /// 
29 ///
30 /// 
31 ///
32 /// These hints may be combined.
33 ///
34 /// Ultimatively, it is up to the windowing system to determine the position
35 /// and size of the popup. You can learn about the result by calling
36 /// [`PopupExt::position_x()`][crate::prelude::PopupExt::position_x()], [`PopupExt::position_y()`][crate::prelude::PopupExt::position_y()],
37 /// [`PopupExt::rect_anchor()`][crate::prelude::PopupExt::rect_anchor()] and [`PopupExt::surface_anchor()`][crate::prelude::PopupExt::surface_anchor()]
38 /// after the popup has been presented. This can be used to adjust the rendering.
39 /// For example, [GtkPopover](../gtk4/class.Popover.html) changes its arrow position
40 /// accordingly. But you have to be careful avoid changing the size of the popover,
41 /// or it has to be presented again.
42 #[derive(Debug, PartialOrd, Ord, Hash)]
43 pub struct PopupLayout(Shared<ffi::GdkPopupLayout>);
44
45 match fn {
46 ref => |ptr| ffi::gdk_popup_layout_ref(ptr),
47 unref => |ptr| ffi::gdk_popup_layout_unref(ptr),
48 type_ => || ffi::gdk_popup_layout_get_type(),
49 }
50}
51
52impl PopupLayout {
53 /// Create a popup layout description.
54 ///
55 /// Used together with [`PopupExt::present()`][crate::prelude::PopupExt::present()] to describe how a popup
56 /// surface should be placed and behave on-screen.
57 ///
58 /// @anchor_rect is relative to the top-left corner of the surface's parent.
59 /// @rect_anchor and @surface_anchor determine anchor points on @anchor_rect
60 /// and surface to pin together.
61 ///
62 /// The position of @anchor_rect's anchor point can optionally be offset using
63 /// [`set_offset()`][Self::set_offset()], which is equivalent to offsetting the
64 /// position of surface.
65 /// ## `anchor_rect`
66 /// the anchor [`Rectangle`][crate::Rectangle] to align @surface with
67 /// ## `rect_anchor`
68 /// the point on @anchor_rect to align with @surface's anchor point
69 /// ## `surface_anchor`
70 /// the point on @surface to align with @rect's anchor point
71 ///
72 /// # Returns
73 ///
74 /// newly created instance of [`PopupLayout`][crate::PopupLayout]
75 #[doc(alias = "gdk_popup_layout_new")]
76 pub fn new(
77 anchor_rect: &Rectangle,
78 rect_anchor: Gravity,
79 surface_anchor: Gravity,
80 ) -> PopupLayout {
81 assert_initialized_main_thread!();
82 unsafe {
83 from_glib_full(ffi::gdk_popup_layout_new(
84 anchor_rect.to_glib_none().0,
85 rect_anchor.into_glib(),
86 surface_anchor.into_glib(),
87 ))
88 }
89 }
90
91 #[doc(alias = "gdk_popup_layout_copy")]
92 #[must_use]
93 pub fn copy(&self) -> PopupLayout {
94 unsafe { from_glib_full(ffi::gdk_popup_layout_copy(self.to_glib_none().0)) }
95 }
96
97 #[doc(alias = "gdk_popup_layout_equal")]
98 fn equal(&self, other: &PopupLayout) -> bool {
99 unsafe {
100 from_glib(ffi::gdk_popup_layout_equal(
101 self.to_glib_none().0,
102 other.to_glib_none().0,
103 ))
104 }
105 }
106
107 /// Get the [`AnchorHints`][crate::AnchorHints].
108 ///
109 /// # Returns
110 ///
111 /// the [`AnchorHints`][crate::AnchorHints]
112 #[doc(alias = "gdk_popup_layout_get_anchor_hints")]
113 #[doc(alias = "get_anchor_hints")]
114 pub fn anchor_hints(&self) -> AnchorHints {
115 unsafe {
116 from_glib(ffi::gdk_popup_layout_get_anchor_hints(
117 self.to_glib_none().0,
118 ))
119 }
120 }
121
122 /// Get the anchor rectangle.
123 ///
124 /// # Returns
125 ///
126 /// The anchor rectangle
127 #[doc(alias = "gdk_popup_layout_get_anchor_rect")]
128 #[doc(alias = "get_anchor_rect")]
129 pub fn anchor_rect(&self) -> Rectangle {
130 unsafe { from_glib_none(ffi::gdk_popup_layout_get_anchor_rect(self.to_glib_none().0)) }
131 }
132
133 /// Returns the anchor position on the anchor rectangle.
134 ///
135 /// # Returns
136 ///
137 /// the anchor on the anchor rectangle.
138 #[doc(alias = "gdk_popup_layout_get_rect_anchor")]
139 #[doc(alias = "get_rect_anchor")]
140 pub fn rect_anchor(&self) -> Gravity {
141 unsafe { from_glib(ffi::gdk_popup_layout_get_rect_anchor(self.to_glib_none().0)) }
142 }
143
144 /// Obtains the shadow widths of this layout.
145 ///
146 /// # Returns
147 ///
148 ///
149 /// ## `left`
150 /// return location for the left shadow width
151 ///
152 /// ## `right`
153 /// return location for the right shadow width
154 ///
155 /// ## `top`
156 /// return location for the top shadow width
157 ///
158 /// ## `bottom`
159 /// return location for the bottom shadow width
160 #[cfg(feature = "v4_2")]
161 #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
162 #[doc(alias = "gdk_popup_layout_get_shadow_width")]
163 #[doc(alias = "get_shadow_width")]
164 pub fn shadow_width(&self) -> (i32, i32, i32, i32) {
165 unsafe {
166 let mut left = std::mem::MaybeUninit::uninit();
167 let mut right = std::mem::MaybeUninit::uninit();
168 let mut top = std::mem::MaybeUninit::uninit();
169 let mut bottom = std::mem::MaybeUninit::uninit();
170 ffi::gdk_popup_layout_get_shadow_width(
171 self.to_glib_none().0,
172 left.as_mut_ptr(),
173 right.as_mut_ptr(),
174 top.as_mut_ptr(),
175 bottom.as_mut_ptr(),
176 );
177 (
178 left.assume_init(),
179 right.assume_init(),
180 top.assume_init(),
181 bottom.assume_init(),
182 )
183 }
184 }
185
186 /// Returns the anchor position on the popup surface.
187 ///
188 /// # Returns
189 ///
190 /// the anchor on the popup surface.
191 #[doc(alias = "gdk_popup_layout_get_surface_anchor")]
192 #[doc(alias = "get_surface_anchor")]
193 pub fn surface_anchor(&self) -> Gravity {
194 unsafe {
195 from_glib(ffi::gdk_popup_layout_get_surface_anchor(
196 self.to_glib_none().0,
197 ))
198 }
199 }
200
201 /// Set new anchor hints.
202 ///
203 /// The set @anchor_hints determines how @surface will be moved
204 /// if the anchor points cause it to move off-screen. For example,
205 /// [`AnchorHints::FLIP_X`][crate::AnchorHints::FLIP_X] will replace [`Gravity::NorthWest`][crate::Gravity::NorthWest] with
206 /// [`Gravity::NorthEast`][crate::Gravity::NorthEast] and vice versa if @surface extends
207 /// beyond the left or right edges of the monitor.
208 /// ## `anchor_hints`
209 /// the new [`AnchorHints`][crate::AnchorHints]
210 #[doc(alias = "gdk_popup_layout_set_anchor_hints")]
211 pub fn set_anchor_hints(&self, anchor_hints: AnchorHints) {
212 unsafe {
213 ffi::gdk_popup_layout_set_anchor_hints(self.to_glib_none().0, anchor_hints.into_glib());
214 }
215 }
216
217 /// Set the anchor rectangle.
218 /// ## `anchor_rect`
219 /// the new anchor rectangle
220 #[doc(alias = "gdk_popup_layout_set_anchor_rect")]
221 pub fn set_anchor_rect(&self, anchor_rect: &Rectangle) {
222 unsafe {
223 ffi::gdk_popup_layout_set_anchor_rect(
224 self.to_glib_none().0,
225 anchor_rect.to_glib_none().0,
226 );
227 }
228 }
229
230 /// Offset the position of the anchor rectangle with the given delta.
231 /// ## `dx`
232 /// x delta to offset the anchor rectangle with
233 /// ## `dy`
234 /// y delta to offset the anchor rectangle with
235 #[doc(alias = "gdk_popup_layout_set_offset")]
236 pub fn set_offset(&self, dx: i32, dy: i32) {
237 unsafe {
238 ffi::gdk_popup_layout_set_offset(self.to_glib_none().0, dx, dy);
239 }
240 }
241
242 /// Set the anchor on the anchor rectangle.
243 /// ## `anchor`
244 /// the new rect anchor
245 #[doc(alias = "gdk_popup_layout_set_rect_anchor")]
246 pub fn set_rect_anchor(&self, anchor: Gravity) {
247 unsafe {
248 ffi::gdk_popup_layout_set_rect_anchor(self.to_glib_none().0, anchor.into_glib());
249 }
250 }
251
252 /// Sets the shadow width of the popup.
253 ///
254 /// The shadow width corresponds to the part of the computed
255 /// surface size that would consist of the shadow margin
256 /// surrounding the window, would there be any.
257 /// ## `left`
258 /// width of the left part of the shadow
259 /// ## `right`
260 /// width of the right part of the shadow
261 /// ## `top`
262 /// height of the top part of the shadow
263 /// ## `bottom`
264 /// height of the bottom part of the shadow
265 #[cfg(feature = "v4_2")]
266 #[cfg_attr(docsrs, doc(cfg(feature = "v4_2")))]
267 #[doc(alias = "gdk_popup_layout_set_shadow_width")]
268 pub fn set_shadow_width(&self, left: i32, right: i32, top: i32, bottom: i32) {
269 unsafe {
270 ffi::gdk_popup_layout_set_shadow_width(self.to_glib_none().0, left, right, top, bottom);
271 }
272 }
273
274 /// Set the anchor on the popup surface.
275 /// ## `anchor`
276 /// the new popup surface anchor
277 #[doc(alias = "gdk_popup_layout_set_surface_anchor")]
278 pub fn set_surface_anchor(&self, anchor: Gravity) {
279 unsafe {
280 ffi::gdk_popup_layout_set_surface_anchor(self.to_glib_none().0, anchor.into_glib());
281 }
282 }
283}
284
285impl PartialEq for PopupLayout {
286 #[inline]
287 fn eq(&self, other: &Self) -> bool {
288 self.equal(other)
289 }
290}
291
292impl Eq for PopupLayout {}