Trait gtk::prelude::LabelExt [−][src]
pub trait LabelExt: 'static {}Show methods
fn angle(&self) -> f64; fn attributes(&self) -> Option<AttrList>; fn current_uri(&self) -> Option<GString>; fn ellipsize(&self) -> EllipsizeMode; fn justify(&self) -> Justification; fn label(&self) -> GString; fn layout(&self) -> Option<Layout>; fn layout_offsets(&self) -> (i32, i32); fn is_line_wrap(&self) -> bool; fn line_wrap_mode(&self) -> WrapMode; fn lines(&self) -> i32; fn max_width_chars(&self) -> i32; fn mnemonic_keyval(&self) -> u32; fn mnemonic_widget(&self) -> Option<Widget>; fn is_selectable(&self) -> bool; fn selection_bounds(&self) -> Option<(i32, i32)>; fn is_single_line_mode(&self) -> bool; fn text(&self) -> GString; fn tracks_visited_links(&self) -> bool; fn uses_markup(&self) -> bool; fn uses_underline(&self) -> bool; fn width_chars(&self) -> i32; fn xalign(&self) -> f32; fn yalign(&self) -> f32; fn select_region(&self, start_offset: i32, end_offset: i32); fn set_angle(&self, angle: f64); fn set_attributes(&self, attrs: Option<&AttrList>); fn set_ellipsize(&self, mode: EllipsizeMode); fn set_justify(&self, jtype: Justification); fn set_label(&self, str: &str); fn set_line_wrap(&self, wrap: bool); fn set_line_wrap_mode(&self, wrap_mode: WrapMode); fn set_lines(&self, lines: i32); fn set_markup(&self, str: &str); fn set_markup_with_mnemonic(&self, str: &str); fn set_max_width_chars(&self, n_chars: i32); fn set_mnemonic_widget<P: IsA<Widget>>(&self, widget: Option<&P>); fn set_pattern(&self, pattern: &str); fn set_selectable(&self, setting: bool); fn set_single_line_mode(&self, single_line_mode: bool); fn set_text(&self, str: &str); fn set_text_with_mnemonic(&self, str: &str); fn set_track_visited_links(&self, track_links: bool); fn set_use_markup(&self, setting: bool); fn set_use_underline(&self, setting: bool); fn set_width_chars(&self, n_chars: i32); fn set_xalign(&self, xalign: f32); fn set_yalign(&self, yalign: f32); fn cursor_position(&self) -> i32; fn selection_bound(&self) -> i32; fn wraps(&self) -> bool; fn set_wrap(&self, wrap: bool); fn wrap_mode(&self) -> WrapMode; fn set_wrap_mode(&self, wrap_mode: WrapMode); fn connect_activate_current_link<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn emit_activate_current_link(&self); fn connect_activate_link<F: Fn(&Self, &str) -> Inhibit + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_copy_clipboard<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn emit_copy_clipboard(&self); fn connect_move_cursor<F: Fn(&Self, MovementStep, i32, bool) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn emit_move_cursor(
&self,
step: MovementStep,
count: i32,
extend_selection: bool
); fn connect_populate_popup<F: Fn(&Self, &Menu) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_angle_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_attributes_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_cursor_position_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_ellipsize_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_justify_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_label_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_lines_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_max_width_chars_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_mnemonic_keyval_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_mnemonic_widget_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_pattern_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_selectable_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_selection_bound_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_single_line_mode_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_track_visited_links_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_use_markup_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_use_underline_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_width_chars_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_wrap_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_wrap_mode_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_xalign_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId; fn connect_yalign_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId;
Expand description
Required methods
Gets the angle of rotation for the label. See
set_angle()
.
Returns
the angle of rotation for the label
fn attributes(&self) -> Option<AttrList>
fn attributes(&self) -> Option<AttrList>
Gets the attribute list that was set on the label using
set_attributes()
, if any. This function does
not reflect attributes that come from the labels markup
(see set_markup()
). If you want to get the
effective attributes for the label, use
pango_layout_get_attribute (gtk_label_get_layout (label)).
Returns
the attribute list, or None
if none was set.
fn current_uri(&self) -> Option<GString>
fn current_uri(&self) -> Option<GString>
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::Label::activate-link
handler
or for use in a signal::Widget::query-tooltip
handler.
Returns
the currently active URI. The string is owned by GTK+ and must not be freed or modified.
fn ellipsize(&self) -> EllipsizeMode
fn ellipsize(&self) -> EllipsizeMode
fn justify(&self) -> Justification
fn justify(&self) -> Justification
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 layout_offsets()
.
The returned layout is owned by the self
so need not be
freed by the caller. The self
is free to recreate its layout at
any time, so it should be considered read-only.
Returns
the pango::Layout
for this label
Obtains the coordinates where the label will draw the pango::Layout
representing the text in the label; useful to convert mouse events
into coordinates inside the pango::Layout
, 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 windowless (they return false
from
WidgetExt::has_window()
). Remember
when using the pango::Layout
functions you need to convert to
and from pixels using PANGO_PIXELS() or PANGO_SCALE
.
Returns
x
location to store X offset of layout, or None
y
location to store Y offset of layout, or None
fn is_line_wrap(&self) -> bool
fn is_line_wrap(&self) -> bool
Returns whether lines in the label are automatically wrapped.
See set_line_wrap()
.
Returns
true
if the lines of the label are automatically wrapped.
fn line_wrap_mode(&self) -> WrapMode
fn line_wrap_mode(&self) -> WrapMode
Returns line wrap mode used by the label. See set_line_wrap_mode()
.
Returns
true
if the lines of the label are automatically wrapped.
Gets the number of lines to which an ellipsized, wrapping
label should be limited. See set_lines()
.
Returns
The number of lines
fn max_width_chars(&self) -> i32
fn max_width_chars(&self) -> i32
Retrieves the desired maximum width of self
, in characters. See
set_width_chars()
.
Returns
the maximum width of the label in characters.
fn mnemonic_keyval(&self) -> u32
fn mnemonic_keyval(&self) -> u32
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
.
Returns
GDK keyval usable for accelerators, or GDK_KEY_VoidSymbol
fn mnemonic_widget(&self) -> Option<Widget>
fn mnemonic_widget(&self) -> Option<Widget>
Retrieves the target of the mnemonic (keyboard shortcut) of this
label. See set_mnemonic_widget()
.
Returns
the target of the label’s mnemonic,
or None
if none has been set and the default algorithm will be used.
fn is_selectable(&self) -> bool
fn is_selectable(&self) -> bool
fn is_single_line_mode(&self) -> bool
fn is_single_line_mode(&self) -> bool
fn tracks_visited_links(&self) -> bool
fn tracks_visited_links(&self) -> bool
fn uses_markup(&self) -> bool
fn uses_markup(&self) -> bool
fn uses_underline(&self) -> bool
fn uses_underline(&self) -> bool
Returns whether an embedded underline in the label indicates a
mnemonic. See set_use_underline()
.
Returns
true
whether an embedded underline in the label indicates
the mnemonic accelerator keys.
fn width_chars(&self) -> i32
fn width_chars(&self) -> i32
Retrieves the desired width of self
, in characters. See
set_width_chars()
.
Returns
the width of the label in characters.
fn select_region(&self, start_offset: i32, end_offset: i32)
fn select_region(&self, start_offset: i32, end_offset: i32)
Selects a range of characters in the label, if the label is selectable.
See 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.
start_offset
start offset (in characters not bytes)
end_offset
end offset (in characters not bytes)
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.
angle
the angle that the baseline of the label makes with the horizontal, in degrees, measured counterclockwise
fn set_attributes(&self, attrs: Option<&AttrList>)
fn set_attributes(&self, attrs: Option<&AttrList>)
Sets a pango::AttrList
; the attributes in the list are applied 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::Label::use-underline
or property::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.
attrs
a pango::AttrList
, or None
fn set_ellipsize(&self, mode: EllipsizeMode)
fn set_ellipsize(&self, mode: EllipsizeMode)
Sets the mode used to ellipsize (add an ellipsis: “…”) to the text if there is not enough space to render the entire string.
mode
fn set_justify(&self, jtype: Justification)
fn set_justify(&self, jtype: Justification)
Sets the alignment of the lines in the text of the label relative to
each other. Justification::Left
is the default value when the widget is
first created with Label::new()
. If you instead want to set the
alignment of the label as a whole, use WidgetExt::set_halign()
instead.
set_justify()
has no effect on labels containing only a
single line.
jtype
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::Label::use-underline
and
property::Label::use-markup
properties.
str
the new text to set for the label
fn set_line_wrap(&self, wrap: bool)
fn set_line_wrap(&self, wrap: bool)
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.
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 WidgetExt::set_size_request()
.
wrap
the setting
fn set_line_wrap_mode(&self, wrap_mode: WrapMode)
fn set_line_wrap_mode(&self, wrap_mode: WrapMode)
If line wrapping is on (see set_line_wrap()
) this controls how
the line wrapping is done. The default is pango::WrapMode::Word
which means
wrap on word boundaries.
wrap_mode
the line wrapping mode
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.
lines
the desired number of lines, or -1
fn set_markup(&self, str: &str)
fn set_markup(&self, str: &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 the str
is external data, you may need to escape it with
g_markup_escape_text()
or g_markup_printf_escaped()
:
⚠️ The following code is in C ⚠️
GtkWidget *label = gtk_label_new (NULL);
const char *str = "some text";
const char *format = "<span style=\"italic\">\%s</span>";
char *markup;
markup = g_markup_printf_escaped (format, str);
gtk_label_set_markup (GTK_LABEL (label), markup);
g_free (markup);
This function will set the property::Label::use-markup
property to true
as
a side effect.
If you set the label contents using the property::Label::label
property you
should also ensure that you set the property::Label::use-markup
property
accordingly.
See also: set_text()
str
a markup string (see [Pango markup format][PangoMarkupFormat])
fn set_markup_with_mnemonic(&self, str: &str)
fn set_markup_with_mnemonic(&self, str: &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.
The mnemonic key can be used to activate another widget, chosen
automatically, or explicitly using set_mnemonic_widget()
.
str
a markup string (see [Pango markup format][PangoMarkupFormat])
fn set_max_width_chars(&self, n_chars: i32)
fn set_max_width_chars(&self, n_chars: i32)
Sets the desired maximum width in characters of self
to n_chars
.
n_chars
the new desired maximum width, in characters.
If the label has been set so that it has an mnemonic key (using
i.e. set_markup_with_mnemonic()
,
set_text_with_mnemonic()
, Label::with_mnemonic()
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 the 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.
widget
fn set_pattern(&self, pattern: &str)
fn set_pattern(&self, pattern: &str)
fn set_selectable(&self, setting: bool)
fn set_selectable(&self, setting: bool)
fn set_single_line_mode(&self, single_line_mode: bool)
fn set_single_line_mode(&self, single_line_mode: bool)
Sets whether the label is in single line mode.
single_line_mode
true
if the label should be in single line mode
Sets the text within the Label
widget. It overwrites any text that
was there before.
This function will clear any previously set mnemonic accelerators, and
set the property::Label::use-underline
property to false
as a side effect.
This function will set the property::Label::use-markup
property to false
as a side effect.
See also: set_markup()
str
The text you want to set
fn set_text_with_mnemonic(&self, str: &str)
fn set_text_with_mnemonic(&self, str: &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 set_mnemonic_widget()
.
str
a string
fn set_track_visited_links(&self, track_links: bool)
fn set_track_visited_links(&self, track_links: bool)
Sets whether the label should keep track of clicked links (and use a different color for them).
track_links
true
to track visited links
fn set_use_markup(&self, setting: bool)
fn set_use_markup(&self, setting: bool)
Sets whether the text of the label contains markup in
[Pango’s text markup language][PangoMarkupFormat].
See set_markup()
.
setting
true
if the label’s text should be parsed for markup.
fn set_use_underline(&self, setting: bool)
fn set_use_underline(&self, setting: bool)
fn set_width_chars(&self, n_chars: i32)
fn set_width_chars(&self, n_chars: i32)
Sets the desired width in characters of self
to n_chars
.
n_chars
the new desired width, in characters.
fn set_xalign(&self, xalign: f32)
fn set_xalign(&self, xalign: f32)
fn set_yalign(&self, yalign: f32)
fn set_yalign(&self, yalign: f32)
fn cursor_position(&self) -> i32
fn selection_bound(&self) -> i32
If line wrapping is on (see the property::Label::wrap
property) this controls
how the line wrapping is done. The default is pango::WrapMode::Word
, which
means wrap on word boundaries.
fn set_wrap_mode(&self, wrap_mode: WrapMode)
fn set_wrap_mode(&self, wrap_mode: WrapMode)
If line wrapping is on (see the property::Label::wrap
property) this controls
how the line wrapping is done. The default is pango::WrapMode::Word
, which
means wrap on word boundaries.
fn connect_activate_current_link<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_activate_current_link<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
A [keybinding signal][GtkBindingSignal] which gets emitted when the user activates a link in the label.
Applications may also emit the signal with g_signal_emit_by_name()
if they need to control activation of URIs programmatically.
The default bindings for this signal are all forms of the Enter key.
fn emit_activate_current_link(&self)
fn connect_activate_link<F: Fn(&Self, &str) -> Inhibit + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_activate_link<F: Fn(&Self, &str) -> Inhibit + 'static>(
&self,
f: F
) -> SignalHandlerId
The signal which gets emitted to activate a URI.
Applications may connect to it to override the default behaviour,
which is to call show_uri_on_window()
.
uri
the URI that is activated
Returns
true
if the link has been activated
fn connect_copy_clipboard<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_copy_clipboard<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
The ::copy-clipboard signal is a [keybinding signal][GtkBindingSignal] which gets emitted to copy the selection to the clipboard.
The default binding for this signal is Ctrl-c.
fn emit_copy_clipboard(&self)
fn connect_move_cursor<F: Fn(&Self, MovementStep, i32, bool) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_move_cursor<F: Fn(&Self, MovementStep, i32, bool) + 'static>(
&self,
f: F
) -> SignalHandlerId
The ::move-cursor signal is a
[keybinding signal][GtkBindingSignal]
which gets emitted when the user initiates a cursor movement.
If the cursor is not visible in entry
, this signal causes
the viewport to be moved instead.
Applications should not connect to it, but may emit it with
g_signal_emit_by_name()
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
step
the granularity of the move, as a MovementStep
count
the number of step
units to move
extend_selection
true
if the move should extend the selection
fn emit_move_cursor(
&self,
step: MovementStep,
count: i32,
extend_selection: bool
)
fn connect_populate_popup<F: Fn(&Self, &Menu) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_populate_popup<F: Fn(&Self, &Menu) + 'static>(
&self,
f: F
) -> SignalHandlerId
The ::populate-popup signal gets emitted before showing the context menu of the label. Note that only selectable labels have context menus.
If you need to add items to the context menu, connect
to this signal and append your menuitems to the menu
.
menu
the menu that is being populated
fn connect_angle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId
fn connect_attributes_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_cursor_position_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_ellipsize_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_justify_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId
fn connect_lines_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId
fn connect_max_width_chars_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_mnemonic_keyval_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_mnemonic_widget_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_pattern_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_selectable_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_selection_bound_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_single_line_mode_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_track_visited_links_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_use_markup_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_use_underline_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_width_chars_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_wrap_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId
fn connect_wrap_mode_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_xalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId
fn connect_yalign_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId