Learn R Programming

RGtk2 (version 2.20.1)

GtkLabel: GtkLabel

Description

A widget that displays a small to medium amount of text

Arguments

Methods and Functions

gtkLabelNew(str = NULL, show = TRUE) gtkLabelSetText(object, str) gtkLabelSetAttributes(object, attrs) gtkLabelSetMarkup(object, str) gtkLabelSetMarkupWithMnemonic(object, str) gtkLabelSetPattern(object, pattern) gtkLabelSetJustify(object, jtype) gtkLabelSetEllipsize(object, mode) gtkLabelSetWidthChars(object, n.chars) gtkLabelSetMaxWidthChars(object, n.chars) gtkLabelGet(object) gtkLabelParseUline(object, string) gtkLabelSetLineWrap(object, wrap) gtkLabelSetLineWrapMode(object, wrap.mode) gtkLabelGetLayoutOffsets(object) gtkLabelGetMnemonicKeyval(object) gtkLabelGetSelectable(object) gtkLabelGetText(object) gtkLabelNewWithMnemonic(str = NULL, show = TRUE) gtkLabelSelectRegion(object, start.offset, end.offset) gtkLabelSetMnemonicWidget(object, widget) gtkLabelSetSelectable(object, setting) gtkLabelSetTextWithMnemonic(object, str) gtkLabelGetAttributes(object) gtkLabelGetJustify(object) gtkLabelGetEllipsize(object) gtkLabelGetWidthChars(object) gtkLabelGetMaxWidthChars(object) gtkLabelGetLabel(object) gtkLabelGetLayout(object) gtkLabelGetLineWrap(object) gtkLabelGetLineWrapMode(object) gtkLabelGetMnemonicWidget(object) gtkLabelGetSelectionBounds(object) gtkLabelGetUseMarkup(object) gtkLabelGetUseUnderline(object) gtkLabelGetSingleLineMode(object) gtkLabelGetAngle(object) gtkLabelSetLabel(object, str) gtkLabelSetUseMarkup(object, setting) gtkLabelSetUseUnderline(object, setting) gtkLabelSetSingleLineMode(object, single.line.mode) gtkLabelSetAngle(object, angle) gtkLabelGetCurrentUri(object) gtkLabelSetTrackVisitedLinks(object, track.links) gtkLabelGetTrackVisitedLinks(object) gtkLabel(str = NULL, show = TRUE)

Hierarchy

GObject +----GInitiallyUnowned +----GtkObject +----GtkWidget +----GtkMisc +----GtkLabel +----GtkAccelLabel +----GtkTipsQuery

Interfaces

GtkLabel implements AtkImplementorIface and GtkBuildable.

Detailed Description

The GtkLabel widget displays a small amount of text. As the name implies, most labels are used to label another widget such as a GtkButton, a GtkMenuItem, or a GtkOptionMenu.

GtkLabel as GtkBuildable

The GtkLabel implementation of the GtkBuildable interface supports a custom element, which supports any number of elements. the element has attributes named name, value, start and end and allows you to specify PangoAttribute values for this label. A UI definition fragment specifying Pango attributes " 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 gtkLabelNewWithMnemonic or gtkLabelSetTextWithMnemonic. Mnemonics automatically activate any activatable widget the label is inside, such as a GtkButton; if the label is not inside the mnemonic's target widget, you have to tell the label about the target using gtkLabelSetMnemonicWidget. Here's a simple example where the label is inside a button: ## Pressing Alt-H will activate this button button <- gtkButton() label <- gtkLabelNewWithMnemonic("_Hello") button$add(label) There's a convenience function to create buttons with a mnemonic label already inside: ## Pressing Alt+H will activate this button button <- gtkButtonNewWithMnemonic("_Hello") To create a mnemonic for a widget alongside the label, such as a GtkEntry, you have to point the label at the entry with gtkLabelSetMnemonicWidget: ## Pressing Alt+H will focus the entry entry <- gtkEntry() label <- gtkLabelNewWithMnemonic("_Hello") label$setMnemonicWidget(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: label <- gtkLabelNew() label$setMarkup("Small text") (See complete documentation of available tags in the Pango manual.) The markup passed to gtkLabelSetMarkup must be valid; for example, literal /& characters must be escaped as <, >, and &. If you pass text obtained from the user, file, or a network to gtkLabelSetMarkup, you'll want to escape it with gMarkupEscapeText() or gMarkupPrintfEscaped(). Markup strings are just a convenient way to set the PangoAttrList on a label; gtkLabelSetAttributes 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 gtkLabelSetSelectable. 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 gtkLabelSetLineWrap. gtkLabelSetJustify 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 gtkMiscSetAlignment.

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: label$setMarkup("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 gtkLabelGetCurrentUri function.

Convenient Construction

gtkLabel is the result of collapsing the constructors of GtkLabel (gtkLabelNew, gtkLabelNewWithMnemonic) and accepts a subset of its arguments matching the required arguments of one of its delegate constructors.

References

http://library.gnome.org/devel//gtk/GtkLabel.html