Class: Gtk::Label

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#angleFloat

The angle that the baseline of the label makes with the horizontal, in degrees, measured counterclockwise. An angle of 90 reads from from bottom to top, an angle of 270, from top to bottom. Ignored if the label is selectable.

Returns:

  • (Float)

    angle

#angle=(angle) ⇒ Float

The angle that the baseline of the label makes with the horizontal, in degrees, measured counterclockwise. An angle of 90 reads from from bottom to top, an angle of 270, from top to bottom. Ignored if the label is selectable.

Parameters:

  • angle (Float)

Returns:

  • (Float)

    angle

  • (Float)

    angle

#attributesPango::AttrList

Returns attributes.

Returns:

  • (Pango::AttrList)

    attributes

#attributes=(attributes) ⇒ Pango::AttrList

Parameters:

  • attributes (Pango::AttrList)

Returns:

  • (Pango::AttrList)

    attributes

  • (Pango::AttrList)

    attributes

#current_uriString

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 Gtk::Label::activate-link handler or for use in a Gtk::Widget::query-tooltip handler.

Returns:

  • (String)

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

#cursor_positionInteger

Returns cursor-position.

Returns:

  • (Integer)

    cursor-position

#cursor_position=(cursor_position) ⇒ Integer

Parameters:

  • cursor_position (Integer)

Returns:

  • (Integer)

    cursor-position

  • (Integer)

    cursor-position

#ellipsizePango::EllipsizeMode

The preferred place to ellipsize the string, if the label does not have enough room to display the entire string, specified as a Pango::EllipsizeMode.

Note that setting this property to a value other than %PANGO_ELLIPSIZE_NONE has the side-effect that the label requests only enough space to display the ellipsis “…”. In particular, this means that ellipsizing labels do not work well in notebook tabs, unless the Gtk::Notebook tab-expand child property is set to true. Other ways to set a label’s width are gtk_widget_set_size_request() and gtk_label_set_width_chars().

Returns:

#ellipsize=(ellipsize) ⇒ Pango::EllipsizeMode

The preferred place to ellipsize the string, if the label does not have enough room to display the entire string, specified as a Pango::EllipsizeMode.

Note that setting this property to a value other than %PANGO_ELLIPSIZE_NONE has the side-effect that the label requests only enough space to display the ellipsis “…”. In particular, this means that ellipsizing labels do not work well in notebook tabs, unless the Gtk::Notebook tab-expand child property is set to true. Other ways to set a label’s width are gtk_widget_set_size_request() and gtk_label_set_width_chars().

Parameters:

Returns:

#get_layout_offsets(x, y) ⇒ nil

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 Gtk::EventBox to receive the events, and pack the label inside it, since labels are windowless (they return false from gtk_widget_get_has_window()). Remember when using the Pango::Layout functions you need to convert to and from pixels using PANGO_PIXELS() or #PANGO_SCALE.

Parameters:

  • x (Integer)

    location to store X offset of layout, or nil

  • y (Integer)

    location to store Y offset of layout, or nil

Returns:

  • (nil)

#get_selection_bounds(start, end) ⇒ TrueClass

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

Parameters:

  • start (Integer)

    return location for start of selection, as a character offset

  • end (Integer)

    return location for end of selection, as a character offset

Returns:

  • (TrueClass)

    true if selection is non-empty

#justifyGtk::Justification

Returns justify.

Returns:

#justify=(justify) ⇒ Gtk::Justification

Parameters:

Returns:

#labelString

The contents of the label.

If the string contains [Pango XML markup], you will have to set the Gtk::Label:use-markup property to true in order for the label to display the markup attributes. See also gtk_label_set_markup() for a convenience function that sets both this property and the Gtk::Label:use-markup property at the same time.

If the string contains underlines acting as mnemonics, you will have to set the Gtk::Label:use-underline property to true in order for the label to display them.

Returns:

  • (String)

    label

#label=(label) ⇒ String

The contents of the label.

If the string contains [Pango XML markup], you will have to set the Gtk::Label:use-markup property to true in order for the label to display the markup attributes. See also gtk_label_set_markup() for a convenience function that sets both this property and the Gtk::Label:use-markup property at the same time.

If the string contains underlines acting as mnemonics, you will have to set the Gtk::Label:use-underline property to true in order for the label to display them.

Parameters:

  • label (String)

Returns:

  • (String)

    label

  • (String)

    label

#layoutPango::Layout

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 gtk_label_get_layout_offsets(). The returned layout is owned by the label so need not be freed by the caller. The label is free to recreate its layout at any time, so it should be considered read-only.

Returns:

#line_wrapTrueClass

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

Returns:

  • (TrueClass)

    true if the lines of the label are automatically wrapped.

#line_wrap=(wrap) ⇒ nil

Toggles line wrapping within the Gtk::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 gtk_widget_set_size_request().

Parameters:

  • wrap (TrueClass)

    the setting

Returns:

  • (nil)

#line_wrap_modePango::WrapMode

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

Returns:

  • (Pango::WrapMode)

    true if the lines of the label are automatically wrapped.

#line_wrap_mode=(wrap_mode) ⇒ nil

If line wrapping is on (see gtk_label_set_line_wrap()) this controls how the line wrapping is done. The default is %PANGO_WRAP_WORD which means wrap on word boundaries.

Parameters:

Returns:

  • (nil)

#linesInteger

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

Returns:

  • (Integer)

    lines

#lines=(lines) ⇒ Integer

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

Parameters:

  • lines (Integer)

Returns:

  • (Integer)

    lines

  • (Integer)

    lines

#markup=(str) ⇒ nil

Parses str which is marked up with the [Pango text markup language], 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():

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 Gtk::Label:use-markup property to true as a side effect.

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

See also: gtk_label_set_text()

Parameters:

  • str (String)

    a markup string (see [Pango markup format])

Returns:

  • (nil)

#markup_with_mnemonic=(str) ⇒ nil

Parses str which is marked up with the [Pango text markup language], 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 gtk_label_set_mnemonic_widget().

Parameters:

  • str (String)

    a markup string (see [Pango markup format])

Returns:

  • (nil)

#max_width_charsInteger

The desired maximum width of the label, in characters. If this property is set to -1, the width will be calculated automatically.

See the section on [text layout] for details of how Gtk::Label:width-chars and #GtkLabel:max-width-chars determine the width of ellipsized and wrapped labels.

Returns:

  • (Integer)

    max-width-chars

#max_width_chars=(max_width_chars) ⇒ Integer

The desired maximum width of the label, in characters. If this property is set to -1, the width will be calculated automatically.

See the section on [text layout] for details of how Gtk::Label:width-chars and #GtkLabel:max-width-chars determine the width of ellipsized and wrapped labels.

Parameters:

  • max_width_chars (Integer)

Returns:

  • (Integer)

    max-width-chars

  • (Integer)

    max-width-chars

#mnemonic_keyvalInteger

Returns mnemonic-keyval.

Returns:

  • (Integer)

    mnemonic-keyval

#mnemonic_keyval=(mnemonic_keyval) ⇒ Integer

Parameters:

  • mnemonic_keyval (Integer)

Returns:

  • (Integer)

    mnemonic-keyval

  • (Integer)

    mnemonic-keyval

#mnemonic_widgetGtk::Widget

Returns mnemonic-widget.

Returns:

#mnemonic_widget=(mnemonic_widget) ⇒ Gtk::Widget

Parameters:

Returns:

#new(str) ⇒ Gtk::Widget

Creates a new label with the given text inside it. You can pass nil to get an empty label widget.

Parameters:

  • str (String)

    The text of the label

Returns:

#new_with_mnemonic(str) ⇒ Gtk::Widget

Creates a new Gtk::Label, containing the text in str.

If characters in str are preceded by an underscore, they are underlined. If you need a literal underscore character in a label, use ‘__’ (two underscores). The first underlined character represents a keyboard accelerator called a mnemonic. The mnemonic key can be used to activate another widget, chosen automatically, or explicitly using gtk_label_set_mnemonic_widget().

If gtk_label_set_mnemonic_widget() is not called, then the first activatable ancestor of the Gtk::Label will be chosen as the mnemonic widget. For instance, if the label is inside a button or menu item, the button or menu item will automatically become the mnemonic widget and be activated by the mnemonic.

Parameters:

  • str (String)

    The text of the label, with an underscore in front of the mnemonic character

Returns:

#pattern=(pattern) ⇒ String

Returns pattern.

Parameters:

  • pattern (String)

Returns:

  • (String)

    pattern

#select_region(start_offset, end_offset) ⇒ nil

Selects a range of characters in the label, if the label is selectable. See gtk_label_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.

Parameters:

  • start_offset (Integer)

    start offset (in characters not bytes)

  • end_offset (Integer)

    end offset (in characters not bytes)

Returns:

  • (nil)

#selectableTrueClass

Gets the value set by gtk_label_set_selectable().

Returns:

  • (TrueClass)

    true if the user can copy text from the label

#selectable=(selectable) ⇒ TrueClass

Parameters:

  • selectable (TrueClass)

Returns:

  • (TrueClass)

    selectable

  • (TrueClass)

    selectable

#selectable?TrueClass

Returns selectable.

Returns:

  • (TrueClass)

    selectable

#selection_boundInteger

Returns selection-bound.

Returns:

  • (Integer)

    selection-bound

#selection_bound=(selection_bound) ⇒ Integer

Parameters:

  • selection_bound (Integer)

Returns:

  • (Integer)

    selection-bound

  • (Integer)

    selection-bound

#single_line_modeTrueClass

Returns whether the label is in single line mode.

Returns:

  • (TrueClass)

    true when the label is in single line mode.

#single_line_mode=(single_line_mode) ⇒ TrueClass

Whether the label is in single line mode. In single line mode, the height of the label does not depend on the actual text, it is always set to ascent + descent of the font. This can be an advantage in situations where resizing the label because of text changes would be distracting, e.g. in a statusbar.

Parameters:

  • single_line_mode (TrueClass)

Returns:

  • (TrueClass)

    single-line-mode

  • (TrueClass)

    single-line-mode

#single_line_mode?TrueClass

Whether the label is in single line mode. In single line mode, the height of the label does not depend on the actual text, it is always set to ascent + descent of the font. This can be an advantage in situations where resizing the label because of text changes would be distracting, e.g. in a statusbar.

Returns:

  • (TrueClass)

    single-line-mode

#textString

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 gtk_label_get_label())

Returns:

  • (String)

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

#text=(str) ⇒ nil

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

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

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

See also: gtk_label_set_markup()

Parameters:

  • str (String)

    The text you want to set

Returns:

  • (nil)

#text_with_mnemonic=(str) ⇒ nil

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 gtk_label_set_mnemonic_widget().

Parameters:

  • str (String)

    a string

Returns:

  • (nil)

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

Returns:

  • (TrueClass)

    true if clicked links are remembered

#track_visited_links=(track_visited_links) ⇒ TrueClass

Set this property to true to make the label track which links have been visited. It will then apply the #GTK_STATE_FLAG_VISITED when rendering this link, in addition to #GTK_STATE_FLAG_LINK.

Parameters:

  • track_visited_links (TrueClass)

Returns:

  • (TrueClass)

    track-visited-links

  • (TrueClass)

    track-visited-links

#track_visited_links?TrueClass

Set this property to true to make the label track which links have been visited. It will then apply the #GTK_STATE_FLAG_VISITED when rendering this link, in addition to #GTK_STATE_FLAG_LINK.

Returns:

  • (TrueClass)

    track-visited-links

#use_markupTrueClass

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

Returns:

  • (TrueClass)

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

#use_markup=(use_markup) ⇒ TrueClass

Parameters:

  • use_markup (TrueClass)

Returns:

  • (TrueClass)

    use-markup

  • (TrueClass)

    use-markup

#use_markup?TrueClass

Returns use-markup.

Returns:

  • (TrueClass)

    use-markup

#use_underlineTrueClass

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

Returns:

  • (TrueClass)

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

#use_underline=(use_underline) ⇒ TrueClass

Parameters:

  • use_underline (TrueClass)

Returns:

  • (TrueClass)

    use-underline

  • (TrueClass)

    use-underline

#use_underline?TrueClass

Returns use-underline.

Returns:

  • (TrueClass)

    use-underline

#width_charsInteger

The desired width of the label, in characters. If this property is set to -1, the width will be calculated automatically.

See the section on [text layout] for details of how Gtk::Label:width-chars and #GtkLabel:max-width-chars determine the width of ellipsized and wrapped labels.

Returns:

  • (Integer)

    width-chars

#width_chars=(width_chars) ⇒ Integer

The desired width of the label, in characters. If this property is set to -1, the width will be calculated automatically.

See the section on [text layout] for details of how Gtk::Label:width-chars and #GtkLabel:max-width-chars determine the width of ellipsized and wrapped labels.

Parameters:

  • width_chars (Integer)

Returns:

  • (Integer)

    width-chars

  • (Integer)

    width-chars

#wrap=(wrap) ⇒ TrueClass

Parameters:

  • wrap (TrueClass)

Returns:

  • (TrueClass)

    wrap

  • (TrueClass)

    wrap

#wrap?TrueClass

Returns wrap.

Returns:

  • (TrueClass)

    wrap

#wrap_modePango::WrapMode

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

Returns:

#wrap_mode=(wrap_mode) ⇒ Pango::WrapMode

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

Parameters:

Returns:

#xalignGtk::gfloat

The xalign property determines the horizontal aligment of the label text inside the labels size allocation. Compare this to Gtk::Widget:halign, which determines how the labels size allocation is positioned in the space available for the label.

Returns:

  • (Gtk::gfloat)

    xalign

#xalign=(xalign) ⇒ Gtk::gfloat

The xalign property determines the horizontal aligment of the label text inside the labels size allocation. Compare this to Gtk::Widget:halign, which determines how the labels size allocation is positioned in the space available for the label.

Parameters:

  • xalign (Gtk::gfloat)

Returns:

  • (Gtk::gfloat)

    xalign

  • (Gtk::gfloat)

    xalign

#yalignGtk::gfloat

The yalign property determines the vertical aligment of the label text inside the labels size allocation. Compare this to Gtk::Widget:valign, which determines how the labels size allocation is positioned in the space available for the label.

Returns:

  • (Gtk::gfloat)

    yalign

#yalign=(yalign) ⇒ Gtk::gfloat

The yalign property determines the vertical aligment of the label text inside the labels size allocation. Compare this to Gtk::Widget:valign, which determines how the labels size allocation is positioned in the space available for the label.

Parameters:

  • yalign (Gtk::gfloat)

Returns:

  • (Gtk::gfloat)

    yalign

  • (Gtk::gfloat)

    yalign