Class: Gtk::Label
- Defined in:
- lib/gtk3/label.rb
Overview
Displays a small amount of text.
Most labels are used to label another widget (such as an [classEntry]).
Shortcuts and Gestures
GtkLabel supports the following keyboard shortcuts, when the cursor is
visible:
- Shift+F10 or Menu opens the context menu.
- Ctrl+A or Ctrl+/
selects all. - Ctrl+Shift+A or
Ctrl+\ unselects all.
Additionally, the following signals have default keybindings:
- [signalGtk.Label::activate-current-link]
- [signalGtk.Label::copy-clipboard]
- [signalGtk.Label::move-cursor]
Actions
GtkLabel defines a set of built-in actions:
clipboard.copycopies the text to the clipboard.clipboard.cutdoesn't do anything, since text in labels can't be deleted.clipboard.pastedoesn't do anything, since text in labels can't be
edited.link.openopens the link, when activated on a link inside the label.link.copycopies the link to the clipboard, when activated on a link
inside the label.menu.popupopens the context menu.selection.deletedoesn't do anything, since text in labels can't be
deleted.selection.select-allselects all of the text, if the label allows
selection.
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 [structPango.Attribute]
values for this label.
An example of a UI definition fragment specifying Pango attributes:
<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 [enumGtk.AccessibleRole.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 [ctorGtk.Label.new_with_mnemonic] or
[methodGtk.Label.set_text_with_mnemonic].
Mnemonics automatically activate any activatable widget the label is
inside, such as a [classGtk.Button]; if the label is not inside the
mnemonic’s target widget, you have to tell the label about the target
using [methodGtk.Label.set_mnemonic_widget].
Here’s a simple example where the label is inside a button:
// 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:
// 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
[classGtk.Entry], you have to point the label at the entry with
[methodGtk.Label.set_mnemonic_widget]:
// 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:
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, [funcPango.parse_markup])
The markup passed to [methodGtk.Label.set_markup] must be valid XML; for example,
literal <, > and & characters must be escaped as <, >, and &.
If you pass text obtained from the user, file, or a network to
[methodGtk.Label.set_markup], you’ll want to escape it with
[funcGLib.markup_escape_text] or [funcGLib.markup_printf_escaped].
Markup strings are just a convenient way to set the [structPango.AttrList]
on a label; [methodGtk.Label.set_attributes] may be a simpler way to set
attributes in some cases. Be careful though; [structPango.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 [structPango.Attribute] requires knowledge of the exact
string being displayed, so translations will cause problems.
Selectable labels
Labels can be made selectable with [methodGtk.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 [methodGtk.Label.set_wrap].
[methodGtk.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 [propertyGtk.Widget:halign] and
[propertyGtk.Widget:valign] properties.
The [propertyGtk.Label:width-chars] and [propertyGtk.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> tag
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 of inline links looks like this:
const char *text =
"Go to the "
"<a href=\"https://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 [signalGtk.Label::activate-link] signal and the
[methodGtk.Label.get_current_uri] function.
Instance Method Summary collapse
-
#attributes ⇒ Pango::AttrList
A list of style attributes to apply to the text of the label.
-
#attributes=(attributes) ⇒ Pango::AttrList
A list of style attributes to apply to the text of the label.
-
#current_uri ⇒ String
Returns the URI for the active link in the label.
-
#ellipsize ⇒ Pango::EllipsizeMode
The preferred place to ellipsize the string, if the label does not have enough room to display the entire string.
-
#ellipsize=(ellipsize) ⇒ Pango::EllipsizeMode
The preferred place to ellipsize the string, if the label does not have enough room to display the entire string.
-
#extra_menu ⇒ Gio::MenuModel
A menu model whose contents will be appended to the context menu.
-
#extra_menu=(extra_menu) ⇒ Gio::MenuModel
A menu model whose contents will be appended to the context menu.
-
#get_layout_offsets(x, y) ⇒ nil
Obtains the coordinates where the label will draw its Pango layout.
-
#get_selection_bounds(start, end) ⇒ Boolean
Gets the selected range of characters in the label.
-
#initialize(text = nil, options = {}) ⇒ Gtk::Widget
constructor
Creates a new label with the given text inside it, and a mnemonic.
-
#initialize_raw ⇒ Gtk::Widget
Creates a new label with the given text inside it, and a mnemonic.
-
#justify ⇒ Gtk::Justification
The alignment of the lines in the text of the label, relative to each other.
-
#justify=(justify) ⇒ Gtk::Justification
The alignment of the lines in the text of the label, relative to each other.
-
#label ⇒ String
The contents of the label.
-
#label=(label) ⇒ String
The contents of the label.
-
#layout ⇒ Pango::Layout
Gets the Pango layout used to display the label.
-
#lines ⇒ Integer
The number of lines to which an ellipsized, wrapping label should display before it gets ellipsized.
-
#lines=(lines) ⇒ Integer
The number of lines to which an ellipsized, wrapping label should display before it gets ellipsized.
-
#markup=(str) ⇒ nil
Sets the labels text and attributes from markup.
-
#markup_with_mnemonic=(str) ⇒ nil
Sets the labels text, attributes and mnemonic from markup.
-
#max_width_chars ⇒ Integer
The desired maximum width of the label, in characters.
-
#max_width_chars=(max_width_chars) ⇒ Integer
The desired maximum width of the label, in characters.
-
#mnemonic_keyval ⇒ Integer
The mnemonic accelerator key for the label.
-
#mnemonic_keyval=(mnemonic_keyval) ⇒ Integer
The mnemonic accelerator key for the label.
-
#mnemonic_widget ⇒ Gtk::Widget
The widget to be activated when the labels mnemonic key is pressed.
-
#mnemonic_widget=(mnemonic_widget) ⇒ Gtk::Widget
The widget to be activated when the labels mnemonic key is pressed.
-
#natural_wrap_mode ⇒ Gtk::NaturalWrapMode
Select the line wrapping for the natural size request.
-
#natural_wrap_mode=(natural_wrap_mode) ⇒ Gtk::NaturalWrapMode
Select the line wrapping for the natural size request.
-
#select_region(start_offset, end_offset) ⇒ nil
Selects a range of characters in the label, if the label is selectable.
-
#selectable ⇒ Boolean
Returns whether the label is selectable.
-
#selectable=(selectable) ⇒ Boolean
Whether the label text can be selected with the mouse.
-
#selectable? ⇒ Boolean
Whether the label text can be selected with the mouse.
- #set_markup(text, options = {}) ⇒ Object
- #set_markup_raw ⇒ Object
-
#single_line_mode ⇒ Boolean
Returns whether the label is in single line mode.
-
#single_line_mode=(single_line_mode) ⇒ Boolean
Whether the label is in single line mode.
-
#single_line_mode? ⇒ Boolean
Whether the label is in single line mode.
-
#tabs ⇒ Pango::TabArray
Custom tabs for this label.
-
#tabs=(tabs) ⇒ Pango::TabArray
Custom tabs for this label.
-
#text ⇒ String
Gets the text of the label.
-
#text=(str) ⇒ nil
Sets the text for the label.
-
#text_with_mnemonic=(str) ⇒ nil
Sets the text for the label, with mnemonics.
-
#use_markup ⇒ Boolean
Returns whether the label’s text is interpreted as Pango markup.
-
#use_markup=(use_markup) ⇒ Boolean
True if the text of the label includes Pango markup.
-
#use_markup? ⇒ Boolean
True if the text of the label includes Pango markup.
-
#use_underline ⇒ Boolean
Returns whether underlines in the label indicate mnemonics.
-
#use_underline=(use_underline) ⇒ Boolean
True if the text of the label indicates a mnemonic with an
_before the mnemonic character. -
#use_underline? ⇒ Boolean
True if the text of the label indicates a mnemonic with an
_before the mnemonic character. -
#width_chars ⇒ Integer
The desired width of the label, in characters.
-
#width_chars=(width_chars) ⇒ Integer
The desired width of the label, in characters.
-
#wrap ⇒ Boolean
Returns whether lines in the label are automatically wrapped.
-
#wrap=(wrap) ⇒ Boolean
True if the label text will wrap if it gets too wide.
-
#wrap? ⇒ Boolean
True if the label text will wrap if it gets too wide.
-
#wrap_mode ⇒ Pango::WrapMode
Controls how the line wrapping is done.
-
#wrap_mode=(wrap_mode) ⇒ Pango::WrapMode
Controls how the line wrapping is done.
-
#xalign ⇒ Gtk::gfloat
The horizontal alignment of the label text inside its size allocation.
-
#xalign=(xalign) ⇒ Gtk::gfloat
The horizontal alignment of the label text inside its size allocation.
-
#yalign ⇒ Gtk::gfloat
The vertical alignment of the label text inside its size allocation.
-
#yalign=(yalign) ⇒ Gtk::gfloat
The vertical alignment of the label text inside its size allocation.
Methods inherited from Widget
#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_events, #add_events_raw, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #direction, #direction=, #display, #dispose_template, #drag_check_threshold, #drag_dest_set, #drag_dest_set_raw, #drag_source_set, #drag_source_set_raw, #error_bell, #events, #events_raw, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, have_template?, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_action_group_raw, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #limit_events, #limit_events=, #limit_events?, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #render_icon_pixbuf, #render_icon_pixbuf_raw, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_allocation, set_connect_func, set_connect_func_raw, #set_events, #set_events_raw, #set_size_request, #set_size_request_raw, #set_state_flags, #set_template, #set_template_raw, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #style_context_raw, #style_get_property, #style_get_property_raw, #template=, template_children, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #translate_coordinates_raw, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=
Constructor Details
#initialize(text = nil, options = {}) ⇒ Gtk::Widget
Creates a new label with the given text inside it, and a mnemonic.
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
[methodGtk.Label.set_mnemonic_widget].
If [methodGtk.Label.set_mnemonic_widget] 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.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gtk3/label.rb', line 20 def initialize(text=nil, ={}) if == true or == false or .nil? mnemonic = warn "Gtk::Label.new(text, mnemonic) style has been deprecated. " + "Use Gtk::Label.new(text, {:use_underline => #{mnemonic}}) style instead." = { :use_underline => mnemonic, } end if [:use_underline] initialize_new_with_mnemonic(text) else initialize_raw(text || "") end end |
Instance Method Details
#attributes ⇒ Pango::AttrList
A list of style attributes to apply to the text of the label.
#attributes=(attributes) ⇒ Pango::AttrList
A list of style attributes to apply to the text of the label.
#current_uri ⇒ String
Returns the URI for the 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 [signalGtk.Label::activate-link]
handler or for use in a [signalGtk.Widget::query-tooltip] handler.
#ellipsize ⇒ Pango::EllipsizeMode
The preferred place to ellipsize the string, if the label does
not have enough room to display the entire string.
Note that setting this property to a value other than
[enum.Pango.EllipsizeMode.none] has the side-effect that the label requests
only enough space to display the ellipsis "...". In particular, this
means that ellipsizing labels do not work well in notebook tabs, unless
the [propertyGtk.NotebookPage:tab-expand] child property is set to true.
Other ways to set a label's width are [methodGtk.Widget.set_size_request]
and [methodGtk.Label.set_width_chars].
#ellipsize=(ellipsize) ⇒ Pango::EllipsizeMode
The preferred place to ellipsize the string, if the label does
not have enough room to display the entire string.
Note that setting this property to a value other than
[enum.Pango.EllipsizeMode.none] has the side-effect that the label requests
only enough space to display the ellipsis "...". In particular, this
means that ellipsizing labels do not work well in notebook tabs, unless
the [propertyGtk.NotebookPage:tab-expand] child property is set to true.
Other ways to set a label's width are [methodGtk.Widget.set_size_request]
and [methodGtk.Label.set_width_chars].
#extra_menu ⇒ Gio::MenuModel
A menu model whose contents will be appended to the context menu.
#extra_menu=(extra_menu) ⇒ Gio::MenuModel
A menu model whose contents will be appended to the context menu.
#get_layout_offsets(x, y) ⇒ nil
Obtains the coordinates where the label will draw its Pango layout.
The coordinates are useful to convert mouse events into coordinates
inside the [classPango.Layout], e.g. to take some action if some part
of the label is clicked. Remember when using the [classPango.Layout]
functions you need to convert to and from pixels using PANGO_PIXELS()
or [constPango.SCALE].
#get_selection_bounds(start, end) ⇒ Boolean
Gets the selected range of characters in the label.
The returned start and end positions are in characters.
#initialize_raw ⇒ Gtk::Widget
Creates a new label with the given text inside it, and a mnemonic.
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
[methodGtk.Label.set_mnemonic_widget].
If [methodGtk.Label.set_mnemonic_widget] 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.
|
|
# File 'lib/gtk3/label.rb', line 19
|
#justify ⇒ Gtk::Justification
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.
See [propertyGtk.Label:xalign] for that.
#justify=(justify) ⇒ Gtk::Justification
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.
See [propertyGtk.Label:xalign] for that.
#label ⇒ String
The contents of the label.
If the string contains Pango markup (see [funcPango.parse_markup]),
you will have to set the [propertyGtk.Label:use-markup] property to
true in order for the label to display the markup attributes. See also
[methodGtk.Label.set_markup] for a convenience function that sets both
this property and the [propertyGtk.Label:use-markup] property at the
same time.
If the string contains underlines acting as mnemonics, you will have to
set the [propertyGtk.Label:use-underline] property to true in order
for the label to display them.
#label=(label) ⇒ String
The contents of the label.
If the string contains Pango markup (see [funcPango.parse_markup]),
you will have to set the [propertyGtk.Label:use-markup] property to
true in order for the label to display the markup attributes. See also
[methodGtk.Label.set_markup] for a convenience function that sets both
this property and the [propertyGtk.Label:use-markup] property at the
same time.
If the string contains underlines acting as mnemonics, you will have to
set the [propertyGtk.Label:use-underline] property to true in order
for the label to display them.
#layout ⇒ Pango::Layout
Gets the Pango layout used to display the label.
The layout is useful to e.g. convert text positions to pixel
positions, in combination with [methodGtk.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.
#lines ⇒ Integer
The number of lines to which an ellipsized, wrapping label
should display before it gets ellipsized. This both prevents the label
from ellipsizing before this many lines are displayed, and limits the
height request of the label to this many lines.
::: warning
Setting this property has unintuitive and unfortunate consequences
for the minimum width of the label. Specifically, if the height
of the label is such that it fits a smaller number of lines than
the value of this property, the label can not be ellipsized at all,
which means it must be wide enough to fit all the text fully.
This property has no effect if the label is not wrapping or ellipsized.
Set this property to -1 if you don't want to limit the number of lines.
#lines=(lines) ⇒ Integer
The number of lines to which an ellipsized, wrapping label
should display before it gets ellipsized. This both prevents the label
from ellipsizing before this many lines are displayed, and limits the
height request of the label to this many lines.
::: warning
Setting this property has unintuitive and unfortunate consequences
for the minimum width of the label. Specifically, if the height
of the label is such that it fits a smaller number of lines than
the value of this property, the label can not be ellipsized at all,
which means it must be wide enough to fit all the text fully.
This property has no effect if the label is not wrapping or ellipsized.
Set this property to -1 if you don't want to limit the number of lines.
#markup=(str) ⇒ nil
Sets the labels text and attributes from markup.
The string must be marked up with Pango markup
(see [funcPango.parse_markup]).
If str is external data, you may need to escape it
with [funcGLib.markup_escape_text] or [funcGLib.markup_printf_escaped]:
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 sets the [propertyGtk.Label:use-markup] property
to true.
Also see [methodGtk.Label.set_text].
#markup_with_mnemonic=(str) ⇒ nil
Sets the labels text, attributes and mnemonic from markup.
Parses str which is marked up with Pango markup (see [funcPango.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 [methodGtk.Label.set_mnemonic_widget].
#max_width_chars ⇒ Integer
The desired maximum width of the label, in characters.
If this property is set to -1, the width will be calculated automatically.
See the section on text layout for details
of how [propertyGtk.Label:width-chars] and [propertyGtk.Label:max-width-chars]
determine the width of ellipsized and wrapped labels.
#max_width_chars=(max_width_chars) ⇒ Integer
The desired maximum width of the label, in characters.
If this property is set to -1, the width will be calculated automatically.
See the section on text layout for details
of how [propertyGtk.Label:width-chars] and [propertyGtk.Label:max-width-chars]
determine the width of ellipsized and wrapped labels.
#mnemonic_keyval ⇒ Integer
The mnemonic accelerator key for the label.
#mnemonic_keyval=(mnemonic_keyval) ⇒ Integer
The mnemonic accelerator key for the label.
#mnemonic_widget ⇒ Gtk::Widget
The widget to be activated when the labels mnemonic key is pressed.
#mnemonic_widget=(mnemonic_widget) ⇒ Gtk::Widget
The widget to be activated when the labels mnemonic key is pressed.
#natural_wrap_mode ⇒ Gtk::NaturalWrapMode
Select the line wrapping for the natural size request.
This only affects the natural size requested. For the actual wrapping
used, see the [propertyGtk.Label:wrap-mode] property.
The default is [enumGtk.NaturalWrapMode.inherit], which inherits
the behavior of the [propertyGtk.Label:wrap-mode] property.
#natural_wrap_mode=(natural_wrap_mode) ⇒ Gtk::NaturalWrapMode
Select the line wrapping for the natural size request.
This only affects the natural size requested. For the actual wrapping
used, see the [propertyGtk.Label:wrap-mode] property.
The default is [enumGtk.NaturalWrapMode.inherit], which inherits
the behavior of the [propertyGtk.Label:wrap-mode] property.
#select_region(start_offset, end_offset) ⇒ nil
Selects a range of characters in the label, if the label is selectable.
See [methodGtk.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.
#selectable ⇒ Boolean
Returns whether the label is selectable.
#selectable=(selectable) ⇒ Boolean
Whether the label text can be selected with the mouse.
#selectable? ⇒ Boolean
Whether the label text can be selected with the mouse.
#set_markup(text, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gtk3/label.rb', line 38 def set_markup(text, ={}) if == true or == false or .nil? mnemonic = warn "Gtk::Label#set_markup(text, mnemonic) style has been deprecated. " + "Use Gtk::Label#set_markup(text, {:use_underline => #{mnemonic}}) style instead." = { :use_underline => mnemonic, } end if [:use_underline] set_markup_with_mnemonic(text) else set_markup_raw(text) end end |
#set_markup_raw ⇒ Object
37 |
# File 'lib/gtk3/label.rb', line 37 alias_method :set_markup_raw, :set_markup |
#single_line_mode ⇒ Boolean
Returns whether the label is in single line mode.
#single_line_mode=(single_line_mode) ⇒ Boolean
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.
#single_line_mode? ⇒ Boolean
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.
#tabs ⇒ Pango::TabArray
Custom tabs for this label.
#tabs=(tabs) ⇒ Pango::TabArray
Custom tabs for this label.
#text ⇒ String
Gets the text of the label.
The returned text is as it appears on screen. This does not include
any embedded underlines indicating mnemonics or Pango markup. (See
[methodGtk.Label.get_label])
#text=(str) ⇒ nil
Sets the text for the label.
It overwrites any text that was there before and clears any
previously set mnemonic accelerators, and sets the
[propertyGtk.Label:use-underline] and
[propertyGtk.Label:use-markup] properties to false.
Also see [methodGtk.Label.set_markup].
#text_with_mnemonic=(str) ⇒ nil
Sets the text for the label, with mnemonics.
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 [methodGtk.Label.set_mnemonic_widget].
#use_markup ⇒ Boolean
Returns whether the label’s text is interpreted as Pango markup.
See [methodGtk.Label.set_use_markup].
#use_markup=(use_markup) ⇒ Boolean
True if the text of the label includes Pango markup.
See [funcPango.parse_markup].
#use_markup? ⇒ Boolean
True if the text of the label includes Pango markup.
See [funcPango.parse_markup].
#use_underline ⇒ Boolean
Returns whether underlines in the label indicate mnemonics.
See [methodGtk.Label.set_use_underline].
#use_underline=(use_underline) ⇒ Boolean
True if the text of the label indicates a mnemonic with an _
before the mnemonic character.
#use_underline? ⇒ Boolean
True if the text of the label indicates a mnemonic with an _
before the mnemonic character.
#width_chars ⇒ Integer
The desired width of the label, in characters.
If this property is set to -1, the width will be calculated automatically.
See the section on text layout for details
of how [propertyGtk.Label:width-chars] and [propertyGtk.Label:max-width-chars]
determine the width of ellipsized and wrapped labels.
#width_chars=(width_chars) ⇒ Integer
The desired width of the label, in characters.
If this property is set to -1, the width will be calculated automatically.
See the section on text layout for details
of how [propertyGtk.Label:width-chars] and [propertyGtk.Label:max-width-chars]
determine the width of ellipsized and wrapped labels.
#wrap ⇒ Boolean
Returns whether lines in the label are automatically wrapped.
See [methodGtk.Label.set_wrap].
#wrap=(wrap) ⇒ Boolean
True if the label text will wrap if it gets too wide.
#wrap? ⇒ Boolean
True if the label text will wrap if it gets too wide.
#wrap_mode ⇒ Pango::WrapMode
Controls how the line wrapping is done.
This only affects the formatting if line wrapping is on (see the
[propertyGtk.Label:wrap] property). The default is [enumPango.WrapMode.word],
which means wrap on word boundaries.
For sizing behavior, also consider the [propertyGtk.Label:natural-wrap-mode]
property.
#wrap_mode=(wrap_mode) ⇒ Pango::WrapMode
Controls how the line wrapping is done.
This only affects the formatting if line wrapping is on (see the
[propertyGtk.Label:wrap] property). The default is [enumPango.WrapMode.word],
which means wrap on word boundaries.
For sizing behavior, also consider the [propertyGtk.Label:natural-wrap-mode]
property.
#xalign ⇒ Gtk::gfloat
The horizontal alignment of the label text inside its size allocation.
Compare this to [propertyGtk.Widget:halign], which determines how the
labels size allocation is positioned in the space available for the label.
#xalign=(xalign) ⇒ Gtk::gfloat
The horizontal alignment of the label text inside its size allocation.
Compare this to [propertyGtk.Widget:halign], which determines how the
labels size allocation is positioned in the space available for the label.
#yalign ⇒ Gtk::gfloat
The vertical alignment of the label text inside its size allocation.
Compare this to [propertyGtk.Widget:valign], which determines how the
labels size allocation is positioned in the space available for the label.
#yalign=(yalign) ⇒ Gtk::gfloat
The vertical alignment of the label text inside its size allocation.
Compare this to [propertyGtk.Widget:valign], which determines how the
labels size allocation is positioned in the space available for the label.