gtk4/auto/tooltip.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::{ffi, Widget};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// [`Tooltip`][crate::Tooltip] is an object representing a widget tooltip.
10 ///
11 /// Basic tooltips can be realized simply by using
12 /// [`WidgetExt::set_tooltip_text()`][crate::prelude::WidgetExt::set_tooltip_text()] or
13 /// [`WidgetExt::set_tooltip_markup()`][crate::prelude::WidgetExt::set_tooltip_markup()] without
14 /// any explicit tooltip object.
15 ///
16 /// When you need a tooltip with a little more fancy contents,
17 /// like adding an image, or you want the tooltip to have different
18 /// contents per [`TreeView`][crate::TreeView] row or cell, you will have to do a
19 /// little more work:
20 ///
21 /// - Set the [`has-tooltip`][struct@crate::Widget#has-tooltip] property to [`true`].
22 /// This will make GTK monitor the widget for motion and related events
23 /// which are needed to determine when and where to show a tooltip.
24 ///
25 /// - Connect to the [`query-tooltip`][struct@crate::Widget#query-tooltip] signal.
26 /// This signal will be emitted when a tooltip is supposed to be shown.
27 /// One of the arguments passed to the signal handler is a [`Tooltip`][crate::Tooltip]
28 /// object. This is the object that we are about to display as a tooltip,
29 /// and can be manipulated in your callback using functions like
30 /// [`set_icon()`][Self::set_icon()]. There are functions for setting
31 /// the tooltip’s markup, setting an image from a named icon, or even
32 /// putting in a custom widget.
33 ///
34 /// - Return [`true`] from your ::query-tooltip handler. This causes the tooltip
35 /// to be show. If you return [`false`], it will not be shown.
36 ///
37 /// # Implements
38 ///
39 /// [`trait@glib::ObjectExt`]
40 #[doc(alias = "GtkTooltip")]
41 pub struct Tooltip(Object<ffi::GtkTooltip>);
42
43 match fn {
44 type_ => || ffi::gtk_tooltip_get_type(),
45 }
46}
47
48impl Tooltip {
49 /// Replaces the widget packed into the tooltip with
50 /// @custom_widget. @custom_widget does not get destroyed when the tooltip goes
51 /// away.
52 /// By default a box with a [`Image`][crate::Image] and [`Label`][crate::Label] is embedded in
53 /// the tooltip, which can be configured using gtk_tooltip_set_markup()
54 /// and gtk_tooltip_set_icon().
55 /// ## `custom_widget`
56 /// a [`Widget`][crate::Widget], or [`None`] to unset the old custom widget.
57 #[doc(alias = "gtk_tooltip_set_custom")]
58 pub fn set_custom(&self, custom_widget: Option<&impl IsA<Widget>>) {
59 unsafe {
60 ffi::gtk_tooltip_set_custom(
61 self.to_glib_none().0,
62 custom_widget.map(|p| p.as_ref()).to_glib_none().0,
63 );
64 }
65 }
66
67 /// Sets the icon of the tooltip (which is in front of the text) to be
68 /// @paintable. If @paintable is [`None`], the image will be hidden.
69 /// ## `paintable`
70 /// a [`gdk::Paintable`][crate::gdk::Paintable]
71 #[doc(alias = "gtk_tooltip_set_icon")]
72 pub fn set_icon(&self, paintable: Option<&impl IsA<gdk::Paintable>>) {
73 unsafe {
74 ffi::gtk_tooltip_set_icon(
75 self.to_glib_none().0,
76 paintable.map(|p| p.as_ref()).to_glib_none().0,
77 );
78 }
79 }
80
81 /// Sets the icon of the tooltip (which is in front of the text)
82 /// to be the icon indicated by @gicon with the size indicated
83 /// by @size. If @gicon is [`None`], the image will be hidden.
84 /// ## `gicon`
85 /// a `GIcon` representing the icon
86 #[doc(alias = "gtk_tooltip_set_icon_from_gicon")]
87 pub fn set_icon_from_gicon(&self, gicon: Option<&impl IsA<gio::Icon>>) {
88 unsafe {
89 ffi::gtk_tooltip_set_icon_from_gicon(
90 self.to_glib_none().0,
91 gicon.map(|p| p.as_ref()).to_glib_none().0,
92 );
93 }
94 }
95
96 /// Sets the icon of the tooltip (which is in front of the text) to be
97 /// the icon indicated by @icon_name with the size indicated
98 /// by @size. If @icon_name is [`None`], the image will be hidden.
99 /// ## `icon_name`
100 /// an icon name
101 #[doc(alias = "gtk_tooltip_set_icon_from_icon_name")]
102 pub fn set_icon_from_icon_name(&self, icon_name: Option<&str>) {
103 unsafe {
104 ffi::gtk_tooltip_set_icon_from_icon_name(
105 self.to_glib_none().0,
106 icon_name.to_glib_none().0,
107 );
108 }
109 }
110
111 /// Sets the text of the tooltip to be @markup.
112 ///
113 /// The string must be marked up with Pango markup.
114 /// If @markup is [`None`], the label will be hidden.
115 /// ## `markup`
116 /// a string with Pango markup or `NLL`
117 #[doc(alias = "gtk_tooltip_set_markup")]
118 pub fn set_markup(&self, markup: Option<&str>) {
119 unsafe {
120 ffi::gtk_tooltip_set_markup(self.to_glib_none().0, markup.to_glib_none().0);
121 }
122 }
123
124 /// Sets the text of the tooltip to be @text.
125 ///
126 /// If @text is [`None`], the label will be hidden.
127 /// See also [`set_markup()`][Self::set_markup()].
128 /// ## `text`
129 /// a text string
130 #[doc(alias = "gtk_tooltip_set_text")]
131 pub fn set_text(&self, text: Option<&str>) {
132 unsafe {
133 ffi::gtk_tooltip_set_text(self.to_glib_none().0, text.to_glib_none().0);
134 }
135 }
136
137 /// Sets the area of the widget, where the contents of this tooltip apply,
138 /// to be @rect (in widget coordinates). This is especially useful for
139 /// properly setting tooltips on [`TreeView`][crate::TreeView] rows and cells, `GtkIconViews`,
140 /// etc.
141 ///
142 /// For setting tooltips on [`TreeView`][crate::TreeView], please refer to the convenience
143 /// functions for this: gtk_tree_view_set_tooltip_row() and
144 /// gtk_tree_view_set_tooltip_cell().
145 /// ## `rect`
146 /// a [`gdk::Rectangle`][crate::gdk::Rectangle]
147 #[doc(alias = "gtk_tooltip_set_tip_area")]
148 pub fn set_tip_area(&self, rect: &gdk::Rectangle) {
149 unsafe {
150 ffi::gtk_tooltip_set_tip_area(self.to_glib_none().0, rect.to_glib_none().0);
151 }
152 }
153}