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