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 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 /// 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 let f: &F = &*(f as *const F);
259 f(
260 &from_glib_borrow(this),
261 &glib::GString::from_glib_borrow(text),
262 )
263 }
264 unsafe {
265 let f: Box_<F> = Box_::new(f);
266 connect_raw(
267 self.as_ptr() as *mut _,
268 c"emoji-picked".as_ptr() as *const _,
269 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
270 emoji_picked_trampoline::<F> as *const (),
271 )),
272 Box_::into_raw(f),
273 )
274 }
275 }
276}
277
278impl Default for EmojiChooser {
279 fn default() -> Self {
280 Self::new()
281 }
282}
283
284// rustdoc-stripper-ignore-next
285/// A [builder-pattern] type to construct [`EmojiChooser`] objects.
286///
287/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
288#[must_use = "The builder must be built to be used"]
289pub struct EmojiChooserBuilder {
290 builder: glib::object::ObjectBuilder<'static, EmojiChooser>,
291}
292
293impl EmojiChooserBuilder {
294 fn new() -> Self {
295 Self {
296 builder: glib::object::Object::builder(),
297 }
298 }
299
300 /// Whether to dismiss the popover on outside clicks.
301 pub fn autohide(self, autohide: bool) -> Self {
302 Self {
303 builder: self.builder.property("autohide", autohide),
304 }
305 }
306
307 /// Whether the popover pops down after a child popover.
308 ///
309 /// This is used to implement the expected behavior of submenus.
310 pub fn cascade_popdown(self, cascade_popdown: bool) -> Self {
311 Self {
312 builder: self.builder.property("cascade-popdown", cascade_popdown),
313 }
314 }
315
316 /// The child widget.
317 pub fn child(self, child: &impl IsA<Widget>) -> Self {
318 Self {
319 builder: self.builder.property("child", child.clone().upcast()),
320 }
321 }
322
323 /// The default widget inside the popover.
324 pub fn default_widget(self, default_widget: &impl IsA<Widget>) -> Self {
325 Self {
326 builder: self
327 .builder
328 .property("default-widget", default_widget.clone().upcast()),
329 }
330 }
331
332 /// Whether to draw an arrow.
333 pub fn has_arrow(self, has_arrow: bool) -> Self {
334 Self {
335 builder: self.builder.property("has-arrow", has_arrow),
336 }
337 }
338
339 /// Whether mnemonics are currently visible in this popover.
340 pub fn mnemonics_visible(self, mnemonics_visible: bool) -> Self {
341 Self {
342 builder: self
343 .builder
344 .property("mnemonics-visible", mnemonics_visible),
345 }
346 }
347
348 /// Rectangle in the parent widget that the popover points to.
349 pub fn pointing_to(self, pointing_to: &gdk::Rectangle) -> Self {
350 Self {
351 builder: self.builder.property("pointing-to", pointing_to),
352 }
353 }
354
355 /// How to place the popover, relative to its parent.
356 pub fn position(self, position: PositionType) -> Self {
357 Self {
358 builder: self.builder.property("position", position),
359 }
360 }
361
362 /// Whether the widget or any of its descendents can accept
363 /// the input focus.
364 ///
365 /// This property is meant to be set by widget implementations,
366 /// typically in their instance init function.
367 pub fn can_focus(self, can_focus: bool) -> Self {
368 Self {
369 builder: self.builder.property("can-focus", can_focus),
370 }
371 }
372
373 /// Whether the widget can receive pointer events.
374 pub fn can_target(self, can_target: bool) -> Self {
375 Self {
376 builder: self.builder.property("can-target", can_target),
377 }
378 }
379
380 /// A list of css classes applied to this widget.
381 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
382 Self {
383 builder: self.builder.property("css-classes", css_classes.into()),
384 }
385 }
386
387 /// The name of this widget in the CSS tree.
388 ///
389 /// This property is meant to be set by widget implementations,
390 /// typically in their instance init function.
391 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
392 Self {
393 builder: self.builder.property("css-name", css_name.into()),
394 }
395 }
396
397 /// The cursor used by @widget.
398 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
399 Self {
400 builder: self.builder.property("cursor", cursor.clone()),
401 }
402 }
403
404 /// Whether the widget should grab focus when it is clicked with the mouse.
405 ///
406 /// This property is only relevant for widgets that can take focus.
407 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
408 Self {
409 builder: self.builder.property("focus-on-click", focus_on_click),
410 }
411 }
412
413 /// Whether this widget itself will accept the input focus.
414 pub fn focusable(self, focusable: bool) -> Self {
415 Self {
416 builder: self.builder.property("focusable", focusable),
417 }
418 }
419
420 /// How to distribute horizontal space if widget gets extra space.
421 pub fn halign(self, halign: Align) -> Self {
422 Self {
423 builder: self.builder.property("halign", halign),
424 }
425 }
426
427 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
428 /// signal on @widget.
429 ///
430 /// A true value indicates that @widget can have a tooltip, in this case
431 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
432 /// determine whether it will provide a tooltip or not.
433 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
434 Self {
435 builder: self.builder.property("has-tooltip", has_tooltip),
436 }
437 }
438
439 /// Overrides for height request of the widget.
440 ///
441 /// If this is -1, the natural request will be used.
442 pub fn height_request(self, height_request: i32) -> Self {
443 Self {
444 builder: self.builder.property("height-request", height_request),
445 }
446 }
447
448 /// Whether to expand horizontally.
449 pub fn hexpand(self, hexpand: bool) -> Self {
450 Self {
451 builder: self.builder.property("hexpand", hexpand),
452 }
453 }
454
455 /// Whether to use the `hexpand` property.
456 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
457 Self {
458 builder: self.builder.property("hexpand-set", hexpand_set),
459 }
460 }
461
462 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
463 /// the preferred size of the widget, and allocate its children.
464 ///
465 /// This property is meant to be set by widget implementations,
466 /// typically in their instance init function.
467 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
468 Self {
469 builder: self
470 .builder
471 .property("layout-manager", layout_manager.clone().upcast()),
472 }
473 }
474
475 /// Makes this widget act like a modal dialog, with respect to
476 /// event delivery.
477 ///
478 /// Global event controllers will not handle events with targets
479 /// inside the widget, unless they are set up to ignore propagation
480 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
481 #[cfg(feature = "v4_18")]
482 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
483 pub fn limit_events(self, limit_events: bool) -> Self {
484 Self {
485 builder: self.builder.property("limit-events", limit_events),
486 }
487 }
488
489 /// Margin on bottom side of widget.
490 ///
491 /// This property adds margin outside of the widget's normal size
492 /// request, the margin will be added in addition to the size from
493 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
494 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
495 Self {
496 builder: self.builder.property("margin-bottom", margin_bottom),
497 }
498 }
499
500 /// Margin on end of widget, horizontally.
501 ///
502 /// This property supports left-to-right and right-to-left text
503 /// directions.
504 ///
505 /// This property adds margin outside of the widget's normal size
506 /// request, the margin will be added in addition to the size from
507 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
508 pub fn margin_end(self, margin_end: i32) -> Self {
509 Self {
510 builder: self.builder.property("margin-end", margin_end),
511 }
512 }
513
514 /// Margin on start of widget, horizontally.
515 ///
516 /// This property supports left-to-right and right-to-left text
517 /// directions.
518 ///
519 /// This property adds margin outside of the widget's normal size
520 /// request, the margin will be added in addition to the size from
521 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
522 pub fn margin_start(self, margin_start: i32) -> Self {
523 Self {
524 builder: self.builder.property("margin-start", margin_start),
525 }
526 }
527
528 /// Margin on top side of widget.
529 ///
530 /// This property adds margin outside of the widget's normal size
531 /// request, the margin will be added in addition to the size from
532 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
533 pub fn margin_top(self, margin_top: i32) -> Self {
534 Self {
535 builder: self.builder.property("margin-top", margin_top),
536 }
537 }
538
539 /// The name of the widget.
540 pub fn name(self, name: impl Into<glib::GString>) -> Self {
541 Self {
542 builder: self.builder.property("name", name.into()),
543 }
544 }
545
546 /// The requested opacity of the widget.
547 pub fn opacity(self, opacity: f64) -> Self {
548 Self {
549 builder: self.builder.property("opacity", opacity),
550 }
551 }
552
553 /// How content outside the widget's content area is treated.
554 ///
555 /// This property is meant to be set by widget implementations,
556 /// typically in their instance init function.
557 pub fn overflow(self, overflow: Overflow) -> Self {
558 Self {
559 builder: self.builder.property("overflow", overflow),
560 }
561 }
562
563 /// Whether the widget will receive the default action when it is focused.
564 pub fn receives_default(self, receives_default: bool) -> Self {
565 Self {
566 builder: self.builder.property("receives-default", receives_default),
567 }
568 }
569
570 /// Whether the widget responds to input.
571 pub fn sensitive(self, sensitive: bool) -> Self {
572 Self {
573 builder: self.builder.property("sensitive", sensitive),
574 }
575 }
576
577 /// Sets the text of tooltip to be the given string, which is marked up
578 /// with Pango markup.
579 ///
580 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
581 ///
582 /// This is a convenience property which will take care of getting the
583 /// tooltip shown if the given string is not `NULL`:
584 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
585 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
586 /// the default signal handler.
587 ///
588 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
589 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
590 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
591 Self {
592 builder: self
593 .builder
594 .property("tooltip-markup", tooltip_markup.into()),
595 }
596 }
597
598 /// Sets the text of tooltip to be the given string.
599 ///
600 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
601 ///
602 /// This is a convenience property which will take care of getting the
603 /// tooltip shown if the given string is not `NULL`:
604 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
605 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
606 /// the default signal handler.
607 ///
608 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
609 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
610 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
611 Self {
612 builder: self.builder.property("tooltip-text", tooltip_text.into()),
613 }
614 }
615
616 /// How to distribute vertical space if widget gets extra space.
617 pub fn valign(self, valign: Align) -> Self {
618 Self {
619 builder: self.builder.property("valign", valign),
620 }
621 }
622
623 /// Whether to expand vertically.
624 pub fn vexpand(self, vexpand: bool) -> Self {
625 Self {
626 builder: self.builder.property("vexpand", vexpand),
627 }
628 }
629
630 /// Whether to use the `vexpand` property.
631 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
632 Self {
633 builder: self.builder.property("vexpand-set", vexpand_set),
634 }
635 }
636
637 /// Whether the widget is visible.
638 pub fn visible(self, visible: bool) -> Self {
639 Self {
640 builder: self.builder.property("visible", visible),
641 }
642 }
643
644 /// Overrides for width request of the widget.
645 ///
646 /// If this is -1, the natural request will be used.
647 pub fn width_request(self, width_request: i32) -> Self {
648 Self {
649 builder: self.builder.property("width-request", width_request),
650 }
651 }
652
653 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
654 ///
655 /// The accessible role cannot be changed once set.
656 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
657 Self {
658 builder: self.builder.property("accessible-role", accessible_role),
659 }
660 }
661
662 // rustdoc-stripper-ignore-next
663 /// Build the [`EmojiChooser`].
664 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
665 pub fn build(self) -> EmojiChooser {
666 assert_initialized_main_thread!();
667 self.builder.build()
668 }
669}