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
use bitflags;
use Error;
use crate::;
/// Describes where a native popup goes, relative to a rectangle on its parent window.
///
/// Use a popup for menus, comboboxes, context menus and tooltips that should be able to leave
/// the parent window's bounds. Use an in-window element for everything else. Pass the popup to
/// [`WindowKind::AnchoredPopup`](crate::WindowKind::AnchoredPopup) in [`WindowOptions::kind`](crate::WindowOptions::kind).
///
/// The popup is placed relative to `anchor_rect` rather than at an absolute screen position.
/// The platform resolves the final position. That works on Wayland, where the compositor places
/// windows, and on platforms with absolute coordinates.
///
/// The popup's size comes from `window_bounds` in [`WindowOptions`](crate::WindowOptions).
/// Wayland uses only the size, not the origin. All coordinates are in logical pixels.
///
/// Native popups are available on Wayland only. On macOS, Windows, X11 and the web, opening one
/// returns a [`PopupNotSupportedError`] and you can draw the same content in the window instead.
///
/// Pass the parent window and anchor rectangle to [`PopupOptions::new`], then chain setters to
/// configure placement and input grabbing.
///
/// # Examples
///
/// ```
/// # use gpui::{Context, Render, TestApp, Window, div, prelude::*, px, point, size, Bounds};
/// use gpui::popup::{PopupAnchor, PopupGravity, PopupOptions};
/// # struct Root;
/// # impl Render for Root {
/// # fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement { div() }
/// # }
/// # let mut app = TestApp::new();
/// # let _window = app.open_window(|_, _| Root);
/// # let parent = app.windows()[0];
/// // A dropdown below a button whose bounds are `anchor_rect`.
/// let anchor_rect = Bounds::new(point(px(10.), px(20.)), size(px(80.), px(24.)));
/// let options = PopupOptions::new(parent, anchor_rect)
/// .anchor(PopupAnchor::BottomLeft)
/// .gravity(PopupGravity::BottomRight)
/// .grab(true);
///
/// assert_eq!(options.anchor, PopupAnchor::BottomLeft);
/// assert_eq!(options.gravity, PopupGravity::BottomRight);
/// assert!(options.grab);
/// ```
/// The point of the anchor rectangle that a popup is anchored to.
/// The direction in which a popup extends away from its anchor point.
///
/// For instance, a gravity of [`PopupGravity::BottomRight`] places the popup below and to the
/// right of the anchor point.
bitflags!
/// Returned when a platform can't open a native popup window.
///
/// Opening a [`WindowKind::AnchoredPopup`](crate::WindowKind::AnchoredPopup) window fails with
/// this error on macOS, Windows, X11 and the web. Wayland supports native popups.
///
/// Native popups are separate from gpui's in-window popovers, which are drawn as elements inside
/// an existing window. To show a popup on every platform, catch this error and draw the same
/// content in the parent window instead.
;