libadwaita/auto/toast.rs
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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT
use crate::{ffi, ToastPriority};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// A helper object for [`ToastOverlay`][crate::ToastOverlay].
///
/// Toasts are meant to be passed into [`ToastOverlay::add_toast()`][crate::ToastOverlay::add_toast()] as
/// follows:
///
/// **⚠️ The following code is in c ⚠️**
///
/// ```c
/// adw_toast_overlay_add_toast (overlay, adw_toast_new (_("Simple Toast")));
/// ```
///
/// <picture>
/// <source srcset="toast-simple-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="toast-simple.png" alt="toast-simple">
/// </picture>
///
/// Toasts always have a close button. They emit the [`dismissed`][struct@crate::Toast#dismissed]
/// signal when disappearing.
///
/// [`timeout`][struct@crate::Toast#timeout] determines how long the toast stays on screen, while
/// [`priority`][struct@crate::Toast#priority] determines how it behaves if another toast is
/// already being displayed.
///
/// Toast titles use Pango markup by default, set [`use-markup`][struct@crate::Toast#use-markup] to
/// `FALSE` if this is unwanted.
///
/// [`custom-title`][struct@crate::Toast#custom-title] can be used to replace the title label with a
/// custom widget.
///
/// ## Actions
///
/// Toasts can have one button on them, with a label and an attached
/// `Gio::Action`.
///
/// **⚠️ The following code is in c ⚠️**
///
/// ```c
/// AdwToast *toast = adw_toast_new (_("Toast with Action"));
///
/// adw_toast_set_button_label (toast, _("_Example"));
/// adw_toast_set_action_name (toast, "win.example");
///
/// adw_toast_overlay_add_toast (overlay, toast);
/// ```
///
/// <picture>
/// <source srcset="toast-action-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="toast-action.png" alt="toast-action">
/// </picture>
///
/// ## Modifying toasts
///
/// Toasts can be modified after they have been shown. For this, an [`Toast`][crate::Toast]
/// reference must be kept around while the toast is visible.
///
/// A common use case for this is using toasts as undo prompts that stack with
/// each other, allowing to batch undo the last deleted items:
///
/// **⚠️ The following code is in c ⚠️**
///
/// ```c
///
/// static void
/// toast_undo_cb (GtkWidget *sender,
/// const char *action,
/// GVariant *param)
/// {
/// // Undo the deletion
/// }
///
/// static void
/// dismissed_cb (MyWindow *self)
/// {
/// self->undo_toast = NULL;
///
/// // Permanently delete the items
/// }
///
/// static void
/// delete_item (MyWindow *self,
/// MyItem *item)
/// {
/// g_autofree char *title = NULL;
/// int n_items;
///
/// // Mark the item as waiting for deletion
/// n_items = ... // The number of waiting items
///
/// if (!self->undo_toast) {
/// self->undo_toast = adw_toast_new_format (_("‘%s’ deleted"), ...);
///
/// adw_toast_set_priority (self->undo_toast, ADW_TOAST_PRIORITY_HIGH);
/// adw_toast_set_button_label (self->undo_toast, _("_Undo"));
/// adw_toast_set_action_name (self->undo_toast, "toast.undo");
///
/// g_signal_connect_swapped (self->undo_toast, "dismissed",
/// G_CALLBACK (dismissed_cb), self);
///
/// adw_toast_overlay_add_toast (self->toast_overlay, self->undo_toast);
///
/// return;
/// }
///
/// title =
/// g_strdup_printf (ngettext ("<span font_features='tnum=1'>%d</span> item deleted",
/// "<span font_features='tnum=1'>%d</span> items deleted",
/// n_items), n_items);
///
/// adw_toast_set_title (self->undo_toast, title);
///
/// // Bump the toast timeout
/// adw_toast_overlay_add_toast (self->toast_overlay, g_object_ref (self->undo_toast));
/// }
///
/// static void
/// my_window_class_init (MyWindowClass *klass)
/// {
/// GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
///
/// gtk_widget_class_install_action (widget_class, "toast.undo", NULL, toast_undo_cb);
/// }
/// ```
///
/// <picture>
/// <source srcset="toast-undo-dark.png" media="(prefers-color-scheme: dark)">
/// <img src="toast-undo.png" alt="toast-undo">
/// </picture>
///
/// ## Properties
///
///
/// #### `action-name`
/// The name of the associated action.
///
/// It will be activated when clicking the button.
///
/// See [`action-target`][struct@crate::Toast#action-target].
///
/// Readable | Writeable
///
///
/// #### `action-target`
/// The parameter for action invocations.
///
/// Readable | Writeable
///
///
/// #### `button-label`
/// The label to show on the button.
///
/// Underlines in the button text can be used to indicate a mnemonic.
///
/// If set to `NULL`, the button won't be shown.
///
/// See [`action-name`][struct@crate::Toast#action-name].
///
/// Readable | Writeable
///
///
/// #### `custom-title`
/// The custom title widget.
///
/// It will be displayed instead of the title if set. In this case,
/// [`title`][struct@crate::Toast#title] is ignored.
///
/// Setting a custom title will unset [`title`][struct@crate::Toast#title].
///
/// Readable | Writeable
///
///
/// #### `priority`
/// The priority of the toast.
///
/// Priority controls how the toast behaves when another toast is already
/// being displayed.
///
/// If the priority is `ADW_TOAST_PRIORITY_NORMAL`, the toast will be queued.
///
/// If the priority is `ADW_TOAST_PRIORITY_HIGH`, the toast will be displayed
/// immediately, pushing the previous toast into the queue instead.
///
/// Readable | Writeable
///
///
/// #### `timeout`
/// The timeout of the toast, in seconds.
///
/// If timeout is 0, the toast is displayed indefinitely until manually
/// dismissed.
///
/// Toasts cannot disappear while being hovered, pressed (on touchscreen), or
/// have keyboard focus inside them.
///
/// Readable | Writeable
///
///
/// #### `title`
/// The title of the toast.
///
/// The title can be marked up with the Pango text markup language.
///
/// Setting a title will unset [`custom-title`][struct@crate::Toast#custom-title].
///
/// If [`custom-title`][struct@crate::Toast#custom-title] is set, it will be used instead.
///
/// Readable | Writeable
///
///
/// #### `use-markup`
/// Whether to use Pango markup for the toast title.
///
/// See also `parse_markup()`.
///
/// Readable | Writeable
///
/// ## Signals
///
///
/// #### `button-clicked`
/// Emitted after the button has been clicked.
///
/// It can be used as an alternative to setting an action.
///
///
///
///
/// #### `dismissed`
/// Emitted when the toast has been dismissed.
///
///
///
/// # Implements
///
/// [`trait@glib::ObjectExt`]
#[doc(alias = "AdwToast")]
pub struct Toast(Object<ffi::AdwToast, ffi::AdwToastClass>);
match fn {
type_ => || ffi::adw_toast_get_type(),
}
}
impl Toast {
/// Creates a new [`Toast`][crate::Toast].
///
/// The toast will use @title as its title.
///
/// @title can be marked up with the Pango text markup language.
/// ## `title`
/// the title to be displayed
///
/// # Returns
///
/// the new created [`Toast`][crate::Toast]
#[doc(alias = "adw_toast_new")]
pub fn new(title: &str) -> Toast {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::adw_toast_new(title.to_glib_none().0)) }
}
// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct [`Toast`] objects.
///
/// This method returns an instance of [`ToastBuilder`](crate::builders::ToastBuilder) which can be used to create [`Toast`] objects.
pub fn builder() -> ToastBuilder {
ToastBuilder::new()
}
/// Dismisses @self.
///
/// Does nothing if @self has already been dismissed, or hasn't been added to an
/// [`ToastOverlay`][crate::ToastOverlay].
#[doc(alias = "adw_toast_dismiss")]
pub fn dismiss(&self) {
unsafe {
ffi::adw_toast_dismiss(self.to_glib_none().0);
}
}
/// Gets the name of the associated action.
///
/// # Returns
///
/// the action name
#[doc(alias = "adw_toast_get_action_name")]
#[doc(alias = "get_action_name")]
#[doc(alias = "action-name")]
pub fn action_name(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::adw_toast_get_action_name(self.to_glib_none().0)) }
}
/// Gets the parameter for action invocations.
///
/// # Returns
///
/// the action target
#[doc(alias = "adw_toast_get_action_target_value")]
#[doc(alias = "get_action_target_value")]
#[doc(alias = "action-target")]
pub fn action_target_value(&self) -> Option<glib::Variant> {
unsafe {
from_glib_none(ffi::adw_toast_get_action_target_value(
self.to_glib_none().0,
))
}
}
/// Gets the label to show on the button.
///
/// # Returns
///
/// the button label
#[doc(alias = "adw_toast_get_button_label")]
#[doc(alias = "get_button_label")]
#[doc(alias = "button-label")]
pub fn button_label(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::adw_toast_get_button_label(self.to_glib_none().0)) }
}
/// Gets the custom title widget of @self.
///
/// # Returns
///
/// the custom title widget
#[cfg(feature = "v1_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
#[doc(alias = "adw_toast_get_custom_title")]
#[doc(alias = "get_custom_title")]
#[doc(alias = "custom-title")]
pub fn custom_title(&self) -> Option<gtk::Widget> {
unsafe { from_glib_none(ffi::adw_toast_get_custom_title(self.to_glib_none().0)) }
}
/// Gets priority for @self.
///
/// # Returns
///
/// the priority
#[doc(alias = "adw_toast_get_priority")]
#[doc(alias = "get_priority")]
pub fn priority(&self) -> ToastPriority {
unsafe { from_glib(ffi::adw_toast_get_priority(self.to_glib_none().0)) }
}
/// Gets timeout for @self.
///
/// # Returns
///
/// the timeout
#[doc(alias = "adw_toast_get_timeout")]
#[doc(alias = "get_timeout")]
pub fn timeout(&self) -> u32 {
unsafe { ffi::adw_toast_get_timeout(self.to_glib_none().0) }
}
/// Gets the title that will be displayed on the toast.
///
/// If a custom title has been set with [`set_custom_title()`][Self::set_custom_title()]
/// the return value will be [`None`].
///
/// # Returns
///
/// the title
#[doc(alias = "adw_toast_get_title")]
#[doc(alias = "get_title")]
pub fn title(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::adw_toast_get_title(self.to_glib_none().0)) }
}
/// Gets whether to use Pango markup for the toast title.
///
/// # Returns
///
/// whether the toast uses markup
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "adw_toast_get_use_markup")]
#[doc(alias = "get_use_markup")]
#[doc(alias = "use-markup")]
pub fn uses_markup(&self) -> bool {
unsafe { from_glib(ffi::adw_toast_get_use_markup(self.to_glib_none().0)) }
}
/// Sets the name of the associated action.
///
/// It will be activated when clicking the button.
///
/// See [`action-target`][struct@crate::Toast#action-target].
/// ## `action_name`
/// the action name
#[doc(alias = "adw_toast_set_action_name")]
#[doc(alias = "action-name")]
pub fn set_action_name(&self, action_name: Option<&str>) {
unsafe {
ffi::adw_toast_set_action_name(self.to_glib_none().0, action_name.to_glib_none().0);
}
}
/// Sets the parameter for action invocations.
///
/// If the @action_target variant has a floating reference this function
/// will sink it.
/// ## `action_target`
/// the action target
#[doc(alias = "adw_toast_set_action_target_value")]
#[doc(alias = "action-target")]
pub fn set_action_target_value(&self, action_target: Option<&glib::Variant>) {
unsafe {
ffi::adw_toast_set_action_target_value(
self.to_glib_none().0,
action_target.to_glib_none().0,
);
}
}
/// Sets the label to show on the button.
///
/// Underlines in the button text can be used to indicate a mnemonic.
///
/// If set to `NULL`, the button won't be shown.
///
/// See [`action-name`][struct@crate::Toast#action-name].
/// ## `button_label`
/// a button label
#[doc(alias = "adw_toast_set_button_label")]
#[doc(alias = "button-label")]
pub fn set_button_label(&self, button_label: Option<&str>) {
unsafe {
ffi::adw_toast_set_button_label(self.to_glib_none().0, button_label.to_glib_none().0);
}
}
/// Sets the custom title widget of @self.
///
/// It will be displayed instead of the title if set. In this case,
/// [`title`][struct@crate::Toast#title] is ignored.
///
/// Setting a custom title will unset [`title`][struct@crate::Toast#title].
/// ## `widget`
/// the custom title widget
#[cfg(feature = "v1_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
#[doc(alias = "adw_toast_set_custom_title")]
#[doc(alias = "custom-title")]
pub fn set_custom_title(&self, widget: Option<&impl IsA<gtk::Widget>>) {
unsafe {
ffi::adw_toast_set_custom_title(
self.to_glib_none().0,
widget.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
/// Sets the action name and its parameter.
///
/// @detailed_action_name is a string in the format accepted by
/// `Gio::Action::parse_detailed_name()`.
/// ## `detailed_action_name`
/// the detailed action name
#[doc(alias = "adw_toast_set_detailed_action_name")]
pub fn set_detailed_action_name(&self, detailed_action_name: Option<&str>) {
unsafe {
ffi::adw_toast_set_detailed_action_name(
self.to_glib_none().0,
detailed_action_name.to_glib_none().0,
);
}
}
/// Sets priority for @self.
///
/// Priority controls how the toast behaves when another toast is already
/// being displayed.
///
/// If @priority is `ADW_TOAST_PRIORITY_NORMAL`, the toast will be queued.
///
/// If @priority is `ADW_TOAST_PRIORITY_HIGH`, the toast will be displayed
/// immediately, pushing the previous toast into the queue instead.
/// ## `priority`
/// the priority
#[doc(alias = "adw_toast_set_priority")]
#[doc(alias = "priority")]
pub fn set_priority(&self, priority: ToastPriority) {
unsafe {
ffi::adw_toast_set_priority(self.to_glib_none().0, priority.into_glib());
}
}
/// Sets timeout for @self.
///
/// If @timeout is 0, the toast is displayed indefinitely until manually
/// dismissed.
///
/// Toasts cannot disappear while being hovered, pressed (on touchscreen), or
/// have keyboard focus inside them.
/// ## `timeout`
/// the timeout
#[doc(alias = "adw_toast_set_timeout")]
#[doc(alias = "timeout")]
pub fn set_timeout(&self, timeout: u32) {
unsafe {
ffi::adw_toast_set_timeout(self.to_glib_none().0, timeout);
}
}
/// Sets the title that will be displayed on the toast.
///
/// The title can be marked up with the Pango text markup language.
///
/// Setting a title will unset [`custom-title`][struct@crate::Toast#custom-title].
///
/// If [`custom-title`][struct@crate::Toast#custom-title] is set, it will be used instead.
/// ## `title`
/// a title
#[doc(alias = "adw_toast_set_title")]
#[doc(alias = "title")]
pub fn set_title(&self, title: &str) {
unsafe {
ffi::adw_toast_set_title(self.to_glib_none().0, title.to_glib_none().0);
}
}
/// Whether to use Pango markup for the toast title.
///
/// See also `parse_markup()`.
/// ## `use_markup`
/// whether to use markup
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "adw_toast_set_use_markup")]
#[doc(alias = "use-markup")]
pub fn set_use_markup(&self, use_markup: bool) {
unsafe {
ffi::adw_toast_set_use_markup(self.to_glib_none().0, use_markup.into_glib());
}
}
/// Emitted after the button has been clicked.
///
/// It can be used as an alternative to setting an action.
#[cfg(feature = "v1_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
#[doc(alias = "button-clicked")]
pub fn connect_button_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn button_clicked_trampoline<F: Fn(&Toast) + 'static>(
this: *mut ffi::AdwToast,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"button-clicked\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
button_clicked_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
/// Emitted when the toast has been dismissed.
#[doc(alias = "dismissed")]
pub fn connect_dismissed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn dismissed_trampoline<F: Fn(&Toast) + 'static>(
this: *mut ffi::AdwToast,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"dismissed\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
dismissed_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "action-name")]
pub fn connect_action_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_action_name_trampoline<F: Fn(&Toast) + 'static>(
this: *mut ffi::AdwToast,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::action-name\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_action_name_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "action-target")]
pub fn connect_action_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_action_target_trampoline<F: Fn(&Toast) + 'static>(
this: *mut ffi::AdwToast,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::action-target\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_action_target_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "button-label")]
pub fn connect_button_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_button_label_trampoline<F: Fn(&Toast) + 'static>(
this: *mut ffi::AdwToast,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::button-label\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_button_label_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(feature = "v1_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
#[doc(alias = "custom-title")]
pub fn connect_custom_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_custom_title_trampoline<F: Fn(&Toast) + 'static>(
this: *mut ffi::AdwToast,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::custom-title\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_custom_title_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "priority")]
pub fn connect_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_priority_trampoline<F: Fn(&Toast) + 'static>(
this: *mut ffi::AdwToast,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::priority\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_priority_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "timeout")]
pub fn connect_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_timeout_trampoline<F: Fn(&Toast) + 'static>(
this: *mut ffi::AdwToast,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::timeout\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_timeout_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "title")]
pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_title_trampoline<F: Fn(&Toast) + 'static>(
this: *mut ffi::AdwToast,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::title\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_title_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
#[doc(alias = "use-markup")]
pub fn connect_use_markup_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_use_markup_trampoline<F: Fn(&Toast) + 'static>(
this: *mut ffi::AdwToast,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::use-markup\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_use_markup_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl Default for Toast {
fn default() -> Self {
glib::object::Object::new::<Self>()
}
}
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Toast`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct ToastBuilder {
builder: glib::object::ObjectBuilder<'static, Toast>,
}
impl ToastBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
/// The name of the associated action.
///
/// It will be activated when clicking the button.
///
/// See [`action-target`][struct@crate::Toast#action-target].
pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("action-name", action_name.into()),
}
}
/// The parameter for action invocations.
pub fn action_target(self, action_target: &glib::Variant) -> Self {
Self {
builder: self
.builder
.property("action-target", action_target.clone()),
}
}
/// The label to show on the button.
///
/// Underlines in the button text can be used to indicate a mnemonic.
///
/// If set to `NULL`, the button won't be shown.
///
/// See [`action-name`][struct@crate::Toast#action-name].
pub fn button_label(self, button_label: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("button-label", button_label.into()),
}
}
/// The custom title widget.
///
/// It will be displayed instead of the title if set. In this case,
/// [`title`][struct@crate::Toast#title] is ignored.
///
/// Setting a custom title will unset [`title`][struct@crate::Toast#title].
#[cfg(feature = "v1_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
pub fn custom_title(self, custom_title: &impl IsA<gtk::Widget>) -> Self {
Self {
builder: self
.builder
.property("custom-title", custom_title.clone().upcast()),
}
}
/// The priority of the toast.
///
/// Priority controls how the toast behaves when another toast is already
/// being displayed.
///
/// If the priority is `ADW_TOAST_PRIORITY_NORMAL`, the toast will be queued.
///
/// If the priority is `ADW_TOAST_PRIORITY_HIGH`, the toast will be displayed
/// immediately, pushing the previous toast into the queue instead.
pub fn priority(self, priority: ToastPriority) -> Self {
Self {
builder: self.builder.property("priority", priority),
}
}
/// The timeout of the toast, in seconds.
///
/// If timeout is 0, the toast is displayed indefinitely until manually
/// dismissed.
///
/// Toasts cannot disappear while being hovered, pressed (on touchscreen), or
/// have keyboard focus inside them.
pub fn timeout(self, timeout: u32) -> Self {
Self {
builder: self.builder.property("timeout", timeout),
}
}
/// The title of the toast.
///
/// The title can be marked up with the Pango text markup language.
///
/// Setting a title will unset [`custom-title`][struct@crate::Toast#custom-title].
///
/// If [`custom-title`][struct@crate::Toast#custom-title] is set, it will be used instead.
pub fn title(self, title: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("title", title.into()),
}
}
/// Whether to use Pango markup for the toast title.
///
/// See also `parse_markup()`.
#[cfg(feature = "v1_4")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
pub fn use_markup(self, use_markup: bool) -> Self {
Self {
builder: self.builder.property("use-markup", use_markup),
}
}
// rustdoc-stripper-ignore-next
/// Build the [`Toast`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Toast {
assert_initialized_main_thread!();
self.builder.build()
}
}