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