1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.Label; 26 27 private import gio.MenuModel; 28 private import glib.ConstructionException; 29 private import glib.Str; 30 private import glib.c.functions; 31 private import gobject.ObjectG; 32 private import gobject.Signals; 33 private import gtk.Widget; 34 private import gtk.c.functions; 35 public import gtk.c.types; 36 private import pango.PgAttributeList; 37 private import pango.PgLayout; 38 private import std.algorithm; 39 40 41 /** 42 * The `GtkLabel` widget displays a small amount of text. 43 * 44 * As the name implies, most labels are used to label another widget 45 * such as a [class@Button]. 46 * 47 * ![An example GtkLabel](label.png) 48 * 49 * # CSS nodes 50 * 51 * ``` 52 * label 53 * ├── [selection] 54 * ├── [link] 55 * ┊ 56 * ╰── [link] 57 * ``` 58 * 59 * `GtkLabel` has a single CSS node with the name label. A wide variety 60 * of style classes may be applied to labels, such as .title, .subtitle, 61 * .dim-label, etc. In the `GtkShortcutsWindow`, labels are used with the 62 * .keycap style class. 63 * 64 * If the label has a selection, it gets a subnode with name selection. 65 * 66 * If the label has links, there is one subnode per link. These subnodes 67 * carry the link or visited state depending on whether they have been 68 * visited. In this case, label node also gets a .link style class. 69 * 70 * # GtkLabel as GtkBuildable 71 * 72 * The GtkLabel implementation of the GtkBuildable interface supports a 73 * custom <attributes> element, which supports any number of <attribute> 74 * elements. The <attribute> element has attributes named “name“, “value“, 75 * “start“ and “end“ and allows you to specify [struct@Pango.Attribute] 76 * values for this label. 77 * 78 * An example of a UI definition fragment specifying Pango attributes: 79 * ```xml 80 * <object class="GtkLabel"> 81 * <attributes> 82 * <attribute name="weight" value="PANGO_WEIGHT_BOLD"/> 83 * <attribute name="background" value="red" start="5" end="10"/> 84 * </attributes> 85 * </object> 86 * ``` 87 * 88 * The start and end attributes specify the range of characters to which the 89 * Pango attribute applies. If start and end are not specified, the attribute is 90 * applied to the whole text. Note that specifying ranges does not make much 91 * sense with translatable attributes. Use markup embedded in the translatable 92 * content instead. 93 * 94 * # Accessibility 95 * 96 * `GtkLabel` uses the #GTK_ACCESSIBLE_ROLE_LABEL role. 97 * 98 * # Mnemonics 99 * 100 * Labels may contain “mnemonics”. Mnemonics are underlined characters in the 101 * label, used for keyboard navigation. Mnemonics are created by providing a 102 * string with an underscore before the mnemonic character, such as `"_File"`, 103 * to the functions [ctor@Gtk.Label.new_with_mnemonic] or 104 * [method@Gtk.Label.set_text_with_mnemonic]. 105 * 106 * Mnemonics automatically activate any activatable widget the label is 107 * inside, such as a [class@Gtk.Button]; if the label is not inside the 108 * mnemonic’s target widget, you have to tell the label about the target 109 * using [class@Gtk.Label.set_mnemonic_widget]. Here’s a simple example where 110 * the label is inside a button: 111 * 112 * ```c 113 * // Pressing Alt+H will activate this button 114 * GtkWidget *button = gtk_button_new (); 115 * GtkWidget *label = gtk_label_new_with_mnemonic ("_Hello"); 116 * gtk_button_set_child (GTK_BUTTON (button), label); 117 * ``` 118 * 119 * There’s a convenience function to create buttons with a mnemonic label 120 * already inside: 121 * 122 * ```c 123 * // Pressing Alt+H will activate this button 124 * GtkWidget *button = gtk_button_new_with_mnemonic ("_Hello"); 125 * ``` 126 * 127 * To create a mnemonic for a widget alongside the label, such as a 128 * [class@Gtk.Entry], you have to point the label at the entry with 129 * [method@Gtk.Label.set_mnemonic_widget]: 130 * 131 * ```c 132 * // Pressing Alt+H will focus the entry 133 * GtkWidget *entry = gtk_entry_new (); 134 * GtkWidget *label = gtk_label_new_with_mnemonic ("_Hello"); 135 * gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry); 136 * ``` 137 * 138 * # Markup (styled text) 139 * 140 * To make it easy to format text in a label (changing colors, 141 * fonts, etc.), label text can be provided in a simple 142 * markup format: 143 * 144 * Here’s how to create a label with a small font: 145 * ```c 146 * GtkWidget *label = gtk_label_new (NULL); 147 * gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>"); 148 * ``` 149 * 150 * (See the Pango manual for complete documentation] of available 151 * tags, [func@Pango.parse_markup]) 152 * 153 * The markup passed to gtk_label_set_markup() must be valid; for example, 154 * literal <, > and & characters must be escaped as <, >, and &. 155 * If you pass text obtained from the user, file, or a network to 156 * [method@Gtk.Label.set_markup], you’ll want to escape it with 157 * g_markup_escape_text() or g_markup_printf_escaped(). 158 * 159 * Markup strings are just a convenient way to set the [struct@Pango.AttrList] 160 * on a label; [method@Gtk.Label.set_attributes] may be a simpler way to set 161 * attributes in some cases. Be careful though; [struct@Pango.AttrList] tends 162 * to cause internationalization problems, unless you’re applying attributes 163 * to the entire string (i.e. unless you set the range of each attribute 164 * to [0, %G_MAXINT)). The reason is that specifying the start_index and 165 * end_index for a [struct@Pango.Attribute] requires knowledge of the exact 166 * string being displayed, so translations will cause problems. 167 * 168 * # Selectable labels 169 * 170 * Labels can be made selectable with [method@Gtk.Label.set_selectable]. 171 * Selectable labels allow the user to copy the label contents to 172 * the clipboard. Only labels that contain useful-to-copy information 173 * — such as error messages — should be made selectable. 174 * 175 * # Text layout 176 * 177 * A label can contain any number of paragraphs, but will have 178 * performance problems if it contains more than a small number. 179 * Paragraphs are separated by newlines or other paragraph separators 180 * understood by Pango. 181 * 182 * Labels can automatically wrap text if you call [method@Gtk.Label.set_wrap]. 183 * 184 * [method@Gtk.Label.set_justify] sets how the lines in a label align 185 * with one another. If you want to set how the label as a whole aligns 186 * in its available space, see the [property@Gtk.Widget:halign] and 187 * [property@Gtk.Widget:valign] properties. 188 * 189 * The [property@Gtk.Label:width-chars] and [property@Gtk.Label:max-width-chars] 190 * properties can be used to control the size allocation of ellipsized or 191 * wrapped labels. For ellipsizing labels, if either is specified (and less 192 * than the actual text size), it is used as the minimum width, and the actual 193 * text size is used as the natural width of the label. For wrapping labels, 194 * width-chars is used as the minimum width, if specified, and max-width-chars 195 * is used as the natural width. Even if max-width-chars specified, wrapping 196 * labels will be rewrapped to use all of the available width. 197 * 198 * # Links 199 * 200 * GTK supports markup for clickable hyperlinks in addition to regular Pango 201 * markup. The markup for links is borrowed from HTML, using the `<a>` with 202 * “href“, “title“ and “class“ attributes. GTK renders links similar to the 203 * way they appear in web browsers, with colored, underlined text. The “title“ 204 * attribute is displayed as a tooltip on the link. The “class“ attribute is 205 * used as style class on the CSS node for the link. 206 * 207 * An example looks like this: 208 * 209 * ```c 210 * const char *text = 211 * "Go to the" 212 * "<a href=\"http://www.gtk.org title=\"<i>Our</i> website\">" 213 * "GTK website</a> for more..."; 214 * GtkWidget *label = gtk_label_new (NULL); 215 * gtk_label_set_markup (GTK_LABEL (label), text); 216 * ``` 217 * 218 * It is possible to implement custom handling for links and their tooltips 219 * with the [signal@Gtk.Label::activate-link] signal and the 220 * [method@Gtk.Label.get_current_uri] function. 221 */ 222 public class Label : Widget 223 { 224 /** the main Gtk struct */ 225 protected GtkLabel* gtkLabel; 226 227 /** Get the main Gtk struct */ 228 public GtkLabel* getLabelStruct(bool transferOwnership = false) 229 { 230 if (transferOwnership) 231 ownedRef = false; 232 return gtkLabel; 233 } 234 235 /** the main Gtk struct as a void* */ 236 protected override void* getStruct() 237 { 238 return cast(void*)gtkLabel; 239 } 240 241 /** 242 * Sets our main struct and passes it to the parent class. 243 */ 244 public this (GtkLabel* gtkLabel, bool ownedRef = false) 245 { 246 this.gtkLabel = gtkLabel; 247 super(cast(GtkWidget*)gtkLabel, ownedRef); 248 } 249 250 251 /** */ 252 public static GType getType() 253 { 254 return gtk_label_get_type(); 255 } 256 257 /** 258 * Creates a new `GtkLabel`, containing the text in @str. 259 * 260 * If characters in @str are preceded by an underscore, they are 261 * underlined. If you need a literal underscore character in a label, use 262 * '__' (two underscores). The first underlined character represents a 263 * keyboard accelerator called a mnemonic. The mnemonic key can be used 264 * to activate another widget, chosen automatically, or explicitly using 265 * [method@Gtk.Label.set_mnemonic_widget]. 266 * 267 * If [method@Gtk.Label.set_mnemonic_widget] is not called, then the first 268 * activatable ancestor of the `GtkLabel` will be chosen as the mnemonic 269 * widget. For instance, if the label is inside a button or menu item, 270 * the button or menu item will automatically become the mnemonic widget 271 * and be activated by the mnemonic. 272 * 273 * Params: 274 * str = The text of the label, with an underscore in front of the 275 * mnemonic character 276 * 277 * Returns: the new `GtkLabel` 278 * 279 * Throws: ConstructionException GTK+ fails to create the object. 280 */ 281 public this(string str) 282 { 283 auto __p = gtk_label_new_with_mnemonic(Str.toStringz(str)); 284 285 if(__p is null) 286 { 287 throw new ConstructionException("null returned by new_with_mnemonic"); 288 } 289 290 this(cast(GtkLabel*) __p); 291 } 292 293 /** 294 * Gets the labels attribute list. 295 * 296 * This is the [struct@Pango.AttrList] that was set on the label using 297 * [method@Gtk.Label.set_attributes], if any. This function does not 298 * reflect attributes that come from the labels markup (see 299 * [method@Gtk.Label.set_markup]). If you want to get the effective 300 * attributes for the label, use 301 * `pango_layout_get_attribute (gtk_label_get_layout (self))`. 302 * 303 * Returns: the attribute list, or %NULL 304 * if none was set. 305 */ 306 public PgAttributeList getAttributes() 307 { 308 auto __p = gtk_label_get_attributes(gtkLabel); 309 310 if(__p is null) 311 { 312 return null; 313 } 314 315 return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) __p); 316 } 317 318 /** 319 * Returns the URI for the currently active link in the label. 320 * 321 * The active link is the one under the mouse pointer or, in a 322 * selectable label, the link in which the text cursor is currently 323 * positioned. 324 * 325 * This function is intended for use in a [signal@Gtk.Label::activate-link] 326 * handler or for use in a [signal@Gtk.Widget::query-tooltip] handler. 327 * 328 * Returns: the currently active URI or %NULL if there is none. 329 * The string is owned by GTK and must not be freed or modified. 330 */ 331 public string getCurrentUri() 332 { 333 return Str.toString(gtk_label_get_current_uri(gtkLabel)); 334 } 335 336 /** 337 * Returns the ellipsizing position of the label. 338 * 339 * See [method@Gtk.Label.set_ellipsize]. 340 * 341 * Returns: `PangoEllipsizeMode` 342 */ 343 public PangoEllipsizeMode getEllipsize() 344 { 345 return gtk_label_get_ellipsize(gtkLabel); 346 } 347 348 /** 349 * Gets the extra menu model of @label. 350 * 351 * See [method@Gtk.Label.set_extra_menu]. 352 * 353 * Returns: the menu model 354 */ 355 public MenuModel getExtraMenu() 356 { 357 auto __p = gtk_label_get_extra_menu(gtkLabel); 358 359 if(__p is null) 360 { 361 return null; 362 } 363 364 return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) __p); 365 } 366 367 /** 368 * Returns the justification of the label. 369 * 370 * See [method@Gtk.Label.set_justify]. 371 * 372 * Returns: `GtkJustification` 373 */ 374 public GtkJustification getJustify() 375 { 376 return gtk_label_get_justify(gtkLabel); 377 } 378 379 /** 380 * Fetches the text from a label. 381 * 382 * The returned text includes any embedded underlines indicating 383 * mnemonics and Pango markup. (See [method@Gtk.Label.get_text]). 384 * 385 * Returns: the text of the label widget. This string is 386 * owned by the widget and must not be modified or freed. 387 */ 388 public string getLabel() 389 { 390 return Str.toString(gtk_label_get_label(gtkLabel)); 391 } 392 393 /** 394 * Gets the `PangoLayout` used to display the label. 395 * 396 * The layout is useful to e.g. convert text positions to pixel 397 * positions, in combination with [method@Gtk.Label.get_layout_offsets]. 398 * The returned layout is owned by the @label so need not be 399 * freed by the caller. The @label is free to recreate its layout 400 * at any time, so it should be considered read-only. 401 * 402 * Returns: the [class@Pango.Layout] for this label 403 */ 404 public PgLayout getLayout() 405 { 406 auto __p = gtk_label_get_layout(gtkLabel); 407 408 if(__p is null) 409 { 410 return null; 411 } 412 413 return ObjectG.getDObject!(PgLayout)(cast(PangoLayout*) __p); 414 } 415 416 /** 417 * Obtains the coordinates where the label will draw its `PangoLayout`. 418 * 419 * The coordinates are useful to convert mouse events into coordinates 420 * inside the [class@Pango.Layout], e.g. to take some action if some part 421 * of the label is clicked. Remember when using the [class@Pango.Layout] 422 * functions you need to convert to and from pixels using PANGO_PIXELS() 423 * or [constant@Pango.SCALE]. 424 * 425 * Params: 426 * x = location to store X offset of layout, or %NULL 427 * y = location to store Y offset of layout, or %NULL 428 */ 429 public void getLayoutOffsets(out int x, out int y) 430 { 431 gtk_label_get_layout_offsets(gtkLabel, &x, &y); 432 } 433 434 /** 435 * Gets the number of lines to which an ellipsized, wrapping 436 * label should be limited. 437 * 438 * See [method@Gtk.Label.set_lines]. 439 * 440 * Returns: The number of lines 441 */ 442 public int getLines() 443 { 444 return gtk_label_get_lines(gtkLabel); 445 } 446 447 /** 448 * Retrieves the desired maximum width of @label, in characters. 449 * 450 * See [method@Gtk.Label.set_width_chars]. 451 * 452 * Returns: the maximum width of the label in characters. 453 */ 454 public int getMaxWidthChars() 455 { 456 return gtk_label_get_max_width_chars(gtkLabel); 457 } 458 459 /** 460 * Return the mnemonic accelerator. 461 * 462 * If the label has been set so that it has a mnemonic key this function 463 * returns the keyval used for the mnemonic accelerator. If there is no 464 * mnemonic set up it returns `GDK_KEY_VoidSymbol`. 465 * 466 * Returns: GDK keyval usable for accelerators, or `GDK_KEY_VoidSymbol` 467 */ 468 public uint getMnemonicKeyval() 469 { 470 return gtk_label_get_mnemonic_keyval(gtkLabel); 471 } 472 473 /** 474 * Retrieves the target of the mnemonic (keyboard shortcut) of this 475 * label. 476 * 477 * See [method@Gtk.Label.set_mnemonic_widget]. 478 * 479 * Returns: the target of the label’s mnemonic, 480 * or %NULL if none has been set and the default algorithm will be used. 481 */ 482 public Widget getMnemonicWidget() 483 { 484 auto __p = gtk_label_get_mnemonic_widget(gtkLabel); 485 486 if(__p is null) 487 { 488 return null; 489 } 490 491 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 492 } 493 494 /** 495 * Returns whether the label is selectable. 496 * 497 * Returns: %TRUE if the user can copy text from the label 498 */ 499 public bool getSelectable() 500 { 501 return gtk_label_get_selectable(gtkLabel) != 0; 502 } 503 504 /** 505 * Gets the selected range of characters in the label. 506 * 507 * Params: 508 * start = return location for start of selection, as a character offset 509 * end = return location for end of selection, as a character offset 510 * 511 * Returns: %TRUE if selection is non-empty 512 */ 513 public bool getSelectionBounds(out int start, out int end) 514 { 515 return gtk_label_get_selection_bounds(gtkLabel, &start, &end) != 0; 516 } 517 518 /** 519 * Returns whether the label is in single line mode. 520 * 521 * Returns: %TRUE when the label is in single line mode. 522 */ 523 public bool getSingleLineMode() 524 { 525 return gtk_label_get_single_line_mode(gtkLabel) != 0; 526 } 527 528 /** 529 * Fetches the text from a label. 530 * 531 * The returned text is as it appears on screen. This does not include 532 * any embedded underlines indicating mnemonics or Pango markup. (See 533 * [method@Gtk.Label.get_label]) 534 * 535 * Returns: the text in the label widget. This is the internal 536 * string used by the label, and must not be modified. 537 */ 538 public string getText() 539 { 540 return Str.toString(gtk_label_get_text(gtkLabel)); 541 } 542 543 /** 544 * Returns whether the label’s text is interpreted as Pango markup. 545 * 546 * See [method@Gtk.Label.set_use_markup]. 547 * 548 * Returns: %TRUE if the label’s text will be parsed for markup. 549 */ 550 public bool getUseMarkup() 551 { 552 return gtk_label_get_use_markup(gtkLabel) != 0; 553 } 554 555 /** 556 * Returns whether an embedded underlines in the label indicate mnemonics. 557 * 558 * See [method@Gtk.Label.set_use_underline]. 559 * 560 * Returns: %TRUE whether an embedded underline in the label indicates 561 * the mnemonic accelerator keys. 562 */ 563 public bool getUseUnderline() 564 { 565 return gtk_label_get_use_underline(gtkLabel) != 0; 566 } 567 568 /** 569 * Retrieves the desired width of @label, in characters. 570 * 571 * See [method@Gtk.Label.set_width_chars]. 572 * 573 * Returns: the width of the label in characters. 574 */ 575 public int getWidthChars() 576 { 577 return gtk_label_get_width_chars(gtkLabel); 578 } 579 580 /** 581 * Returns whether lines in the label are automatically wrapped. 582 * 583 * See [method@Gtk.Label.set_wrap]. 584 * 585 * Returns: %TRUE if the lines of the label are automatically wrapped. 586 */ 587 public bool getWrap() 588 { 589 return gtk_label_get_wrap(gtkLabel) != 0; 590 } 591 592 /** 593 * Returns line wrap mode used by the label. 594 * 595 * See [method@Gtk.Label.set_wrap_mode]. 596 * 597 * Returns: %TRUE if the lines of the label are automatically wrapped. 598 */ 599 public PangoWrapMode getWrapMode() 600 { 601 return gtk_label_get_wrap_mode(gtkLabel); 602 } 603 604 /** 605 * Gets the `xalign` of the label. 606 * 607 * See the [property@Gtk.Label:xalign] property. 608 * 609 * Returns: the xalign property 610 */ 611 public float getXalign() 612 { 613 return gtk_label_get_xalign(gtkLabel); 614 } 615 616 /** 617 * Gets the `yalign` of the label. 618 * 619 * See the [property@Gtk.Label:yalign] property. 620 * 621 * Returns: the yalign property 622 */ 623 public float getYalign() 624 { 625 return gtk_label_get_yalign(gtkLabel); 626 } 627 628 /** 629 * Selects a range of characters in the label, if the label is selectable. 630 * 631 * See [method@Gtk.Label.set_selectable]. If the label is not selectable, 632 * this function has no effect. If @start_offset or 633 * @end_offset are -1, then the end of the label will be substituted. 634 * 635 * Params: 636 * startOffset = start offset (in characters not bytes) 637 * endOffset = end offset (in characters not bytes) 638 */ 639 public void selectRegion(int startOffset, int endOffset) 640 { 641 gtk_label_select_region(gtkLabel, startOffset, endOffset); 642 } 643 644 /** 645 * Apply attributes to the label text. 646 * 647 * The attributes set with this function will be applied and merged with 648 * any other attributes previously effected by way of the 649 * [property@Gtk.Label:use-underline] or [property@Gtk.Label:use-markup] 650 * properties. While it is not recommended to mix markup strings with 651 * manually set attributes, if you must; know that the attributes will 652 * be applied to the label after the markup string is parsed. 653 * 654 * Params: 655 * attrs = a [struct@Pango.AttrList], or %NULL 656 */ 657 public void setAttributes(PgAttributeList attrs) 658 { 659 gtk_label_set_attributes(gtkLabel, (attrs is null) ? null : attrs.getPgAttributeListStruct()); 660 } 661 662 /** 663 * Sets the mode used to ellipsizei the text. 664 * 665 * The text will be ellipsized if there is not enough space 666 * to render the entire string. 667 * 668 * Params: 669 * mode = a `PangoEllipsizeMode` 670 */ 671 public void setEllipsize(PangoEllipsizeMode mode) 672 { 673 gtk_label_set_ellipsize(gtkLabel, mode); 674 } 675 676 /** 677 * Sets a menu model to add when constructing 678 * the context menu for @label. 679 * 680 * Params: 681 * model = a `GMenuModel` 682 */ 683 public void setExtraMenu(MenuModel model) 684 { 685 gtk_label_set_extra_menu(gtkLabel, (model is null) ? null : model.getMenuModelStruct()); 686 } 687 688 /** 689 * Sets the alignment of the lines in the text of the label relative to 690 * each other. 691 * 692 * %GTK_JUSTIFY_LEFT is the default value when the widget is first created 693 * with [ctor@Gtk.Label.new]. If you instead want to set the alignment of 694 * the label as a whole, use [method@Gtk.Widget.set_halign] instead. 695 * [method@Gtk.Label.set_justify] has no effect on labels containing 696 * only a single line. 697 * 698 * Params: 699 * jtype = a `GtkJustification` 700 */ 701 public void setJustify(GtkJustification jtype) 702 { 703 gtk_label_set_justify(gtkLabel, jtype); 704 } 705 706 /** 707 * Sets the text of the label. 708 * 709 * The label is interpreted as including embedded underlines and/or Pango 710 * markup depending on the values of the [property@Gtk.Label:use-underline] 711 * and [property@Gtk.Label:use-markup] properties. 712 * 713 * Params: 714 * str = the new text to set for the label 715 */ 716 public void setLabel(string str) 717 { 718 gtk_label_set_label(gtkLabel, Str.toStringz(str)); 719 } 720 721 /** 722 * Sets the number of lines to which an ellipsized, wrapping label 723 * should be limited. 724 * 725 * This has no effect if the label is not wrapping or ellipsized. 726 * Set this to -1 if you don’t want to limit the number of lines. 727 * 728 * Params: 729 * lines = the desired number of lines, or -1 730 */ 731 public void setLines(int lines) 732 { 733 gtk_label_set_lines(gtkLabel, lines); 734 } 735 736 /** 737 * Sets the labels text and attributes from markup. 738 * 739 * The string must be marked up with Pango markup 740 * (see [func@Pango.parse_markup]). 741 * 742 * If the @str is external data, you may need to escape it 743 * with g_markup_escape_text() or g_markup_printf_escaped(): 744 * 745 * ```c 746 * GtkWidget *self = gtk_label_new (NULL); 747 * const char *str = "..."; 748 * const char *format = "<span style=\"italic\">\%s</span>"; 749 * char *markup; 750 * 751 * markup = g_markup_printf_escaped (format, str); 752 * gtk_label_set_markup (GTK_LABEL (self), markup); 753 * g_free (markup); 754 * ``` 755 * 756 * This function will set the [property@Gtk.Label:use-markup] property 757 * to %TRUE as a side effect. 758 * 759 * If you set the label contents using the [property@Gtk.Label:label] 760 * property you should also ensure that you set the 761 * [property@Gtk.Label:use-markup] property accordingly. 762 * 763 * See also: [method@Gtk.Label.set_text] 764 * 765 * Params: 766 * str = a markup string 767 */ 768 public void setMarkup(string str) 769 { 770 gtk_label_set_markup(gtkLabel, Str.toStringz(str)); 771 } 772 773 /** 774 * Sets the labels text, attributes and mnemonic from markup. 775 * 776 * Parses @str which is marked up with Pango markup (see [func@Pango.parse_markup]), 777 * setting the label’s text and attribute list based on the parse results. 778 * If characters in @str are preceded by an underscore, they are underlined 779 * indicating that they represent a keyboard accelerator called a mnemonic. 780 * 781 * The mnemonic key can be used to activate another widget, chosen 782 * automatically, or explicitly using method@Gtk.Label.set_mnemonic_widget]. 783 * 784 * Params: 785 * str = a markup string 786 */ 787 public void setMarkupWithMnemonic(string str) 788 { 789 gtk_label_set_markup_with_mnemonic(gtkLabel, Str.toStringz(str)); 790 } 791 792 /** 793 * Sets the desired maximum width in characters of @label to @n_chars. 794 * 795 * Params: 796 * nChars = the new desired maximum width, in characters. 797 */ 798 public void setMaxWidthChars(int nChars) 799 { 800 gtk_label_set_max_width_chars(gtkLabel, nChars); 801 } 802 803 /** 804 * Associate the label with its mnemonic target. 805 * 806 * If the label has been set so that it has a mnemonic key (using 807 * i.e. [method@Gtk.Label.set_markup_with_mnemonic], 808 * [method@Gtk.Label.set_text_with_mnemonic], 809 * [ctor@Gtk.Label.new_with_mnemonic] 810 * or the [property@Gtk.Label:use_underline] property) the label can be 811 * associated with a widget that is the target of the mnemonic. When the 812 * label is inside a widget (like a [class@Gtk.Button] or a 813 * [class@Gtk.Notebook] tab) it is automatically associated with the correct 814 * widget, but sometimes (i.e. when the target is a [class@Gtk.Entry] next to 815 * the label) you need to set it explicitly using this function. 816 * 817 * The target widget will be accelerated by emitting the 818 * [signal@GtkWidget::mnemonic-activate] signal on it. The default handler for 819 * this signal will activate the widget if there are no mnemonic collisions 820 * and toggle focus between the colliding widgets otherwise. 821 * 822 * Params: 823 * widget = the target #GtkWidget, or %NULL to unset 824 */ 825 public void setMnemonicWidget(Widget widget) 826 { 827 gtk_label_set_mnemonic_widget(gtkLabel, (widget is null) ? null : widget.getWidgetStruct()); 828 } 829 830 /** 831 * Makes text in the label selectable. 832 * 833 * Selectable labels allow the user to select text from the label, 834 * for copy-and-paste. 835 * 836 * Params: 837 * setting = %TRUE to allow selecting text in the label 838 */ 839 public void setSelectable(bool setting) 840 { 841 gtk_label_set_selectable(gtkLabel, setting); 842 } 843 844 /** 845 * Sets whether the label is in single line mode. 846 * 847 * Params: 848 * singleLineMode = %TRUE if the label should be in single line mode 849 */ 850 public void setSingleLineMode(bool singleLineMode) 851 { 852 gtk_label_set_single_line_mode(gtkLabel, singleLineMode); 853 } 854 855 /** 856 * Sets the text within the `GtkLabel` widget. 857 * 858 * It overwrites any text that was there before. 859 * 860 * This function will clear any previously set mnemonic accelerators, 861 * and set the [property@Gtk.Label:use-underline property] to %FALSE as 862 * a side effect. 863 * 864 * This function will set the [property@Gtk.Label:use-markup] property 865 * to %FALSE as a side effect. 866 * 867 * See also: [method@Gtk.Label.set_markup] 868 * 869 * Params: 870 * str = The text you want to set 871 */ 872 public void setText(string str) 873 { 874 gtk_label_set_text(gtkLabel, Str.toStringz(str)); 875 } 876 877 /** 878 * Sets the label’s text from the string @str. 879 * 880 * If characters in @str are preceded by an underscore, they are underlined 881 * indicating that they represent a keyboard accelerator called a mnemonic. 882 * The mnemonic key can be used to activate another widget, chosen 883 * automatically, or explicitly using [method@Gtk.Label.set_mnemonic_widget]. 884 * 885 * Params: 886 * str = a string 887 */ 888 public void setTextWithMnemonic(string str) 889 { 890 gtk_label_set_text_with_mnemonic(gtkLabel, Str.toStringz(str)); 891 } 892 893 /** 894 * Sets whether the text of the label contains markup. 895 * 896 * See [method@Gtk.Label.set_markup]. 897 * 898 * Params: 899 * setting = %TRUE if the label’s text should be parsed for markup. 900 */ 901 public void setUseMarkup(bool setting) 902 { 903 gtk_label_set_use_markup(gtkLabel, setting); 904 } 905 906 /** 907 * Sets whether underlines in the text indicate mnemonics. 908 * 909 * Params: 910 * setting = %TRUE if underlines in the text indicate mnemonics 911 */ 912 public void setUseUnderline(bool setting) 913 { 914 gtk_label_set_use_underline(gtkLabel, setting); 915 } 916 917 /** 918 * Sets the desired width in characters of @label to @n_chars. 919 * 920 * Params: 921 * nChars = the new desired width, in characters. 922 */ 923 public void setWidthChars(int nChars) 924 { 925 gtk_label_set_width_chars(gtkLabel, nChars); 926 } 927 928 /** 929 * Toggles line wrapping within the `GtkLabel` widget. 930 * 931 * %TRUE makes it break lines if text exceeds the widget’s size. 932 * %FALSE lets the text get cut off by the edge of the widget if 933 * it exceeds the widget size. 934 * 935 * Note that setting line wrapping to %TRUE does not make the label 936 * wrap at its parent container’s width, because GTK widgets 937 * conceptually can’t make their requisition depend on the parent 938 * container’s size. For a label that wraps at a specific position, 939 * set the label’s width using [method@Gtk.Widget.set_size_request]. 940 * 941 * Params: 942 * wrap = the setting 943 */ 944 public void setWrap(bool wrap) 945 { 946 gtk_label_set_wrap(gtkLabel, wrap); 947 } 948 949 /** 950 * Controls how line wrapping is done. 951 * 952 * This only affects the label if line wrapping is on. (See 953 * [method@Gtk.Label.set_wrap]) The default is %PANGO_WRAP_WORD 954 * which means wrap on word boundaries. 955 * 956 * Params: 957 * wrapMode = the line wrapping mode 958 */ 959 public void setWrapMode(PangoWrapMode wrapMode) 960 { 961 gtk_label_set_wrap_mode(gtkLabel, wrapMode); 962 } 963 964 /** 965 * Sets the `xalign` of the label. 966 * 967 * See the [property@Gtk.Label:xalign] property. 968 * 969 * Params: 970 * xalign = the new xalign value, between 0 and 1 971 */ 972 public void setXalign(float xalign) 973 { 974 gtk_label_set_xalign(gtkLabel, xalign); 975 } 976 977 /** 978 * Sets the `yalign` of the label. 979 * 980 * See the [property@Gtk.Label:yalign] property. 981 * 982 * Params: 983 * yalign = the new yalign value, between 0 and 1 984 */ 985 public void setYalign(float yalign) 986 { 987 gtk_label_set_yalign(gtkLabel, yalign); 988 } 989 990 /** 991 * Gets emitted when the user activates a link in the label. 992 * 993 * The ::activate-current-link is a [keybinding signal](class.SignalAction.html). 994 * 995 * Applications may also emit the signal with g_signal_emit_by_name() 996 * if they need to control activation of URIs programmatically. 997 * 998 * The default bindings for this signal are all forms of the Enter key. 999 */ 1000 gulong addOnActivateCurrentLink(void delegate(Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1001 { 1002 return Signals.connect(this, "activate-current-link", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1003 } 1004 1005 /** 1006 * Gets emitted to activate a URI. 1007 * 1008 * Applications may connect to it to override the default behaviour, 1009 * which is to call gtk_show_uri(). 1010 * 1011 * Params: 1012 * uri = the URI that is activated 1013 * 1014 * Returns: %TRUE if the link has been activated 1015 */ 1016 gulong addOnActivateLink(bool delegate(string, Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1017 { 1018 return Signals.connect(this, "activate-link", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1019 } 1020 1021 /** 1022 * Gets emitted to copy the slection to the clipboard. 1023 * 1024 * The ::copy-clipboard signal is a [keybinding signal](class.SignalAction.html). 1025 * 1026 * The default binding for this signal is Ctrl-c. 1027 */ 1028 gulong addOnCopyClipboard(void delegate(Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1029 { 1030 return Signals.connect(this, "copy-clipboard", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1031 } 1032 1033 /** 1034 * Gets emitted when the user initiates a cursor movement. 1035 * 1036 * The ::move-cursor signal is a [keybinding signal](class.SignalAction.html). 1037 * If the cursor is not visible in @entry, this signal causes the viewport to 1038 * be moved instead. 1039 * 1040 * Applications should not connect to it, but may emit it with 1041 * g_signal_emit_by_name() if they need to control the cursor 1042 * programmatically. 1043 * 1044 * The default bindings for this signal come in two variants, 1045 * the variant with the Shift modifier extends the selection, 1046 * the variant without the Shift modifier does not. 1047 * There are too many key combinations to list them all here. 1048 * - Arrow keys move by individual characters/lines 1049 * - Ctrl-arrow key combinations move by words/paragraphs 1050 * - Home/End keys move to the ends of the buffer 1051 * 1052 * Params: 1053 * step = the granularity of the move, as a #GtkMovementStep 1054 * count = the number of @step units to move 1055 * extendSelection = %TRUE if the move should extend the selection 1056 */ 1057 gulong addOnMoveCursor(void delegate(GtkMovementStep, int, bool, Label) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1058 { 1059 return Signals.connect(this, "move-cursor", dlg, connectFlags ^ ConnectFlags.SWAPPED); 1060 } 1061 }