Skip to main content

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