1use crate::{
6 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Native,
7 Overflow, Popover, PositionType, ShortcutManager, Widget,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 #[doc(alias = "GtkEmojiChooser")]
19 pub struct EmojiChooser(Object<ffi::GtkEmojiChooser, ffi::GtkEmojiChooserClass>) @extends Popover, Widget, @implements Accessible, Buildable, ConstraintTarget, Native, ShortcutManager;
20
21 match fn {
22 type_ => || ffi::gtk_emoji_chooser_get_type(),
23 }
24}
25
26impl EmojiChooser {
27 #[doc(alias = "gtk_emoji_chooser_new")]
28 pub fn new() -> EmojiChooser {
29 assert_initialized_main_thread!();
30 unsafe { Widget::from_glib_none(ffi::gtk_emoji_chooser_new()).unsafe_cast() }
31 }
32
33 pub fn builder() -> EmojiChooserBuilder {
38 EmojiChooserBuilder::new()
39 }
40
41 #[doc(alias = "emoji-picked")]
42 pub fn connect_emoji_picked<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
43 unsafe extern "C" fn emoji_picked_trampoline<F: Fn(&EmojiChooser, &str) + 'static>(
44 this: *mut ffi::GtkEmojiChooser,
45 text: *mut std::ffi::c_char,
46 f: glib::ffi::gpointer,
47 ) {
48 let f: &F = &*(f as *const F);
49 f(
50 &from_glib_borrow(this),
51 &glib::GString::from_glib_borrow(text),
52 )
53 }
54 unsafe {
55 let f: Box_<F> = Box_::new(f);
56 connect_raw(
57 self.as_ptr() as *mut _,
58 c"emoji-picked".as_ptr() as *const _,
59 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
60 emoji_picked_trampoline::<F> as *const (),
61 )),
62 Box_::into_raw(f),
63 )
64 }
65 }
66}
67
68impl Default for EmojiChooser {
69 fn default() -> Self {
70 Self::new()
71 }
72}
73
74#[must_use = "The builder must be built to be used"]
79pub struct EmojiChooserBuilder {
80 builder: glib::object::ObjectBuilder<'static, EmojiChooser>,
81}
82
83impl EmojiChooserBuilder {
84 fn new() -> Self {
85 Self {
86 builder: glib::object::Object::builder(),
87 }
88 }
89
90 pub fn autohide(self, autohide: bool) -> Self {
91 Self {
92 builder: self.builder.property("autohide", autohide),
93 }
94 }
95
96 pub fn cascade_popdown(self, cascade_popdown: bool) -> Self {
97 Self {
98 builder: self.builder.property("cascade-popdown", cascade_popdown),
99 }
100 }
101
102 pub fn child(self, child: &impl IsA<Widget>) -> Self {
103 Self {
104 builder: self.builder.property("child", child.clone().upcast()),
105 }
106 }
107
108 pub fn default_widget(self, default_widget: &impl IsA<Widget>) -> Self {
109 Self {
110 builder: self
111 .builder
112 .property("default-widget", default_widget.clone().upcast()),
113 }
114 }
115
116 pub fn has_arrow(self, has_arrow: bool) -> Self {
117 Self {
118 builder: self.builder.property("has-arrow", has_arrow),
119 }
120 }
121
122 pub fn mnemonics_visible(self, mnemonics_visible: bool) -> Self {
123 Self {
124 builder: self
125 .builder
126 .property("mnemonics-visible", mnemonics_visible),
127 }
128 }
129
130 pub fn pointing_to(self, pointing_to: &gdk::Rectangle) -> Self {
131 Self {
132 builder: self.builder.property("pointing-to", pointing_to),
133 }
134 }
135
136 pub fn position(self, position: PositionType) -> Self {
137 Self {
138 builder: self.builder.property("position", position),
139 }
140 }
141
142 pub fn can_focus(self, can_focus: bool) -> Self {
143 Self {
144 builder: self.builder.property("can-focus", can_focus),
145 }
146 }
147
148 pub fn can_target(self, can_target: bool) -> Self {
149 Self {
150 builder: self.builder.property("can-target", can_target),
151 }
152 }
153
154 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
155 Self {
156 builder: self.builder.property("css-classes", css_classes.into()),
157 }
158 }
159
160 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
161 Self {
162 builder: self.builder.property("css-name", css_name.into()),
163 }
164 }
165
166 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
167 Self {
168 builder: self.builder.property("cursor", cursor.clone()),
169 }
170 }
171
172 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
173 Self {
174 builder: self.builder.property("focus-on-click", focus_on_click),
175 }
176 }
177
178 pub fn focusable(self, focusable: bool) -> Self {
179 Self {
180 builder: self.builder.property("focusable", focusable),
181 }
182 }
183
184 pub fn halign(self, halign: Align) -> Self {
185 Self {
186 builder: self.builder.property("halign", halign),
187 }
188 }
189
190 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
191 Self {
192 builder: self.builder.property("has-tooltip", has_tooltip),
193 }
194 }
195
196 pub fn height_request(self, height_request: i32) -> Self {
197 Self {
198 builder: self.builder.property("height-request", height_request),
199 }
200 }
201
202 pub fn hexpand(self, hexpand: bool) -> Self {
203 Self {
204 builder: self.builder.property("hexpand", hexpand),
205 }
206 }
207
208 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
209 Self {
210 builder: self.builder.property("hexpand-set", hexpand_set),
211 }
212 }
213
214 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
215 Self {
216 builder: self
217 .builder
218 .property("layout-manager", layout_manager.clone().upcast()),
219 }
220 }
221
222 #[cfg(feature = "v4_18")]
223 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
224 pub fn limit_events(self, limit_events: bool) -> Self {
225 Self {
226 builder: self.builder.property("limit-events", limit_events),
227 }
228 }
229
230 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
231 Self {
232 builder: self.builder.property("margin-bottom", margin_bottom),
233 }
234 }
235
236 pub fn margin_end(self, margin_end: i32) -> Self {
237 Self {
238 builder: self.builder.property("margin-end", margin_end),
239 }
240 }
241
242 pub fn margin_start(self, margin_start: i32) -> Self {
243 Self {
244 builder: self.builder.property("margin-start", margin_start),
245 }
246 }
247
248 pub fn margin_top(self, margin_top: i32) -> Self {
249 Self {
250 builder: self.builder.property("margin-top", margin_top),
251 }
252 }
253
254 pub fn name(self, name: impl Into<glib::GString>) -> Self {
255 Self {
256 builder: self.builder.property("name", name.into()),
257 }
258 }
259
260 pub fn opacity(self, opacity: f64) -> Self {
261 Self {
262 builder: self.builder.property("opacity", opacity),
263 }
264 }
265
266 pub fn overflow(self, overflow: Overflow) -> Self {
267 Self {
268 builder: self.builder.property("overflow", overflow),
269 }
270 }
271
272 pub fn receives_default(self, receives_default: bool) -> Self {
273 Self {
274 builder: self.builder.property("receives-default", receives_default),
275 }
276 }
277
278 pub fn sensitive(self, sensitive: bool) -> Self {
279 Self {
280 builder: self.builder.property("sensitive", sensitive),
281 }
282 }
283
284 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
285 Self {
286 builder: self
287 .builder
288 .property("tooltip-markup", tooltip_markup.into()),
289 }
290 }
291
292 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
293 Self {
294 builder: self.builder.property("tooltip-text", tooltip_text.into()),
295 }
296 }
297
298 pub fn valign(self, valign: Align) -> Self {
299 Self {
300 builder: self.builder.property("valign", valign),
301 }
302 }
303
304 pub fn vexpand(self, vexpand: bool) -> Self {
305 Self {
306 builder: self.builder.property("vexpand", vexpand),
307 }
308 }
309
310 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
311 Self {
312 builder: self.builder.property("vexpand-set", vexpand_set),
313 }
314 }
315
316 pub fn visible(self, visible: bool) -> Self {
317 Self {
318 builder: self.builder.property("visible", visible),
319 }
320 }
321
322 pub fn width_request(self, width_request: i32) -> Self {
323 Self {
324 builder: self.builder.property("width-request", width_request),
325 }
326 }
327
328 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
329 Self {
330 builder: self.builder.property("accessible-role", accessible_role),
331 }
332 }
333
334 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
337 pub fn build(self) -> EmojiChooser {
338 assert_initialized_main_thread!();
339 self.builder.build()
340 }
341}