gtk4/auto/emoji_chooser.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::{
6 Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, LayoutManager, Native,
7 Overflow, Popover, PositionType, ShortcutManager, Widget, ffi,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{SignalHandlerId, connect_raw},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 /// Used by text widgets to let users insert Emoji characters.
19 ///
20 /// <picture>
21 /// <source srcset="emojichooser-dark.png" media="(prefers-color-scheme: dark)">
22 /// <img alt="An example GtkEmojiChooser" src="emojichooser.png">
23 /// </picture>
24 ///
25 /// [`EmojiChooser`][crate::EmojiChooser] emits the [`emoji-picked`][struct@crate::EmojiChooser#emoji-picked]
26 /// signal when an Emoji is selected.
27 ///
28 /// # Shortcuts and Gestures
29 ///
30 /// [`EmojiChooser`][crate::EmojiChooser] supports the following keyboard shortcuts:
31 ///
32 /// - <kbd>Ctrl</kbd>+<kbd>N</kbd> scrolls to the next section.
33 /// - <kbd>Ctrl</kbd>+<kbd>P</kbd> scrolls to the previous section.
34 /// - <kbd>Enter</kbd> to select the first emoji result.
35 ///
36 /// # Actions
37 ///
38 /// [`EmojiChooser`][crate::EmojiChooser] defines a set of built-in actions:
39 ///
40 /// - `scroll.section` scrolls to the next or previous section.
41 ///
42 /// # CSS nodes
43 ///
44 /// ```text
45 /// popover
46 /// ├── box.emoji-searchbar
47 /// │ ╰── entry.search
48 /// ╰── box.emoji-toolbar
49 /// ├── button.image-button.emoji-section
50 /// ├── ...
51 /// ╰── button.image-button.emoji-section
52 /// ```
53 ///
54 /// Every [`EmojiChooser`][crate::EmojiChooser] consists of a main node called popover.
55 /// The contents of the popover are largely implementation defined
56 /// and supposed to inherit general styles.
57 /// The top searchbar used to search emoji and gets the .emoji-searchbar
58 /// style class itself.
59 /// The bottom toolbar used to switch between different emoji categories
60 /// consists of buttons with the .emoji-section style class and gets the
61 /// .emoji-toolbar style class itself.
62 ///
63 /// ## Signals
64 ///
65 ///
66 /// #### `emoji-picked`
67 /// Emitted when the user selects an Emoji.
68 ///
69 ///
70 /// <details><summary><h4>Popover</h4></summary>
71 ///
72 ///
73 /// #### `activate-default`
74 /// Emitted whend the user activates the default widget.
75 ///
76 /// This is a [keybinding signal](class.SignalAction.html).
77 ///
78 /// The default binding for this signal is <kbd>Enter</kbd>.
79 ///
80 /// Action
81 ///
82 ///
83 /// #### `closed`
84 /// Emitted when the popover is closed.
85 ///
86 ///
87 /// </details>
88 /// <details><summary><h4>Widget</h4></summary>
89 ///
90 ///
91 /// #### `destroy`
92 /// Signals that all holders of a reference to the widget should release
93 /// the reference that they hold.
94 ///
95 /// May result in finalization of the widget if all references are released.
96 ///
97 /// This signal is not suitable for saving widget state.
98 ///
99 ///
100 ///
101 ///
102 /// #### `direction-changed`
103 /// Emitted when the text direction of a widget changes.
104 ///
105 ///
106 ///
107 ///
108 /// #### `hide`
109 /// Emitted when @widget is hidden.
110 ///
111 ///
112 ///
113 ///
114 /// #### `keynav-failed`
115 /// Emitted if keyboard navigation fails.
116 ///
117 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
118 ///
119 ///
120 ///
121 ///
122 /// #### `map`
123 /// Emitted when @widget is going to be mapped.
124 ///
125 /// A widget is mapped when the widget is visible (which is controlled with
126 /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
127 /// are also visible.
128 ///
129 /// The `::map` signal can be used to determine whether a widget will be drawn,
130 /// for instance it can resume an animation that was stopped during the
131 /// emission of [`unmap`][struct@crate::Widget#unmap].
132 ///
133 ///
134 ///
135 ///
136 /// #### `mnemonic-activate`
137 /// Emitted when a widget is activated via a mnemonic.
138 ///
139 /// The default handler for this signal activates @widget if @group_cycling
140 /// is false, or just makes @widget grab focus if @group_cycling is true.
141 ///
142 ///
143 ///
144 ///
145 /// #### `move-focus`
146 /// Emitted when the focus is moved.
147 ///
148 /// The `::move-focus` signal is a [keybinding signal](class.SignalAction.html).
149 ///
150 /// The default bindings for this signal are <kbd>Tab</kbd> to move forward,
151 /// and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
152 ///
153 /// Action
154 ///
155 ///
156 /// #### `query-tooltip`
157 /// Emitted when the widget’s tooltip is about to be shown.
158 ///
159 /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
160 /// is true and the hover timeout has expired with the cursor hovering
161 /// above @widget; or emitted when @widget got focus in keyboard mode.
162 ///
163 /// Using the given coordinates, the signal handler should determine
164 /// whether a tooltip should be shown for @widget. If this is the case
165 /// true should be returned, false otherwise. Note that if @keyboard_mode
166 /// is true, the values of @x and @y are undefined and should not be used.
167 ///
168 /// The signal handler is free to manipulate @tooltip with the therefore
169 /// destined function calls.
170 ///
171 ///
172 ///
173 ///
174 /// #### `realize`
175 /// Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
176 ///
177 /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
178 /// or the widget has been mapped (that is, it is going to be drawn).
179 ///
180 ///
181 ///
182 ///
183 /// #### `show`
184 /// Emitted when @widget is shown.
185 ///
186 ///
187 ///
188 ///
189 /// #### `state-flags-changed`
190 /// Emitted when the widget state changes.
191 ///
192 /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
193 ///
194 ///
195 ///
196 ///
197 /// #### `unmap`
198 /// Emitted when @widget is going to be unmapped.
199 ///
200 /// A widget is unmapped when either it or any of its parents up to the
201 /// toplevel widget have been set as hidden.
202 ///
203 /// As `::unmap` indicates that a widget will not be shown any longer,
204 /// it can be used to, for example, stop an animation on the widget.
205 ///
206 ///
207 ///
208 ///
209 /// #### `unrealize`
210 /// Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
211 ///
212 /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
213 /// or the widget has been unmapped (that is, it is going to be hidden).
214 ///
215 ///
216 /// </details>
217 ///
218 /// # Implements
219 ///
220 /// [`PopoverExt`][trait@crate::prelude::PopoverExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`NativeExt`][trait@crate::prelude::NativeExt], [`ShortcutManagerExt`][trait@crate::prelude::ShortcutManagerExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
221 #[doc(alias = "GtkEmojiChooser")]
222 pub struct EmojiChooser(Object<ffi::GtkEmojiChooser, ffi::GtkEmojiChooserClass>) @extends Popover, Widget, @implements Accessible, Buildable, ConstraintTarget, Native, ShortcutManager;
223
224 match fn {
225 type_ => || ffi::gtk_emoji_chooser_get_type(),
226 }
227}
228
229impl EmojiChooser {
230 /// Creates a new [`EmojiChooser`][crate::EmojiChooser].
231 ///
232 /// # Returns
233 ///
234 /// a new [`EmojiChooser`][crate::EmojiChooser]
235 #[doc(alias = "gtk_emoji_chooser_new")]
236 pub fn new() -> EmojiChooser {
237 assert_initialized_main_thread!();
238 unsafe { Widget::from_glib_none(ffi::gtk_emoji_chooser_new()).unsafe_cast() }
239 }
240
241 // rustdoc-stripper-ignore-next
242 /// Creates a new builder-pattern struct instance to construct [`EmojiChooser`] objects.
243 ///
244 /// This method returns an instance of [`EmojiChooserBuilder`](crate::builders::EmojiChooserBuilder) which can be used to create [`EmojiChooser`] objects.
245 pub fn builder() -> EmojiChooserBuilder {
246 EmojiChooserBuilder::new()
247 }
248
249 /// Emitted when the user selects an Emoji.
250 /// ## `text`
251 /// the Unicode sequence for the picked Emoji, in UTF-8
252 #[doc(alias = "emoji-picked")]
253 pub fn connect_emoji_picked<F: Fn(&Self, &str) + 'static>(&self, f: F) -> SignalHandlerId {
254 unsafe extern "C" fn emoji_picked_trampoline<F: Fn(&EmojiChooser, &str) + 'static>(
255 this: *mut ffi::GtkEmojiChooser,
256 text: *mut std::ffi::c_char,
257 f: glib::ffi::gpointer,
258 ) {
259 unsafe {
260 let f: &F = &*(f as *const F);
261 f(
262 &from_glib_borrow(this),
263 &glib::GString::from_glib_borrow(text),
264 )
265 }
266 }
267 unsafe {
268 let f: Box_<F> = Box_::new(f);
269 connect_raw(
270 self.as_ptr() as *mut _,
271 c"emoji-picked".as_ptr(),
272 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
273 emoji_picked_trampoline::<F> as *const (),
274 )),
275 Box_::into_raw(f),
276 )
277 }
278 }
279}
280
281impl Default for EmojiChooser {
282 fn default() -> Self {
283 Self::new()
284 }
285}
286
287// rustdoc-stripper-ignore-next
288/// A [builder-pattern] type to construct [`EmojiChooser`] objects.
289///
290/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
291#[must_use = "The builder must be built to be used"]
292pub struct EmojiChooserBuilder {
293 builder: glib::object::ObjectBuilder<'static, EmojiChooser>,
294}
295
296impl EmojiChooserBuilder {
297 fn new() -> Self {
298 Self {
299 builder: glib::object::Object::builder(),
300 }
301 }
302
303 /// Whether to dismiss the popover on outside clicks.
304 pub fn autohide(self, autohide: bool) -> Self {
305 Self {
306 builder: self.builder.property("autohide", autohide),
307 }
308 }
309
310 /// Whether the popover pops down after a child popover.
311 ///
312 /// This is used to implement the expected behavior of submenus.
313 pub fn cascade_popdown(self, cascade_popdown: bool) -> Self {
314 Self {
315 builder: self.builder.property("cascade-popdown", cascade_popdown),
316 }
317 }
318
319 /// The child widget.
320 pub fn child(self, child: &impl IsA<Widget>) -> Self {
321 Self {
322 builder: self.builder.property("child", child.clone().upcast()),
323 }
324 }
325
326 /// The default widget inside the popover.
327 pub fn default_widget(self, default_widget: &impl IsA<Widget>) -> Self {
328 Self {
329 builder: self
330 .builder
331 .property("default-widget", default_widget.clone().upcast()),
332 }
333 }
334
335 /// Whether to draw an arrow.
336 pub fn has_arrow(self, has_arrow: bool) -> Self {
337 Self {
338 builder: self.builder.property("has-arrow", has_arrow),
339 }
340 }
341
342 /// Whether mnemonics are currently visible in this popover.
343 pub fn mnemonics_visible(self, mnemonics_visible: bool) -> Self {
344 Self {
345 builder: self
346 .builder
347 .property("mnemonics-visible", mnemonics_visible),
348 }
349 }
350
351 /// Rectangle in the parent widget that the popover points to.
352 pub fn pointing_to(self, pointing_to: &gdk::Rectangle) -> Self {
353 Self {
354 builder: self.builder.property("pointing-to", pointing_to),
355 }
356 }
357
358 /// How to place the popover, relative to its parent.
359 pub fn position(self, position: PositionType) -> Self {
360 Self {
361 builder: self.builder.property("position", position),
362 }
363 }
364
365 /// Whether the widget or any of its descendents can accept
366 /// the input focus.
367 ///
368 /// This property is meant to be set by widget implementations,
369 /// typically in their instance init function.
370 pub fn can_focus(self, can_focus: bool) -> Self {
371 Self {
372 builder: self.builder.property("can-focus", can_focus),
373 }
374 }
375
376 /// Whether the widget can receive pointer events.
377 pub fn can_target(self, can_target: bool) -> Self {
378 Self {
379 builder: self.builder.property("can-target", can_target),
380 }
381 }
382
383 /// A list of css classes applied to this widget.
384 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
385 Self {
386 builder: self.builder.property("css-classes", css_classes.into()),
387 }
388 }
389
390 /// The name of this widget in the CSS tree.
391 ///
392 /// This property is meant to be set by widget implementations,
393 /// typically in their instance init function.
394 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
395 Self {
396 builder: self.builder.property("css-name", css_name.into()),
397 }
398 }
399
400 /// The cursor used by @widget.
401 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
402 Self {
403 builder: self.builder.property("cursor", cursor.clone()),
404 }
405 }
406
407 /// Whether the widget should grab focus when it is clicked with the mouse.
408 ///
409 /// This property is only relevant for widgets that can take focus.
410 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
411 Self {
412 builder: self.builder.property("focus-on-click", focus_on_click),
413 }
414 }
415
416 /// Whether this widget itself will accept the input focus.
417 pub fn focusable(self, focusable: bool) -> Self {
418 Self {
419 builder: self.builder.property("focusable", focusable),
420 }
421 }
422
423 /// How to distribute horizontal space if widget gets extra space.
424 pub fn halign(self, halign: Align) -> Self {
425 Self {
426 builder: self.builder.property("halign", halign),
427 }
428 }
429
430 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
431 /// signal on @widget.
432 ///
433 /// A true value indicates that @widget can have a tooltip, in this case
434 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
435 /// determine whether it will provide a tooltip or not.
436 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
437 Self {
438 builder: self.builder.property("has-tooltip", has_tooltip),
439 }
440 }
441
442 /// Overrides for height request of the widget.
443 ///
444 /// If this is -1, the natural request will be used.
445 pub fn height_request(self, height_request: i32) -> Self {
446 Self {
447 builder: self.builder.property("height-request", height_request),
448 }
449 }
450
451 /// Whether to expand horizontally.
452 pub fn hexpand(self, hexpand: bool) -> Self {
453 Self {
454 builder: self.builder.property("hexpand", hexpand),
455 }
456 }
457
458 /// Whether to use the `hexpand` property.
459 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
460 Self {
461 builder: self.builder.property("hexpand-set", hexpand_set),
462 }
463 }
464
465 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
466 /// the preferred size of the widget, and allocate its children.
467 ///
468 /// This property is meant to be set by widget implementations,
469 /// typically in their instance init function.
470 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
471 Self {
472 builder: self
473 .builder
474 .property("layout-manager", layout_manager.clone().upcast()),
475 }
476 }
477
478 /// Makes this widget act like a modal dialog, with respect to
479 /// event delivery.
480 ///
481 /// Global event controllers will not handle events with targets
482 /// inside the widget, unless they are set up to ignore propagation
483 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
484 #[cfg(feature = "v4_18")]
485 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
486 pub fn limit_events(self, limit_events: bool) -> Self {
487 Self {
488 builder: self.builder.property("limit-events", limit_events),
489 }
490 }
491
492 /// Margin on bottom side of widget.
493 ///
494 /// This property adds margin outside of the widget's normal size
495 /// request, the margin will be added in addition to the size from
496 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
497 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
498 Self {
499 builder: self.builder.property("margin-bottom", margin_bottom),
500 }
501 }
502
503 /// Margin on end of widget, horizontally.
504 ///
505 /// This property supports left-to-right and right-to-left text
506 /// directions.
507 ///
508 /// This property adds margin outside of the widget's normal size
509 /// request, the margin will be added in addition to the size from
510 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
511 pub fn margin_end(self, margin_end: i32) -> Self {
512 Self {
513 builder: self.builder.property("margin-end", margin_end),
514 }
515 }
516
517 /// Margin on start of widget, horizontally.
518 ///
519 /// This property supports left-to-right and right-to-left text
520 /// directions.
521 ///
522 /// This property adds margin outside of the widget's normal size
523 /// request, the margin will be added in addition to the size from
524 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
525 pub fn margin_start(self, margin_start: i32) -> Self {
526 Self {
527 builder: self.builder.property("margin-start", margin_start),
528 }
529 }
530
531 /// Margin on top side of widget.
532 ///
533 /// This property adds margin outside of the widget's normal size
534 /// request, the margin will be added in addition to the size from
535 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
536 pub fn margin_top(self, margin_top: i32) -> Self {
537 Self {
538 builder: self.builder.property("margin-top", margin_top),
539 }
540 }
541
542 /// The name of the widget.
543 pub fn name(self, name: impl Into<glib::GString>) -> Self {
544 Self {
545 builder: self.builder.property("name", name.into()),
546 }
547 }
548
549 /// The requested opacity of the widget.
550 pub fn opacity(self, opacity: f64) -> Self {
551 Self {
552 builder: self.builder.property("opacity", opacity),
553 }
554 }
555
556 /// How content outside the widget's content area is treated.
557 ///
558 /// This property is meant to be set by widget implementations,
559 /// typically in their instance init function.
560 pub fn overflow(self, overflow: Overflow) -> Self {
561 Self {
562 builder: self.builder.property("overflow", overflow),
563 }
564 }
565
566 /// Whether the widget will receive the default action when it is focused.
567 pub fn receives_default(self, receives_default: bool) -> Self {
568 Self {
569 builder: self.builder.property("receives-default", receives_default),
570 }
571 }
572
573 /// Whether the widget responds to input.
574 pub fn sensitive(self, sensitive: bool) -> Self {
575 Self {
576 builder: self.builder.property("sensitive", sensitive),
577 }
578 }
579
580 /// Sets the text of tooltip to be the given string, which is marked up
581 /// with Pango markup.
582 ///
583 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
584 ///
585 /// This is a convenience property which will take care of getting the
586 /// tooltip shown if the given string is not `NULL`:
587 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
588 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
589 /// the default signal handler.
590 ///
591 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
592 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
593 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
594 Self {
595 builder: self
596 .builder
597 .property("tooltip-markup", tooltip_markup.into()),
598 }
599 }
600
601 /// Sets the text of tooltip to be the given string.
602 ///
603 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
604 ///
605 /// This is a convenience property which will take care of getting the
606 /// tooltip shown if the given string is not `NULL`:
607 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
608 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
609 /// the default signal handler.
610 ///
611 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
612 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
613 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
614 Self {
615 builder: self.builder.property("tooltip-text", tooltip_text.into()),
616 }
617 }
618
619 /// How to distribute vertical space if widget gets extra space.
620 pub fn valign(self, valign: Align) -> Self {
621 Self {
622 builder: self.builder.property("valign", valign),
623 }
624 }
625
626 /// Whether to expand vertically.
627 pub fn vexpand(self, vexpand: bool) -> Self {
628 Self {
629 builder: self.builder.property("vexpand", vexpand),
630 }
631 }
632
633 /// Whether to use the `vexpand` property.
634 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
635 Self {
636 builder: self.builder.property("vexpand-set", vexpand_set),
637 }
638 }
639
640 /// Whether the widget is visible.
641 pub fn visible(self, visible: bool) -> Self {
642 Self {
643 builder: self.builder.property("visible", visible),
644 }
645 }
646
647 /// Overrides for width request of the widget.
648 ///
649 /// If this is -1, the natural request will be used.
650 pub fn width_request(self, width_request: i32) -> Self {
651 Self {
652 builder: self.builder.property("width-request", width_request),
653 }
654 }
655
656 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
657 ///
658 /// The accessible role cannot be changed once set.
659 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
660 Self {
661 builder: self.builder.property("accessible-role", accessible_role),
662 }
663 }
664
665 // rustdoc-stripper-ignore-next
666 /// Build the [`EmojiChooser`].
667 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
668 pub fn build(self) -> EmojiChooser {
669 assert_initialized_main_thread!();
670 self.builder.build()
671 }
672}