W Wrapl, The Programming Language

Libraries:Gtk:Gtk:Label

Types

T

Inherits from:

The T widget displays a small amount of text. As the name implies, most labels are used to label another widget such as a Gtk.Gtk.Button.T, a Gtk.Gtk.MenuItem.T, or a Gtk.Gtk.OptionMenu.T.

GtkLabel as GtkBuildable

The GtkLabel implementation of the GtkBuildable interface supports a custom <attributes> element, which supports any number of <attribute> elements. the <attribute> element has attributes named name, value, start and end and allows you to specify PangoAttribute values for this label.

Example 13. A UI definition fragment specifying Pango attributes

1
2
3
4
5
6
<object class="GtkLabel">
  <attributes>
    <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
    <attribute name="background" value="red" start="5" end="10"/>"
  </attributes>
</object>


The start and end attributes specify the range of characters to which the Pango attribute applies. If start and end are not specified, the attribute is applied to the whole text. Note that specifying ranges does not make much sense with translatable attributes. Use markup embedded in the translatable content instead.


Mnemonics

Labels may contain mnemonics. Mnemonics are underlined characters in the label, used for keyboard navigation. Mnemonics are created by providing a string with an underscore before the mnemonic character, such as "_File", to the functions gtk_label_new_with_mnemonic() or SetTextWithMnemonic.

Mnemonics automatically activate any activatable widget the label is inside, such as a Gtk.Gtk.Button.T; if the label is not inside the mnemonic's target widget, you have to tell the label about the target using SetMnemonicWidget. Here's a simple example where the label is inside a button:

1
2
3
4
/* Pressing Alt+H will activate this button */
button = gtk_button_new ();
label = gtk_label_new_with_mnemonic ("_Hello");
gtk_container_add (GTK_CONTAINER (button), label);

There's a convenience function to create buttons with a mnemonic label already inside:

1
2
/* Pressing Alt+H will activate this button */
button = gtk_button_new_with_mnemonic ("_Hello");

To create a mnemonic for a widget alongside the label, such as a Gtk.Gtk.Entry.T, you have to point the label at the entry with SetMnemonicWidget:

1
2
3
4
/* Pressing Alt+H will focus the entry */
entry = gtk_entry_new ();
label = gtk_label_new_with_mnemonic ("_Hello");
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);

Markup (styled text)

To make it easy to format text in a label (changing colors, fonts, etc.), label text can be provided in a simple markup format. Here's how to create a label with a small font:

1
2
label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>");

(See complete documentation of available tags in the Pango manual.)

The markup passed to SetMarkup must be valid; for example, literal </>/& characters must be escaped as &lt;, &gt;, and &amp;. If you pass text obtained from the user, file, or a network to SetMarkup, you'll want to escape it with g_markup_escape_text() or g_markup_printf_escaped().

Markup strings are just a convenient way to set the PangoAttrList on a label; SetAttributes may be a simpler way to set attributes in some cases. Be careful though; PangoAttrList tends to cause internationalization problems, unless you're applying attributes to the entire string (i.e. unless you set the range of each attribute to [0, G_MAXINT)). The reason is that specifying the start_index and end_index for a PangoAttribute requires knowledge of the exact string being displayed, so translations will cause problems.


Selectable labels

Labels can be made selectable with SetSelectable. Selectable labels allow the user to copy the label contents to the clipboard. Only labels that contain useful-to-copy information - such as error messages - should be made selectable.


Text layout

A label can contain any number of paragraphs, but will have performance problems if it contains more than a small number. Paragraphs are separated by newlines or other paragraph separators understood by Pango.

Labels can automatically wrap text if you call SetLineWrap.

SetJustify sets how the lines in a label align with one another. If you want to set how the label as a whole aligns in its available space, see Gtk.Gtk.Misc.SetAlignment.


Links

Since 2.18, GTK+ supports markup for clickable hyperlinks in addition to regular Pango markup. The markup for links is borrowed from HTML, using the a with href and title attributes. GTK+ renders links similar to the way they appear in web browsers, with colored, underlined text. The title attribute is displayed as a tooltip on the link. An example looks like this:

1
gtk_label_set_markup (label, "Go to the <a href=\"http://www.gtk.org\" title=\"&lt;i&gt;Our&/i&gt; website\">GTK+ website</a> for more...");

It is possible to implement custom handling for links and their tooltips with the "activate-link" signal and the GetCurrentUri function.



Constants

Nil : T

Functions

GetType() : Gtk.GObject.Type.T



New(str @ Std.String.T) : Gtk.Gtk.Label.T

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

str The text of the label
Returns the new T


NewWithMnemonic(str @ Std.String.T) : Gtk.Gtk.Label.T

Creates a new T, 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 SetMnemonicWidget.

If SetMnemonicWidget is not called, then the first activatable ancestor of the T 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.

str The text of the label, with an underscore in front of the mnemonic character
Returns the new T


Methods

:Get(self @ T, str @ Agg.List.T) : Std.Object.T

Warning

Get is deprecated and should not be used in newly-written code. Use GetText instead.



:GetAngle(self @ T) : Std.Real.T

Gets the angle of rotation for the label. See SetAngle.

label a T
Returns the angle of rotation for the label


:GetAttributes(self @ T) : Gtk.Pango.AttrList.T

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

label a T
Returns the attribute list, or NULL if none was set. [transfer none]


:GetCurrentUri(self @ T) : Std.String.T

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 "activate-link" handler or for use in a "query-tooltip" handler.

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


:GetEllipsize(self @ T) : Gtk.Pango.EllipsizeMode.T

Returns the ellipsizing position of the label. See SetEllipsize.

label a T
Returns PangoEllipsizeMode


:GetJustify(self @ T) : Gtk.Gtk.Justification.T

Returns the justification of the label. See SetJustify.

label a T
Returns Gtk.Gtk.Justification.T


:GetLabel(self @ T) : Std.String.T

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

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


:GetLayout(self @ T) : Gtk.Pango.Layout.T

Gets the PangoLayout used to display the label. The layout is useful to e.g. convert text positions to pixel positions, in combination with GetLayoutOffsets. The returned layout is owned by the label so need not be freed by the caller.

label a T
Returns the PangoLayout for this label. [transfer none]


:GetLayoutOffsets(self @ T, x @ Std.Object.T, y @ Std.Object.T) : Std.Object.T

Obtains the coordinates where the label will draw the PangoLayout representing the text in the label; useful to convert mouse events into coordinates inside the PangoLayout, e.g. to take some action if some part of the label is clicked. Of course you will need to create a Gtk.Gtk.EventBox.T to receive the events, and pack the label inside it, since labels are a Gtk.Gtk.WidgetFlags.NoWindow widget. Remember when using the PangoLayout functions you need to convert to and from pixels using PANGO_PIXELS() or PANGO_SCALE.

label a T
x location to store X offset of layout, or NULL. [out][allow-none]
y location to store Y offset of layout, or NULL. [out][allow-none]


:GetLineWrap(self @ T) : Std.Symbol.T

Returns whether lines in the label are automatically wrapped. See SetLineWrap.

label a T
Returns TRUE if the lines of the label are automatically wrapped.


:GetLineWrapMode(self @ T) : Gtk.Pango.WrapMode.T

Returns line wrap mode used by the label. See SetLineWrapMode.

label a T
Returns TRUE if the lines of the label are automatically wrapped.


:GetMaxWidthChars(self @ T) : Std.Integer.SmallT

Retrieves the desired maximum width of label, in characters. See SetWidthChars.

label a T
Returns the maximum width of the label in characters.


:GetMnemonicKeyval(self @ T) : Std.Integer.SmallT

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_VoidSymbol.

label a T
Returns GDK keyval usable for accelerators, or GDK_VoidSymbol


:GetMnemonicWidget(self @ T) : Gtk.Gtk.Widget.T

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

label a T
Returns the target of the label's mnemonic, or NULL if none has been set and the default algorithm will be used. [transfer none]


:GetSelectable(self @ T) : Std.Symbol.T

Gets the value set by SetSelectable.

label a T
Returns TRUE if the user can copy text from the label


:GetSelectionBounds(self @ T, start @ Std.Object.T, end @ Std.Object.T) : Std.Symbol.T

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

label a T
start return location for start of selection, as a character offset. [out]
end return location for end of selection, as a character offset. [out]
Returns TRUE if selection is non-empty


:GetSingleLineMode(self @ T) : Std.Symbol.T

Returns whether the label is in single line mode.

label a T
Returns TRUE when the label is in single line mode.


:GetText(self @ T) : Std.String.T

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 GetLabel)

label a T
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.

label a T
Returns TRUE if clicked links are remembered


:GetUseMarkup(self @ T) : Std.Symbol.T

Returns whether the label's text is interpreted as marked up with the Pango text markup language. See SetUseMarkup.

label a T
Returns TRUE if the label's text will be parsed for markup.


:GetUseUnderline(self @ T) : Std.Symbol.T

Returns whether an embedded underline in the label indicates a mnemonic. See SetUseUnderline.

label a T
Returns TRUE whether an embedded underline in the label indicates the mnemonic accelerator keys.


:GetWidthChars(self @ T) : Std.Integer.SmallT

Retrieves the desired width of label, in characters. See SetWidthChars.

label a T
Returns the width of the label in characters.


:ParseUline(self @ T, string @ Std.String.T) : Std.Integer.SmallT

Warning

ParseUline is deprecated and should not be used in newly-written code. Use SetUseUnderline instead.



:SelectRegion(self @ T, start_offset @ Std.Integer.SmallT, end_offset @ Std.Integer.SmallT) : Std.Object.T

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

label a T
start_offset start offset (in characters not bytes)
end_offset end offset (in characters not bytes)


:SetAngle(self @ T, angle @ Std.Real.T) : Std.Object.T

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.

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


:SetAttributes(self @ T, attrs @ Gtk.Pango.AttrList.T) : Std.Object.T

Sets a PangoAttrList; the attributes in the list are applied to the label text.

Note

The attributes set with this function will be applied and merged with any other attributes previously effected by way of the "use-underline" or "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.



:SetEllipsize(self @ T, mode @ Gtk.Pango.EllipsizeMode.T) : Std.Object.T

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

label a T
mode a PangoEllipsizeMode


:SetJustify(self @ T, jtype @ Gtk.Gtk.Justification.T) : Std.Object.T

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

label a T
jtype a Gtk.Gtk.Justification.T


:SetLabel(self @ T, str @ Std.String.T) : Std.Object.T

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

label a T
str the new text to set for the label


:SetLineWrap(self @ T, wrap @ Std.Symbol.T) : Std.Object.T

Toggles line wrapping within the T 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.Gtk.Widget.SetSizeRequest.

label a T
wrap the setting


:SetLineWrapMode(self @ T, wrap_mode @ Gtk.Pango.WrapMode.T) : Std.Object.T

If line wrapping is on (see SetLineWrap) this controls how the line wrapping is done. The default is Gtk.Pango.WrapMode.Word which means wrap on word boundaries.

label a T
wrap_mode the line wrapping mode


:SetMarkup(self @ T, str @ Std.String.T) : Std.Object.T

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

1
2
3
4
5
char *markup;
  
markup = g_markup_printf_escaped ("<span style=\"italic\">%s</span>", str);
gtk_label_set_markup (GTK_LABEL (label), markup);
g_free (markup);


:SetMarkupWithMnemonic(self @ T, str @ Std.String.T) : Std.Object.T

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 SetMnemonicWidget.

label a T
str a markup string (see Pango markup format)


:SetMaxWidthChars(self @ T, n_chars @ Std.Integer.SmallT) : Std.Object.T

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

label a T
n_chars the new desired maximum width, in characters.


:SetMnemonicWidget(self @ T, widget @ Gtk.Gtk.Widget.T) : Std.Object.T

If the label has been set so that it has an mnemonic key (using i.e. SetMarkupWithMnemonic, SetTextWithMnemonic, gtk_label_new_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 Gtk.Gtk.Button.T or a Gtk.Gtk.Notebook.T tab) it is automatically associated with the correct widget, but sometimes (i.e. when the target is a Gtk.Gtk.Entry.T 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.

label a T
widget the target Gtk.Gtk.Widget.T. [allow-none]


:SetPattern(self @ T, pattern @ Std.String.T) : Std.Object.T

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

label The T you want to set the pattern to.
pattern The pattern as described above.


:SetSelectable(self @ T, setting @ Std.Symbol.T) : Std.Object.T

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

label a T
setting TRUE to allow selecting text in the label


:SetSingleLineMode(self @ T, single_line_mode @ Std.Symbol.T) : Std.Object.T

Sets whether the label is in single line mode.

label a T
single_line_mode TRUE if the label should be in single line mode


:SetText(self @ T, str @ Std.String.T) : Std.Object.T

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

This will also clear any previously set mnemonic accelerators.

label a T
str The text you want to set


:SetTextWithMnemonic(self @ T, str @ Std.String.T) : Std.Object.T

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 SetMnemonicWidget.

label a T
str a string


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

label a T
track_links TRUE to track visited links


:SetUseMarkup(self @ T, setting @ Std.Symbol.T) : Std.Object.T

Sets whether the text of the label contains markup in Pango's text markup language. See SetMarkup.

label a T
setting TRUE if the label's text should be parsed for markup.


:SetUseUnderline(self @ T, setting @ Std.Symbol.T) : Std.Object.T

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

label a T
setting TRUE if underlines in the text indicate mnemonics


:SetWidthChars(self @ T, n_chars @ Std.Integer.SmallT) : Std.Object.T

Sets the desired width in characters of label to n_chars.

label a T
n_chars the new desired width, in characters.