AccelLabel

The #GtkAccelLabel widget is a subclass of #GtkLabel that also displays an accelerator key on the right of the label text, e.g. “Ctrl+S”. It is commonly used in menus to show the keyboard short-cuts for commands.

The accelerator key to display is typically not set explicitly (although it can be, with gtk.accel_label.AccelLabel.setAccel). Instead, the #GtkAccelLabel displays the accelerators which have been added to a particular widget. This widget is set by calling gtk.accel_label.AccelLabel.setAccelWidget.

For example, a #GtkMenuItem widget may have an accelerator added to emit the “activate” signal when the “Ctrl+S” key combination is pressed. A #GtkAccelLabel is created and added to the #GtkMenuItem, and gtk.accel_label.AccelLabel.setAccelWidget is called with the #GtkMenuItem as the second argument. The #GtkAccelLabel will now display “Ctrl+S” after its label.

Note that creating a #GtkMenuItem with gtk.menu_item.MenuItem.newWithLabel (or one of the similar functions for #GtkCheckMenuItem and #GtkRadioMenuItem) automatically adds a #GtkAccelLabel to the #GtkMenuItem and calls gtk.accel_label.AccelLabel.setAccelWidget to set it up for you.

A #GtkAccelLabel will only display accelerators which have gtk.types.AccelFlags.Visible set (see #GtkAccelFlags). A #GtkAccelLabel can display multiple accelerators and even signal names, though it is almost always used to display just one accelerator key.

Creating a simple menu item with an accelerator key.

GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
GtkWidget *menu = gtk_menu_new ();
GtkWidget *save_item;
GtkAccelGroup *accel_group;

// Create a GtkAccelGroup and add it to the window.
accel_group = gtk_accel_group_new ();
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);

// Create the menu item using the convenience function.
save_item = gtk_menu_item_new_with_label ("Save");
gtk_widget_show (save_item);
gtk_container_add (GTK_CONTAINER (menu), save_item);

// Now add the accelerator to the GtkMenuItem. Note that since we
// called gtk_menu_item_new_with_label() to create the GtkMenuItem
// the GtkAccelLabel is automatically set up to display the
// GtkMenuItem accelerators. We just need to make sure we use
// GTK_ACCEL_VISIBLE here.
gtk_widget_add_accelerator (save_item, "activate", accel_group,
                            GDK_KEY_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

CSS nodes

label
╰── accelerator

Like #GtkLabel, GtkAccelLabel has a main CSS node with the name label. It adds a subnode with name accelerator.

Constructors

this
this(void* ptr, Flag!"Take" take)
this
this(string string_)

Creates a new #GtkAccelLabel.

Members

Functions

getAccel
void getAccel(uint acceleratorKey, gdk.types.ModifierType acceleratorMods)

Gets the keyval and modifier mask set with gtk.accel_label.AccelLabel.setAccel.

getAccelWidget
gtk.widget.Widget getAccelWidget()

Fetches the widget monitored by this accelerator label. See gtk.accel_label.AccelLabel.setAccelWidget.

getAccelWidth
uint getAccelWidth()

Returns the width needed to display the accelerator key(s). This is used by menus to align all of the #GtkMenuItem widgets, and shouldn't be needed by applications.

refetch
bool refetch()

Recreates the string representing the accelerator keys. This should not be needed since the string is automatically updated whenever accelerators are added or removed from the associated widget.

self
AccelLabel self()

Returns this, for use in with statements.

setAccel
void setAccel(uint acceleratorKey, gdk.types.ModifierType acceleratorMods)

Manually sets a keyval and modifier mask as the accelerator rendered by accel_label.

setAccelClosure
void setAccelClosure(gobject.closure.Closure accelClosure)

Sets the closure to be monitored by this accelerator label. The closure must be connected to an accelerator group; see gtk.accel_group.AccelGroup.connect. Passing null for accel_closure will dissociate accel_label from its current closure, if any.

setAccelWidget
void setAccelWidget(gtk.widget.Widget accelWidget)

Sets the widget to be monitored by this accelerator label. Passing null for accel_widget will dissociate accel_label from its current widget, if any.

Properties

_gType
GType _gType [@property getter]
accelClosure
gobject.closure.Closure accelClosure [@property getter]
accelClosure
gobject.closure.Closure accelClosure [@property setter]
accelWidget
gtk.widget.Widget accelWidget [@property getter]
accelWidget
gtk.widget.Widget accelWidget [@property setter]

Static functions

_getGType
GType _getGType()
builder
AccelLabelGidBuilder builder()

Get builder for gtk.accel_label.AccelLabel

Inherited Members

From Label

_getGType
GType _getGType()
_gType
GType _gType [@property getter]
self
Label self()

Returns this, for use in with statements.

builder
LabelGidBuilder builder()

Get builder for gtk.label.Label

angle
double angle [@property getter]

Get angle property.

angle
double angle [@property setter]

Set angle property.

attributes
pango.attr_list.AttrList attributes [@property getter]
attributes
pango.attr_list.AttrList attributes [@property setter]
cursorPosition
int cursorPosition [@property getter]
ellipsize
pango.types.EllipsizeMode ellipsize [@property getter]

Get ellipsize property.

ellipsize
pango.types.EllipsizeMode ellipsize [@property setter]

Set ellipsize property.

justify
gtk.types.Justification justify [@property getter]
justify
gtk.types.Justification justify [@property setter]
label
string label [@property getter]

Get label property.

label
string label [@property setter]

Set label property.

lines
int lines [@property getter]

Get lines property.

lines
int lines [@property setter]

Set lines property.

maxWidthChars
int maxWidthChars [@property getter]

Get maxWidthChars property.

maxWidthChars
int maxWidthChars [@property setter]

Set maxWidthChars property.

mnemonicKeyval
uint mnemonicKeyval [@property getter]
mnemonicWidget
gtk.widget.Widget mnemonicWidget [@property getter]
mnemonicWidget
gtk.widget.Widget mnemonicWidget [@property setter]
pattern
string pattern [@property setter]
selectable
bool selectable [@property getter]
selectable
bool selectable [@property setter]
selectionBound
int selectionBound [@property getter]
singleLineMode
bool singleLineMode [@property getter]

Get singleLineMode property.

singleLineMode
bool singleLineMode [@property setter]

Set singleLineMode property.

trackVisitedLinks
bool trackVisitedLinks [@property getter]

Get trackVisitedLinks property.

trackVisitedLinks
bool trackVisitedLinks [@property setter]

Set trackVisitedLinks property.

useMarkup
bool useMarkup [@property getter]
useMarkup
bool useMarkup [@property setter]
useUnderline
bool useUnderline [@property getter]
useUnderline
bool useUnderline [@property setter]
widthChars
int widthChars [@property getter]

Get widthChars property.

widthChars
int widthChars [@property setter]

Set widthChars property.

wrap
bool wrap [@property getter]
wrap
bool wrap [@property setter]
wrapMode
pango.types.WrapMode wrapMode [@property getter]

Get wrapMode property.

wrapMode
pango.types.WrapMode wrapMode [@property setter]

Set wrapMode property.

xalign
float xalign [@property getter]

Get xalign property.

xalign
float xalign [@property setter]

Set xalign property.

yalign
float yalign [@property getter]

Get yalign property.

yalign
float yalign [@property setter]

Set yalign property.

newWithMnemonic
gtk.label.Label newWithMnemonic(string str)

Creates a new #GtkLabel, containing the text in str.

getAngle
double getAngle()

Gets the angle of rotation for the label. See gtk.label.Label.setAngle.

getAttributes
pango.attr_list.AttrList getAttributes()

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

getCurrentUri
string 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.

getEllipsize
pango.types.EllipsizeMode getEllipsize()

Returns the ellipsizing position of the label. See gtk.label.Label.setEllipsize.

getJustify
gtk.types.Justification getJustify()

Returns the justification of the label. See gtk.label.Label.setJustify.

getLabel
string getLabel()

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

getLayout
pango.layout.Layout 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 gtk.label.Label.getLayoutOffsets. 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.

getLayoutOffsets
void getLayoutOffsets(int x, int y)

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 #GtkEventBox to receive the events, and pack the label inside it, since labels are windowless (they return false from gtk.widget.Widget.getHasWindow). Remember when using the #PangoLayout functions you need to convert to and from pixels using PANGO_PIXELS() or #PANGO_SCALE.

getLineWrap
bool getLineWrap()

Returns whether lines in the label are automatically wrapped. See gtk.label.Label.setLineWrap.

getLineWrapMode
pango.types.WrapMode getLineWrapMode()

Returns line wrap mode used by the label. See gtk.label.Label.setLineWrapMode.

getLines
int getLines()

Gets the number of lines to which an ellipsized, wrapping label should be limited. See gtk.label.Label.setLines.

getMaxWidthChars
int getMaxWidthChars()

Retrieves the desired maximum width of label, in characters. See gtk.label.Label.setWidthChars.

getMnemonicKeyval
uint getMnemonicKeyval()

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.

getMnemonicWidget
gtk.widget.Widget getMnemonicWidget()

Retrieves the target of the mnemonic (keyboard shortcut) of this label. See gtk.label.Label.setMnemonicWidget.

getSelectable
bool getSelectable()

Gets the value set by gtk.label.Label.setSelectable.

getSelectionBounds
bool getSelectionBounds(int start, int end)

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

getSingleLineMode
bool getSingleLineMode()

Returns whether the label is in single line mode.

getText
string getText()

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.Label.getLabel)

getTrackVisitedLinks
bool getTrackVisitedLinks()

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

getUseMarkup
bool getUseMarkup()

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

getUseUnderline
bool getUseUnderline()

Returns whether an embedded underline in the label indicates a mnemonic. See gtk.label.Label.setUseUnderline.

getWidthChars
int getWidthChars()

Retrieves the desired width of label, in characters. See gtk.label.Label.setWidthChars.

getXalign
float getXalign()

Gets the #GtkLabel:xalign property for label.

getYalign
float getYalign()

Gets the #GtkLabel:yalign property for label.

selectRegion
void selectRegion(int startOffset, int endOffset)

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

setAngle
void setAngle(double angle)

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.

setAttributes
void setAttributes(pango.attr_list.AttrList attrs)

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

setEllipsize
void setEllipsize(pango.types.EllipsizeMode mode)

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

setJustify
void setJustify(gtk.types.Justification jtype)

Sets the alignment of the lines in the text of the label relative to each other. gtk.types.Justification.Left is the default value when the widget is first created with gtk.label.Label.new_. If you instead want to set the alignment of the label as a whole, use gtk.widget.Widget.setHalign instead. gtk.label.Label.setJustify has no effect on labels containing only a single line.

setLabel
void setLabel(string str)

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

setLineWrap
void setLineWrap(bool 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.

setLineWrapMode
void setLineWrapMode(pango.types.WrapMode wrapMode)

If line wrapping is on (see gtk.label.Label.setLineWrap) this controls how the line wrapping is done. The default is pango.types.WrapMode.Word which means wrap on word boundaries.

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

setMarkup
void setMarkup(string str)

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.

setMarkupWithMnemonic
void setMarkupWithMnemonic(string str)

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.

setMaxWidthChars
void setMaxWidthChars(int nChars)

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

setMnemonicWidget
void setMnemonicWidget(gtk.widget.Widget widget)

If the label has been set so that it has an mnemonic key (using i.e. gtk.label.Label.setMarkupWithMnemonic, gtk.label.Label.setTextWithMnemonic, gtk.label.Label.newWithMnemonic 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 #GtkButton or a #GtkNotebook tab) it is automatically associated with the correct widget, but sometimes (i.e. when the target is a #GtkEntry next to the label) you need to set it explicitly using this function.

setPattern
void setPattern(string pattern)

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

setSelectable
void setSelectable(bool setting)

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

setSingleLineMode
void setSingleLineMode(bool singleLineMode)

Sets whether the label is in single line mode.

setText
void setText(string str)

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

setTextWithMnemonic
void setTextWithMnemonic(string str)

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.Label.setMnemonicWidget.

setTrackVisitedLinks
void setTrackVisitedLinks(bool trackLinks)

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

setUseMarkup
void setUseMarkup(bool setting)

Sets whether the text of the label contains markup in [Pango’s text markup language]PangoMarkupFormat. See gtk.label.Label.setMarkup.

setUseUnderline
void setUseUnderline(bool setting)

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

setWidthChars
void setWidthChars(int nChars)

Sets the desired width in characters of label to n_chars.

setXalign
void setXalign(float xalign)

Sets the #GtkLabel:xalign property for label.

setYalign
void setYalign(float yalign)

Sets the #GtkLabel:yalign property for label.

connectActivateCurrentLink
gulong connectActivateCurrentLink(T callback, Flag!"After" after)

Connect to ActivateCurrentLink signal.

connectActivateLink
gulong connectActivateLink(T callback, Flag!"After" after)

Connect to ActivateLink signal.

connectCopyClipboard
gulong connectCopyClipboard(T callback, Flag!"After" after)

Connect to CopyClipboard signal.

connectMoveCursor
gulong connectMoveCursor(T callback, Flag!"After" after)

Connect to MoveCursor signal.

connectPopulatePopup
gulong connectPopulatePopup(T callback, Flag!"After" after)

Connect to PopulatePopup signal.