pub trait LabelExt: 'static {
Show 84 methods fn angle(&self) -> f64; fn attributes(&self) -> Option<AttrList>; fn current_uri(&self) -> Option<GString>; fn ellipsize(&self) -> EllipsizeMode; fn justify(&self) -> Justification; fn label(&self) -> GString; fn layout(&self) -> Option<Layout>; fn layout_offsets(&self) -> (i32, i32); fn is_line_wrap(&self) -> bool; fn line_wrap_mode(&self) -> WrapMode; fn lines(&self) -> i32; fn max_width_chars(&self) -> i32; fn mnemonic_keyval(&self) -> u32; fn mnemonic_widget(&self) -> Option<Widget>; fn is_selectable(&self) -> bool; fn selection_bounds(&self) -> Option<(i32, i32)>; fn is_single_line_mode(&self) -> bool; fn text(&self) -> GString; fn tracks_visited_links(&self) -> bool; fn uses_markup(&self) -> bool; fn uses_underline(&self) -> bool; fn width_chars(&self) -> i32; fn xalign(&self) -> f32; fn yalign(&self) -> f32; fn select_region(&self, start_offset: i32, end_offset: i32); fn set_angle(&self, angle: f64); fn set_attributes(&self, attrs: Option<&AttrList>); fn set_ellipsize(&self, mode: EllipsizeMode); fn set_justify(&self, jtype: Justification); fn set_label(&self, str: &str); fn set_line_wrap(&self, wrap: bool); fn set_line_wrap_mode(&self, wrap_mode: WrapMode); fn set_lines(&self, lines: i32); fn set_markup(&self, str: &str); fn set_markup_with_mnemonic(&self, str: &str); fn set_max_width_chars(&self, n_chars: i32); fn set_mnemonic_widget(&self, widget: Option<&impl IsA<Widget>>); fn set_pattern(&self, pattern: &str); fn set_selectable(&self, setting: bool); fn set_single_line_mode(&self, single_line_mode: bool); fn set_text(&self, str: &str); fn set_text_with_mnemonic(&self, str: &str); fn set_track_visited_links(&self, track_links: bool); fn set_use_markup(&self, setting: bool); fn set_use_underline(&self, setting: bool); fn set_width_chars(&self, n_chars: i32); fn set_xalign(&self, xalign: f32); fn set_yalign(&self, yalign: f32); fn cursor_position(&self) -> i32; fn selection_bound(&self) -> i32; fn wraps(&self) -> bool; fn set_wrap(&self, wrap: bool); fn wrap_mode(&self) -> WrapMode; fn set_wrap_mode(&self, wrap_mode: WrapMode); fn connect_activate_current_link<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn emit_activate_current_link(&self); fn connect_activate_link<F: Fn(&Self, &str) -> Inhibit + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_copy_clipboard<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn emit_copy_clipboard(&self); fn connect_move_cursor<F: Fn(&Self, MovementStep, i32, bool) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn emit_move_cursor(
        &self,
        step: MovementStep,
        count: i32,
        extend_selection: bool
    ); fn connect_populate_popup<F: Fn(&Self, &Menu) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_angle_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_attributes_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_cursor_position_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_ellipsize_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_justify_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_label_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_lines_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_max_width_chars_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_mnemonic_keyval_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_mnemonic_widget_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_pattern_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_selectable_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_selection_bound_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_single_line_mode_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_track_visited_links_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_use_markup_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_use_underline_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_width_chars_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_wrap_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_wrap_mode_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_xalign_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId; fn connect_yalign_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F
    ) -> SignalHandlerId;
}
Expand description

Trait containing all Label methods.

Implementors

AccelLabel, Label

Required Methods

Gets the angle of rotation for the label. See set_angle().

Returns

the angle of rotation for the label

Gets the attribute list that was set on the label using set_attributes(), if any. This function does not reflect attributes that come from the labels markup (see set_markup()). If you want to get the effective attributes for the label, use pango_layout_get_attribute (gtk_label_get_layout (label)).

Returns

the attribute list, or None if none was set.

Returns the URI for the currently active link in the label. The active link is the one under the mouse pointer or, in a selectable label, the link in which the text cursor is currently positioned.

This function is intended for use in a signal::Label::activate-link handler or for use in a signal::Widget::query-tooltip handler.

Returns

the currently active URI. The string is owned by GTK+ and must not be freed or modified.

Returns the ellipsizing position of the label. See set_ellipsize().

Returns

pango::EllipsizeMode

Returns the justification of the label. See set_justify().

Returns

Justification

Fetches the text from a label widget including any embedded underlines indicating mnemonics and Pango markup. (See text()).

Returns

the text of the label widget. This string is owned by the widget and must not be modified or freed.

Gets the pango::Layout used to display the label. The layout is useful to e.g. convert text positions to pixel positions, in combination with layout_offsets(). The returned layout is owned by the self so need not be freed by the caller. The self is free to recreate its layout at any time, so it should be considered read-only.

Returns

the pango::Layout for this label

Obtains the coordinates where the label will draw the pango::Layout representing the text in the label; useful to convert mouse events into coordinates inside the pango::Layout, e.g. to take some action if some part of the label is clicked. Of course you will need to create a EventBox to receive the events, and pack the label inside it, since labels are windowless (they return false from WidgetExt::has_window()). Remember when using the pango::Layout functions you need to convert to and from pixels using PANGO_PIXELS() or PANGO_SCALE.

Returns
x

location to store X offset of layout, or None

y

location to store Y offset of layout, or None

Returns whether lines in the label are automatically wrapped. See set_line_wrap().

Returns

true if the lines of the label are automatically wrapped.

Returns line wrap mode used by the label. See set_line_wrap_mode().

Returns

true if the lines of the label are automatically wrapped.

Gets the number of lines to which an ellipsized, wrapping label should be limited. See set_lines().

Returns

The number of lines

Retrieves the desired maximum width of self, in characters. See set_width_chars().

Returns

the maximum width of the label in characters.

If the label has been set so that it has an mnemonic key this function returns the keyval used for the mnemonic accelerator. If there is no mnemonic set up it returns GDK_KEY_VoidSymbol.

Returns

GDK keyval usable for accelerators, or GDK_KEY_VoidSymbol

Retrieves the target of the mnemonic (keyboard shortcut) of this label. See set_mnemonic_widget().

Returns

the target of the label’s mnemonic, or None if none has been set and the default algorithm will be used.

Gets the value set by set_selectable().

Returns

true if the user can copy text from the label

Gets the selected range of characters in the label, returning true if there’s a selection.

Returns

true if selection is non-empty

start

return location for start of selection, as a character offset

end

return location for end of selection, as a character offset

Returns whether the label is in single line mode.

Returns

true when the label is in single line mode.

Fetches the text from a label widget, as displayed on the screen. This does not include any embedded underlines indicating mnemonics or Pango markup. (See label())

Returns

the text in the label widget. This is the internal string used by the label, and must not be modified.

Returns whether the label is currently keeping track of clicked links.

Returns

true if clicked links are remembered

Returns whether the label’s text is interpreted as marked up with the [Pango text markup language][PangoMarkupFormat]. See gtk_label_set_use_markup ().

Returns

true if the label’s text will be parsed for markup.

Returns whether an embedded underline in the label indicates a mnemonic. See set_use_underline().

Returns

true whether an embedded underline in the label indicates the mnemonic accelerator keys.

Retrieves the desired width of self, in characters. See set_width_chars().

Returns

the width of the label in characters.

Gets the property::Label::xalign property for self.

Returns

the xalign property

Gets the property::Label::yalign property for self.

Returns

the yalign property

Selects a range of characters in the label, if the label is selectable. See set_selectable(). If the label is not selectable, this function has no effect. If start_offset or end_offset are -1, then the end of the label will be substituted.

start_offset

start offset (in characters not bytes)

end_offset

end offset (in characters not bytes)

Sets the angle of rotation for the label. An angle of 90 reads from from bottom to top, an angle of 270, from top to bottom. The angle setting for the label is ignored if the label is selectable, wrapped, or ellipsized.

angle

the angle that the baseline of the label makes with the horizontal, in degrees, measured counterclockwise

Sets a pango::AttrList; the attributes in the list are applied to the label text.

The attributes set with this function will be applied and merged with any other attributes previously effected by way of the property::Label::use-underline or property::Label::use-markup properties. While it is not recommended to mix markup strings with manually set attributes, if you must; know that the attributes will be applied to the label after the markup string is parsed.

attrs

a pango::AttrList, or None

Sets the mode used to ellipsize (add an ellipsis: “…”) to the text if there is not enough space to render the entire string.

mode

a pango::EllipsizeMode

Sets the alignment of the lines in the text of the label relative to each other. Justification::Left is the default value when the widget is first created with Label::new(). If you instead want to set the alignment of the label as a whole, use WidgetExt::set_halign() instead. set_justify() has no effect on labels containing only a single line.

jtype

a Justification

Sets the text of the label. The label is interpreted as including embedded underlines and/or Pango markup depending on the values of the property::Label::use-underline and property::Label::use-markup properties.

str

the new text to set for the label

Toggles line wrapping within the Label widget. true makes it break lines if text exceeds the widget’s size. false lets the text get cut off by the edge of the widget if it exceeds the widget size.

Note that setting line wrapping to true does not make the label wrap at its parent container’s width, because GTK+ widgets conceptually can’t make their requisition depend on the parent container’s size. For a label that wraps at a specific position, set the label’s width using WidgetExt::set_size_request().

wrap

the setting

If line wrapping is on (see set_line_wrap()) this controls how the line wrapping is done. The default is pango::WrapMode::Word which means wrap on word boundaries.

wrap_mode

the line wrapping mode

Sets the number of lines to which an ellipsized, wrapping label should be limited. This has no effect if the label is not wrapping or ellipsized. Set this to -1 if you don’t want to limit the number of lines.

lines

the desired number of lines, or -1

Parses str which is marked up with the [Pango text markup language][PangoMarkupFormat], setting the label’s text and attribute list based on the parse results.

If the str is external data, you may need to escape it with g_markup_escape_text() or g_markup_printf_escaped():

⚠️ The following code is in C ⚠️

GtkWidget *label = gtk_label_new (NULL);
const char *str = "some text";
const char *format = "<span style=\"italic\">\%s</span>";
char *markup;

markup = g_markup_printf_escaped (format, str);
gtk_label_set_markup (GTK_LABEL (label), markup);
g_free (markup);

This function will set the property::Label::use-markup property to true as a side effect.

If you set the label contents using the property::Label::label property you should also ensure that you set the property::Label::use-markup property accordingly.

See also: set_text()

str

a markup string (see [Pango markup format][PangoMarkupFormat])

Parses str which is marked up with the [Pango text markup language][PangoMarkupFormat], setting the label’s text and attribute list based on the parse results. If characters in str are preceded by an underscore, they are underlined indicating that they represent a keyboard accelerator called a mnemonic.

The mnemonic key can be used to activate another widget, chosen automatically, or explicitly using set_mnemonic_widget().

str

a markup string (see [Pango markup format][PangoMarkupFormat])

Sets the desired maximum width in characters of self to n_chars.

n_chars

the new desired maximum width, in characters.

If the label has been set so that it has an mnemonic key (using i.e. set_markup_with_mnemonic(), set_text_with_mnemonic(), Label::with_mnemonic() or the “use_underline” property) the label can be associated with a widget that is the target of the mnemonic. When the label is inside a widget (like a Button or a Notebook tab) it is automatically associated with the correct widget, but sometimes (i.e. when the target is a Entry next to the label) you need to set it explicitly using this function.

The target widget will be accelerated by emitting the GtkWidget::mnemonic-activate signal on it. The default handler for this signal will activate the widget if there are no mnemonic collisions and toggle focus between the colliding widgets otherwise.

widget

the target Widget, or None to unset

The pattern of underlines you want under the existing text within the Label widget. For example if the current text of the label says “FooBarBaz” passing a pattern of “___ ___” will underline “Foo” and “Baz” but not “Bar”.

pattern

The pattern as described above.

Selectable labels allow the user to select text from the label, for copy-and-paste.

setting

true to allow selecting text in the label

Sets whether the label is in single line mode.

single_line_mode

true if the label should be in single line mode

Sets the text within the Label widget. It overwrites any text that was there before.

This function will clear any previously set mnemonic accelerators, and set the property::Label::use-underline property to false as a side effect.

This function will set the property::Label::use-markup property to false as a side effect.

See also: set_markup()

str

The text you want to set

Sets the label’s text from the string str. If characters in str are preceded by an underscore, they are underlined indicating that they represent a keyboard accelerator called a mnemonic. The mnemonic key can be used to activate another widget, chosen automatically, or explicitly using set_mnemonic_widget().

str

a string

Sets whether the label should keep track of clicked links (and use a different color for them).

true to track visited links

Sets whether the text of the label contains markup in [Pango’s text markup language][PangoMarkupFormat]. See set_markup().

setting

true if the label’s text should be parsed for markup.

If true, an underline in the text indicates the next character should be used for the mnemonic accelerator key.

setting

true if underlines in the text indicate mnemonics

Sets the desired width in characters of self to n_chars.

n_chars

the new desired width, in characters.

Sets the property::Label::xalign property for self.

xalign

the new xalign value, between 0 and 1

Sets the property::Label::yalign property for self.

yalign

the new yalign value, between 0 and 1

If line wrapping is on (see the property::Label::wrap property) this controls how the line wrapping is done. The default is pango::WrapMode::Word, which means wrap on word boundaries.

If line wrapping is on (see the property::Label::wrap property) this controls how the line wrapping is done. The default is pango::WrapMode::Word, which means wrap on word boundaries.

A [keybinding signal][GtkBindingSignal] which gets emitted when the user activates a link in the label.

Applications may also emit the signal with g_signal_emit_by_name() if they need to control activation of URIs programmatically.

The default bindings for this signal are all forms of the Enter key.

The signal which gets emitted to activate a URI. Applications may connect to it to override the default behaviour, which is to call show_uri_on_window().

uri

the URI that is activated

Returns

true if the link has been activated

The ::copy-clipboard signal is a [keybinding signal][GtkBindingSignal] which gets emitted to copy the selection to the clipboard.

The default binding for this signal is Ctrl-c.

The ::move-cursor signal is a [keybinding signal][GtkBindingSignal] which gets emitted when the user initiates a cursor movement. If the cursor is not visible in entry, this signal causes the viewport to be moved instead.

Applications should not connect to it, but may emit it with g_signal_emit_by_name() if they need to control the cursor programmatically.

The default bindings for this signal come in two variants, the variant with the Shift modifier extends the selection, the variant without the Shift modifer does not. There are too many key combinations to list them all here.

  • Arrow keys move by individual characters/lines
  • Ctrl-arrow key combinations move by words/paragraphs
  • Home/End keys move to the ends of the buffer
step

the granularity of the move, as a MovementStep

count

the number of step units to move

extend_selection

true if the move should extend the selection

The ::populate-popup signal gets emitted before showing the context menu of the label. Note that only selectable labels have context menus.

If you need to add items to the context menu, connect to this signal and append your menuitems to the menu.

the menu that is being populated

Implementors