Maintainer | gtk2hs-users@lists.sourceforge.net |
---|---|
Stability | provisional |
Portability | portable (depends on GHC) |
Safe Haskell | None |
Language | Haskell98 |
A widget that displays a small to medium amount of text
- data Label
- class MiscClass o => LabelClass o
- castToLabel :: GObjectClass obj => obj -> Label
- gTypeLabel :: GType
- toLabel :: LabelClass o => o -> Label
- labelNew :: GlibString string => Maybe string -> IO Label
- labelNewWithMnemonic :: GlibString string => string -> IO Label
- labelSetText :: (LabelClass self, GlibString string) => self -> string -> IO ()
- labelSetLabel :: (LabelClass self, GlibString string) => self -> string -> IO ()
- labelSetTextWithMnemonic :: (LabelClass self, GlibString string) => self -> string -> IO ()
- labelSetMarkup :: (LabelClass self, GlibString markup) => self -> markup -> IO ()
- labelSetMarkupWithMnemonic :: (LabelClass self, GlibString markup) => self -> markup -> IO ()
- labelSetMnemonicWidget :: (LabelClass self, WidgetClass widget) => self -> widget -> IO ()
- labelGetMnemonicWidget :: LabelClass self => self -> IO (Maybe Widget)
- type KeyVal = Word32
- labelGetMnemonicKeyval :: LabelClass self => self -> IO KeyVal
- labelSetUseMarkup :: LabelClass self => self -> Bool -> IO ()
- labelGetUseMarkup :: LabelClass self => self -> IO Bool
- labelSetUseUnderline :: LabelClass self => self -> Bool -> IO ()
- labelGetUseUnderline :: LabelClass self => self -> IO Bool
- labelGetText :: (LabelClass self, GlibString string) => self -> IO string
- labelGetLabel :: (LabelClass self, GlibString string) => self -> IO string
- labelSetAttributes :: LabelClass self => self -> [PangoAttribute] -> IO ()
- labelGetAttributes :: LabelClass self => self -> IO [PangoAttribute]
- labelSetPattern :: LabelClass l => l -> [Int] -> IO ()
- data Justification
- labelSetJustify :: LabelClass self => self -> Justification -> IO ()
- labelGetJustify :: LabelClass self => self -> IO Justification
- labelGetLayout :: LabelClass self => self -> IO PangoLayout
- labelSetLineWrap :: LabelClass self => self -> Bool -> IO ()
- labelGetLineWrap :: LabelClass self => self -> IO Bool
- labelSetLineWrapMode :: LabelClass self => self -> LayoutWrapMode -> IO ()
- labelGetLineWrapMode :: LabelClass self => self -> IO LayoutWrapMode
- labelSetSelectable :: LabelClass self => self -> Bool -> IO ()
- labelGetSelectable :: LabelClass self => self -> IO Bool
- labelSelectRegion :: LabelClass self => self -> Int -> Int -> IO ()
- labelGetSelectionBounds :: LabelClass self => self -> IO (Maybe (Int, Int))
- labelGetLayoutOffsets :: LabelClass self => self -> IO (Int, Int)
- labelSetEllipsize :: LabelClass self => self -> EllipsizeMode -> IO ()
- labelGetEllipsize :: LabelClass self => self -> IO EllipsizeMode
- labelSetWidthChars :: LabelClass self => self -> Int -> IO ()
- labelGetWidthChars :: LabelClass self => self -> IO Int
- labelSetMaxWidthChars :: LabelClass self => self -> Int -> IO ()
- labelGetMaxWidthChars :: LabelClass self => self -> IO Int
- labelSetSingleLineMode :: LabelClass self => self -> Bool -> IO ()
- labelGetSingleLineMode :: LabelClass self => self -> IO Bool
- labelSetAngle :: LabelClass self => self -> Double -> IO ()
- labelGetAngle :: LabelClass self => self -> IO Double
- labelLabel :: (LabelClass self, GlibString string) => Attr self string
- labelUseMarkup :: LabelClass self => Attr self Bool
- labelUseUnderline :: LabelClass self => Attr self Bool
- labelJustify :: LabelClass self => Attr self Justification
- labelWrap :: LabelClass self => Attr self Bool
- labelWrapMode :: LabelClass self => Attr self LayoutWrapMode
- labelSelectable :: LabelClass self => Attr self Bool
- labelMnemonicWidget :: (LabelClass self, WidgetClass widget) => ReadWriteAttr self (Maybe Widget) widget
- labelMnemonicKeyval :: LabelClass self => ReadAttr self Int
- labelPattern :: (LabelClass self, GlibString string) => WriteAttr self string
- labelCursorPosition :: LabelClass self => ReadAttr self Int
- labelSelectionBound :: LabelClass self => ReadAttr self Int
- labelEllipsize :: LabelClass self => Attr self EllipsizeMode
- labelWidthChars :: LabelClass self => Attr self Int
- labelSingleLineMode :: LabelClass self => Attr self Bool
- labelAngle :: LabelClass self => Attr self Double
- labelAttributes :: LabelClass self => Attr self [PangoAttribute]
- labelMaxWidthChars :: LabelClass self => Attr self Int
- labelLineWrap :: LabelClass self => Attr self Bool
- labelText :: (LabelClass self, GlibString string) => Attr self string
- labelActiveCurrentLink :: LabelClass self => Signal self (IO ())
- labelActiveLink :: (LabelClass self, GlibString string) => Signal self (string -> IO ())
- labelCopyClipboard :: LabelClass self => Signal self (IO ())
- labelMoveCursor :: LabelClass self => Signal self (MovementStep -> Int -> Bool -> IO ())
- labelPopulatePopup :: LabelClass self => Signal self (Menu -> IO ())
Detail
The Label
widget displays a small amount of text. As the name implies,
most labels are used to label another widget such as a Button
, a
MenuItem
, or a OptionMenu
.
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 labelNewWithMnemonic
or
labelSetTextWithMnemonic
.
Mnemonics automatically activate any activatable widget the label is
inside, such as a Button
; if the label is not inside the mnemonic's target
widget, you have to tell the label about the target using
labelSetMnemonicWidget
. Here's a simple example where the label is inside
a button: There's a convenience function to create buttons with a mnemonic
label already inside: To create a mnemonic for a widget alongside the label,
such as a Entry
, you have to point the label at the entry with
labelSetMnemonicWidget
:
-- Pressing Alt+H will activate this button button <- buttonNew label <- labelNewWithMnemonic "_Hello" containerAdd button label
-- Pressing Alt+H will activate this button button <- buttonNewWithMnemonic "_Hello"
-- Pressing Alt+H will focus the entry entry <- entryNew label <- labelNewWithMnemonic "_Hello" labelSetMnemonicWidget 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: (See complete documentation of available tags in the Pango manual.)
label <- labelNew Nothing labelSetMarkup label "<small>Small text</small>"
The markup passed to labelSetMarkup
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 labelSetMarkup
, you'll
want to escape it with escapeMarkup
.
Selectable labels
Labels can be made selectable with labelSetSelectable
. 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 labelSetLineWrap
.
labelSetJustify
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 miscSetAlignment
.
Class Hierarchy
|GObject
| +----Object
| +----Widget
| +----Misc
| +----Label | +----AccelLabel
| +----TipsQuery
Types
class MiscClass o => LabelClass o Source
castToLabel :: GObjectClass obj => obj -> Label Source
toLabel :: LabelClass o => o -> Label Source
Constructors
labelNew :: GlibString string => Maybe string -> IO Label Source
Creates a new label with the given text inside it. You can pass Nothing
to get an empty label widget.
:: GlibString string | |
=> string |
|
-> IO Label |
Creates a new 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
labelSetMnemonicWidget
.
If labelSetMnemonicWidget
is not called, then the first activatable
ancestor of the 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.
Methods
labelSetText :: (LabelClass self, GlibString string) => self -> string -> IO () Source
Sets the text within the Label
widget. It overwrites any text that was
there before.
This will also clear any previously set mnemonic accelerators.
labelSetLabel :: (LabelClass self, GlibString string) => self -> string -> IO () Source
Sets the text of the label. The label is interpreted as including embedded underlines and/or Pango markup depending on the markup and underline properties.
labelSetTextWithMnemonic :: (LabelClass self, GlibString string) => self -> string -> IO () Source
Sets the label's text from the given string. If characters in the string 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
labelSetMnemonicWidget
.
:: (LabelClass self, GlibString markup) | |
=> self | |
-> markup |
|
-> IO () |
Parses str
which is marked up with the Pango text markup language,
as defined in Graphics.Rendering.Pango.Markup,
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.
labelSetMarkupWithMnemonic Source
:: (LabelClass self, GlibString markup) | |
=> self | |
-> markup |
|
-> IO () |
Parses str
which is marked up with the Pango text markup language,
as defined in Graphics.Rendering.Pango.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 labelSetMnemonicWidget
.
:: (LabelClass self, WidgetClass widget) | |
=> self | |
-> widget |
|
-> IO () |
If the label has been set so that it has an mnemonic key (using i.e.
labelSetMarkupWithMnemonic
, labelSetTextWithMnemonic
,
labelNewWithMnemonic
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 Button
or a Notebook
tab) it is automatically
associated with the correct widget, but sometimes (i.e. when the target is a
Entry
next to the label) you need to set it explicitly using this
function.
The target widget will be accelerated by emitting "mnemonic_activate" 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.
:: LabelClass self | |
=> self | |
-> IO (Maybe Widget) | returns the target of the label's mnemonic, or
|
Retrieves the target of the mnemonic (keyboard shortcut) of this label.
See labelSetMnemonicWidget
.
Key values are the codes which are sent whenever a key is pressed or released.
labelGetMnemonicKeyval :: LabelClass self => self -> IO KeyVal Source
If the label has been set so that it has an mnemonic key this function returns the keyval used for the mnemonic accelerator.
:: LabelClass self | |
=> self | |
-> Bool |
|
-> IO () |
Sets whether the text of the label contains markup in Pango's text markup
language. See labelSetMarkup
.
:: LabelClass self | |
=> self | |
-> IO Bool | returns |
Returns whether the label's text is interpreted as marked up with the
Pango text markup language. See labelSetUseMarkup
.
labelSetUseUnderline :: LabelClass self => self -> Bool -> IO () Source
If True
, an underline in the text indicates the next character should be
used for the mnemonic accelerator key.
labelGetUseUnderline :: LabelClass self => self -> IO Bool Source
Returns whether an embedded underline in the label indicates a mnemonic.
See labelSetUseUnderline
.
labelGetText :: (LabelClass self, GlibString string) => self -> IO string Source
Gets the text from a label widget, as displayed on the screen. This
does not include any embedded underlines indicating mnemonics or Pango
markup. (See labelGetLabel
)
labelGetLabel :: (LabelClass self, GlibString string) => self -> IO string Source
Gets the text from a label widget including any embedded underlines
indicating mnemonics and Pango markup. (See labelGetText
).
:: LabelClass self | |
=> self | |
-> [PangoAttribute] |
|
-> IO () |
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 labelUseUnderline
or
labelUseMarkup
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.
:: LabelClass self | |
=> self | |
-> IO [PangoAttribute] | return the attribute list, or Emtpy if none was set. |
Gets the attribute list that was set on the label using labelSetAttributes
, if any.
This function does not reflect attributes that come from the labels markup (see labelSetMarkup
).
If you want to get the effective attributes for the label, use layoutGetAttributes
(labelGetLayout
(label)).
labelSetPattern :: LabelClass l => l -> [Int] -> IO () Source
Underline parts of the text, odd indices of the list represent underlined parts.
data Justification Source
Justification for label and maybe other widgets (text?)
labelSetJustify :: LabelClass self => self -> Justification -> IO () Source
Sets the alignment of the lines in the text of the label relative to each
other. JustifyLeft
is the default value when the widget is first created
with labelNew
. If you instead want to set the alignment of the label as a
whole, use miscSetAlignment
instead.
labelSetJustify
has no effect on labels containing only a single line.
labelGetJustify :: LabelClass self => self -> IO Justification Source
Returns the justification of the label. See labelSetJustify
.
labelGetLayout :: LabelClass self => self -> IO PangoLayout Source
Gets the PangoLayout
used to display the label. The layout is useful to
e.g. convert text positions to pixel positions, in combination with
labelGetLayoutOffsets
.
:: LabelClass self | |
=> self | |
-> Bool |
|
-> IO () |
Toggles line wrapping within the 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.
:: LabelClass self | |
=> self | |
-> IO Bool | returns |
Returns whether lines in the label are automatically wrapped. See
labelSetLineWrap
.
:: LabelClass self | |
=> self | |
-> LayoutWrapMode |
|
-> IO () |
If line wrapping is on (see labelSetLineWrap
) this controls how the line wrapping is done.
The default is WrapWholeWords
which means wrap on word boundaries.
- Available since Gtk+ version 2.10
:: LabelClass self | |
=> self | |
-> IO LayoutWrapMode | return the line wrapping mode |
Returns line wrap mode used by the label. See labelSetLineWrapMode
.
- Available since Gtk+ version 2.10
:: LabelClass self | |
=> self | |
-> Bool |
|
-> IO () |
Selectable labels allow the user to select text from the label, for copy-and-paste.
:: LabelClass self | |
=> self | |
-> IO Bool | returns |
Gets whether the text selectable.
:: LabelClass self | |
=> self | |
-> Int |
|
-> Int |
|
-> IO () |
Selects a range of characters in the label, if the label is selectable.
See labelSetSelectable
. If the label is not selectable, this function has
no effect. If startOffset
or endOffset
are -1, then the end of the label
will be substituted.
labelGetSelectionBounds :: LabelClass self => self -> IO (Maybe (Int, Int)) Source
Gets the selected range of characters in the label, if any. If there is a range selected the result is the start and end of the selection as character offsets.
labelGetLayoutOffsets :: LabelClass self => self -> IO (Int, Int) Source
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 EventBox
to
receive the events, and pack the label inside it, since labels are a
'NoWindow' widget.
:: LabelClass self | |
=> self | |
-> EllipsizeMode |
|
-> IO () |
Sets the mode used to ellipsize (add an ellipsis: "...") to the text if there is not enough space to render the entire string.
- Available since Gtk+ version 2.6
:: LabelClass self | |
=> self | |
-> IO EllipsizeMode | returns |
Returns the ellipsizing position of the label. See labelSetEllipsize
.
- Available since Gtk+ version 2.6
:: LabelClass self | |
=> self | |
-> Int |
|
-> IO () |
Sets the desired width in characters of label
to nChars
.
- Available since Gtk+ version 2.6
:: LabelClass self | |
=> self | |
-> IO Int | returns the width of the label in characters. |
Retrieves the desired width of label
, in characters. See
labelSetWidthChars
.
- Available since Gtk+ version 2.6
:: LabelClass self | |
=> self | |
-> Int |
|
-> IO () |
Sets the desired maximum width in characters of label
to nChars
.
- Available since Gtk+ version 2.6
:: LabelClass self | |
=> self | |
-> IO Int | returns the maximum width of the label in characters. |
Retrieves the desired maximum width of label
, in characters. See
labelSetWidthChars
.
- Available since Gtk+ version 2.6
:: LabelClass self | |
=> self | |
-> Bool |
|
-> IO () |
Sets whether the label is in single line mode.
- Available since Gtk+ version 2.6
:: LabelClass self | |
=> self | |
-> IO Bool | returns |
Returns whether the label is in single line mode.
- Available since Gtk+ version 2.6
:: LabelClass self | |
=> self | |
-> Double |
|
-> IO () |
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.
- Available since Gtk+ version 2.6
:: LabelClass self | |
=> self | |
-> IO Double | returns the angle of rotation for the label |
Gets the angle of rotation for the label. See gtk_label_set_angle.
- Available since Gtk+ version 2.6
Attributes
labelLabel :: (LabelClass self, GlibString string) => Attr self string Source
The text of the label.
labelUseMarkup :: LabelClass self => Attr self Bool Source
The text of the label includes XML markup. See pango_parse_markup().
Default value: False
labelUseUnderline :: LabelClass self => Attr self Bool Source
If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key.
Default value: False
labelJustify :: LabelClass self => Attr self Justification Source
The alignment of the lines in the text of the label relative to each other. This does NOT affect the alignment of the label within its allocation.
Default value: JustifyLeft
labelWrap :: LabelClass self => Attr self Bool Source
If set, wrap lines if the text becomes too wide.
Default value: False
labelWrapMode :: LabelClass self => Attr self LayoutWrapMode Source
If line wrapping is on (see the labelWrap
property) this controls how the line wrapping is done.
The default is WrapWholeWords
, which means wrap on word boundaries.
Default value: WrapWholeWords
- Available since Gtk+ version 2.10
labelSelectable :: LabelClass self => Attr self Bool Source
Whether the label text can be selected with the mouse.
Default value: False
labelMnemonicWidget :: (LabelClass self, WidgetClass widget) => ReadWriteAttr self (Maybe Widget) widget Source
The widget to be activated when the label's mnemonic key is pressed.
labelMnemonicKeyval :: LabelClass self => ReadAttr self Int Source
The mnemonic accelerator key for this label.
Default value: 16777215
labelPattern :: (LabelClass self, GlibString string) => WriteAttr self string Source
A string with _ characters in positions correspond to characters in the text to underline.
Default value: "\"
labelCursorPosition :: LabelClass self => ReadAttr self Int Source
The current position of the insertion cursor in chars.
Allowed values: >= 0
Default value: 0
labelSelectionBound :: LabelClass self => ReadAttr self Int Source
The position of the opposite end of the selection from the cursor in chars.
Allowed values: >= 0
Default value: 0
labelEllipsize :: LabelClass self => Attr self EllipsizeMode Source
The preferred place to ellipsize the string, if the label does not have
enough room to display the entire string, specified as a EllipsizeMode
.
Note that setting this property to a value other than EllipsizeNone
has
the side-effect that the label requests only enough space to display the
ellipsis "...". In particular, this means that ellipsizing labels don't
work well in notebook tabs, unless the tab's tab-expand property is set to
True
. Other means to set a label's width are
widgetSetSizeRequest
and
labelSetWidthChars
.
Default value: EllipsizeNone
labelWidthChars :: LabelClass self => Attr self Int Source
The desired width of the label, in characters. If this property is set to -1, the width will be calculated automatically, otherwise the label will request either 3 characters or the property value, whichever is greater. If the width-chars property is set to a positive value, then the max-width-chars property is ignored.
Allowed values: >= -1
Default value: -1
labelSingleLineMode :: LabelClass self => Attr self Bool Source
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.
Default value: False
labelAngle :: LabelClass self => Attr self Double Source
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, wrapped, or ellipsized.
Allowed values: [0,360]
Default value: 0
labelAttributes :: LabelClass self => Attr self [PangoAttribute] Source
A list of style attributes to apply to the text of the label.
labelMaxWidthChars :: LabelClass self => Attr self Int Source
The desired maximum width of the label, in characters. If this property is set to -1, the width will be calculated automatically, otherwise the label will request space for no more than the requested number of characters. If the width-chars property is set to a positive value, then the max-width-chars property is ignored.
Allowed values: >= -1
Default value: -1
labelLineWrap :: LabelClass self => Attr self Bool Source
'lineWrap' property. See labelGetLineWrap
and labelSetLineWrap
labelText :: (LabelClass self, GlibString string) => Attr self string Source
'text' property. See labelGetText
and labelSetText
Signals
labelActiveCurrentLink :: LabelClass self => Signal self (IO ()) Source
The labelActiveCurrentLink
signal a keybinding signal which gets emitted when the user activates
a link in the label.
labelActiveLink :: (LabelClass self, GlibString string) => Signal self (string -> IO ()) Source
The labelActiveLink
signal is emitted when a URI is activated. Default is to use showURI.
labelCopyClipboard :: LabelClass self => Signal self (IO ()) Source
The labelCopyClipboard
signal is a keybinding signal which gets emitted to copy the selection to the
clipboard.
labelMoveCursor :: LabelClass self => Signal self (MovementStep -> Int -> Bool -> IO ()) Source
The labelMoveCursor
signal is a keybinding signal which gets emitted when the user initiates a cursor
movement. If the cursor is not visible in label, this signal causes the viewport to be moved
instead.
Applications should not connect to it, but may emit it with signalEmitByName
if they need to
control the cursor programmatically.
The default bindings for this signal come in two variants, the variant with the Shift modifier extends the selection, the variant without the Shift modifer does not. There are too many key combinations to list them all here.
- Arrow keys move by individual characters/lines
- Ctrl-arrow key combinations move by words/paragraphs
- Home/End keys move to the ends of the buffer
labelPopulatePopup :: LabelClass self => Signal self (Menu -> IO ()) Source
The labelPopulatePopup
signal gets emitted before showing the context menu of the label.
If you need to add items to the context menu, connect to this signal and append your menuitems to the menu.