Package ch.bailu.gtk.gtk
Class Label
- All Implemented Interfaces:
PointerInterface
The `GtkLabel` widget displays a small amount of text.
As the name implies, most labels are used to label another widget
such as a [class@Button].
![An example GtkLabel](label.png)
# CSS nodes
```
label
├── [selection]
├── [link]
┊
╰── [link]
```
`GtkLabel` has a single CSS node with the name label. A wide variety
of style classes may be applied to labels, such as .title, .subtitle,
.dim-label, etc. In the `GtkShortcutsWindow`, labels are used with the
.keycap style class.
If the label has a selection, it gets a subnode with name selection.
If the label has links, there is one subnode per link. These subnodes
carry the link or visited state depending on whether they have been
visited. In this case, label node also gets a .link style class.
# 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 [struct@Pango.Attribute]
values for this label.
An example of a UI definition fragment specifying Pango attributes:
```xml
<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.
# Accessibility
`GtkLabel` uses the %GTK_ACCESSIBLE_ROLE_LABEL role.
# 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 [ctor@Gtk.Label.new_with_mnemonic] or
[method@Gtk.Label.set_text_with_mnemonic].
Mnemonics automatically activate any activatable widget the label is
inside, such as a [class@Gtk.Button]; if the label is not inside the
mnemonic’s target widget, you have to tell the label about the target
using [class@Gtk.Label.set_mnemonic_widget]. Here’s a simple example where
the label is inside a button:
```c
// Pressing Alt+H will activate this button
GtkWidget *button = gtk_button_new ();
GtkWidget *label = gtk_label_new_with_mnemonic ("_Hello");
gtk_button_set_child (GTK_BUTTON (button), label);
```
There’s a convenience function to create buttons with a mnemonic label
already inside:
```c
// Pressing Alt+H will activate this button
GtkWidget *button = gtk_button_new_with_mnemonic ("_Hello");
```
To create a mnemonic for a widget alongside the label, such as a
[class@Gtk.Entry], you have to point the label at the entry with
[method@Gtk.Label.set_mnemonic_widget]:
```c
// Pressing Alt+H will focus the entry
GtkWidget *entry = gtk_entry_new ();
GtkWidget *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:
```c
GtkWidget *label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>");
```
(See the Pango manual for complete documentation] of available
tags, [func@Pango.parse_markup])
The markup passed to gtk_label_set_markup() must be valid; for example,
literal <, > and & characters must be escaped as <, >, and &.
If you pass text obtained from the user, file, or a network to
[method@Gtk.Label.set_markup], 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 [struct@Pango.AttrList]
on a label; [method@Gtk.Label.set_attributes] may be a simpler way to set
attributes in some cases. Be careful though; [struct@Pango.AttrList] 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 [struct@Pango.Attribute] requires knowledge of the exact
string being displayed, so translations will cause problems.
# Selectable labels
Labels can be made selectable with [method@Gtk.Label.set_selectable].
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 [method@Gtk.Label.set_wrap].
[method@Gtk.Label.set_justify] 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 the [property@Gtk.Widget:halign] and
[property@Gtk.Widget:valign] properties.
The [property@Gtk.Label:width-chars] and [property@Gtk.Label:max-width-chars]
properties can be used to control the size allocation of ellipsized or
wrapped labels. For ellipsizing labels, if either is specified (and less
than the actual text size), it is used as the minimum width, and the actual
text size is used as the natural width of the label. For wrapping labels,
width-chars is used as the minimum width, if specified, and max-width-chars
is used as the natural width. Even if max-width-chars specified, wrapping
labels will be rewrapped to use all of the available width.
# Links
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“, “title“ and “class“ 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. The “class“ attribute is
used as style class on the CSS node for the link.
An example looks like this:
```c
const char *text =
"Go to the"
"<a href=\"http://www.gtk.org title=\"<i>Our</i> website\">"
"GTK website</a> for more...";
GtkWidget *label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), text);
```
It is possible to implement custom handling for links and their tooltips
with the [signal@Gtk.Label::activate-link] signal and the
[method@Gtk.Label.get_current_uri] function.
As the name implies, most labels are used to label another widget
such as a [class@Button].
![An example GtkLabel](label.png)
# CSS nodes
```
label
├── [selection]
├── [link]
┊
╰── [link]
```
`GtkLabel` has a single CSS node with the name label. A wide variety
of style classes may be applied to labels, such as .title, .subtitle,
.dim-label, etc. In the `GtkShortcutsWindow`, labels are used with the
.keycap style class.
If the label has a selection, it gets a subnode with name selection.
If the label has links, there is one subnode per link. These subnodes
carry the link or visited state depending on whether they have been
visited. In this case, label node also gets a .link style class.
# 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 [struct@Pango.Attribute]
values for this label.
An example of a UI definition fragment specifying Pango attributes:
```xml
<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.
# Accessibility
`GtkLabel` uses the %GTK_ACCESSIBLE_ROLE_LABEL role.
# 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 [ctor@Gtk.Label.new_with_mnemonic] or
[method@Gtk.Label.set_text_with_mnemonic].
Mnemonics automatically activate any activatable widget the label is
inside, such as a [class@Gtk.Button]; if the label is not inside the
mnemonic’s target widget, you have to tell the label about the target
using [class@Gtk.Label.set_mnemonic_widget]. Here’s a simple example where
the label is inside a button:
```c
// Pressing Alt+H will activate this button
GtkWidget *button = gtk_button_new ();
GtkWidget *label = gtk_label_new_with_mnemonic ("_Hello");
gtk_button_set_child (GTK_BUTTON (button), label);
```
There’s a convenience function to create buttons with a mnemonic label
already inside:
```c
// Pressing Alt+H will activate this button
GtkWidget *button = gtk_button_new_with_mnemonic ("_Hello");
```
To create a mnemonic for a widget alongside the label, such as a
[class@Gtk.Entry], you have to point the label at the entry with
[method@Gtk.Label.set_mnemonic_widget]:
```c
// Pressing Alt+H will focus the entry
GtkWidget *entry = gtk_entry_new ();
GtkWidget *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:
```c
GtkWidget *label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>");
```
(See the Pango manual for complete documentation] of available
tags, [func@Pango.parse_markup])
The markup passed to gtk_label_set_markup() must be valid; for example,
literal <, > and & characters must be escaped as <, >, and &.
If you pass text obtained from the user, file, or a network to
[method@Gtk.Label.set_markup], 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 [struct@Pango.AttrList]
on a label; [method@Gtk.Label.set_attributes] may be a simpler way to set
attributes in some cases. Be careful though; [struct@Pango.AttrList] 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 [struct@Pango.Attribute] requires knowledge of the exact
string being displayed, so translations will cause problems.
# Selectable labels
Labels can be made selectable with [method@Gtk.Label.set_selectable].
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 [method@Gtk.Label.set_wrap].
[method@Gtk.Label.set_justify] 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 the [property@Gtk.Widget:halign] and
[property@Gtk.Widget:valign] properties.
The [property@Gtk.Label:width-chars] and [property@Gtk.Label:max-width-chars]
properties can be used to control the size allocation of ellipsized or
wrapped labels. For ellipsizing labels, if either is specified (and less
than the actual text size), it is used as the minimum width, and the actual
text size is used as the natural width of the label. For wrapping labels,
width-chars is used as the minimum width, if specified, and max-width-chars
is used as the natural width. Even if max-width-chars specified, wrapping
labels will be rewrapped to use all of the available width.
# Links
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“, “title“ and “class“ 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. The “class“ attribute is
used as style class on the CSS node for the link.
An example looks like this:
```c
const char *text =
"Go to the"
"<a href=\"http://www.gtk.org title=\"<i>Our</i> website\">"
"GTK website</a> for more...";
GtkWidget *label = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL (label), text);
```
It is possible to implement custom handling for links and their tooltips
with the [signal@Gtk.Label::activate-link] signal and the
[method@Gtk.Label.get_current_uri] function.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gtk.Widget
Widget.OnDestroy, Widget.OnDestroyNotify, Widget.OnDirectionChanged, Widget.OnHide, Widget.OnKeynavFailed, Widget.OnMap, Widget.OnMnemonicActivate, Widget.OnMoveFocus, Widget.OnQueryTooltip, Widget.OnRealize, Widget.OnShow, Widget.OnStateFlagsChanged, Widget.OnTickCallback, Widget.OnUnmap, Widget.OnUnrealize
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
Fields inherited from class ch.bailu.gtk.gtk.Widget
SIGNAL_ON_DESTROY, SIGNAL_ON_DIRECTION_CHANGED, SIGNAL_ON_HIDE, SIGNAL_ON_KEYNAV_FAILED, SIGNAL_ON_MAP, SIGNAL_ON_MNEMONIC_ACTIVATE, SIGNAL_ON_MOVE_FOCUS, SIGNAL_ON_QUERY_TOOLTIP, SIGNAL_ON_REALIZE, SIGNAL_ON_SHOW, SIGNAL_ON_STATE_FLAGS_CHANGED, SIGNAL_ON_UNMAP, SIGNAL_ON_UNREALIZE
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionImplements interfaceAccessible
.Implements interfaceBuildable
.Implements interfaceConstraintTarget
.Gets the labels attribute list.static ClassHandler
Returns the URI for the currently active link in the label.int
Returns the ellipsizing position of the label.Gets the extra menu model of @label.static int
int
Returns the justification of the label.getLabel()
Fetches the text from a label.Gets the `PangoLayout` used to display the label.void
getLayoutOffsets
(Int x, Int y) Obtains the coordinates where the label will draw its `PangoLayout`.int
getLines()
Gets the number of lines to which an ellipsized, wrapping
label should be limited.int
Retrieves the desired maximum width of @label, in characters.int
Return the mnemonic accelerator.Retrieves the target of the mnemonic (keyboard shortcut) of this
label.int
Returns line wrap mode used by the label.static long
static TypeSystem.TypeSize
boolean
Returns whether the label is selectable.boolean
getSelectionBounds
(Int start, Int end) Gets the selected range of characters in the label.boolean
Returns whether the label is in single line mode.getTabs()
Gets the tabs for @self.getText()
Fetches the text from a label.static long
static TypeSystem.TypeSize
boolean
Returns whether the label’s text is interpreted as Pango markup.boolean
Returns whether an embedded underlines in the label indicate mnemonics.int
Retrieves the desired width of @label, in characters.boolean
getWrap()
Returns whether lines in the label are automatically wrapped.int
Returns line wrap mode used by the label.float
Gets the `xalign` of the label.float
Gets the `yalign` of the label.static Label
newWithMnemonicLabel
(Str str) Creates a new `GtkLabel`, containing the text in @str.static Label
Creates a new `GtkLabel`, containing the text in @str.Connect to signal "activate-current-link".onActivateLink
(Label.OnActivateLink signal) Connect to signal "activate-link".onCopyClipboard
(Label.OnCopyClipboard signal) Connect to signal "copy-clipboard".onMoveCursor
(Label.OnMoveCursor signal) Connect to signal "move-cursor".void
selectRegion
(int start_offset, int end_offset) Selects a range of characters in the label, if the label is selectable.void
setAttributes
(AttrList attrs) Apply attributes to the label text.void
setEllipsize
(int mode) Sets the mode used to ellipsizei the text.void
setExtraMenu
(MenuModel model) Sets a menu model to add when constructing
the context menu for @label.void
setJustify
(int jtype) Sets the alignment of the lines in the text of the label relative to
each other.void
Sets the text of the label.void
Sets the text of the label.void
setLines
(int lines) Sets the number of lines to which an ellipsized, wrapping label
should be limited.void
Sets the labels text and attributes from markup.void
Sets the labels text and attributes from markup.void
setMarkupWithMnemonic
(Str str) Sets the labels text, attributes and mnemonic from markup.void
Sets the labels text, attributes and mnemonic from markup.void
setMaxWidthChars
(int n_chars) Sets the desired maximum width in characters of @label to @n_chars.void
setMnemonicWidget
(Widget widget) Associate the label with its mnemonic target.void
setNaturalWrapMode
(int wrap_mode) Select the line wrapping for the natural size request.void
setSelectable
(boolean setting) Makes text in the label selectable.void
setSingleLineMode
(boolean single_line_mode) Sets whether the label is in single line mode.void
Sets the default tab stops for paragraphs in @self.void
Sets the text within the `GtkLabel` widget.void
Sets the text within the `GtkLabel` widget.void
setTextWithMnemonic
(Str str) Sets the label’s text from the string @str.void
Sets the label’s text from the string @str.void
setUseMarkup
(boolean setting) Sets whether the text of the label contains markup.void
setUseUnderline
(boolean setting) Sets whether underlines in the text indicate mnemonics.void
setWidthChars
(int n_chars) Sets the desired width in characters of @label to @n_chars.void
setWrap
(boolean wrap) Toggles line wrapping within the `GtkLabel` widget.void
setWrapMode
(int wrap_mode) Controls how line wrapping is done.void
setXalign
(float xalign) Sets the `xalign` of the label.void
setYalign
(float yalign) Sets the `yalign` of the label.Methods inherited from class ch.bailu.gtk.gtk.Widget
actionSetEnabled, actionSetEnabled, activate, activateAction, activateAction, activateActionVariant, activateActionVariant, activateDefault, addController, addCssClass, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, createPangoLayout, disposeTemplate, dragCheckThreshold, errorBell, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getCanFocus, getCanTarget, getChildVisible, getClipboard, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeCssClass, removeMnemonicLabel, removeTickCallback, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setTooltipMarkup, setTooltipMarkup, setTooltipText, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, snapshotChild, triggerTooltipQuery, unmap, unparent, unrealize, unsetStateFlags
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_ACTIVATE_CURRENT_LINK
- See Also:
-
SIGNAL_ON_ACTIVATE_LINK
- See Also:
-
SIGNAL_ON_COPY_CLIPBOARD
- See Also:
-
SIGNAL_ON_MOVE_CURSOR
- See Also:
-
-
Constructor Details
-
Label
-
Label
Creates a new label with the given text inside it.
You can pass %NULL to get an empty label widget.- Parameters:
str
- The text of the label
-
Label
Creates a new label with the given text inside it.
You can pass %NULL to get an empty label widget.- Parameters:
str
- The text of the label
-
-
Method Details
-
getClassHandler
-
newWithMnemonicLabel
Creates a new `GtkLabel`, 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
[method@Gtk.Label.set_mnemonic_widget].
If [method@Gtk.Label.set_mnemonic_widget] is not called, then the first
activatable ancestor of the `GtkLabel` 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
- The text of the label, with an underscore in front of the mnemonic character- Returns:
- the new `GtkLabel`
-
newWithMnemonicLabel
Creates a new `GtkLabel`, 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
[method@Gtk.Label.set_mnemonic_widget].
If [method@Gtk.Label.set_mnemonic_widget] is not called, then the first
activatable ancestor of the `GtkLabel` 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
- The text of the label, with an underscore in front of the mnemonic character- Returns:
- the new `GtkLabel`
-
getAttributes
Gets the labels attribute list.
This is the [struct@Pango.AttrList] that was set on the label using
[method@Gtk.Label.set_attributes], if any. This function does not
reflect attributes that come from the labels markup (see
[method@Gtk.Label.set_markup]). If you want to get the effective
attributes for the label, use
`pango_layout_get_attribute (gtk_label_get_layout (self))`.- Returns:
- the attribute list
-
getCurrentUri
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@Gtk.Label::activate-link]
handler or for use in a [signal@Gtk.Widget::query-tooltip] handler.- Returns:
- the currently active URI
-
getEllipsize
public int getEllipsize()Returns the ellipsizing position of the label.
See [method@Gtk.Label.set_ellipsize].- Returns:
- `PangoEllipsizeMode`
-
getExtraMenu
Gets the extra menu model of @label.
See [method@Gtk.Label.set_extra_menu].- Returns:
- the menu model
-
getJustify
public int getJustify()Returns the justification of the label.
See [method@Gtk.Label.set_justify].- Returns:
- `GtkJustification`
-
getLabel
Fetches the text from a label.
The returned text includes any embedded underlines indicating
mnemonics and Pango markup. (See [method@Gtk.Label.get_text]).- Returns:
- the text of the label widget. This string is owned by the widget and must not be modified or freed.
-
getLayout
Gets the `PangoLayout` used to display the label.
The layout is useful to e.g. convert text positions to pixel
positions, in combination with [method@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:
- the [class@Pango.Layout] for this label
-
getLayoutOffsets
Obtains the coordinates where the label will draw its `PangoLayout`.
The coordinates are useful to convert mouse events into coordinates
inside the [class@Pango.Layout], e.g. to take some action if some part
of the label is clicked. Remember when using the [class@Pango.Layout]
functions you need to convert to and from pixels using PANGO_PIXELS()
or [const@Pango.SCALE].- Parameters:
x
- location to store X offset of layouty
- location to store Y offset of layout
-
getLines
public int getLines()Gets the number of lines to which an ellipsized, wrapping
label should be limited.
See [method@Gtk.Label.set_lines].- Returns:
- The number of lines
-
getMaxWidthChars
public int getMaxWidthChars()Retrieves the desired maximum width of @label, in characters.
See [method@Gtk.Label.set_width_chars].- Returns:
- the maximum width of the label in characters.
-
getMnemonicKeyval
public int getMnemonicKeyval()Return the mnemonic accelerator.
If the label has been set so that it has a 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`
-
getMnemonicWidget
Retrieves the target of the mnemonic (keyboard shortcut) of this
label.
See [method@Gtk.Label.set_mnemonic_widget].- Returns:
- the target of the label’s mnemonic, or %NULL if none has been set and the default algorithm will be used.
-
getNaturalWrapMode
public int getNaturalWrapMode()Returns line wrap mode used by the label.
See [method@Gtk.Label.set_natural_wrap_mode].- Returns:
- the natural line wrap mode
-
getSelectable
public boolean getSelectable()Returns whether the label is selectable.- Returns:
- %TRUE if the user can copy text from the label
-
getSelectionBounds
Gets the selected range of characters in the label.- Parameters:
start
- return location for start of selection, as a character offsetend
- return location for end of selection, as a character offset- Returns:
- %TRUE if selection is non-empty
-
getSingleLineMode
public boolean getSingleLineMode()Returns whether the label is in single line mode.- Returns:
- %TRUE when the label is in single line mode.
-
getTabs
Gets the tabs for @self.
The returned array will be %NULL if “standard” (8-space) tabs are used.
Free the return value with [method@Pango.TabArray.free].- Returns:
- copy of default tab array, or %NULL if standard tabs are used; must be freed with [method@Pango.TabArray.free].
-
getText
Fetches the text from a label.
The returned text is as it appears on screen. This does not include
any embedded underlines indicating mnemonics or Pango markup. (See
[method@Gtk.Label.get_label])- Returns:
- the text in the label widget. This is the internal string used by the label, and must not be modified.
-
getUseMarkup
public boolean getUseMarkup()Returns whether the label’s text is interpreted as Pango markup.
See [method@Gtk.Label.set_use_markup].- Returns:
- %TRUE if the label’s text will be parsed for markup.
-
getUseUnderline
public boolean getUseUnderline()Returns whether an embedded underlines in the label indicate mnemonics.
See [method@Gtk.Label.set_use_underline].- Returns:
- %TRUE whether an embedded underline in the label indicates the mnemonic accelerator keys.
-
getWidthChars
public int getWidthChars()Retrieves the desired width of @label, in characters.
See [method@Gtk.Label.set_width_chars].- Returns:
- the width of the label in characters.
-
getWrap
public boolean getWrap()Returns whether lines in the label are automatically wrapped.
See [method@Gtk.Label.set_wrap].- Returns:
- %TRUE if the lines of the label are automatically wrapped.
-
getWrapMode
public int getWrapMode()Returns line wrap mode used by the label.
See [method@Gtk.Label.set_wrap_mode].- Returns:
- the line wrap mode
-
getXalign
public float getXalign()Gets the `xalign` of the label.
See the [property@Gtk.Label:xalign] property.- Returns:
- the xalign property
-
getYalign
public float getYalign()Gets the `yalign` of the label.
See the [property@Gtk.Label:yalign] property.- Returns:
- the yalign property
-
selectRegion
public void selectRegion(int start_offset, int end_offset) Selects a range of characters in the label, if the label is selectable.
See [method@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
- start offset (in characters not bytes)end_offset
- end offset (in characters not bytes)
-
setAttributes
Apply attributes 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@Gtk.Label:use-underline] or [property@Gtk.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.- Parameters:
attrs
- a [struct@Pango.AttrList]
-
setEllipsize
public void setEllipsize(int mode) Sets the mode used to ellipsizei the text.
The text will be ellipsized if there is not enough space
to render the entire string.- Parameters:
mode
- a `PangoEllipsizeMode`
-
setExtraMenu
Sets a menu model to add when constructing
the context menu for @label.- Parameters:
model
- a `GMenuModel`
-
setJustify
public void setJustify(int jtype) Sets the alignment of the lines in the text of the label relative to
each other.
%GTK_JUSTIFY_LEFT is the default value when the widget is first created
with [ctor@Gtk.Label.new]. If you instead want to set the alignment of
the label as a whole, use [method@Gtk.Widget.set_halign] instead.
[method@Gtk.Label.set_justify] has no effect on labels containing
only a single line.- Parameters:
jtype
- a `GtkJustification`
-
setLabel
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@Gtk.Label:use-underline]
and [property@Gtk.Label:use-markup] properties.- Parameters:
str
- the new text to set for the label
-
setLabel
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@Gtk.Label:use-underline]
and [property@Gtk.Label:use-markup] properties.- Parameters:
str
- the new text to set for the label
-
setLines
public void setLines(int lines) 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.- Parameters:
lines
- the desired number of lines, or -1
-
setMarkup
Sets the labels text and attributes from markup.
The string must be marked up with Pango markup
(see [func@Pango.parse_markup]).
If the @str is external data, you may need to escape it
with g_markup_escape_text() or g_markup_printf_escaped():
```c
GtkWidget *self = gtk_label_new (NULL);
const char *str = "...";
const char *format = "<span style=\"italic\">\%s</span>";
char *markup;
markup = g_markup_printf_escaped (format, str);
gtk_label_set_markup (GTK_LABEL (self), markup);
g_free (markup);
```
This function will set the [property@Gtk.Label:use-markup] property
to %TRUE as a side effect.
If you set the label contents using the [property@Gtk.Label:label]
property you should also ensure that you set the
[property@Gtk.Label:use-markup] property accordingly.
See also: [method@Gtk.Label.set_text]- Parameters:
str
- a markup string
-
setMarkup
Sets the labels text and attributes from markup.
The string must be marked up with Pango markup
(see [func@Pango.parse_markup]).
If the @str is external data, you may need to escape it
with g_markup_escape_text() or g_markup_printf_escaped():
```c
GtkWidget *self = gtk_label_new (NULL);
const char *str = "...";
const char *format = "<span style=\"italic\">\%s</span>";
char *markup;
markup = g_markup_printf_escaped (format, str);
gtk_label_set_markup (GTK_LABEL (self), markup);
g_free (markup);
```
This function will set the [property@Gtk.Label:use-markup] property
to %TRUE as a side effect.
If you set the label contents using the [property@Gtk.Label:label]
property you should also ensure that you set the
[property@Gtk.Label:use-markup] property accordingly.
See also: [method@Gtk.Label.set_text]- Parameters:
str
- a markup string
-
setMarkupWithMnemonic
Sets the labels text, attributes and mnemonic from markup.
Parses @str which is marked up with Pango markup (see [func@Pango.parse_markup]),
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 [method@Gtk.Label.set_mnemonic_widget].- Parameters:
str
- a markup string
-
setMarkupWithMnemonic
Sets the labels text, attributes and mnemonic from markup.
Parses @str which is marked up with Pango markup (see [func@Pango.parse_markup]),
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 [method@Gtk.Label.set_mnemonic_widget].- Parameters:
str
- a markup string
-
setMaxWidthChars
public void setMaxWidthChars(int n_chars) Sets the desired maximum width in characters of @label to @n_chars.- Parameters:
n_chars
- the new desired maximum width, in characters.
-
setMnemonicWidget
Associate the label with its mnemonic target.
If the label has been set so that it has a mnemonic key (using
i.e. [method@Gtk.Label.set_markup_with_mnemonic],
[method@Gtk.Label.set_text_with_mnemonic],
[ctor@Gtk.Label.new_with_mnemonic]
or the [property@Gtk.Label: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 [class@Gtk.Button] or a
[class@Gtk.Notebook] tab) it is automatically associated with the correct
widget, but sometimes (i.e. when the target is a [class@Gtk.Entry] next to
the label) you need to set it explicitly using this function.
The target widget will be accelerated by emitting the
[signal@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.- Parameters:
widget
- the target `GtkWidget`, or %NULL to unset
-
setNaturalWrapMode
public void setNaturalWrapMode(int wrap_mode) Select the line wrapping for the natural size request.
This only affects the natural size requested, for the actual wrapping used,
see the [property@Gtk.Label:wrap-mode] property.- Parameters:
wrap_mode
- the line wrapping mode
-
setSelectable
public void setSelectable(boolean setting) Makes text in the label selectable.
Selectable labels allow the user to select text from the label,
for copy-and-paste.- Parameters:
setting
- %TRUE to allow selecting text in the label
-
setSingleLineMode
public void setSingleLineMode(boolean single_line_mode) Sets whether the label is in single line mode.- Parameters:
single_line_mode
- %TRUE if the label should be in single line mode
-
setTabs
Sets the default tab stops for paragraphs in @self.- Parameters:
tabs
- tabs as a `PangoTabArray`
-
setText
Sets the text within the `GtkLabel` widget.
It overwrites any text that was there before.
This function will clear any previously set mnemonic accelerators,
and set the [property@Gtk.Label:use-underline property] to %FALSE as
a side effect.
This function will set the [property@Gtk.Label:use-markup] property
to %FALSE as a side effect.
See also: [method@Gtk.Label.set_markup]- Parameters:
str
- The text you want to set
-
setText
Sets the text within the `GtkLabel` widget.
It overwrites any text that was there before.
This function will clear any previously set mnemonic accelerators,
and set the [property@Gtk.Label:use-underline property] to %FALSE as
a side effect.
This function will set the [property@Gtk.Label:use-markup] property
to %FALSE as a side effect.
See also: [method@Gtk.Label.set_markup]- Parameters:
str
- The text you want to set
-
setTextWithMnemonic
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 [method@Gtk.Label.set_mnemonic_widget].- Parameters:
str
- a string
-
setTextWithMnemonic
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 [method@Gtk.Label.set_mnemonic_widget].- Parameters:
str
- a string
-
setUseMarkup
public void setUseMarkup(boolean setting) Sets whether the text of the label contains markup.
See [method@Gtk.Label.set_markup].- Parameters:
setting
- %TRUE if the label’s text should be parsed for markup.
-
setUseUnderline
public void setUseUnderline(boolean setting) Sets whether underlines in the text indicate mnemonics.- Parameters:
setting
- %TRUE if underlines in the text indicate mnemonics
-
setWidthChars
public void setWidthChars(int n_chars) Sets the desired width in characters of @label to @n_chars.- Parameters:
n_chars
- the new desired width, in characters.
-
setWrap
public void setWrap(boolean wrap) Toggles line wrapping within the `GtkLabel` 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 [method@Gtk.Widget.set_size_request].- Parameters:
wrap
- the setting
-
setWrapMode
public void setWrapMode(int wrap_mode) Controls how line wrapping is done.
This only affects the label if line wrapping is on. (See
[method@Gtk.Label.set_wrap]) The default is %PANGO_WRAP_WORD
which means wrap on word boundaries.
For sizing behavior, also consider the [property@Gtk.Label:natural-wrap-mode]
property.- Parameters:
wrap_mode
- the line wrapping mode
-
setXalign
public void setXalign(float xalign) Sets the `xalign` of the label.
See the [property@Gtk.Label:xalign] property.- Parameters:
xalign
- the new xalign value, between 0 and 1
-
setYalign
public void setYalign(float yalign) Sets the `yalign` of the label.
See the [property@Gtk.Label:yalign] property.- Parameters:
yalign
- the new yalign value, between 0 and 1
-
onActivateCurrentLink
Connect to signal "activate-current-link".
SeeLabel.OnActivateCurrentLink.onActivateCurrentLink()
for signal description.
FieldSIGNAL_ON_ACTIVATE_CURRENT_LINK
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onActivateLink
Connect to signal "activate-link".
SeeLabel.OnActivateLink.onActivateLink(ch.bailu.gtk.type.Str)
for signal description.
FieldSIGNAL_ON_ACTIVATE_LINK
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onCopyClipboard
Connect to signal "copy-clipboard".
SeeLabel.OnCopyClipboard.onCopyClipboard()
for signal description.
FieldSIGNAL_ON_COPY_CLIPBOARD
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onMoveCursor
Connect to signal "move-cursor".
SeeLabel.OnMoveCursor.onMoveCursor(int, int, boolean)
for signal description.
FieldSIGNAL_ON_MOVE_CURSOR
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
asAccessible
Implements interfaceAccessible
. Call this to get access to interface functions.- Overrides:
asAccessible
in classWidget
- Returns:
Accessible
-
asBuildable
Implements interfaceBuildable
. Call this to get access to interface functions.- Overrides:
asBuildable
in classWidget
- Returns:
Buildable
-
asConstraintTarget
Implements interfaceConstraintTarget
. Call this to get access to interface functions.- Overrides:
asConstraintTarget
in classWidget
- Returns:
ConstraintTarget
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-