1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 A widget that displays a small to medium amount of text
7 <!-- ##### SECTION Long_Description ##### -->
9 The #GtkLabel widget displays a small amount of text. As the name
10 implies, most labels are used to label another widget such as a
11 #GtkButton, a #GtkMenuItem, or a #GtkOptionMenu.
14 <refsect2 id="GtkLabel-BUILDER-UI">
15 <title>GtkLabel as GtkBuildable</title>
17 The GtkLabel implementation of the GtkBuildable interface supports a
18 custom <attributes> element, which supports any number of <attribute>
19 elements. the <attribute> element has attributes named name, value,
20 start and end and allows you to specify #PangoAttribute values for this label.
23 <title>A UI definition fragment specifying Pango attributes</title>
24 <programlisting><![CDATA[
25 <object class="GtkLabel">
27 <attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
28 <attribute name="background" value="red" start="5" end="10"/>"
34 The start and end attributes specify the range of characters to which the
35 Pango attribute applies. If start and end are not specified, the attribute is
36 applied to the whole text. Note that specifying ranges does not make much
37 sense with translatable attributes. Use markup embedded in the translatable
44 <title>Mnemonics</title>
47 Labels may contain <firstterm>mnemonics</firstterm>. Mnemonics are
48 underlined characters in the label, used for keyboard navigation.
49 Mnemonics are created by providing a string with an underscore before
50 the mnemonic character, such as <literal>"_File"</literal>, to the
51 functions gtk_label_new_with_mnemonic() or
52 gtk_label_set_text_with_mnemonic().
56 Mnemonics automatically activate any activatable widget the label is
57 inside, such as a #GtkButton; if the label is not inside the
58 mnemonic's target widget, you have to tell the label about the target
59 using gtk_label_set_mnemonic_widget(). Here's a simple example where
60 the label is inside a button:
64 /* Pressing Alt+H will activate this button */
65 button = gtk_button_new (<!-- -->);
66 label = gtk_label_new_with_mnemonic ("_Hello");
67 gtk_container_add (GTK_CONTAINER (button), label);
70 There's a convenience function to create buttons with a mnemonic label
75 /* Pressing Alt+H will activate this button */
76 button = gtk_button_new_with_mnemonic ("_Hello");
80 To create a mnemonic for a widget alongside the label, such as a
81 #GtkEntry, you have to point the label at the entry with
82 gtk_label_set_mnemonic_widget():
85 /* Pressing Alt+H will focus the entry */
86 entry = gtk_entry_new (<!-- -->);
87 label = gtk_label_new_with_mnemonic ("_Hello");
88 gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
97 <title>Markup (styled text)</title>
100 To make it easy to format text in a label (changing colors, fonts,
101 etc.), label text can be provided in a simple <link
102 linkend="PangoMarkupFormat">markup format</link>.
103 Here's how to create a label with a small font:
106 label = gtk_label_new (NULL);
107 gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>");
111 linkend="PangoMarkupFormat">complete documentation</link> of available
112 tags in the Pango manual.)
115 The markup passed to gtk_label_set_markup() must be valid; for example,
116 literal </>/& characters must be escaped as &lt;,
117 &gt;, and &amp;. If you pass text obtained from the user, file,
118 or a network to gtk_label_set_markup(), you'll want to escape it with
119 g_markup_escape_text() or g_markup_printf_escaped().
122 Markup strings are just a convenient way to set the #PangoAttrList on
123 a label; gtk_label_set_attributes() may be a simpler way to set
124 attributes in some cases. Be careful though; #PangoAttrList tends to
125 cause internationalization problems, unless you're applying attributes
126 to the entire string (i.e. unless you set the range of each attribute
127 to [0, G_MAXINT)). The reason is that specifying the start_index and
128 end_index for a #PangoAttribute requires knowledge of the exact string
129 being displayed, so translations will cause problems.
134 <title>Selectable labels</title>
137 Labels can be made selectable with gtk_label_set_selectable().
138 Selectable labels allow the user to copy the label contents to
139 the clipboard. Only labels that contain useful-to-copy information
140 — such as error messages — should be made selectable.
144 <refsect2 id="label-text-layout">
145 <title>Text layout</title>
148 A label can contain any number of paragraphs, but will have
149 performance problems if it contains more than a small number.
150 Paragraphs are separated by newlines or other paragraph separators
154 Labels can automatically wrap text if you call
155 gtk_label_set_line_wrap().
158 gtk_label_set_justify() sets how the lines in a label align
159 with one another. If you want to set how the label as a whole
160 aligns in its available space, see gtk_misc_set_alignment().
163 The #GtkLabel:width-chars and #GtkLabel:max-width-chars properties
164 can be used to control the size allocation of ellipsized or wrapped
165 labels. For ellipsizing labels, if either is specified (and less
166 than the actual text size), it is used as the minimum width, and the actual
167 text size is used as the natural width of the label. For wrapping labels,
168 width-chars is used as the minimum width, if specified, and max-width-chars
169 is used as the natural width. Even if max-width-chars specified, wrapping
170 labels will be rewrapped to use all of the available width.
172 <note><para>Note that the interpretation of #GtkLabel:width-chars and
173 #GtkLabel:max-width-chars has changed a bit with the introduction of
174 width-for-height geometry management and #GtkExtendedLayout.</para></note>
181 Since 2.18, GTK+ supports markup for clickable hyperlinks in addition
182 to regular Pango markup. The markup for links is borrowed from HTML, using the
183 <tag>a</tag> with href and title attributes. GTK+ renders links similar to the
184 way they appear in web browsers, with colored, underlined text. The title
185 attribute is displayed as a tooltip on the link. An example looks like this:
186 <informalexample><programlisting>
187 gtk_label_set_markup (label, "Go to the <a href=\"http://www.gtk.org\" title=\"&lt;i&gt;Our&/i&gt; website\">GTK+ website</a> for more...");
188 </programlisting></informalexample>
189 It is possible to implement custom handling for links and their tooltips with
190 the #GtkLabel::activate-link signal and the gtk_label_get_current_uri() function.
195 <!-- ##### SECTION See_Also ##### -->
200 <!-- ##### SECTION Stability_Level ##### -->
203 <!-- ##### STRUCT GtkLabel ##### -->
205 This should not be accessed directly. Use the accessor functions as
210 <!-- ##### SIGNAL GtkLabel::activate-current-link ##### -->
215 @label: the object which received the signal.
217 <!-- ##### SIGNAL GtkLabel::activate-link ##### -->
222 @label: the object which received the signal.
226 <!-- ##### SIGNAL GtkLabel::copy-clipboard ##### -->
231 @label: the object which received the signal.
233 <!-- ##### SIGNAL GtkLabel::move-cursor ##### -->
238 @label: the object which received the signal.
243 <!-- ##### SIGNAL GtkLabel::populate-popup ##### -->
248 @label: the object which received the signal.
251 <!-- ##### ARG GtkLabel:angle ##### -->
256 <!-- ##### ARG GtkLabel:attributes ##### -->
261 <!-- ##### ARG GtkLabel:cursor-position ##### -->
266 <!-- ##### ARG GtkLabel:ellipsize ##### -->
271 <!-- ##### ARG GtkLabel:justify ##### -->
276 <!-- ##### ARG GtkLabel:label ##### -->
281 <!-- ##### ARG GtkLabel:max-width-chars ##### -->
286 <!-- ##### ARG GtkLabel:mnemonic-keyval ##### -->
291 <!-- ##### ARG GtkLabel:mnemonic-widget ##### -->
296 <!-- ##### ARG GtkLabel:pattern ##### -->
301 <!-- ##### ARG GtkLabel:selectable ##### -->
306 <!-- ##### ARG GtkLabel:selection-bound ##### -->
311 <!-- ##### ARG GtkLabel:single-line-mode ##### -->
316 <!-- ##### ARG GtkLabel:track-visited-links ##### -->
321 <!-- ##### ARG GtkLabel:use-markup ##### -->
326 <!-- ##### ARG GtkLabel:use-underline ##### -->
331 <!-- ##### ARG GtkLabel:width-chars ##### -->
336 <!-- ##### ARG GtkLabel:wrap ##### -->
341 <!-- ##### ARG GtkLabel:wrap-mode ##### -->
346 <!-- ##### FUNCTION gtk_label_new ##### -->
355 <!-- ##### FUNCTION gtk_label_set_text ##### -->
364 <!-- ##### FUNCTION gtk_label_set_attributes ##### -->
373 <!-- ##### FUNCTION gtk_label_set_markup ##### -->
382 <!-- ##### FUNCTION gtk_label_set_markup_with_mnemonic ##### -->
391 <!-- ##### FUNCTION gtk_label_set_pattern ##### -->
393 The pattern of underlines you want under the existing text within the
394 #GtkLabel widget. For example if the current text of the label says
395 "FooBarBaz" passing a pattern of "___ ___" will underline
396 "Foo" and "Baz" but not "Bar".
399 @label: The #GtkLabel you want to set the pattern to.
400 @pattern: The pattern as described above.
403 <!-- ##### FUNCTION gtk_label_set_justify ##### -->
412 <!-- ##### FUNCTION gtk_label_set_ellipsize ##### -->
421 <!-- ##### FUNCTION gtk_label_set_width_chars ##### -->
430 <!-- ##### FUNCTION gtk_label_set_max_width_chars ##### -->
439 <!-- ##### FUNCTION gtk_label_get ##### -->
441 Gets the current string of text within the #GtkLabel and writes it to
442 the given @str argument. It does not make a copy of this string so you
443 must not write to it.
446 @label: The #GtkLabel widget you want to get the text from.
447 @str: The reference to the pointer you want to point to the text.
448 @Deprecated: Use gtk_label_get_text() instead.
451 <!-- ##### FUNCTION gtk_label_parse_uline ##### -->
453 Parses the given string for underscores and converts the next
454 character to an underlined character. The last character that
455 was underlined will have its lower-cased accelerator keyval returned (i.e.
456 "_File" would return the keyval for "f". This is
457 probably only used within the GTK+ library itself for menu items and such.
460 @label: The #GtkLabel you want to affect.
461 @string: The string you want to parse for underlines.
462 @Returns: The lowercase keyval of the last character underlined.
463 @Deprecated: Use gtk_label_set_use_underline() instead.
466 <!-- ##### FUNCTION gtk_label_set_line_wrap ##### -->
475 <!-- ##### FUNCTION gtk_label_set_line_wrap_mode ##### -->
484 <!-- ##### MACRO gtk_label_set ##### -->
486 Sets the text within the GtkLabel widget.
489 @Deprecated: Use gtk_label_set_text() instead.
492 <!-- ##### FUNCTION gtk_label_get_layout_offsets ##### -->
502 <!-- ##### FUNCTION gtk_label_get_mnemonic_keyval ##### -->
511 <!-- ##### FUNCTION gtk_label_get_selectable ##### -->
520 <!-- ##### FUNCTION gtk_label_get_text ##### -->
529 <!-- ##### FUNCTION gtk_label_new_with_mnemonic ##### -->
538 <!-- ##### FUNCTION gtk_label_select_region ##### -->
548 <!-- ##### FUNCTION gtk_label_set_mnemonic_widget ##### -->
557 <!-- ##### FUNCTION gtk_label_set_selectable ##### -->
566 <!-- ##### FUNCTION gtk_label_set_text_with_mnemonic ##### -->
575 <!-- ##### FUNCTION gtk_label_get_attributes ##### -->
584 <!-- ##### FUNCTION gtk_label_get_justify ##### -->
593 <!-- ##### FUNCTION gtk_label_get_ellipsize ##### -->
602 <!-- ##### FUNCTION gtk_label_get_width_chars ##### -->
611 <!-- ##### FUNCTION gtk_label_get_max_width_chars ##### -->
620 <!-- ##### FUNCTION gtk_label_get_label ##### -->
629 <!-- ##### FUNCTION gtk_label_get_layout ##### -->
638 <!-- ##### FUNCTION gtk_label_get_line_wrap ##### -->
647 <!-- ##### FUNCTION gtk_label_get_line_wrap_mode ##### -->
656 <!-- ##### FUNCTION gtk_label_get_mnemonic_widget ##### -->
665 <!-- ##### FUNCTION gtk_label_get_selection_bounds ##### -->
676 <!-- ##### FUNCTION gtk_label_get_use_markup ##### -->
685 <!-- ##### FUNCTION gtk_label_get_use_underline ##### -->
694 <!-- ##### FUNCTION gtk_label_get_single_line_mode ##### -->
703 <!-- ##### FUNCTION gtk_label_get_angle ##### -->
712 <!-- ##### FUNCTION gtk_label_set_label ##### -->
721 <!-- ##### FUNCTION gtk_label_set_use_markup ##### -->
730 <!-- ##### FUNCTION gtk_label_set_use_underline ##### -->
739 <!-- ##### FUNCTION gtk_label_set_single_line_mode ##### -->
748 <!-- ##### FUNCTION gtk_label_set_angle ##### -->
757 <!-- ##### FUNCTION gtk_label_get_current_uri ##### -->
766 <!-- ##### FUNCTION gtk_label_set_track_visited_links ##### -->
775 <!-- ##### FUNCTION gtk_label_get_track_visited_links ##### -->