gtk4/auto/label.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
5#[cfg(feature = "v4_22")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
7use crate::AccessibleHypertext;
8#[cfg(feature = "v4_14")]
9#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
10use crate::AccessibleText;
11#[cfg(feature = "v4_6")]
12#[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
13use crate::NaturalWrapMode;
14use crate::{
15 Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, Justification, LayoutManager,
16 MovementStep, Overflow, Widget, ffi,
17};
18use glib::{
19 object::ObjectType as _,
20 prelude::*,
21 signal::{SignalHandlerId, connect_raw},
22 translate::*,
23};
24use std::boxed::Box as Box_;
25
26#[cfg(feature = "v4_22")]
27#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
28glib::wrapper! {
29 /// Displays a small amount of text.
30 ///
31 /// Most labels are used to label another widget (such as an [`Entry`][crate::Entry]).
32 ///
33 /// <picture>
34 /// <source srcset="label-dark.png" media="(prefers-color-scheme: dark)">
35 /// <img alt="An example GtkLabel" src="label.png">
36 /// </picture>
37 ///
38 /// ## Shortcuts and Gestures
39 ///
40 /// [`Label`][crate::Label] supports the following keyboard shortcuts, when the cursor is
41 /// visible:
42 ///
43 /// - <kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Menu</kbd> opens the context menu.
44 /// - <kbd>Ctrl</kbd>+<kbd>A</kbd> or <kbd>Ctrl</kbd>+<kbd>/</kbd>
45 /// selects all.
46 /// - <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>A</kbd> or
47 /// <kbd>Ctrl</kbd>+<kbd>\</kbd> unselects all.
48 ///
49 /// Additionally, the following signals have default keybindings:
50 ///
51 /// - [`activate-current-link`][struct@crate::Label#activate-current-link]
52 /// - [`copy-clipboard`][struct@crate::Label#copy-clipboard]
53 /// - [`move-cursor`][struct@crate::Label#move-cursor]
54 ///
55 /// ## Actions
56 ///
57 /// [`Label`][crate::Label] defines a set of built-in actions:
58 ///
59 /// - `clipboard.copy` copies the text to the clipboard.
60 /// - `clipboard.cut` doesn't do anything, since text in labels can't be deleted.
61 /// - `clipboard.paste` doesn't do anything, since text in labels can't be
62 /// edited.
63 /// - `link.open` opens the link, when activated on a link inside the label.
64 /// - `link.copy` copies the link to the clipboard, when activated on a link
65 /// inside the label.
66 /// - `menu.popup` opens the context menu.
67 /// - `selection.delete` doesn't do anything, since text in labels can't be
68 /// deleted.
69 /// - `selection.select-all` selects all of the text, if the label allows
70 /// selection.
71 ///
72 /// ## CSS nodes
73 ///
74 /// ```text
75 /// label
76 /// ├── [selection]
77 /// ├── [link]
78 /// ┊
79 /// ╰── [link]
80 /// ```
81 ///
82 /// [`Label`][crate::Label] has a single CSS node with the name label. A wide variety
83 /// of style classes may be applied to labels, such as .title, .subtitle,
84 /// .dim-label, etc. In the [`ShortcutsWindow`][crate::ShortcutsWindow], labels are used with the
85 /// .keycap style class.
86 ///
87 /// If the label has a selection, it gets a subnode with name selection.
88 ///
89 /// If the label has links, there is one subnode per link. These subnodes
90 /// carry the link or visited state depending on whether they have been
91 /// visited. In this case, label node also gets a .link style class.
92 ///
93 /// ## GtkLabel as GtkBuildable
94 ///
95 /// The GtkLabel implementation of the GtkBuildable interface supports a
96 /// custom `<attributes>` element, which supports any number of `<attribute>`
97 /// elements. The `<attribute>` element has attributes named “name“, “value“,
98 /// “start“ and “end“ and allows you to specify `Pango::Attribute`
99 /// values for this label.
100 ///
101 /// An example of a UI definition fragment specifying Pango attributes:
102 ///
103 /// ```xml
104 /// <object class="GtkLabel">
105 /// <attributes>
106 /// <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
107 /// <attribute name="background" value="red" start="5" end="10"/>
108 /// </attributes>
109 /// </object>
110 /// ```
111 ///
112 /// The start and end attributes specify the range of characters to which the
113 /// Pango attribute applies. If start and end are not specified, the attribute is
114 /// applied to the whole text. Note that specifying ranges does not make much
115 /// sense with translatable attributes. Use markup embedded in the translatable
116 /// content instead.
117 ///
118 /// ## Accessibility
119 ///
120 /// [`Label`][crate::Label] uses the [enum@Gtk.AccessibleRole.label] role.
121 ///
122 /// ## Mnemonics
123 ///
124 /// Labels may contain “mnemonics”. Mnemonics are underlined characters in the
125 /// label, used for keyboard navigation. Mnemonics are created by providing a
126 /// string with an underscore before the mnemonic character, such as `"_File"`,
127 /// to the functions [`with_mnemonic()`][Self::with_mnemonic()] or
128 /// [`set_text_with_mnemonic()`][Self::set_text_with_mnemonic()].
129 ///
130 /// Mnemonics automatically activate any activatable widget the label is
131 /// inside, such as a [`Button`][crate::Button]; if the label is not inside the
132 /// mnemonic’s target widget, you have to tell the label about the target
133 /// using [`set_mnemonic_widget()`][Self::set_mnemonic_widget()].
134 ///
135 /// Here’s a simple example where the label is inside a button:
136 ///
137 /// **⚠️ The following code is in c ⚠️**
138 ///
139 /// ```c
140 /// // Pressing Alt+H will activate this button
141 /// GtkWidget *button = gtk_button_new ();
142 /// GtkWidget *label = gtk_label_new_with_mnemonic ("_Hello");
143 /// gtk_button_set_child (GTK_BUTTON (button), label);
144 /// ```
145 ///
146 /// There’s a convenience function to create buttons with a mnemonic label
147 /// already inside:
148 ///
149 /// **⚠️ The following code is in c ⚠️**
150 ///
151 /// ```c
152 /// // Pressing Alt+H will activate this button
153 /// GtkWidget *button = gtk_button_new_with_mnemonic ("_Hello");
154 /// ```
155 ///
156 /// To create a mnemonic for a widget alongside the label, such as a
157 /// [`Entry`][crate::Entry], you have to point the label at the entry with
158 /// [`set_mnemonic_widget()`][Self::set_mnemonic_widget()]:
159 ///
160 /// **⚠️ The following code is in c ⚠️**
161 ///
162 /// ```c
163 /// // Pressing Alt+H will focus the entry
164 /// GtkWidget *entry = gtk_entry_new ();
165 /// GtkWidget *label = gtk_label_new_with_mnemonic ("_Hello");
166 /// gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
167 /// ```
168 ///
169 /// ## Markup (styled text)
170 ///
171 /// To make it easy to format text in a label (changing colors, fonts, etc.),
172 /// label text can be provided in a simple markup format:
173 ///
174 /// Here’s how to create a label with a small font:
175 /// **⚠️ The following code is in c ⚠️**
176 ///
177 /// ```c
178 /// GtkWidget *label = gtk_label_new (NULL);
179 /// gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>");
180 /// ```
181 ///
182 /// (See the Pango manual for complete documentation] of available
183 /// tags, `parse_markup()`)
184 ///
185 /// The markup passed to [`set_markup()`][Self::set_markup()] must be valid XML; for example,
186 /// literal `<`, `>` and `&` characters must be escaped as `<`, `>`, and `&`.
187 /// If you pass text obtained from the user, file, or a network to
188 /// [`set_markup()`][Self::set_markup()], you’ll want to escape it with
189 /// `markup_escape_text()` or `markup_printf_escaped()`.
190 ///
191 /// Markup strings are just a convenient way to set the [`pango::AttrList`][crate::pango::AttrList]
192 /// on a label; [`set_attributes()`][Self::set_attributes()] may be a simpler way to set
193 /// attributes in some cases. Be careful though; [`pango::AttrList`][crate::pango::AttrList] tends
194 /// to cause internationalization problems, unless you’re applying attributes
195 /// to the entire string (i.e. unless you set the range of each attribute
196 /// to [0, `G_MAXINT`)). The reason is that specifying the `start_index` and
197 /// `end_index` for a `Pango::Attribute` requires knowledge of the exact
198 /// string being displayed, so translations will cause problems.
199 ///
200 /// ## Selectable labels
201 ///
202 /// Labels can be made selectable with [`set_selectable()`][Self::set_selectable()].
203 /// Selectable labels allow the user to copy the label contents to the
204 /// clipboard. Only labels that contain useful-to-copy information — such
205 /// as error messages — should be made selectable.
206 ///
207 /// ## Text layout
208 ///
209 /// A label can contain any number of paragraphs, but will have
210 /// performance problems if it contains more than a small number.
211 /// Paragraphs are separated by newlines or other paragraph separators
212 /// understood by Pango.
213 ///
214 /// Labels can automatically wrap text if you call [`set_wrap()`][Self::set_wrap()].
215 ///
216 /// [`set_justify()`][Self::set_justify()] sets how the lines in a label align
217 /// with one another. If you want to set how the label as a whole aligns
218 /// in its available space, see the [`halign`][struct@crate::Widget#halign] and
219 /// [`valign`][struct@crate::Widget#valign] properties.
220 ///
221 /// The [`width-chars`][struct@crate::Label#width-chars] and [`max-width-chars`][struct@crate::Label#max-width-chars]
222 /// properties can be used to control the size allocation of ellipsized or
223 /// wrapped labels. For ellipsizing labels, if either is specified (and less
224 /// than the actual text size), it is used as the minimum width, and the actual
225 /// text size is used as the natural width of the label. For wrapping labels,
226 /// width-chars is used as the minimum width, if specified, and max-width-chars
227 /// is used as the natural width. Even if max-width-chars specified, wrapping
228 /// labels will be rewrapped to use all of the available width.
229 ///
230 /// ## Links
231 ///
232 /// GTK supports markup for clickable hyperlinks in addition to regular Pango
233 /// markup. The markup for links is borrowed from HTML, using the `<a>` tag
234 /// with “href“, “title“ and “class“ attributes. GTK renders links similar to
235 /// the way they appear in web browsers, with colored, underlined text. The
236 /// “title“ attribute is displayed as a tooltip on the link. The “class“
237 /// attribute is used as style class on the CSS node for the link.
238 ///
239 /// An example of inline links looks like this:
240 ///
241 /// **⚠️ The following code is in c ⚠️**
242 ///
243 /// ```c
244 /// const char *text =
245 /// "Go to the "
246 /// "<a href=\"https://www.gtk.org\" title=\"<i>Our</i> website\">"
247 /// "GTK website</a> for more...";
248 /// GtkWidget *label = gtk_label_new (NULL);
249 /// gtk_label_set_markup (GTK_LABEL (label), text);
250 /// ```
251 ///
252 /// It is possible to implement custom handling for links and their tooltips
253 /// with the [`activate-link`][struct@crate::Label#activate-link] signal and the
254 /// [`current_uri()`][Self::current_uri()] function.
255 ///
256 /// ## Properties
257 ///
258 ///
259 /// #### `attributes`
260 /// A list of style attributes to apply to the text of the label.
261 ///
262 /// Readable | Writeable
263 ///
264 ///
265 /// #### `ellipsize`
266 /// The preferred place to ellipsize the string, if the label does
267 /// not have enough room to display the entire string.
268 ///
269 /// Note that setting this property to a value other than
270 /// [enum.Pango.EllipsizeMode.none] has the side-effect that the label requests
271 /// only enough space to display the ellipsis "...". In particular, this
272 /// means that ellipsizing labels do not work well in notebook tabs, unless
273 /// the [`tab-expand`][struct@crate::NotebookPage#tab-expand] child property is set to true.
274 ///
275 /// Other ways to set a label's width are [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()]
276 /// and [`Label::set_width_chars()`][crate::Label::set_width_chars()].
277 ///
278 /// Readable | Writeable
279 ///
280 ///
281 /// #### `extra-menu`
282 /// A menu model whose contents will be appended to the context menu.
283 ///
284 /// Readable | Writeable
285 ///
286 ///
287 /// #### `justify`
288 /// The alignment of the lines in the text of the label, relative to each other.
289 ///
290 /// This does *not* affect the alignment of the label within its allocation.
291 /// See [`xalign`][struct@crate::Label#xalign] for that.
292 ///
293 /// Readable | Writeable
294 ///
295 ///
296 /// #### `label`
297 /// The contents of the label.
298 ///
299 /// If the string contains Pango markup (see `parse_markup()`),
300 /// you will have to set the [`use-markup`][struct@crate::Label#use-markup] property to
301 /// true in order for the label to display the markup attributes. See also
302 /// [`Label::set_markup()`][crate::Label::set_markup()] for a convenience function that sets both
303 /// this property and the [`use-markup`][struct@crate::Label#use-markup] property at the
304 /// same time.
305 ///
306 /// If the string contains underlines acting as mnemonics, you will have to
307 /// set the [`use-underline`][struct@crate::Label#use-underline] property to true in order
308 /// for the label to display them.
309 ///
310 /// Readable | Writeable
311 ///
312 ///
313 /// #### `lines`
314 /// The number of lines to which an ellipsized, wrapping label
315 /// should display before it gets ellipsized. This both prevents the label
316 /// from ellipsizing before this many lines are displayed, and limits the
317 /// height request of the label to this many lines.
318 ///
319 /// ::: warning
320 /// Setting this property has unintuitive and unfortunate consequences
321 /// for the minimum _width_ of the label. Specifically, if the height
322 /// of the label is such that it fits a smaller number of lines than
323 /// the value of this property, the label can not be ellipsized at all,
324 /// which means it must be wide enough to fit all the text fully.
325 ///
326 /// This property has no effect if the label is not wrapping or ellipsized.
327 ///
328 /// Set this property to -1 if you don't want to limit the number of lines.
329 ///
330 /// Readable | Writeable
331 ///
332 ///
333 /// #### `max-width-chars`
334 /// The desired maximum width of the label, in characters.
335 ///
336 /// If this property is set to -1, the width will be calculated automatically.
337 ///
338 /// See the section on [text layout](class.Label.html#text-layout) for details
339 /// of how [`width-chars`][struct@crate::Label#width-chars] and [`max-width-chars`][struct@crate::Label#max-width-chars]
340 /// determine the width of ellipsized and wrapped labels.
341 ///
342 /// Readable | Writeable
343 ///
344 ///
345 /// #### `mnemonic-keyval`
346 /// The mnemonic accelerator key for the label.
347 ///
348 /// Readable
349 ///
350 ///
351 /// #### `mnemonic-widget`
352 /// The widget to be activated when the labels mnemonic key is pressed.
353 ///
354 /// Readable | Writeable
355 ///
356 ///
357 /// #### `natural-wrap-mode`
358 /// Select the line wrapping for the natural size request.
359 ///
360 /// This only affects the natural size requested. For the actual wrapping
361 /// used, see the [`wrap-mode`][struct@crate::Label#wrap-mode] property.
362 ///
363 /// The default is [enum@Gtk.NaturalWrapMode.inherit], which inherits
364 /// the behavior of the [`wrap-mode`][struct@crate::Label#wrap-mode] property.
365 ///
366 /// Readable | Writeable
367 ///
368 ///
369 /// #### `selectable`
370 /// Whether the label text can be selected with the mouse.
371 ///
372 /// Readable | Writeable
373 ///
374 ///
375 /// #### `single-line-mode`
376 /// Whether the label is in single line mode.
377 ///
378 /// In single line mode, the height of the label does not depend on the
379 /// actual text, it is always set to ascent + descent of the font. This
380 /// can be an advantage in situations where resizing the label because
381 /// of text changes would be distracting, e.g. in a statusbar.
382 ///
383 /// Readable | Writeable
384 ///
385 ///
386 /// #### `tabs`
387 /// Custom tabs for this label.
388 ///
389 /// Readable | Writeable
390 ///
391 ///
392 /// #### `use-markup`
393 /// True if the text of the label includes Pango markup.
394 ///
395 /// See `parse_markup()`.
396 ///
397 /// Readable | Writeable
398 ///
399 ///
400 /// #### `use-underline`
401 /// True if the text of the label indicates a mnemonic with an `_`
402 /// before the mnemonic character.
403 ///
404 /// Readable | Writeable
405 ///
406 ///
407 /// #### `width-chars`
408 /// The desired width of the label, in characters.
409 ///
410 /// If this property is set to -1, the width will be calculated automatically.
411 ///
412 /// See the section on [text layout](class.Label.html#text-layout) for details
413 /// of how [`width-chars`][struct@crate::Label#width-chars] and [`max-width-chars`][struct@crate::Label#max-width-chars]
414 /// determine the width of ellipsized and wrapped labels.
415 ///
416 /// Readable | Writeable
417 ///
418 ///
419 /// #### `wrap`
420 /// True if the label text will wrap if it gets too wide.
421 ///
422 /// Readable | Writeable
423 ///
424 ///
425 /// #### `wrap-mode`
426 /// Controls how the line wrapping is done.
427 ///
428 /// This only affects the formatting if line wrapping is on (see the
429 /// [`wrap`][struct@crate::Label#wrap] property). The default is [enum@Pango.WrapMode.word],
430 /// which means wrap on word boundaries.
431 ///
432 /// For sizing behavior, also consider the [`natural-wrap-mode`][struct@crate::Label#natural-wrap-mode]
433 /// property.
434 ///
435 /// Readable | Writeable
436 ///
437 ///
438 /// #### `xalign`
439 /// The horizontal alignment of the label text inside its size allocation.
440 ///
441 /// Compare this to [`halign`][struct@crate::Widget#halign], which determines how the
442 /// labels size allocation is positioned in the space available for the label.
443 ///
444 /// Readable | Writeable
445 ///
446 ///
447 /// #### `yalign`
448 /// The vertical alignment of the label text inside its size allocation.
449 ///
450 /// Compare this to [`valign`][struct@crate::Widget#valign], which determines how the
451 /// labels size allocation is positioned in the space available for the label.
452 ///
453 /// Readable | Writeable
454 /// <details><summary><h4>Widget</h4></summary>
455 ///
456 ///
457 /// #### `can-focus`
458 /// Whether the widget or any of its descendents can accept
459 /// the input focus.
460 ///
461 /// This property is meant to be set by widget implementations,
462 /// typically in their instance init function.
463 ///
464 /// Readable | Writeable
465 ///
466 ///
467 /// #### `can-target`
468 /// Whether the widget can receive pointer events.
469 ///
470 /// Readable | Writeable
471 ///
472 ///
473 /// #### `css-classes`
474 /// A list of css classes applied to this widget.
475 ///
476 /// Readable | Writeable
477 ///
478 ///
479 /// #### `css-name`
480 /// The name of this widget in the CSS tree.
481 ///
482 /// This property is meant to be set by widget implementations,
483 /// typically in their instance init function.
484 ///
485 /// Readable | Writeable | Construct Only
486 ///
487 ///
488 /// #### `cursor`
489 /// The cursor used by @widget.
490 ///
491 /// Readable | Writeable
492 ///
493 ///
494 /// #### `focus-on-click`
495 /// Whether the widget should grab focus when it is clicked with the mouse.
496 ///
497 /// This property is only relevant for widgets that can take focus.
498 ///
499 /// Readable | Writeable
500 ///
501 ///
502 /// #### `focusable`
503 /// Whether this widget itself will accept the input focus.
504 ///
505 /// Readable | Writeable
506 ///
507 ///
508 /// #### `halign`
509 /// How to distribute horizontal space if widget gets extra space.
510 ///
511 /// Readable | Writeable
512 ///
513 ///
514 /// #### `has-default`
515 /// Whether the widget is the default widget.
516 ///
517 /// Readable
518 ///
519 ///
520 /// #### `has-focus`
521 /// Whether the widget has the input focus.
522 ///
523 /// Readable
524 ///
525 ///
526 /// #### `has-tooltip`
527 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
528 /// signal on @widget.
529 ///
530 /// A true value indicates that @widget can have a tooltip, in this case
531 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
532 /// determine whether it will provide a tooltip or not.
533 ///
534 /// Readable | Writeable
535 ///
536 ///
537 /// #### `height-request`
538 /// Overrides for height request of the widget.
539 ///
540 /// If this is -1, the natural request will be used.
541 ///
542 /// Readable | Writeable
543 ///
544 ///
545 /// #### `hexpand`
546 /// Whether to expand horizontally.
547 ///
548 /// Readable | Writeable
549 ///
550 ///
551 /// #### `hexpand-set`
552 /// Whether to use the `hexpand` property.
553 ///
554 /// Readable | Writeable
555 ///
556 ///
557 /// #### `layout-manager`
558 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
559 /// the preferred size of the widget, and allocate its children.
560 ///
561 /// This property is meant to be set by widget implementations,
562 /// typically in their instance init function.
563 ///
564 /// Readable | Writeable
565 ///
566 ///
567 /// #### `limit-events`
568 /// Makes this widget act like a modal dialog, with respect to
569 /// event delivery.
570 ///
571 /// Global event controllers will not handle events with targets
572 /// inside the widget, unless they are set up to ignore propagation
573 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
574 ///
575 /// Readable | Writeable
576 ///
577 ///
578 /// #### `margin-bottom`
579 /// Margin on bottom side of widget.
580 ///
581 /// This property adds margin outside of the widget's normal size
582 /// request, the margin will be added in addition to the size from
583 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
584 ///
585 /// Readable | Writeable
586 ///
587 ///
588 /// #### `margin-end`
589 /// Margin on end of widget, horizontally.
590 ///
591 /// This property supports left-to-right and right-to-left text
592 /// directions.
593 ///
594 /// This property adds margin outside of the widget's normal size
595 /// request, the margin will be added in addition to the size from
596 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
597 ///
598 /// Readable | Writeable
599 ///
600 ///
601 /// #### `margin-start`
602 /// Margin on start of widget, horizontally.
603 ///
604 /// This property supports left-to-right and right-to-left text
605 /// directions.
606 ///
607 /// This property adds margin outside of the widget's normal size
608 /// request, the margin will be added in addition to the size from
609 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
610 ///
611 /// Readable | Writeable
612 ///
613 ///
614 /// #### `margin-top`
615 /// Margin on top side of widget.
616 ///
617 /// This property adds margin outside of the widget's normal size
618 /// request, the margin will be added in addition to the size from
619 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
620 ///
621 /// Readable | Writeable
622 ///
623 ///
624 /// #### `name`
625 /// The name of the widget.
626 ///
627 /// Readable | Writeable
628 ///
629 ///
630 /// #### `opacity`
631 /// The requested opacity of the widget.
632 ///
633 /// Readable | Writeable
634 ///
635 ///
636 /// #### `overflow`
637 /// How content outside the widget's content area is treated.
638 ///
639 /// This property is meant to be set by widget implementations,
640 /// typically in their instance init function.
641 ///
642 /// Readable | Writeable
643 ///
644 ///
645 /// #### `parent`
646 /// The parent widget of this widget.
647 ///
648 /// Readable
649 ///
650 ///
651 /// #### `receives-default`
652 /// Whether the widget will receive the default action when it is focused.
653 ///
654 /// Readable | Writeable
655 ///
656 ///
657 /// #### `root`
658 /// The [`Root`][crate::Root] widget of the widget tree containing this widget.
659 ///
660 /// This will be `NULL` if the widget is not contained in a root widget.
661 ///
662 /// Readable
663 ///
664 ///
665 /// #### `scale-factor`
666 /// The scale factor of the widget.
667 ///
668 /// Readable
669 ///
670 ///
671 /// #### `sensitive`
672 /// Whether the widget responds to input.
673 ///
674 /// Readable | Writeable
675 ///
676 ///
677 /// #### `tooltip-markup`
678 /// Sets the text of tooltip to be the given string, which is marked up
679 /// with Pango markup.
680 ///
681 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
682 ///
683 /// This is a convenience property which will take care of getting the
684 /// tooltip shown if the given string is not `NULL`:
685 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
686 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
687 /// the default signal handler.
688 ///
689 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
690 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
691 ///
692 /// Readable | Writeable
693 ///
694 ///
695 /// #### `tooltip-text`
696 /// Sets the text of tooltip to be the given string.
697 ///
698 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
699 ///
700 /// This is a convenience property which will take care of getting the
701 /// tooltip shown if the given string is not `NULL`:
702 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
703 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
704 /// the default signal handler.
705 ///
706 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
707 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
708 ///
709 /// Readable | Writeable
710 ///
711 ///
712 /// #### `valign`
713 /// How to distribute vertical space if widget gets extra space.
714 ///
715 /// Readable | Writeable
716 ///
717 ///
718 /// #### `vexpand`
719 /// Whether to expand vertically.
720 ///
721 /// Readable | Writeable
722 ///
723 ///
724 /// #### `vexpand-set`
725 /// Whether to use the `vexpand` property.
726 ///
727 /// Readable | Writeable
728 ///
729 ///
730 /// #### `visible`
731 /// Whether the widget is visible.
732 ///
733 /// Readable | Writeable
734 ///
735 ///
736 /// #### `width-request`
737 /// Overrides for width request of the widget.
738 ///
739 /// If this is -1, the natural request will be used.
740 ///
741 /// Readable | Writeable
742 /// </details>
743 /// <details><summary><h4>Accessible</h4></summary>
744 ///
745 ///
746 /// #### `accessible-role`
747 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
748 ///
749 /// The accessible role cannot be changed once set.
750 ///
751 /// Readable | Writeable
752 /// </details>
753 ///
754 /// ## Signals
755 ///
756 ///
757 /// #### `activate-current-link`
758 /// Gets emitted when the user activates a link in the label.
759 ///
760 /// The `::activate-current-link` is a [keybinding signal](class.SignalAction.html).
761 ///
762 /// Applications may also emit the signal with g_signal_emit_by_name()
763 /// if they need to control activation of URIs programmatically.
764 ///
765 /// The default bindings for this signal are all forms of the <kbd>Enter</kbd> key.
766 ///
767 /// Action
768 ///
769 ///
770 /// #### `activate-link`
771 /// Gets emitted to activate a URI.
772 ///
773 /// Applications may connect to it to override the default behaviour,
774 /// which is to call [`FileLauncher::launch()`][crate::FileLauncher::launch()].
775 ///
776 ///
777 ///
778 ///
779 /// #### `copy-clipboard`
780 /// Gets emitted to copy the selection to the clipboard.
781 ///
782 /// The `::copy-clipboard` signal is a [keybinding signal](class.SignalAction.html).
783 ///
784 /// The default binding for this signal is <kbd>Ctrl</kbd>+<kbd>c</kbd>.
785 ///
786 /// Action
787 ///
788 ///
789 /// #### `move-cursor`
790 /// Gets emitted when the user initiates a cursor movement.
791 ///
792 /// The `::move-cursor` signal is a [keybinding signal](class.SignalAction.html).
793 /// If the cursor is not visible in @entry, this signal causes the viewport to
794 /// be moved instead.
795 ///
796 /// Applications should not connect to it, but may emit it with
797 /// `signal_emit_by_name()` if they need to control
798 /// the cursor programmatically.
799 ///
800 /// The default bindings for this signal come in two variants, the
801 /// variant with the <kbd>Shift</kbd> modifier extends the selection,
802 /// the variant without the <kbd>Shift</kbd> modifier does not.
803 /// There are too many key combinations to list them all here.
804 ///
805 /// - <kbd>←</kbd>, <kbd>→</kbd>, <kbd>↑</kbd>, <kbd>↓</kbd>
806 /// move by individual characters/lines
807 /// - <kbd>Ctrl</kbd>+<kbd>←</kbd>, etc. move by words/paragraphs
808 /// - <kbd>Home</kbd> and <kbd>End</kbd> move to the ends of the buffer
809 ///
810 /// Action
811 /// <details><summary><h4>Widget</h4></summary>
812 ///
813 ///
814 /// #### `destroy`
815 /// Signals that all holders of a reference to the widget should release
816 /// the reference that they hold.
817 ///
818 /// May result in finalization of the widget if all references are released.
819 ///
820 /// This signal is not suitable for saving widget state.
821 ///
822 ///
823 ///
824 ///
825 /// #### `direction-changed`
826 /// Emitted when the text direction of a widget changes.
827 ///
828 ///
829 ///
830 ///
831 /// #### `hide`
832 /// Emitted when @widget is hidden.
833 ///
834 ///
835 ///
836 ///
837 /// #### `keynav-failed`
838 /// Emitted if keyboard navigation fails.
839 ///
840 /// See [`WidgetExt::keynav_failed()`][crate::prelude::WidgetExt::keynav_failed()] for details.
841 ///
842 ///
843 ///
844 ///
845 /// #### `map`
846 /// Emitted when @widget is going to be mapped.
847 ///
848 /// A widget is mapped when the widget is visible (which is controlled with
849 /// [`visible`][struct@crate::Widget#visible]) and all its parents up to the toplevel widget
850 /// are also visible.
851 ///
852 /// The `::map` signal can be used to determine whether a widget will be drawn,
853 /// for instance it can resume an animation that was stopped during the
854 /// emission of [`unmap`][struct@crate::Widget#unmap].
855 ///
856 ///
857 ///
858 ///
859 /// #### `mnemonic-activate`
860 /// Emitted when a widget is activated via a mnemonic.
861 ///
862 /// The default handler for this signal activates @widget if @group_cycling
863 /// is false, or just makes @widget grab focus if @group_cycling is true.
864 ///
865 ///
866 ///
867 ///
868 /// #### `move-focus`
869 /// Emitted when the focus is moved.
870 ///
871 /// The `::move-focus` signal is a [keybinding signal](class.SignalAction.html).
872 ///
873 /// The default bindings for this signal are <kbd>Tab</kbd> to move forward,
874 /// and <kbd>Shift</kbd>+<kbd>Tab</kbd> to move backward.
875 ///
876 /// Action
877 ///
878 ///
879 /// #### `query-tooltip`
880 /// Emitted when the widget’s tooltip is about to be shown.
881 ///
882 /// This happens when the [`has-tooltip`][struct@crate::Widget#has-tooltip] property
883 /// is true and the hover timeout has expired with the cursor hovering
884 /// above @widget; or emitted when @widget got focus in keyboard mode.
885 ///
886 /// Using the given coordinates, the signal handler should determine
887 /// whether a tooltip should be shown for @widget. If this is the case
888 /// true should be returned, false otherwise. Note that if @keyboard_mode
889 /// is true, the values of @x and @y are undefined and should not be used.
890 ///
891 /// The signal handler is free to manipulate @tooltip with the therefore
892 /// destined function calls.
893 ///
894 ///
895 ///
896 ///
897 /// #### `realize`
898 /// Emitted when @widget is associated with a [`gdk::Surface`][crate::gdk::Surface].
899 ///
900 /// This means that [`WidgetExt::realize()`][crate::prelude::WidgetExt::realize()] has been called
901 /// or the widget has been mapped (that is, it is going to be drawn).
902 ///
903 ///
904 ///
905 ///
906 /// #### `show`
907 /// Emitted when @widget is shown.
908 ///
909 ///
910 ///
911 ///
912 /// #### `state-flags-changed`
913 /// Emitted when the widget state changes.
914 ///
915 /// See [`WidgetExt::state_flags()`][crate::prelude::WidgetExt::state_flags()].
916 ///
917 ///
918 ///
919 ///
920 /// #### `unmap`
921 /// Emitted when @widget is going to be unmapped.
922 ///
923 /// A widget is unmapped when either it or any of its parents up to the
924 /// toplevel widget have been set as hidden.
925 ///
926 /// As `::unmap` indicates that a widget will not be shown any longer,
927 /// it can be used to, for example, stop an animation on the widget.
928 ///
929 ///
930 ///
931 ///
932 /// #### `unrealize`
933 /// Emitted when the [`gdk::Surface`][crate::gdk::Surface] associated with @widget is destroyed.
934 ///
935 /// This means that [`WidgetExt::unrealize()`][crate::prelude::WidgetExt::unrealize()] has been called
936 /// or the widget has been unmapped (that is, it is going to be hidden).
937 ///
938 ///
939 /// </details>
940 ///
941 /// # Implements
942 ///
943 /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`AccessibleHypertextExt`][trait@crate::prelude::AccessibleHypertextExt], [`AccessibleTextExt`][trait@crate::prelude::AccessibleTextExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
944 #[doc(alias = "GtkLabel")]
945 pub struct Label(Object<ffi::GtkLabel>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, AccessibleHypertext, AccessibleText;
946
947 match fn {
948 type_ => || ffi::gtk_label_get_type(),
949 }
950}
951
952#[cfg(not(any(feature = "v4_22")))]
953#[cfg(feature = "v4_14")]
954glib::wrapper! {
955 #[doc(alias = "GtkLabel")]
956 pub struct Label(Object<ffi::GtkLabel>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, AccessibleText;
957
958 match fn {
959 type_ => || ffi::gtk_label_get_type(),
960 }
961}
962
963#[cfg(not(any(feature = "v4_14")))]
964glib::wrapper! {
965 #[doc(alias = "GtkLabel")]
966 pub struct Label(Object<ffi::GtkLabel>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
967
968 match fn {
969 type_ => || ffi::gtk_label_get_type(),
970 }
971}
972
973impl Label {
974 /// Creates a new label with the given text inside it.
975 ///
976 /// You can pass `NULL` to get an empty label widget.
977 /// ## `str`
978 /// the text of the label
979 ///
980 /// # Returns
981 ///
982 /// the new label
983 #[doc(alias = "gtk_label_new")]
984 pub fn new(str: Option<&str>) -> Label {
985 assert_initialized_main_thread!();
986 unsafe { Widget::from_glib_none(ffi::gtk_label_new(str.to_glib_none().0)).unsafe_cast() }
987 }
988
989 /// Creates a new label with the given text inside it, and a mnemonic.
990 ///
991 /// If characters in @str are preceded by an underscore, they are
992 /// underlined. If you need a literal underscore character in a label, use
993 /// '__' (two underscores). The first underlined character represents a
994 /// keyboard accelerator called a mnemonic. The mnemonic key can be used
995 /// to activate another widget, chosen automatically, or explicitly using
996 /// [`set_mnemonic_widget()`][Self::set_mnemonic_widget()].
997 ///
998 /// If [`set_mnemonic_widget()`][Self::set_mnemonic_widget()] is not called, then the first
999 /// activatable ancestor of the label will be chosen as the mnemonic
1000 /// widget. For instance, if the label is inside a button or menu item,
1001 /// the button or menu item will automatically become the mnemonic widget
1002 /// and be activated by the mnemonic.
1003 /// ## `str`
1004 /// the text of the label, with an underscore in front of the
1005 /// mnemonic character
1006 ///
1007 /// # Returns
1008 ///
1009 /// the new label
1010 #[doc(alias = "gtk_label_new_with_mnemonic")]
1011 #[doc(alias = "new_with_mnemonic")]
1012 pub fn with_mnemonic(str: &str) -> Label {
1013 assert_initialized_main_thread!();
1014 unsafe {
1015 Widget::from_glib_none(ffi::gtk_label_new_with_mnemonic(str.to_glib_none().0))
1016 .unsafe_cast()
1017 }
1018 }
1019
1020 // rustdoc-stripper-ignore-next
1021 /// Creates a new builder-pattern struct instance to construct [`Label`] objects.
1022 ///
1023 /// This method returns an instance of [`LabelBuilder`](crate::builders::LabelBuilder) which can be used to create [`Label`] objects.
1024 pub fn builder() -> LabelBuilder {
1025 LabelBuilder::new()
1026 }
1027
1028 /// Gets the label's attribute list.
1029 ///
1030 /// This is the [`pango::AttrList`][crate::pango::AttrList] that was set on the label using
1031 /// [`set_attributes()`][Self::set_attributes()], if any. This function does not
1032 /// reflect attributes that come from the label's markup (see
1033 /// [`set_markup()`][Self::set_markup()]). If you want to get the effective
1034 /// attributes for the label, use
1035 /// `pango_layout_get_attributes (gtk_label_get_layout (self))`.
1036 ///
1037 /// # Returns
1038 ///
1039 /// the attribute list
1040 #[doc(alias = "gtk_label_get_attributes")]
1041 #[doc(alias = "get_attributes")]
1042 pub fn attributes(&self) -> Option<pango::AttrList> {
1043 unsafe { from_glib_none(ffi::gtk_label_get_attributes(self.to_glib_none().0)) }
1044 }
1045
1046 /// Returns the URI for the active link in the label.
1047 ///
1048 /// The active link is the one under the mouse pointer or, in a
1049 /// selectable label, the link in which the text cursor is currently
1050 /// positioned.
1051 ///
1052 /// This function is intended for use in a [`activate-link`][struct@crate::Label#activate-link]
1053 /// handler or for use in a [`query-tooltip`][struct@crate::Widget#query-tooltip] handler.
1054 ///
1055 /// # Returns
1056 ///
1057 /// the active URI
1058 #[doc(alias = "gtk_label_get_current_uri")]
1059 #[doc(alias = "get_current_uri")]
1060 pub fn current_uri(&self) -> Option<glib::GString> {
1061 unsafe { from_glib_none(ffi::gtk_label_get_current_uri(self.to_glib_none().0)) }
1062 }
1063
1064 /// Returns the ellipsization mode of the label.
1065 ///
1066 /// See [`set_ellipsize()`][Self::set_ellipsize()].
1067 ///
1068 /// # Returns
1069 ///
1070 /// the ellipsization mode
1071 #[doc(alias = "gtk_label_get_ellipsize")]
1072 #[doc(alias = "get_ellipsize")]
1073 pub fn ellipsize(&self) -> pango::EllipsizeMode {
1074 unsafe { from_glib(ffi::gtk_label_get_ellipsize(self.to_glib_none().0)) }
1075 }
1076
1077 /// Gets the extra menu model of the label.
1078 ///
1079 /// See [`set_extra_menu()`][Self::set_extra_menu()].
1080 ///
1081 /// # Returns
1082 ///
1083 /// the menu model
1084 #[doc(alias = "gtk_label_get_extra_menu")]
1085 #[doc(alias = "get_extra_menu")]
1086 #[doc(alias = "extra-menu")]
1087 pub fn extra_menu(&self) -> Option<gio::MenuModel> {
1088 unsafe { from_glib_none(ffi::gtk_label_get_extra_menu(self.to_glib_none().0)) }
1089 }
1090
1091 /// Returns the justification of the label.
1092 ///
1093 /// See [`set_justify()`][Self::set_justify()].
1094 ///
1095 /// # Returns
1096 ///
1097 /// the justification value
1098 #[doc(alias = "gtk_label_get_justify")]
1099 #[doc(alias = "get_justify")]
1100 pub fn justify(&self) -> Justification {
1101 unsafe { from_glib(ffi::gtk_label_get_justify(self.to_glib_none().0)) }
1102 }
1103
1104 /// Fetches the text from a label.
1105 ///
1106 /// The returned text includes any embedded underlines indicating
1107 /// mnemonics and Pango markup. (See [`text()`][Self::text()]).
1108 ///
1109 /// # Returns
1110 ///
1111 /// the text of the label widget
1112 #[doc(alias = "gtk_label_get_label")]
1113 #[doc(alias = "get_label")]
1114 pub fn label(&self) -> glib::GString {
1115 unsafe { from_glib_none(ffi::gtk_label_get_label(self.to_glib_none().0)) }
1116 }
1117
1118 /// Gets the Pango layout used to display the label.
1119 ///
1120 /// The layout is useful to e.g. convert text positions to pixel
1121 /// positions, in combination with [`layout_offsets()`][Self::layout_offsets()].
1122 /// The returned layout is owned by the @label so need not be
1123 /// freed by the caller. The @label is free to recreate its layout
1124 /// at any time, so it should be considered read-only.
1125 ///
1126 /// # Returns
1127 ///
1128 /// the [`pango::Layout`][crate::pango::Layout] for this label
1129 #[doc(alias = "gtk_label_get_layout")]
1130 #[doc(alias = "get_layout")]
1131 pub fn layout(&self) -> pango::Layout {
1132 unsafe { from_glib_none(ffi::gtk_label_get_layout(self.to_glib_none().0)) }
1133 }
1134
1135 /// Obtains the coordinates where the label will draw its Pango layout.
1136 ///
1137 /// The coordinates are useful to convert mouse events into coordinates
1138 /// inside the [`pango::Layout`][crate::pango::Layout], e.g. to take some action if some part
1139 /// of the label is clicked. Remember when using the [`pango::Layout`][crate::pango::Layout]
1140 /// functions you need to convert to and from pixels using `PANGO_PIXELS()`
1141 /// or `Pango::SCALE`.
1142 ///
1143 /// # Returns
1144 ///
1145 ///
1146 /// ## `x`
1147 /// location to store X offset of layout
1148 ///
1149 /// ## `y`
1150 /// location to store Y offset of layout
1151 #[doc(alias = "gtk_label_get_layout_offsets")]
1152 #[doc(alias = "get_layout_offsets")]
1153 pub fn layout_offsets(&self) -> (i32, i32) {
1154 unsafe {
1155 let mut x = std::mem::MaybeUninit::uninit();
1156 let mut y = std::mem::MaybeUninit::uninit();
1157 ffi::gtk_label_get_layout_offsets(
1158 self.to_glib_none().0,
1159 x.as_mut_ptr(),
1160 y.as_mut_ptr(),
1161 );
1162 (x.assume_init(), y.assume_init())
1163 }
1164 }
1165
1166 /// Gets the number of lines to which an ellipsized, wrapping
1167 /// label should be limited.
1168 ///
1169 /// See [`set_lines()`][Self::set_lines()].
1170 ///
1171 /// # Returns
1172 ///
1173 /// the number of lines
1174 #[doc(alias = "gtk_label_get_lines")]
1175 #[doc(alias = "get_lines")]
1176 pub fn lines(&self) -> i32 {
1177 unsafe { ffi::gtk_label_get_lines(self.to_glib_none().0) }
1178 }
1179
1180 /// Retrieves the maximum width of the label in characters.
1181 ///
1182 /// See [`set_width_chars()`][Self::set_width_chars()].
1183 ///
1184 /// # Returns
1185 ///
1186 /// the maximum width of the label, in characters
1187 #[doc(alias = "gtk_label_get_max_width_chars")]
1188 #[doc(alias = "get_max_width_chars")]
1189 #[doc(alias = "max-width-chars")]
1190 pub fn max_width_chars(&self) -> i32 {
1191 unsafe { ffi::gtk_label_get_max_width_chars(self.to_glib_none().0) }
1192 }
1193
1194 /// Retrieves the mnemonic target of this label.
1195 ///
1196 /// See [`set_mnemonic_widget()`][Self::set_mnemonic_widget()].
1197 ///
1198 /// # Returns
1199 ///
1200 /// the target of the label’s mnemonic,
1201 /// or `NULL` if none has been set and the default algorithm will be used.
1202 #[doc(alias = "gtk_label_get_mnemonic_widget")]
1203 #[doc(alias = "get_mnemonic_widget")]
1204 #[doc(alias = "mnemonic-widget")]
1205 pub fn mnemonic_widget(&self) -> Option<Widget> {
1206 unsafe { from_glib_none(ffi::gtk_label_get_mnemonic_widget(self.to_glib_none().0)) }
1207 }
1208
1209 /// Returns natural line wrap mode used by the label.
1210 ///
1211 /// See [`set_natural_wrap_mode()`][Self::set_natural_wrap_mode()].
1212 ///
1213 /// # Returns
1214 ///
1215 /// the natural line wrap mode
1216 #[cfg(feature = "v4_6")]
1217 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
1218 #[doc(alias = "gtk_label_get_natural_wrap_mode")]
1219 #[doc(alias = "get_natural_wrap_mode")]
1220 #[doc(alias = "natural-wrap-mode")]
1221 pub fn natural_wrap_mode(&self) -> NaturalWrapMode {
1222 unsafe { from_glib(ffi::gtk_label_get_natural_wrap_mode(self.to_glib_none().0)) }
1223 }
1224
1225 /// Returns whether the label is selectable.
1226 ///
1227 /// # Returns
1228 ///
1229 /// true if the user can copy text from the label
1230 #[doc(alias = "gtk_label_get_selectable")]
1231 #[doc(alias = "get_selectable")]
1232 #[doc(alias = "selectable")]
1233 pub fn is_selectable(&self) -> bool {
1234 unsafe { from_glib(ffi::gtk_label_get_selectable(self.to_glib_none().0)) }
1235 }
1236
1237 /// Gets the selected range of characters in the label.
1238 ///
1239 /// The returned @start and @end positions are in characters.
1240 ///
1241 /// # Returns
1242 ///
1243 /// true if selection is non-empty
1244 ///
1245 /// ## `start`
1246 /// return location for start of selection
1247 ///
1248 /// ## `end`
1249 /// return location for end of selection
1250 #[doc(alias = "gtk_label_get_selection_bounds")]
1251 #[doc(alias = "get_selection_bounds")]
1252 pub fn selection_bounds(&self) -> Option<(i32, i32)> {
1253 unsafe {
1254 let mut start = std::mem::MaybeUninit::uninit();
1255 let mut end = std::mem::MaybeUninit::uninit();
1256 let ret = from_glib(ffi::gtk_label_get_selection_bounds(
1257 self.to_glib_none().0,
1258 start.as_mut_ptr(),
1259 end.as_mut_ptr(),
1260 ));
1261 if ret {
1262 Some((start.assume_init(), end.assume_init()))
1263 } else {
1264 None
1265 }
1266 }
1267 }
1268
1269 /// Returns whether the label is in single line mode.
1270 ///
1271 /// # Returns
1272 ///
1273 /// true if the label is in single line mode
1274 #[doc(alias = "gtk_label_get_single_line_mode")]
1275 #[doc(alias = "get_single_line_mode")]
1276 #[doc(alias = "single-line-mode")]
1277 pub fn is_single_line_mode(&self) -> bool {
1278 unsafe { from_glib(ffi::gtk_label_get_single_line_mode(self.to_glib_none().0)) }
1279 }
1280
1281 /// Gets the tab stops for the label.
1282 ///
1283 /// The returned array will be `NULL` if “standard” (8-space) tabs are used.
1284 ///
1285 /// # Returns
1286 ///
1287 /// copy of default tab array,
1288 /// or `NULL` if standard tabs are used
1289 #[cfg(feature = "v4_8")]
1290 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
1291 #[doc(alias = "gtk_label_get_tabs")]
1292 #[doc(alias = "get_tabs")]
1293 pub fn tabs(&self) -> Option<pango::TabArray> {
1294 unsafe { from_glib_full(ffi::gtk_label_get_tabs(self.to_glib_none().0)) }
1295 }
1296
1297 /// Gets the text of the label.
1298 ///
1299 /// The returned text is as it appears on screen. This does not include
1300 /// any embedded underlines indicating mnemonics or Pango markup. (See
1301 /// [`label()`][Self::label()])
1302 ///
1303 /// # Returns
1304 ///
1305 /// the text in the label widget
1306 #[doc(alias = "gtk_label_get_text")]
1307 #[doc(alias = "get_text")]
1308 pub fn text(&self) -> glib::GString {
1309 unsafe { from_glib_none(ffi::gtk_label_get_text(self.to_glib_none().0)) }
1310 }
1311
1312 /// Returns whether the label’s text is interpreted as Pango markup.
1313 ///
1314 /// See [`set_use_markup()`][Self::set_use_markup()].
1315 ///
1316 /// # Returns
1317 ///
1318 /// true if the label’s text will be parsed for markup
1319 #[doc(alias = "gtk_label_get_use_markup")]
1320 #[doc(alias = "get_use_markup")]
1321 #[doc(alias = "use-markup")]
1322 pub fn uses_markup(&self) -> bool {
1323 unsafe { from_glib(ffi::gtk_label_get_use_markup(self.to_glib_none().0)) }
1324 }
1325
1326 /// Returns whether underlines in the label indicate mnemonics.
1327 ///
1328 /// See [`set_use_underline()`][Self::set_use_underline()].
1329 ///
1330 /// # Returns
1331 ///
1332 /// true if underlines in the label indicate mnemonics
1333 #[doc(alias = "gtk_label_get_use_underline")]
1334 #[doc(alias = "get_use_underline")]
1335 #[doc(alias = "use-underline")]
1336 pub fn uses_underline(&self) -> bool {
1337 unsafe { from_glib(ffi::gtk_label_get_use_underline(self.to_glib_none().0)) }
1338 }
1339
1340 /// Retrieves the desired width of the label in characters.
1341 ///
1342 /// See [`set_width_chars()`][Self::set_width_chars()].
1343 ///
1344 /// # Returns
1345 ///
1346 /// the desired width of the label, in characters
1347 #[doc(alias = "gtk_label_get_width_chars")]
1348 #[doc(alias = "get_width_chars")]
1349 #[doc(alias = "width-chars")]
1350 pub fn width_chars(&self) -> i32 {
1351 unsafe { ffi::gtk_label_get_width_chars(self.to_glib_none().0) }
1352 }
1353
1354 /// Returns whether lines in the label are automatically wrapped.
1355 ///
1356 /// See [`set_wrap()`][Self::set_wrap()].
1357 ///
1358 /// # Returns
1359 ///
1360 /// true if the lines of the label are automatically wrapped
1361 #[doc(alias = "gtk_label_get_wrap")]
1362 #[doc(alias = "get_wrap")]
1363 #[doc(alias = "wrap")]
1364 pub fn wraps(&self) -> bool {
1365 unsafe { from_glib(ffi::gtk_label_get_wrap(self.to_glib_none().0)) }
1366 }
1367
1368 /// Returns line wrap mode used by the label.
1369 ///
1370 /// See [`set_wrap_mode()`][Self::set_wrap_mode()].
1371 ///
1372 /// # Returns
1373 ///
1374 /// the line wrap mode
1375 #[doc(alias = "gtk_label_get_wrap_mode")]
1376 #[doc(alias = "get_wrap_mode")]
1377 #[doc(alias = "wrap-mode")]
1378 pub fn wrap_mode(&self) -> pango::WrapMode {
1379 unsafe { from_glib(ffi::gtk_label_get_wrap_mode(self.to_glib_none().0)) }
1380 }
1381
1382 /// Gets the `xalign` of the label.
1383 ///
1384 /// See the [`xalign`][struct@crate::Label#xalign] property.
1385 ///
1386 /// # Returns
1387 ///
1388 /// the xalign value
1389 #[doc(alias = "gtk_label_get_xalign")]
1390 #[doc(alias = "get_xalign")]
1391 pub fn xalign(&self) -> f32 {
1392 unsafe { ffi::gtk_label_get_xalign(self.to_glib_none().0) }
1393 }
1394
1395 /// Gets the `yalign` of the label.
1396 ///
1397 /// See the [`yalign`][struct@crate::Label#yalign] property.
1398 ///
1399 /// # Returns
1400 ///
1401 /// the yalign value
1402 #[doc(alias = "gtk_label_get_yalign")]
1403 #[doc(alias = "get_yalign")]
1404 pub fn yalign(&self) -> f32 {
1405 unsafe { ffi::gtk_label_get_yalign(self.to_glib_none().0) }
1406 }
1407
1408 /// Selects a range of characters in the label, if the label is selectable.
1409 ///
1410 /// See [`set_selectable()`][Self::set_selectable()]. If the label is not selectable,
1411 /// this function has no effect. If @start_offset or
1412 /// @end_offset are -1, then the end of the label will be substituted.
1413 /// ## `start_offset`
1414 /// start offset, in characters
1415 /// ## `end_offset`
1416 /// end offset, in characters
1417 #[doc(alias = "gtk_label_select_region")]
1418 pub fn select_region(&self, start_offset: i32, end_offset: i32) {
1419 unsafe {
1420 ffi::gtk_label_select_region(self.to_glib_none().0, start_offset, end_offset);
1421 }
1422 }
1423
1424 /// Apply attributes to the label text.
1425 ///
1426 /// The attributes set with this function will be applied and merged with
1427 /// any other attributes previously effected by way of the
1428 /// [`use-underline`][struct@crate::Label#use-underline] or [`use-markup`][struct@crate::Label#use-markup]
1429 /// properties
1430 ///
1431 /// While it is not recommended to mix markup strings with manually set
1432 /// attributes, if you must; know that the attributes will be applied
1433 /// to the label after the markup string is parsed.
1434 /// ## `attrs`
1435 /// a list of style attributes
1436 #[doc(alias = "gtk_label_set_attributes")]
1437 #[doc(alias = "attributes")]
1438 pub fn set_attributes(&self, attrs: Option<&pango::AttrList>) {
1439 unsafe {
1440 ffi::gtk_label_set_attributes(self.to_glib_none().0, attrs.to_glib_none().0);
1441 }
1442 }
1443
1444 /// Sets the mode used to ellipsize the text.
1445 ///
1446 /// The text will be ellipsized if there is not
1447 /// enough space to render the entire string.
1448 /// ## `mode`
1449 /// the ellipsization mode
1450 #[doc(alias = "gtk_label_set_ellipsize")]
1451 #[doc(alias = "ellipsize")]
1452 pub fn set_ellipsize(&self, mode: pango::EllipsizeMode) {
1453 unsafe {
1454 ffi::gtk_label_set_ellipsize(self.to_glib_none().0, mode.into_glib());
1455 }
1456 }
1457
1458 /// Sets a menu model to add to the context menu of the label.
1459 /// ## `model`
1460 /// a menu model
1461 #[doc(alias = "gtk_label_set_extra_menu")]
1462 #[doc(alias = "extra-menu")]
1463 pub fn set_extra_menu(&self, model: Option<&impl IsA<gio::MenuModel>>) {
1464 unsafe {
1465 ffi::gtk_label_set_extra_menu(
1466 self.to_glib_none().0,
1467 model.map(|p| p.as_ref()).to_glib_none().0,
1468 );
1469 }
1470 }
1471
1472 /// Sets the alignment of lines in the label relative to each other.
1473 ///
1474 /// This function has no effect on labels containing only a single line.
1475 ///
1476 /// [enum@Gtk.Justification.left] is the default value when the widget
1477 /// is first created with [`new()`][Self::new()].
1478 ///
1479 /// If you instead want to set the alignment of the label as a whole,
1480 /// use [`WidgetExt::set_halign()`][crate::prelude::WidgetExt::set_halign()] instead.
1481 /// ## `jtype`
1482 /// the new justification
1483 #[doc(alias = "gtk_label_set_justify")]
1484 #[doc(alias = "justify")]
1485 pub fn set_justify(&self, jtype: Justification) {
1486 unsafe {
1487 ffi::gtk_label_set_justify(self.to_glib_none().0, jtype.into_glib());
1488 }
1489 }
1490
1491 /// Sets the text of the label.
1492 ///
1493 /// The label is interpreted as including embedded underlines and/or Pango
1494 /// markup depending on the values of the [`use-underline`][struct@crate::Label#use-underline]
1495 /// and [`use-markup`][struct@crate::Label#use-markup] properties.
1496 /// ## `str`
1497 /// the new text to set for the label
1498 #[doc(alias = "gtk_label_set_label")]
1499 #[doc(alias = "label")]
1500 pub fn set_label(&self, str: &str) {
1501 unsafe {
1502 ffi::gtk_label_set_label(self.to_glib_none().0, str.to_glib_none().0);
1503 }
1504 }
1505
1506 /// Sets the number of lines to which an ellipsized, wrapping label
1507 /// should be limited.
1508 ///
1509 /// This has no effect if the label is not wrapping or ellipsized.
1510 /// Set this to -1 if you don’t want to limit the number of lines.
1511 /// ## `lines`
1512 /// the desired number of lines, or -1
1513 #[doc(alias = "gtk_label_set_lines")]
1514 #[doc(alias = "lines")]
1515 pub fn set_lines(&self, lines: i32) {
1516 unsafe {
1517 ffi::gtk_label_set_lines(self.to_glib_none().0, lines);
1518 }
1519 }
1520
1521 /// Sets the labels text and attributes from markup.
1522 ///
1523 /// The string must be marked up with Pango markup
1524 /// (see `parse_markup()`).
1525 ///
1526 /// If @str is external data, you may need to escape it
1527 /// with `markup_escape_text()` or `markup_printf_escaped()`:
1528 ///
1529 /// **⚠️ The following code is in c ⚠️**
1530 ///
1531 /// ```c
1532 /// GtkWidget *self = gtk_label_new (NULL);
1533 /// const char *str = "...";
1534 /// const char *format = "<span style=\"italic\">\%s</span>";
1535 /// char *markup;
1536 ///
1537 /// markup = g_markup_printf_escaped (format, str);
1538 /// gtk_label_set_markup (GTK_LABEL (self), markup);
1539 /// g_free (markup);
1540 /// ```
1541 ///
1542 /// This function sets the [`use-markup`][struct@crate::Label#use-markup] property
1543 /// to true.
1544 ///
1545 /// Also see [`set_text()`][Self::set_text()].
1546 /// ## `str`
1547 /// the markup string
1548 #[doc(alias = "gtk_label_set_markup")]
1549 pub fn set_markup(&self, str: &str) {
1550 unsafe {
1551 ffi::gtk_label_set_markup(self.to_glib_none().0, str.to_glib_none().0);
1552 }
1553 }
1554
1555 /// Sets the labels text, attributes and mnemonic from markup.
1556 ///
1557 /// Parses @str which is marked up with Pango markup (see `parse_markup()`),
1558 /// setting the label’s text and attribute list based on the parse results.
1559 /// If characters in @str are preceded by an underscore, they are underlined
1560 /// indicating that they represent a keyboard accelerator called a mnemonic.
1561 ///
1562 /// The mnemonic key can be used to activate another widget, chosen
1563 /// automatically, or explicitly using [`set_mnemonic_widget()`][Self::set_mnemonic_widget()].
1564 /// ## `str`
1565 /// the markup string
1566 #[doc(alias = "gtk_label_set_markup_with_mnemonic")]
1567 pub fn set_markup_with_mnemonic(&self, str: &str) {
1568 unsafe {
1569 ffi::gtk_label_set_markup_with_mnemonic(self.to_glib_none().0, str.to_glib_none().0);
1570 }
1571 }
1572
1573 /// Sets the maximum width of the label in characters.
1574 /// ## `n_chars`
1575 /// the new maximum width, in characters.
1576 #[doc(alias = "gtk_label_set_max_width_chars")]
1577 #[doc(alias = "max-width-chars")]
1578 pub fn set_max_width_chars(&self, n_chars: i32) {
1579 unsafe {
1580 ffi::gtk_label_set_max_width_chars(self.to_glib_none().0, n_chars);
1581 }
1582 }
1583
1584 /// Associate the label with its mnemonic target.
1585 ///
1586 /// If the label has been set so that it has a mnemonic key (using
1587 /// i.e. [`set_markup_with_mnemonic()`][Self::set_markup_with_mnemonic()],
1588 /// [`set_text_with_mnemonic()`][Self::set_text_with_mnemonic()],
1589 /// [`with_mnemonic()`][Self::with_mnemonic()]
1590 /// or the [`use_underline`][struct@crate::Label#use_underline] property) the label can
1591 /// be associated with a widget that is the target of the mnemonic.
1592 /// When the label is inside a widget (like a [`Button`][crate::Button] or a
1593 /// [`Notebook`][crate::Notebook] tab) it is automatically associated with the
1594 /// correct widget, but sometimes (i.e. when the target is a [`Entry`][crate::Entry]
1595 /// next to the label) you need to set it explicitly using this function.
1596 ///
1597 /// The target widget will be accelerated by emitting the
1598 /// [`mnemonic-activate`][struct@crate::Widget#mnemonic-activate] signal on it. The default handler
1599 /// for this signal will activate the widget if there are no mnemonic
1600 /// collisions and toggle focus between the colliding widgets otherwise.
1601 /// ## `widget`
1602 /// the target widget
1603 #[doc(alias = "gtk_label_set_mnemonic_widget")]
1604 #[doc(alias = "mnemonic-widget")]
1605 pub fn set_mnemonic_widget(&self, widget: Option<&impl IsA<Widget>>) {
1606 unsafe {
1607 ffi::gtk_label_set_mnemonic_widget(
1608 self.to_glib_none().0,
1609 widget.map(|p| p.as_ref()).to_glib_none().0,
1610 );
1611 }
1612 }
1613
1614 /// Selects the line wrapping for the natural size request.
1615 ///
1616 /// This only affects the natural size requested, for the actual wrapping used,
1617 /// see the [`wrap-mode`][struct@crate::Label#wrap-mode] property.
1618 /// ## `wrap_mode`
1619 /// the line wrapping mode
1620 #[cfg(feature = "v4_6")]
1621 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
1622 #[doc(alias = "gtk_label_set_natural_wrap_mode")]
1623 #[doc(alias = "natural-wrap-mode")]
1624 pub fn set_natural_wrap_mode(&self, wrap_mode: NaturalWrapMode) {
1625 unsafe {
1626 ffi::gtk_label_set_natural_wrap_mode(self.to_glib_none().0, wrap_mode.into_glib());
1627 }
1628 }
1629
1630 /// Makes text in the label selectable.
1631 ///
1632 /// Selectable labels allow the user to select text from the label,
1633 /// for copy-and-paste.
1634 /// ## `setting`
1635 /// true to allow selecting text in the label
1636 #[doc(alias = "gtk_label_set_selectable")]
1637 #[doc(alias = "selectable")]
1638 pub fn set_selectable(&self, setting: bool) {
1639 unsafe {
1640 ffi::gtk_label_set_selectable(self.to_glib_none().0, setting.into_glib());
1641 }
1642 }
1643
1644 /// Sets whether the label is in single line mode.
1645 /// ## `single_line_mode`
1646 /// true to enable single line mode
1647 #[doc(alias = "gtk_label_set_single_line_mode")]
1648 #[doc(alias = "single-line-mode")]
1649 pub fn set_single_line_mode(&self, single_line_mode: bool) {
1650 unsafe {
1651 ffi::gtk_label_set_single_line_mode(
1652 self.to_glib_none().0,
1653 single_line_mode.into_glib(),
1654 );
1655 }
1656 }
1657
1658 /// Sets tab stops for the label.
1659 /// ## `tabs`
1660 /// tab stops
1661 #[cfg(feature = "v4_8")]
1662 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
1663 #[doc(alias = "gtk_label_set_tabs")]
1664 #[doc(alias = "tabs")]
1665 pub fn set_tabs(&self, tabs: Option<&pango::TabArray>) {
1666 unsafe {
1667 ffi::gtk_label_set_tabs(self.to_glib_none().0, mut_override(tabs.to_glib_none().0));
1668 }
1669 }
1670
1671 /// Sets the text for the label.
1672 ///
1673 /// It overwrites any text that was there before and clears any
1674 /// previously set mnemonic accelerators, and sets the
1675 /// [`use-underline`][struct@crate::Label#use-underline] and
1676 /// [`use-markup`][struct@crate::Label#use-markup] properties to false.
1677 ///
1678 /// Also see [`set_markup()`][Self::set_markup()].
1679 /// ## `str`
1680 /// the text to show in @self
1681 #[doc(alias = "gtk_label_set_text")]
1682 pub fn set_text(&self, str: &str) {
1683 unsafe {
1684 ffi::gtk_label_set_text(self.to_glib_none().0, str.to_glib_none().0);
1685 }
1686 }
1687
1688 /// Sets the text for the label, with mnemonics.
1689 ///
1690 /// If characters in @str are preceded by an underscore, they are underlined
1691 /// indicating that they represent a keyboard accelerator called a mnemonic.
1692 /// The mnemonic key can be used to activate another widget, chosen
1693 /// automatically, or explicitly using [`set_mnemonic_widget()`][Self::set_mnemonic_widget()].
1694 /// ## `str`
1695 /// the text
1696 #[doc(alias = "gtk_label_set_text_with_mnemonic")]
1697 pub fn set_text_with_mnemonic(&self, str: &str) {
1698 unsafe {
1699 ffi::gtk_label_set_text_with_mnemonic(self.to_glib_none().0, str.to_glib_none().0);
1700 }
1701 }
1702
1703 /// Sets whether the text of the label contains markup.
1704 ///
1705 /// See [`set_markup()`][Self::set_markup()].
1706 /// ## `setting`
1707 /// true if the label’s text should be parsed for markup.
1708 #[doc(alias = "gtk_label_set_use_markup")]
1709 #[doc(alias = "use-markup")]
1710 pub fn set_use_markup(&self, setting: bool) {
1711 unsafe {
1712 ffi::gtk_label_set_use_markup(self.to_glib_none().0, setting.into_glib());
1713 }
1714 }
1715
1716 /// Sets whether underlines in the text indicate mnemonics.
1717 /// ## `setting`
1718 /// true if underlines in the text indicate mnemonics
1719 #[doc(alias = "gtk_label_set_use_underline")]
1720 #[doc(alias = "use-underline")]
1721 pub fn set_use_underline(&self, setting: bool) {
1722 unsafe {
1723 ffi::gtk_label_set_use_underline(self.to_glib_none().0, setting.into_glib());
1724 }
1725 }
1726
1727 /// Sets the desired width in characters of the label.
1728 /// ## `n_chars`
1729 /// the new desired width, in characters.
1730 #[doc(alias = "gtk_label_set_width_chars")]
1731 #[doc(alias = "width-chars")]
1732 pub fn set_width_chars(&self, n_chars: i32) {
1733 unsafe {
1734 ffi::gtk_label_set_width_chars(self.to_glib_none().0, n_chars);
1735 }
1736 }
1737
1738 /// Toggles line wrapping within the label.
1739 ///
1740 /// True makes it break lines if text exceeds the widget’s size.
1741 /// false lets the text get cut off by the edge of the widget if
1742 /// it exceeds the widget size.
1743 ///
1744 /// Note that setting line wrapping to true does not make the label
1745 /// wrap at its parent widget’s width, because GTK widgets conceptually
1746 /// can’t make their requisition depend on the parent widget’s size.
1747 /// For a label that wraps at a specific position, set the label’s width
1748 /// using [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()].
1749 /// ## `wrap`
1750 /// whether to wrap lines
1751 #[doc(alias = "gtk_label_set_wrap")]
1752 #[doc(alias = "wrap")]
1753 pub fn set_wrap(&self, wrap: bool) {
1754 unsafe {
1755 ffi::gtk_label_set_wrap(self.to_glib_none().0, wrap.into_glib());
1756 }
1757 }
1758
1759 /// Controls how line wrapping is done.
1760 ///
1761 /// This only affects the label if line wrapping is on. (See
1762 /// [`set_wrap()`][Self::set_wrap()])
1763 ///
1764 /// The default is [enum@Pango.WrapMode.word], which means
1765 /// wrap on word boundaries.
1766 ///
1767 /// For sizing behavior, also consider the
1768 /// [`natural-wrap-mode`][struct@crate::Label#natural-wrap-mode] property.
1769 /// ## `wrap_mode`
1770 /// the line wrapping mode
1771 #[doc(alias = "gtk_label_set_wrap_mode")]
1772 #[doc(alias = "wrap-mode")]
1773 pub fn set_wrap_mode(&self, wrap_mode: pango::WrapMode) {
1774 unsafe {
1775 ffi::gtk_label_set_wrap_mode(self.to_glib_none().0, wrap_mode.into_glib());
1776 }
1777 }
1778
1779 /// Sets the `xalign` of the label.
1780 ///
1781 /// See the [`xalign`][struct@crate::Label#xalign] property.
1782 /// ## `xalign`
1783 /// the new xalign value, between 0 and 1
1784 #[doc(alias = "gtk_label_set_xalign")]
1785 #[doc(alias = "xalign")]
1786 pub fn set_xalign(&self, xalign: f32) {
1787 unsafe {
1788 ffi::gtk_label_set_xalign(self.to_glib_none().0, xalign);
1789 }
1790 }
1791
1792 /// Sets the `yalign` of the label.
1793 ///
1794 /// See the [`yalign`][struct@crate::Label#yalign] property.
1795 /// ## `yalign`
1796 /// the new yalign value, between 0 and 1
1797 #[doc(alias = "gtk_label_set_yalign")]
1798 #[doc(alias = "yalign")]
1799 pub fn set_yalign(&self, yalign: f32) {
1800 unsafe {
1801 ffi::gtk_label_set_yalign(self.to_glib_none().0, yalign);
1802 }
1803 }
1804
1805 /// Gets emitted when the user activates a link in the label.
1806 ///
1807 /// The `::activate-current-link` is a [keybinding signal](class.SignalAction.html).
1808 ///
1809 /// Applications may also emit the signal with g_signal_emit_by_name()
1810 /// if they need to control activation of URIs programmatically.
1811 ///
1812 /// The default bindings for this signal are all forms of the <kbd>Enter</kbd> key.
1813 #[doc(alias = "activate-current-link")]
1814 pub fn connect_activate_current_link<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1815 unsafe extern "C" fn activate_current_link_trampoline<F: Fn(&Label) + 'static>(
1816 this: *mut ffi::GtkLabel,
1817 f: glib::ffi::gpointer,
1818 ) {
1819 unsafe {
1820 let f: &F = &*(f as *const F);
1821 f(&from_glib_borrow(this))
1822 }
1823 }
1824 unsafe {
1825 let f: Box_<F> = Box_::new(f);
1826 connect_raw(
1827 self.as_ptr() as *mut _,
1828 c"activate-current-link".as_ptr() as *const _,
1829 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1830 activate_current_link_trampoline::<F> as *const (),
1831 )),
1832 Box_::into_raw(f),
1833 )
1834 }
1835 }
1836
1837 pub fn emit_activate_current_link(&self) {
1838 self.emit_by_name::<()>("activate-current-link", &[]);
1839 }
1840
1841 /// Gets emitted to activate a URI.
1842 ///
1843 /// Applications may connect to it to override the default behaviour,
1844 /// which is to call [`FileLauncher::launch()`][crate::FileLauncher::launch()].
1845 /// ## `uri`
1846 /// the URI that is activated
1847 ///
1848 /// # Returns
1849 ///
1850 /// true if the link has been activated
1851 #[doc(alias = "activate-link")]
1852 pub fn connect_activate_link<F: Fn(&Self, &str) -> glib::Propagation + 'static>(
1853 &self,
1854 f: F,
1855 ) -> SignalHandlerId {
1856 unsafe extern "C" fn activate_link_trampoline<
1857 F: Fn(&Label, &str) -> glib::Propagation + 'static,
1858 >(
1859 this: *mut ffi::GtkLabel,
1860 uri: *mut std::ffi::c_char,
1861 f: glib::ffi::gpointer,
1862 ) -> glib::ffi::gboolean {
1863 unsafe {
1864 let f: &F = &*(f as *const F);
1865 f(
1866 &from_glib_borrow(this),
1867 &glib::GString::from_glib_borrow(uri),
1868 )
1869 .into_glib()
1870 }
1871 }
1872 unsafe {
1873 let f: Box_<F> = Box_::new(f);
1874 connect_raw(
1875 self.as_ptr() as *mut _,
1876 c"activate-link".as_ptr() as *const _,
1877 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1878 activate_link_trampoline::<F> as *const (),
1879 )),
1880 Box_::into_raw(f),
1881 )
1882 }
1883 }
1884
1885 /// Gets emitted to copy the selection to the clipboard.
1886 ///
1887 /// The `::copy-clipboard` signal is a [keybinding signal](class.SignalAction.html).
1888 ///
1889 /// The default binding for this signal is <kbd>Ctrl</kbd>+<kbd>c</kbd>.
1890 #[doc(alias = "copy-clipboard")]
1891 pub fn connect_copy_clipboard<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1892 unsafe extern "C" fn copy_clipboard_trampoline<F: Fn(&Label) + 'static>(
1893 this: *mut ffi::GtkLabel,
1894 f: glib::ffi::gpointer,
1895 ) {
1896 unsafe {
1897 let f: &F = &*(f as *const F);
1898 f(&from_glib_borrow(this))
1899 }
1900 }
1901 unsafe {
1902 let f: Box_<F> = Box_::new(f);
1903 connect_raw(
1904 self.as_ptr() as *mut _,
1905 c"copy-clipboard".as_ptr() as *const _,
1906 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1907 copy_clipboard_trampoline::<F> as *const (),
1908 )),
1909 Box_::into_raw(f),
1910 )
1911 }
1912 }
1913
1914 pub fn emit_copy_clipboard(&self) {
1915 self.emit_by_name::<()>("copy-clipboard", &[]);
1916 }
1917
1918 /// Gets emitted when the user initiates a cursor movement.
1919 ///
1920 /// The `::move-cursor` signal is a [keybinding signal](class.SignalAction.html).
1921 /// If the cursor is not visible in @entry, this signal causes the viewport to
1922 /// be moved instead.
1923 ///
1924 /// Applications should not connect to it, but may emit it with
1925 /// `signal_emit_by_name()` if they need to control
1926 /// the cursor programmatically.
1927 ///
1928 /// The default bindings for this signal come in two variants, the
1929 /// variant with the <kbd>Shift</kbd> modifier extends the selection,
1930 /// the variant without the <kbd>Shift</kbd> modifier does not.
1931 /// There are too many key combinations to list them all here.
1932 ///
1933 /// - <kbd>←</kbd>, <kbd>→</kbd>, <kbd>↑</kbd>, <kbd>↓</kbd>
1934 /// move by individual characters/lines
1935 /// - <kbd>Ctrl</kbd>+<kbd>←</kbd>, etc. move by words/paragraphs
1936 /// - <kbd>Home</kbd> and <kbd>End</kbd> move to the ends of the buffer
1937 /// ## `step`
1938 /// the granularity of the move, as a [`MovementStep`][crate::MovementStep]
1939 /// ## `count`
1940 /// the number of @step units to move
1941 /// ## `extend_selection`
1942 /// true if the move should extend the selection
1943 #[doc(alias = "move-cursor")]
1944 pub fn connect_move_cursor<F: Fn(&Self, MovementStep, i32, bool) + 'static>(
1945 &self,
1946 f: F,
1947 ) -> SignalHandlerId {
1948 unsafe extern "C" fn move_cursor_trampoline<
1949 F: Fn(&Label, MovementStep, i32, bool) + 'static,
1950 >(
1951 this: *mut ffi::GtkLabel,
1952 step: ffi::GtkMovementStep,
1953 count: std::ffi::c_int,
1954 extend_selection: glib::ffi::gboolean,
1955 f: glib::ffi::gpointer,
1956 ) {
1957 unsafe {
1958 let f: &F = &*(f as *const F);
1959 f(
1960 &from_glib_borrow(this),
1961 from_glib(step),
1962 count,
1963 from_glib(extend_selection),
1964 )
1965 }
1966 }
1967 unsafe {
1968 let f: Box_<F> = Box_::new(f);
1969 connect_raw(
1970 self.as_ptr() as *mut _,
1971 c"move-cursor".as_ptr() as *const _,
1972 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1973 move_cursor_trampoline::<F> as *const (),
1974 )),
1975 Box_::into_raw(f),
1976 )
1977 }
1978 }
1979
1980 pub fn emit_move_cursor(&self, step: MovementStep, count: i32, extend_selection: bool) {
1981 self.emit_by_name::<()>("move-cursor", &[&step, &count, &extend_selection]);
1982 }
1983
1984 #[doc(alias = "attributes")]
1985 pub fn connect_attributes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1986 unsafe extern "C" fn notify_attributes_trampoline<F: Fn(&Label) + 'static>(
1987 this: *mut ffi::GtkLabel,
1988 _param_spec: glib::ffi::gpointer,
1989 f: glib::ffi::gpointer,
1990 ) {
1991 unsafe {
1992 let f: &F = &*(f as *const F);
1993 f(&from_glib_borrow(this))
1994 }
1995 }
1996 unsafe {
1997 let f: Box_<F> = Box_::new(f);
1998 connect_raw(
1999 self.as_ptr() as *mut _,
2000 c"notify::attributes".as_ptr() as *const _,
2001 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2002 notify_attributes_trampoline::<F> as *const (),
2003 )),
2004 Box_::into_raw(f),
2005 )
2006 }
2007 }
2008
2009 #[doc(alias = "ellipsize")]
2010 pub fn connect_ellipsize_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2011 unsafe extern "C" fn notify_ellipsize_trampoline<F: Fn(&Label) + 'static>(
2012 this: *mut ffi::GtkLabel,
2013 _param_spec: glib::ffi::gpointer,
2014 f: glib::ffi::gpointer,
2015 ) {
2016 unsafe {
2017 let f: &F = &*(f as *const F);
2018 f(&from_glib_borrow(this))
2019 }
2020 }
2021 unsafe {
2022 let f: Box_<F> = Box_::new(f);
2023 connect_raw(
2024 self.as_ptr() as *mut _,
2025 c"notify::ellipsize".as_ptr() as *const _,
2026 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2027 notify_ellipsize_trampoline::<F> as *const (),
2028 )),
2029 Box_::into_raw(f),
2030 )
2031 }
2032 }
2033
2034 #[doc(alias = "extra-menu")]
2035 pub fn connect_extra_menu_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2036 unsafe extern "C" fn notify_extra_menu_trampoline<F: Fn(&Label) + 'static>(
2037 this: *mut ffi::GtkLabel,
2038 _param_spec: glib::ffi::gpointer,
2039 f: glib::ffi::gpointer,
2040 ) {
2041 unsafe {
2042 let f: &F = &*(f as *const F);
2043 f(&from_glib_borrow(this))
2044 }
2045 }
2046 unsafe {
2047 let f: Box_<F> = Box_::new(f);
2048 connect_raw(
2049 self.as_ptr() as *mut _,
2050 c"notify::extra-menu".as_ptr() as *const _,
2051 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2052 notify_extra_menu_trampoline::<F> as *const (),
2053 )),
2054 Box_::into_raw(f),
2055 )
2056 }
2057 }
2058
2059 #[doc(alias = "justify")]
2060 pub fn connect_justify_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2061 unsafe extern "C" fn notify_justify_trampoline<F: Fn(&Label) + 'static>(
2062 this: *mut ffi::GtkLabel,
2063 _param_spec: glib::ffi::gpointer,
2064 f: glib::ffi::gpointer,
2065 ) {
2066 unsafe {
2067 let f: &F = &*(f as *const F);
2068 f(&from_glib_borrow(this))
2069 }
2070 }
2071 unsafe {
2072 let f: Box_<F> = Box_::new(f);
2073 connect_raw(
2074 self.as_ptr() as *mut _,
2075 c"notify::justify".as_ptr() as *const _,
2076 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2077 notify_justify_trampoline::<F> as *const (),
2078 )),
2079 Box_::into_raw(f),
2080 )
2081 }
2082 }
2083
2084 #[doc(alias = "label")]
2085 pub fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2086 unsafe extern "C" fn notify_label_trampoline<F: Fn(&Label) + 'static>(
2087 this: *mut ffi::GtkLabel,
2088 _param_spec: glib::ffi::gpointer,
2089 f: glib::ffi::gpointer,
2090 ) {
2091 unsafe {
2092 let f: &F = &*(f as *const F);
2093 f(&from_glib_borrow(this))
2094 }
2095 }
2096 unsafe {
2097 let f: Box_<F> = Box_::new(f);
2098 connect_raw(
2099 self.as_ptr() as *mut _,
2100 c"notify::label".as_ptr() as *const _,
2101 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2102 notify_label_trampoline::<F> as *const (),
2103 )),
2104 Box_::into_raw(f),
2105 )
2106 }
2107 }
2108
2109 #[doc(alias = "lines")]
2110 pub fn connect_lines_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2111 unsafe extern "C" fn notify_lines_trampoline<F: Fn(&Label) + 'static>(
2112 this: *mut ffi::GtkLabel,
2113 _param_spec: glib::ffi::gpointer,
2114 f: glib::ffi::gpointer,
2115 ) {
2116 unsafe {
2117 let f: &F = &*(f as *const F);
2118 f(&from_glib_borrow(this))
2119 }
2120 }
2121 unsafe {
2122 let f: Box_<F> = Box_::new(f);
2123 connect_raw(
2124 self.as_ptr() as *mut _,
2125 c"notify::lines".as_ptr() as *const _,
2126 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2127 notify_lines_trampoline::<F> as *const (),
2128 )),
2129 Box_::into_raw(f),
2130 )
2131 }
2132 }
2133
2134 #[doc(alias = "max-width-chars")]
2135 pub fn connect_max_width_chars_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2136 unsafe extern "C" fn notify_max_width_chars_trampoline<F: Fn(&Label) + 'static>(
2137 this: *mut ffi::GtkLabel,
2138 _param_spec: glib::ffi::gpointer,
2139 f: glib::ffi::gpointer,
2140 ) {
2141 unsafe {
2142 let f: &F = &*(f as *const F);
2143 f(&from_glib_borrow(this))
2144 }
2145 }
2146 unsafe {
2147 let f: Box_<F> = Box_::new(f);
2148 connect_raw(
2149 self.as_ptr() as *mut _,
2150 c"notify::max-width-chars".as_ptr() as *const _,
2151 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2152 notify_max_width_chars_trampoline::<F> as *const (),
2153 )),
2154 Box_::into_raw(f),
2155 )
2156 }
2157 }
2158
2159 #[doc(alias = "mnemonic-keyval")]
2160 pub fn connect_mnemonic_keyval_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2161 unsafe extern "C" fn notify_mnemonic_keyval_trampoline<F: Fn(&Label) + 'static>(
2162 this: *mut ffi::GtkLabel,
2163 _param_spec: glib::ffi::gpointer,
2164 f: glib::ffi::gpointer,
2165 ) {
2166 unsafe {
2167 let f: &F = &*(f as *const F);
2168 f(&from_glib_borrow(this))
2169 }
2170 }
2171 unsafe {
2172 let f: Box_<F> = Box_::new(f);
2173 connect_raw(
2174 self.as_ptr() as *mut _,
2175 c"notify::mnemonic-keyval".as_ptr() as *const _,
2176 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2177 notify_mnemonic_keyval_trampoline::<F> as *const (),
2178 )),
2179 Box_::into_raw(f),
2180 )
2181 }
2182 }
2183
2184 #[doc(alias = "mnemonic-widget")]
2185 pub fn connect_mnemonic_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2186 unsafe extern "C" fn notify_mnemonic_widget_trampoline<F: Fn(&Label) + 'static>(
2187 this: *mut ffi::GtkLabel,
2188 _param_spec: glib::ffi::gpointer,
2189 f: glib::ffi::gpointer,
2190 ) {
2191 unsafe {
2192 let f: &F = &*(f as *const F);
2193 f(&from_glib_borrow(this))
2194 }
2195 }
2196 unsafe {
2197 let f: Box_<F> = Box_::new(f);
2198 connect_raw(
2199 self.as_ptr() as *mut _,
2200 c"notify::mnemonic-widget".as_ptr() as *const _,
2201 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2202 notify_mnemonic_widget_trampoline::<F> as *const (),
2203 )),
2204 Box_::into_raw(f),
2205 )
2206 }
2207 }
2208
2209 #[cfg(feature = "v4_6")]
2210 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
2211 #[doc(alias = "natural-wrap-mode")]
2212 pub fn connect_natural_wrap_mode_notify<F: Fn(&Self) + 'static>(
2213 &self,
2214 f: F,
2215 ) -> SignalHandlerId {
2216 unsafe extern "C" fn notify_natural_wrap_mode_trampoline<F: Fn(&Label) + 'static>(
2217 this: *mut ffi::GtkLabel,
2218 _param_spec: glib::ffi::gpointer,
2219 f: glib::ffi::gpointer,
2220 ) {
2221 unsafe {
2222 let f: &F = &*(f as *const F);
2223 f(&from_glib_borrow(this))
2224 }
2225 }
2226 unsafe {
2227 let f: Box_<F> = Box_::new(f);
2228 connect_raw(
2229 self.as_ptr() as *mut _,
2230 c"notify::natural-wrap-mode".as_ptr() as *const _,
2231 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2232 notify_natural_wrap_mode_trampoline::<F> as *const (),
2233 )),
2234 Box_::into_raw(f),
2235 )
2236 }
2237 }
2238
2239 #[doc(alias = "selectable")]
2240 pub fn connect_selectable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2241 unsafe extern "C" fn notify_selectable_trampoline<F: Fn(&Label) + 'static>(
2242 this: *mut ffi::GtkLabel,
2243 _param_spec: glib::ffi::gpointer,
2244 f: glib::ffi::gpointer,
2245 ) {
2246 unsafe {
2247 let f: &F = &*(f as *const F);
2248 f(&from_glib_borrow(this))
2249 }
2250 }
2251 unsafe {
2252 let f: Box_<F> = Box_::new(f);
2253 connect_raw(
2254 self.as_ptr() as *mut _,
2255 c"notify::selectable".as_ptr() as *const _,
2256 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2257 notify_selectable_trampoline::<F> as *const (),
2258 )),
2259 Box_::into_raw(f),
2260 )
2261 }
2262 }
2263
2264 #[doc(alias = "single-line-mode")]
2265 pub fn connect_single_line_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2266 unsafe extern "C" fn notify_single_line_mode_trampoline<F: Fn(&Label) + 'static>(
2267 this: *mut ffi::GtkLabel,
2268 _param_spec: glib::ffi::gpointer,
2269 f: glib::ffi::gpointer,
2270 ) {
2271 unsafe {
2272 let f: &F = &*(f as *const F);
2273 f(&from_glib_borrow(this))
2274 }
2275 }
2276 unsafe {
2277 let f: Box_<F> = Box_::new(f);
2278 connect_raw(
2279 self.as_ptr() as *mut _,
2280 c"notify::single-line-mode".as_ptr() as *const _,
2281 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2282 notify_single_line_mode_trampoline::<F> as *const (),
2283 )),
2284 Box_::into_raw(f),
2285 )
2286 }
2287 }
2288
2289 #[cfg(feature = "v4_8")]
2290 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
2291 #[doc(alias = "tabs")]
2292 pub fn connect_tabs_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2293 unsafe extern "C" fn notify_tabs_trampoline<F: Fn(&Label) + 'static>(
2294 this: *mut ffi::GtkLabel,
2295 _param_spec: glib::ffi::gpointer,
2296 f: glib::ffi::gpointer,
2297 ) {
2298 unsafe {
2299 let f: &F = &*(f as *const F);
2300 f(&from_glib_borrow(this))
2301 }
2302 }
2303 unsafe {
2304 let f: Box_<F> = Box_::new(f);
2305 connect_raw(
2306 self.as_ptr() as *mut _,
2307 c"notify::tabs".as_ptr() as *const _,
2308 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2309 notify_tabs_trampoline::<F> as *const (),
2310 )),
2311 Box_::into_raw(f),
2312 )
2313 }
2314 }
2315
2316 #[doc(alias = "use-markup")]
2317 pub fn connect_use_markup_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2318 unsafe extern "C" fn notify_use_markup_trampoline<F: Fn(&Label) + 'static>(
2319 this: *mut ffi::GtkLabel,
2320 _param_spec: glib::ffi::gpointer,
2321 f: glib::ffi::gpointer,
2322 ) {
2323 unsafe {
2324 let f: &F = &*(f as *const F);
2325 f(&from_glib_borrow(this))
2326 }
2327 }
2328 unsafe {
2329 let f: Box_<F> = Box_::new(f);
2330 connect_raw(
2331 self.as_ptr() as *mut _,
2332 c"notify::use-markup".as_ptr() as *const _,
2333 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2334 notify_use_markup_trampoline::<F> as *const (),
2335 )),
2336 Box_::into_raw(f),
2337 )
2338 }
2339 }
2340
2341 #[doc(alias = "use-underline")]
2342 pub fn connect_use_underline_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2343 unsafe extern "C" fn notify_use_underline_trampoline<F: Fn(&Label) + 'static>(
2344 this: *mut ffi::GtkLabel,
2345 _param_spec: glib::ffi::gpointer,
2346 f: glib::ffi::gpointer,
2347 ) {
2348 unsafe {
2349 let f: &F = &*(f as *const F);
2350 f(&from_glib_borrow(this))
2351 }
2352 }
2353 unsafe {
2354 let f: Box_<F> = Box_::new(f);
2355 connect_raw(
2356 self.as_ptr() as *mut _,
2357 c"notify::use-underline".as_ptr() as *const _,
2358 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2359 notify_use_underline_trampoline::<F> as *const (),
2360 )),
2361 Box_::into_raw(f),
2362 )
2363 }
2364 }
2365
2366 #[doc(alias = "width-chars")]
2367 pub fn connect_width_chars_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2368 unsafe extern "C" fn notify_width_chars_trampoline<F: Fn(&Label) + 'static>(
2369 this: *mut ffi::GtkLabel,
2370 _param_spec: glib::ffi::gpointer,
2371 f: glib::ffi::gpointer,
2372 ) {
2373 unsafe {
2374 let f: &F = &*(f as *const F);
2375 f(&from_glib_borrow(this))
2376 }
2377 }
2378 unsafe {
2379 let f: Box_<F> = Box_::new(f);
2380 connect_raw(
2381 self.as_ptr() as *mut _,
2382 c"notify::width-chars".as_ptr() as *const _,
2383 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2384 notify_width_chars_trampoline::<F> as *const (),
2385 )),
2386 Box_::into_raw(f),
2387 )
2388 }
2389 }
2390
2391 #[doc(alias = "wrap")]
2392 pub fn connect_wrap_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2393 unsafe extern "C" fn notify_wrap_trampoline<F: Fn(&Label) + 'static>(
2394 this: *mut ffi::GtkLabel,
2395 _param_spec: glib::ffi::gpointer,
2396 f: glib::ffi::gpointer,
2397 ) {
2398 unsafe {
2399 let f: &F = &*(f as *const F);
2400 f(&from_glib_borrow(this))
2401 }
2402 }
2403 unsafe {
2404 let f: Box_<F> = Box_::new(f);
2405 connect_raw(
2406 self.as_ptr() as *mut _,
2407 c"notify::wrap".as_ptr() as *const _,
2408 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2409 notify_wrap_trampoline::<F> as *const (),
2410 )),
2411 Box_::into_raw(f),
2412 )
2413 }
2414 }
2415
2416 #[doc(alias = "wrap-mode")]
2417 pub fn connect_wrap_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2418 unsafe extern "C" fn notify_wrap_mode_trampoline<F: Fn(&Label) + 'static>(
2419 this: *mut ffi::GtkLabel,
2420 _param_spec: glib::ffi::gpointer,
2421 f: glib::ffi::gpointer,
2422 ) {
2423 unsafe {
2424 let f: &F = &*(f as *const F);
2425 f(&from_glib_borrow(this))
2426 }
2427 }
2428 unsafe {
2429 let f: Box_<F> = Box_::new(f);
2430 connect_raw(
2431 self.as_ptr() as *mut _,
2432 c"notify::wrap-mode".as_ptr() as *const _,
2433 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2434 notify_wrap_mode_trampoline::<F> as *const (),
2435 )),
2436 Box_::into_raw(f),
2437 )
2438 }
2439 }
2440
2441 #[doc(alias = "xalign")]
2442 pub fn connect_xalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2443 unsafe extern "C" fn notify_xalign_trampoline<F: Fn(&Label) + 'static>(
2444 this: *mut ffi::GtkLabel,
2445 _param_spec: glib::ffi::gpointer,
2446 f: glib::ffi::gpointer,
2447 ) {
2448 unsafe {
2449 let f: &F = &*(f as *const F);
2450 f(&from_glib_borrow(this))
2451 }
2452 }
2453 unsafe {
2454 let f: Box_<F> = Box_::new(f);
2455 connect_raw(
2456 self.as_ptr() as *mut _,
2457 c"notify::xalign".as_ptr() as *const _,
2458 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2459 notify_xalign_trampoline::<F> as *const (),
2460 )),
2461 Box_::into_raw(f),
2462 )
2463 }
2464 }
2465
2466 #[doc(alias = "yalign")]
2467 pub fn connect_yalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
2468 unsafe extern "C" fn notify_yalign_trampoline<F: Fn(&Label) + 'static>(
2469 this: *mut ffi::GtkLabel,
2470 _param_spec: glib::ffi::gpointer,
2471 f: glib::ffi::gpointer,
2472 ) {
2473 unsafe {
2474 let f: &F = &*(f as *const F);
2475 f(&from_glib_borrow(this))
2476 }
2477 }
2478 unsafe {
2479 let f: Box_<F> = Box_::new(f);
2480 connect_raw(
2481 self.as_ptr() as *mut _,
2482 c"notify::yalign".as_ptr() as *const _,
2483 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
2484 notify_yalign_trampoline::<F> as *const (),
2485 )),
2486 Box_::into_raw(f),
2487 )
2488 }
2489 }
2490}
2491
2492impl Default for Label {
2493 fn default() -> Self {
2494 glib::object::Object::new::<Self>()
2495 }
2496}
2497
2498// rustdoc-stripper-ignore-next
2499/// A [builder-pattern] type to construct [`Label`] objects.
2500///
2501/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
2502#[must_use = "The builder must be built to be used"]
2503pub struct LabelBuilder {
2504 builder: glib::object::ObjectBuilder<'static, Label>,
2505}
2506
2507impl LabelBuilder {
2508 fn new() -> Self {
2509 Self {
2510 builder: glib::object::Object::builder(),
2511 }
2512 }
2513
2514 /// A list of style attributes to apply to the text of the label.
2515 pub fn attributes(self, attributes: &pango::AttrList) -> Self {
2516 Self {
2517 builder: self.builder.property("attributes", attributes.clone()),
2518 }
2519 }
2520
2521 /// The preferred place to ellipsize the string, if the label does
2522 /// not have enough room to display the entire string.
2523 ///
2524 /// Note that setting this property to a value other than
2525 /// [enum.Pango.EllipsizeMode.none] has the side-effect that the label requests
2526 /// only enough space to display the ellipsis "...". In particular, this
2527 /// means that ellipsizing labels do not work well in notebook tabs, unless
2528 /// the [`tab-expand`][struct@crate::NotebookPage#tab-expand] child property is set to true.
2529 ///
2530 /// Other ways to set a label's width are [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()]
2531 /// and [`Label::set_width_chars()`][crate::Label::set_width_chars()].
2532 pub fn ellipsize(self, ellipsize: pango::EllipsizeMode) -> Self {
2533 Self {
2534 builder: self.builder.property("ellipsize", ellipsize),
2535 }
2536 }
2537
2538 /// A menu model whose contents will be appended to the context menu.
2539 pub fn extra_menu(self, extra_menu: &impl IsA<gio::MenuModel>) -> Self {
2540 Self {
2541 builder: self
2542 .builder
2543 .property("extra-menu", extra_menu.clone().upcast()),
2544 }
2545 }
2546
2547 /// The alignment of the lines in the text of the label, relative to each other.
2548 ///
2549 /// This does *not* affect the alignment of the label within its allocation.
2550 /// See [`xalign`][struct@crate::Label#xalign] for that.
2551 pub fn justify(self, justify: Justification) -> Self {
2552 Self {
2553 builder: self.builder.property("justify", justify),
2554 }
2555 }
2556
2557 /// The contents of the label.
2558 ///
2559 /// If the string contains Pango markup (see `parse_markup()`),
2560 /// you will have to set the [`use-markup`][struct@crate::Label#use-markup] property to
2561 /// true in order for the label to display the markup attributes. See also
2562 /// [`Label::set_markup()`][crate::Label::set_markup()] for a convenience function that sets both
2563 /// this property and the [`use-markup`][struct@crate::Label#use-markup] property at the
2564 /// same time.
2565 ///
2566 /// If the string contains underlines acting as mnemonics, you will have to
2567 /// set the [`use-underline`][struct@crate::Label#use-underline] property to true in order
2568 /// for the label to display them.
2569 pub fn label(self, label: impl Into<glib::GString>) -> Self {
2570 Self {
2571 builder: self.builder.property("label", label.into()),
2572 }
2573 }
2574
2575 /// The number of lines to which an ellipsized, wrapping label
2576 /// should display before it gets ellipsized. This both prevents the label
2577 /// from ellipsizing before this many lines are displayed, and limits the
2578 /// height request of the label to this many lines.
2579 ///
2580 /// ::: warning
2581 /// Setting this property has unintuitive and unfortunate consequences
2582 /// for the minimum _width_ of the label. Specifically, if the height
2583 /// of the label is such that it fits a smaller number of lines than
2584 /// the value of this property, the label can not be ellipsized at all,
2585 /// which means it must be wide enough to fit all the text fully.
2586 ///
2587 /// This property has no effect if the label is not wrapping or ellipsized.
2588 ///
2589 /// Set this property to -1 if you don't want to limit the number of lines.
2590 pub fn lines(self, lines: i32) -> Self {
2591 Self {
2592 builder: self.builder.property("lines", lines),
2593 }
2594 }
2595
2596 /// The desired maximum width of the label, in characters.
2597 ///
2598 /// If this property is set to -1, the width will be calculated automatically.
2599 ///
2600 /// See the section on [text layout](class.Label.html#text-layout) for details
2601 /// of how [`width-chars`][struct@crate::Label#width-chars] and [`max-width-chars`][struct@crate::Label#max-width-chars]
2602 /// determine the width of ellipsized and wrapped labels.
2603 pub fn max_width_chars(self, max_width_chars: i32) -> Self {
2604 Self {
2605 builder: self.builder.property("max-width-chars", max_width_chars),
2606 }
2607 }
2608
2609 /// The widget to be activated when the labels mnemonic key is pressed.
2610 pub fn mnemonic_widget(self, mnemonic_widget: &impl IsA<Widget>) -> Self {
2611 Self {
2612 builder: self
2613 .builder
2614 .property("mnemonic-widget", mnemonic_widget.clone().upcast()),
2615 }
2616 }
2617
2618 /// Select the line wrapping for the natural size request.
2619 ///
2620 /// This only affects the natural size requested. For the actual wrapping
2621 /// used, see the [`wrap-mode`][struct@crate::Label#wrap-mode] property.
2622 ///
2623 /// The default is [enum@Gtk.NaturalWrapMode.inherit], which inherits
2624 /// the behavior of the [`wrap-mode`][struct@crate::Label#wrap-mode] property.
2625 #[cfg(feature = "v4_6")]
2626 #[cfg_attr(docsrs, doc(cfg(feature = "v4_6")))]
2627 pub fn natural_wrap_mode(self, natural_wrap_mode: NaturalWrapMode) -> Self {
2628 Self {
2629 builder: self
2630 .builder
2631 .property("natural-wrap-mode", natural_wrap_mode),
2632 }
2633 }
2634
2635 /// Whether the label text can be selected with the mouse.
2636 pub fn selectable(self, selectable: bool) -> Self {
2637 Self {
2638 builder: self.builder.property("selectable", selectable),
2639 }
2640 }
2641
2642 /// Whether the label is in single line mode.
2643 ///
2644 /// In single line mode, the height of the label does not depend on the
2645 /// actual text, it is always set to ascent + descent of the font. This
2646 /// can be an advantage in situations where resizing the label because
2647 /// of text changes would be distracting, e.g. in a statusbar.
2648 pub fn single_line_mode(self, single_line_mode: bool) -> Self {
2649 Self {
2650 builder: self.builder.property("single-line-mode", single_line_mode),
2651 }
2652 }
2653
2654 /// Custom tabs for this label.
2655 #[cfg(feature = "v4_8")]
2656 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
2657 pub fn tabs(self, tabs: &pango::TabArray) -> Self {
2658 Self {
2659 builder: self.builder.property("tabs", tabs),
2660 }
2661 }
2662
2663 /// True if the text of the label includes Pango markup.
2664 ///
2665 /// See `parse_markup()`.
2666 pub fn use_markup(self, use_markup: bool) -> Self {
2667 Self {
2668 builder: self.builder.property("use-markup", use_markup),
2669 }
2670 }
2671
2672 /// True if the text of the label indicates a mnemonic with an `_`
2673 /// before the mnemonic character.
2674 pub fn use_underline(self, use_underline: bool) -> Self {
2675 Self {
2676 builder: self.builder.property("use-underline", use_underline),
2677 }
2678 }
2679
2680 /// The desired width of the label, in characters.
2681 ///
2682 /// If this property is set to -1, the width will be calculated automatically.
2683 ///
2684 /// See the section on [text layout](class.Label.html#text-layout) for details
2685 /// of how [`width-chars`][struct@crate::Label#width-chars] and [`max-width-chars`][struct@crate::Label#max-width-chars]
2686 /// determine the width of ellipsized and wrapped labels.
2687 pub fn width_chars(self, width_chars: i32) -> Self {
2688 Self {
2689 builder: self.builder.property("width-chars", width_chars),
2690 }
2691 }
2692
2693 /// True if the label text will wrap if it gets too wide.
2694 pub fn wrap(self, wrap: bool) -> Self {
2695 Self {
2696 builder: self.builder.property("wrap", wrap),
2697 }
2698 }
2699
2700 /// Controls how the line wrapping is done.
2701 ///
2702 /// This only affects the formatting if line wrapping is on (see the
2703 /// [`wrap`][struct@crate::Label#wrap] property). The default is [enum@Pango.WrapMode.word],
2704 /// which means wrap on word boundaries.
2705 ///
2706 /// For sizing behavior, also consider the [`natural-wrap-mode`][struct@crate::Label#natural-wrap-mode]
2707 /// property.
2708 pub fn wrap_mode(self, wrap_mode: pango::WrapMode) -> Self {
2709 Self {
2710 builder: self.builder.property("wrap-mode", wrap_mode),
2711 }
2712 }
2713
2714 /// The horizontal alignment of the label text inside its size allocation.
2715 ///
2716 /// Compare this to [`halign`][struct@crate::Widget#halign], which determines how the
2717 /// labels size allocation is positioned in the space available for the label.
2718 pub fn xalign(self, xalign: f32) -> Self {
2719 Self {
2720 builder: self.builder.property("xalign", xalign),
2721 }
2722 }
2723
2724 /// The vertical alignment of the label text inside its size allocation.
2725 ///
2726 /// Compare this to [`valign`][struct@crate::Widget#valign], which determines how the
2727 /// labels size allocation is positioned in the space available for the label.
2728 pub fn yalign(self, yalign: f32) -> Self {
2729 Self {
2730 builder: self.builder.property("yalign", yalign),
2731 }
2732 }
2733
2734 /// Whether the widget or any of its descendents can accept
2735 /// the input focus.
2736 ///
2737 /// This property is meant to be set by widget implementations,
2738 /// typically in their instance init function.
2739 pub fn can_focus(self, can_focus: bool) -> Self {
2740 Self {
2741 builder: self.builder.property("can-focus", can_focus),
2742 }
2743 }
2744
2745 /// Whether the widget can receive pointer events.
2746 pub fn can_target(self, can_target: bool) -> Self {
2747 Self {
2748 builder: self.builder.property("can-target", can_target),
2749 }
2750 }
2751
2752 /// A list of css classes applied to this widget.
2753 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
2754 Self {
2755 builder: self.builder.property("css-classes", css_classes.into()),
2756 }
2757 }
2758
2759 /// The name of this widget in the CSS tree.
2760 ///
2761 /// This property is meant to be set by widget implementations,
2762 /// typically in their instance init function.
2763 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
2764 Self {
2765 builder: self.builder.property("css-name", css_name.into()),
2766 }
2767 }
2768
2769 /// The cursor used by @widget.
2770 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
2771 Self {
2772 builder: self.builder.property("cursor", cursor.clone()),
2773 }
2774 }
2775
2776 /// Whether the widget should grab focus when it is clicked with the mouse.
2777 ///
2778 /// This property is only relevant for widgets that can take focus.
2779 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
2780 Self {
2781 builder: self.builder.property("focus-on-click", focus_on_click),
2782 }
2783 }
2784
2785 /// Whether this widget itself will accept the input focus.
2786 pub fn focusable(self, focusable: bool) -> Self {
2787 Self {
2788 builder: self.builder.property("focusable", focusable),
2789 }
2790 }
2791
2792 /// How to distribute horizontal space if widget gets extra space.
2793 pub fn halign(self, halign: Align) -> Self {
2794 Self {
2795 builder: self.builder.property("halign", halign),
2796 }
2797 }
2798
2799 /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
2800 /// signal on @widget.
2801 ///
2802 /// A true value indicates that @widget can have a tooltip, in this case
2803 /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
2804 /// determine whether it will provide a tooltip or not.
2805 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
2806 Self {
2807 builder: self.builder.property("has-tooltip", has_tooltip),
2808 }
2809 }
2810
2811 /// Overrides for height request of the widget.
2812 ///
2813 /// If this is -1, the natural request will be used.
2814 pub fn height_request(self, height_request: i32) -> Self {
2815 Self {
2816 builder: self.builder.property("height-request", height_request),
2817 }
2818 }
2819
2820 /// Whether to expand horizontally.
2821 pub fn hexpand(self, hexpand: bool) -> Self {
2822 Self {
2823 builder: self.builder.property("hexpand", hexpand),
2824 }
2825 }
2826
2827 /// Whether to use the `hexpand` property.
2828 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
2829 Self {
2830 builder: self.builder.property("hexpand-set", hexpand_set),
2831 }
2832 }
2833
2834 /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
2835 /// the preferred size of the widget, and allocate its children.
2836 ///
2837 /// This property is meant to be set by widget implementations,
2838 /// typically in their instance init function.
2839 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
2840 Self {
2841 builder: self
2842 .builder
2843 .property("layout-manager", layout_manager.clone().upcast()),
2844 }
2845 }
2846
2847 /// Makes this widget act like a modal dialog, with respect to
2848 /// event delivery.
2849 ///
2850 /// Global event controllers will not handle events with targets
2851 /// inside the widget, unless they are set up to ignore propagation
2852 /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
2853 #[cfg(feature = "v4_18")]
2854 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
2855 pub fn limit_events(self, limit_events: bool) -> Self {
2856 Self {
2857 builder: self.builder.property("limit-events", limit_events),
2858 }
2859 }
2860
2861 /// Margin on bottom side of widget.
2862 ///
2863 /// This property adds margin outside of the widget's normal size
2864 /// request, the margin will be added in addition to the size from
2865 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
2866 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
2867 Self {
2868 builder: self.builder.property("margin-bottom", margin_bottom),
2869 }
2870 }
2871
2872 /// Margin on end of widget, horizontally.
2873 ///
2874 /// This property supports left-to-right and right-to-left text
2875 /// directions.
2876 ///
2877 /// This property adds margin outside of the widget's normal size
2878 /// request, the margin will be added in addition to the size from
2879 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
2880 pub fn margin_end(self, margin_end: i32) -> Self {
2881 Self {
2882 builder: self.builder.property("margin-end", margin_end),
2883 }
2884 }
2885
2886 /// Margin on start of widget, horizontally.
2887 ///
2888 /// This property supports left-to-right and right-to-left text
2889 /// directions.
2890 ///
2891 /// This property adds margin outside of the widget's normal size
2892 /// request, the margin will be added in addition to the size from
2893 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
2894 pub fn margin_start(self, margin_start: i32) -> Self {
2895 Self {
2896 builder: self.builder.property("margin-start", margin_start),
2897 }
2898 }
2899
2900 /// Margin on top side of widget.
2901 ///
2902 /// This property adds margin outside of the widget's normal size
2903 /// request, the margin will be added in addition to the size from
2904 /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
2905 pub fn margin_top(self, margin_top: i32) -> Self {
2906 Self {
2907 builder: self.builder.property("margin-top", margin_top),
2908 }
2909 }
2910
2911 /// The name of the widget.
2912 pub fn name(self, name: impl Into<glib::GString>) -> Self {
2913 Self {
2914 builder: self.builder.property("name", name.into()),
2915 }
2916 }
2917
2918 /// The requested opacity of the widget.
2919 pub fn opacity(self, opacity: f64) -> Self {
2920 Self {
2921 builder: self.builder.property("opacity", opacity),
2922 }
2923 }
2924
2925 /// How content outside the widget's content area is treated.
2926 ///
2927 /// This property is meant to be set by widget implementations,
2928 /// typically in their instance init function.
2929 pub fn overflow(self, overflow: Overflow) -> Self {
2930 Self {
2931 builder: self.builder.property("overflow", overflow),
2932 }
2933 }
2934
2935 /// Whether the widget will receive the default action when it is focused.
2936 pub fn receives_default(self, receives_default: bool) -> Self {
2937 Self {
2938 builder: self.builder.property("receives-default", receives_default),
2939 }
2940 }
2941
2942 /// Whether the widget responds to input.
2943 pub fn sensitive(self, sensitive: bool) -> Self {
2944 Self {
2945 builder: self.builder.property("sensitive", sensitive),
2946 }
2947 }
2948
2949 /// Sets the text of tooltip to be the given string, which is marked up
2950 /// with Pango markup.
2951 ///
2952 /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
2953 ///
2954 /// This is a convenience property which will take care of getting the
2955 /// tooltip shown if the given string is not `NULL`:
2956 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
2957 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
2958 /// the default signal handler.
2959 ///
2960 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
2961 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
2962 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
2963 Self {
2964 builder: self
2965 .builder
2966 .property("tooltip-markup", tooltip_markup.into()),
2967 }
2968 }
2969
2970 /// Sets the text of tooltip to be the given string.
2971 ///
2972 /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
2973 ///
2974 /// This is a convenience property which will take care of getting the
2975 /// tooltip shown if the given string is not `NULL`:
2976 /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
2977 /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
2978 /// the default signal handler.
2979 ///
2980 /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
2981 /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
2982 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
2983 Self {
2984 builder: self.builder.property("tooltip-text", tooltip_text.into()),
2985 }
2986 }
2987
2988 /// How to distribute vertical space if widget gets extra space.
2989 pub fn valign(self, valign: Align) -> Self {
2990 Self {
2991 builder: self.builder.property("valign", valign),
2992 }
2993 }
2994
2995 /// Whether to expand vertically.
2996 pub fn vexpand(self, vexpand: bool) -> Self {
2997 Self {
2998 builder: self.builder.property("vexpand", vexpand),
2999 }
3000 }
3001
3002 /// Whether to use the `vexpand` property.
3003 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
3004 Self {
3005 builder: self.builder.property("vexpand-set", vexpand_set),
3006 }
3007 }
3008
3009 /// Whether the widget is visible.
3010 pub fn visible(self, visible: bool) -> Self {
3011 Self {
3012 builder: self.builder.property("visible", visible),
3013 }
3014 }
3015
3016 /// Overrides for width request of the widget.
3017 ///
3018 /// If this is -1, the natural request will be used.
3019 pub fn width_request(self, width_request: i32) -> Self {
3020 Self {
3021 builder: self.builder.property("width-request", width_request),
3022 }
3023 }
3024
3025 /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
3026 ///
3027 /// The accessible role cannot be changed once set.
3028 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
3029 Self {
3030 builder: self.builder.property("accessible-role", accessible_role),
3031 }
3032 }
3033
3034 // rustdoc-stripper-ignore-next
3035 /// Build the [`Label`].
3036 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
3037 pub fn build(self) -> Label {
3038 assert_initialized_main_thread!();
3039 self.builder.build()
3040 }
3041}