Toc Gallery Index Tree Gtk.Label

Screenshot

No screeshot

Hierarchy

Description

A Gtk_Label is a light widget associated with some text you want to display on the screen. You can change the text dynamically if needed.

The text can be on multiple lines if you separate each line with the ASCII.LF character. However, this is not the recommended way to display long texts (see the Gtk_Text widget instead).

Mnemonics ========= Labels may contain mnemonics. Mnemonics are underlined characters in the label, used for keyboard navigation. Mnemonics are created by providing string with an underscore before the mnemonic character, such as "_File", to the functions gtk_new_with_mnemonic or set_text_with_mnemonic().

Mnemonics automatically activate any activatable widget the label is inside, such as a Gtk_Button; if the label is not inside the mnemonic's target widget, you have to tell the label about the target using set_mnemonic_widget(). For instance: declare Button : Gtk_Button; Label : Gtk_Label; begin Gtk_New (Button); Gtk_New_With_Mnemonic (Label, "_File"); Add (Button, Label); end; However, there exists a convenience function in Gtk.Button to create such a button already.

Markup ====== 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: Gtk_New (Label, "hello");

The markup must be valid, and <>& characters must be escaped with < > and &

Markup strings are just a convenient way to set the Pango_Attr_List on label; Set_Attributes() may be a simpler way to set attributes in some cases. Be careful though; Pango_Attr_List 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 Pango_Attribute requires knowledge of the exact string being displayed, so translations will cause problems.

Selectable labels ================= Labels can be made selectable with Set_Selectable. Selectable labels allow the user to copy the label contents to the clipboard. Only should be made selectable.

Types

  • type Gtk_Label is access all Gtk_Label_Record'Class;
  • type Gtk_Label_Record is new Misc.Gtk_Misc_Record with private;

Subprograms

  • procedure Gtk_New (Label : out Gtk_Label; Str : UTF8_String := "");
    procedure Initialize (Label : access Gtk_Label_Record'Class; Str : UTF8_String);
    Creates or initializes a new label. Str is the string to be displayed.
  • procedure Gtk_New_With_Mnemonic (Label : out Gtk_Label; Str : UTF8_String);
    procedure Initialize_With_Mnemonic (Label : access Gtk_Label_Record'Class; Str : UTF8_String);
    Creates or initializes a new label containing the text in 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 explicitely using Set_Mnemonic_Widget.
  • function Get_Type return Glib.GType;
    Return the internal value associated with a Gtk_Label.
  • procedure Set_Justify (Label : access Gtk_Label_Record; Jtype : Enums.Gtk_Justification);
    function Get_Justify (Label : access Gtk_Label_Record) return Enums.Gtk_Justification;
    Set the justification for the label. The default value is Justify_Center, which means that the text will be centered in the label. Note that this setting has an impact only when the Gtk_Label is larger than the text (its default width is the same as the text) and contains multiple lines. To justify a single line label, you should instead call Set_Alignment and make sure that the label or any surrounding container fills its horizontal allocated space.
  • procedure Set_Line_Wrap (Label : access Gtk_Label_Record; Wrap : Boolean);
    function Get_Line_Wrap (Label : access Gtk_Label_Record) return Boolean;
    Toggle line wrapping within Label. if Wrap is True, then Label will break lines if the text is larger then the widget's size. If Wrap is False, then the text is simply cut off.
  • procedure Set_Selectable (Label : access Gtk_Label_Record; Selectable : Boolean);
    function Get_Selectable (Label : access Gtk_Label_Record) return Boolean;
    Selectable labels allow the user to select text from the label, for copy-and-paste.
  • procedure Set_Use_Markup (Label : access Gtk_Label_Record; Markup : Boolean);
    function Get_Use_Markup (Label : access Gtk_Label_Record) return Boolean;
    Sets whether the text of the label contains markup in Pango's text markup language. If Markup is True, then Label will be parsed for markup.
  • procedure Set_Use_Underline (Label : access Gtk_Label_Record; Underline : Boolean);
    function Get_Use_Underline (Label : access Gtk_Label_Record) return Boolean;
    Indicates wether an embedded underline in the label indicates the mnemonic accelerator key.
  • procedure Set_Angle (Label : access Gtk_Label_Record; Angle : Gdouble);
    function Get_Angle (Label : access Gtk_Label_Record) return Gdouble;
    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.
  • procedure Set_Ellipsize (Label : access Gtk_Label_Record; Mode : Pango.Layout.Pango_Ellipsize_Mode);
    function Get_Ellipsize (Label : access Gtk_Label_Record) return Pango.Layout.Pango_Ellipsize_Mode;
    Sets the mode used to ellipsize (add an ellipsis: "...") to the text if there is not enough space to render the entire string.
  • procedure Set_Text (Label : access Gtk_Label_Record; Str : UTF8_String);
    function Get_Text (Label : access Gtk_Label_Record) return UTF8_String;
    Change the text of the label. The new text is visible on the screen at once. Note that the underline pattern is not modified.
  • procedure Set_Label (Label : access Gtk_Label_Record; Str : String);
    function Get_Label (Label : access Gtk_Label_Record) return String;
    Sets the text of the label. The label is interpreted as including embedded underlines and/or Pango markup depending on the values of label->use_underline and label->use_markup.
  • function Get_Layout (Label : access Gtk_Label_Record) return Pango.Layout.Pango_Layout;
    Gets the layout used to display the label. The layout is useful to e.g. convert text positions to pixel positions, in combination with Get_Layout_Offsets(). The returned layout is owned by the label so need not be freed by the caller.
  • procedure Get_Layout_Offsets (Label : access Gtk_Label_Record; X, Y : out Gint);
    Obtains the coordinates where the label will draw the layout representing the text in the label; useful to convert mouse events into coordinates inside the layout, e.g. to take some action if some part of the label is clicked. Of course you will need to create a Gtk_Event_Box to receive the events, and pack the label inside it, since labels are a #GTK_NO_WINDOW widget. Remember when using the layout functions you need to convert to and from pixels using PANGO_PIXELS() or #PANGO_SCALE.
  • procedure Set_Max_Width_Chars (Label : access Gtk_Label_Record; N_Chars : Gint);
    function Get_Max_Width_Chars (Label : access Gtk_Label_Record) return Gint;
    Sets the desired maximum width in characters of Label
  • procedure Set_Width_Chars (Label : access Gtk_Label_Record; N_Chars : Gint);
    function Get_Width_Chars (Label : access Gtk_Label_Record) return Gint;
    Sets the desired width in characters of Label.
  • procedure Set_Single_Line_Mode (Label : access Gtk_Label_Record; Single_Line_Mode : Boolean);
    function Get_Single_Line_Mode (Label : access Gtk_Label_Record) return Boolean;
    Sets whether the label is in single line mode.
  • function Get_Mnemonic_Keyval (Label : access Gtk_Label_Record) return Gdk.Types.Gdk_Key_Type;
    Return the key value of the mnemonic accelerator key indicated by an embedded underline in the label. If there is no mnemonic set up it returns Gdk.Types.Keysyms.GDK_VoidSymbol.
  • procedure Set_Attributes (Label : access Gtk_Label_Record; Attrs : Pango.Attributes.Pango_Attr_List);
    function Get_Attributes (Label : access Gtk_Label_Record) return Pango.Attributes.Pango_Attr_List;
    Sets a list of attributes to be applied to the label text. These attributes will be ignored if the use_underline or use_markup properties are set. Get_Attributes does not reflect attributes that come from the label's markup (see Set_Markup). If you want to get the effective attributes for the label, use Pango.Layout.Get_Attribute (Get_Layout (Label)).
  • procedure Set_Text_With_Mnemonic (Label : access Gtk_Label_Record; Str : UTF8_String);
    Change the text and mnemonic key of the label. The new text and mnemonic are visible on the screen at once. The mnemonic key can be used to activate another widget, chosen automatically or explicitely using Set_Mnemonic_Widget.
  • procedure Set_Markup (Label : access Gtk_Label_Record; Str : UTF8_String);
    Parses Str which is marked up with the Pango text markup language, setting the label's text and attribute list based on the parse results.
  • procedure Set_Markup_With_Mnemonic (Label : access Gtk_Label_Record; Str : UTF8_String);
    Parse Str which is marked up with the Pango text markup language, 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 mnemonic. The mnemonic key can be used to activate another widget, chosen automatically or explicitely using Set_Mnemonic_Widget.
  • procedure Set_Mnemonic_Widget (Label : access Gtk_Label_Record; Widget : access Gtk.Widget.Gtk_Widget_Record'Class);
    function Get_Mnemonic_Widget (Label : access Gtk_Label_Record) return Gtk.Widget.Gtk_Widget;
    If the label has been set so that it has an mnemonic key, the label can be associated with a widget that is the target of the mnemonic. When the label is inside a widget (like a Gtk_Button or a Gtk_Notebook tab), it is automatically associated with the correct widget, but sometimes (i.e. when the target is a Gtk_Entry next to the label), you need to set it explicitly using this procedure. The target widget will be accelerated by emitting "mnemonic_activate" on it. The default handler for this signal will activate the widget if there are no mnemonic collisions and toggle focus between the colliding widgets otherwise.
  • procedure Select_Region (Label : access Gtk_Label_Record; Start_Offset : Integer := -1; End_Offset : Integer := -1);
    Selects a range of characters in the label, if the label is selectable. If Start or End are -1, then the end of the label will be substituted.
  • procedure Get_Selection_Bounds (Label : access Gtk_Label_Record; First, Last : out Gint; Has_Selection : out Boolean);
    Gets the selected range of characters in the label, returning True if there's a selection.
  • procedure Set_Pattern (Label : access Gtk_Label_Record; Pattern : String);
    Change the underlines pattern. Pattern is a simple string made of underscore and space characters, matching the ones in the string. GtkAda will underline every letter that matches an underscore. An empty string disables the underlines. example: If the text is FooBarBaz and the Pattern is "___ ___" then both "Foo" and "Baz" will be underlined, but not "Bar".

Signals

  • copy_clipboard
    procedure Handler (Label : access Gtk_Label_Record'Class);
    Request a copy the label's text into the clipboard. This should be bound to a key.
  • move_cursor
    procedure Handler (Label : access Gtk_Label_Record'Class; Step : Gtk_Movement_Step; Amount : Gint; Extend_Selection : Boolean);
    You should emit this signal to request that the cursor be moved inside the label. This is mostly useful from a keybinding. The cursor is also used as the insertion point when modifying the label
  • populate_popup
    procedure Handler (Label : access Gtk_Label_Record'Class; Menu : access Gtk_Menu_Record'Class);
    ???

Properties

  • Angle_Property
    Double
    Angle at which the label is rotated
  • Attributes_Property
    Pango_Type_Attr_List
    A list of style attributes to apply to the text of the label.
    See: ??? Unsupported yet
  • Cursor_Position_Property
    Int
    The current position of the insertion cursor in chars
  • Ellipsize_Property
    Enum
    The preferred place to ellipsize the string, if the label does
  • Justify_Property
    Gtk_Justification
    The alignment of the lines in the text of the label relative to
  • Label_Property
    UTF8_String
    The text of the label.
    See: Set_Text and Get_Text
  • Max_Width_Chars_Property
    Int
    The desired maximum width of the label, in characters
  • Mnemonic_Keyval_Property
    Guint
    The mnemonic accelerator key for this label.
    See: Gtk_New_With_Mnemonic
  • Mnemonic_Widget_Property
    Gtk_Widget_Record'Class
    The widget to be activated when the label's mnemonic key is
  • Pattern_Property
    String
    A string with _ characters in positions correspond to
  • Selectable_Property
    Boolean
    Whether the label text can be selected with the mouse.
    See:
  • Selection_Bound_Property
    Int
    The position of the opposite end of the selection from the cursor
  • Single_Line_Mode_Property
    Boolean
    Whether the label is in single line mode
  • Use_Markup_Property
    Boolean
    The text of the label includes XML markup.
  • Use_Underline_Property
    Boolean
    If set, an underline in the text indicates the next character
  • Width_Chars_Property
    Int
    The desired width of the label, in characters
  • Wrap_Property
    Boolean
    If set, wrap lines if the text becomes too wide.
    See: Set_Line_Wrap

Testgtk source code

This code is part of testgtk, a demo application packaged with GtkAda. Testgtk demonstrates the various widgets of GtkAda
----------------------------------------------------------------------- -- GtkAda - Ada95 binding for the Gimp Toolkit -- -- -- -- Copyright (C) 2000 -- -- Emmanuel Briot, Joel Brobecker and Arnaud Charlet -- -- Copyright (C) 2003 ACT Europe -- -- -- -- This library is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU General Public -- -- License as published by the Free Software Foundation; either -- -- version 2 of the License, or (at your option) any later version. -- -- -- -- This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- -- General Public License for more details. -- -- -- -- You should have received a copy of the GNU General Public -- -- License along with this library; if not, write to the -- -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- -- Boston, MA 02111-1307, USA. -- -- -- -- -- -- -- -- -- -- ----------------------------------------------------------------------- with Gtk.Box; use Gtk.Box; with Gtk.Enums; use Gtk.Enums; with Gtk.Frame; use Gtk.Frame; with Gtk.Label; use Gtk.Label; with Glib.Convert; use Glib.Convert; package body Create_Label is ---------- -- Help -- ---------- function Help return String is begin return "A @bGtk_Label@B is used to display any kind of text on the" & " screen, even on multiple line." & ASCII.LF & "This is a passive widget, in that it does not react to any event."; end Help; --------- -- Run -- --------- procedure Run (Frame : access Gtk.Frame.Gtk_Frame_Record'Class) is Vbox, Hbox : Gtk_Box; Label : Gtk_Label; Frame2 : Gtk_Frame; begin Set_Label (Frame, "Label"); Gtk_New_Vbox (Vbox, False, 5); Gtk_New_Hbox (Hbox, False, 5); Add (Frame, Hbox); Pack_Start (Hbox, Vbox, False, False, 0); Gtk_New (Frame2, "Normal Label"); Gtk_New (Label, "This is a Normal Label"); Add (Frame2, Label); Pack_Start (Vbox, Frame2, False, False, 0); Gtk_New (Frame2, "Multi-line Label"); Gtk_New (Label, "This is a Multi-line label." & ASCII.LF & "Second Line" & ASCII.LF & "Third line"); Add (Frame2, Label); Pack_Start (Vbox, Frame2, False, False, 0); Gtk_New (Frame2, "Left Justified Label"); Gtk_New (Label, "This is a Left-Justified" & ASCII.LF & "Multi-line label." & ASCII.LF & "Third line"); Set_Justify (Label, Justify_Left); Add (Frame2, Label); Pack_Start (Vbox, Frame2, False, False, 0); Gtk_New (Frame2, "Right Justified Label"); Gtk_New (Label, "This is a Right-Justified" & ASCII.LF & "Multi-line label." & ASCII.LF & "Fourth line"); Set_Justify (Label, Justify_Right); Add (Frame2, Label); Pack_Start (Vbox, Frame2, False, False, 0); Gtk_New (Frame2, "Selectable Label"); Gtk_New (Label, "This is a selectable label " & ASCII.LF & "you can select the text with the " & ASCII.LF & "mouse and paste it."); Set_Selectable (Label, True); Add (Frame2, Label); Pack_Start (Vbox, Frame2, False, False, 0); Gtk_New_Vbox (Vbox, False, 5); Pack_Start (Hbox, Vbox, False, False, 0); Gtk_New (Frame2, "Line wrapped Label"); Gtk_New (Label, "This is an example of a line-wrapped label. It should not " & "be taking up the entire " & "width allocated to it, but automatically wraps the words " & "to fit. The time has come, for all good men, to come to " & "the aid of their party. The sixth sheik's six sheep's sick." & ASCII.LF & " It supports multiple paragraphs correctly, and " & "correctly adds many extra spaces. "); Set_Line_Wrap (Label, True); Add (Frame2, Label); Pack_Start (Vbox, Frame2, False, False, 0); Gtk_New (Frame2, "Filled, wrapped Label"); Gtk_New (Label, "This is an example of a line-wrapped label. It should " & "be taking up the entire " & "width allocated to it, but automatically wraps the words " & "to fit. The time has come, for all good men, to come to " & "the aid of their party. The sixth sheik's six sheep's sick." & ASCII.LF & " It supports multiple paragraphs correctly, and " & "correctly adds many extra spaces. "); Set_Line_Wrap (Label, True); Set_Justify (Label, Justify_Fill); Add (Frame2, Label); Pack_Start (Vbox, Frame2, False, False, 0); Gtk_New (Frame2, "Underlined Label"); Gtk_New (Label, Locale_To_UTF8 ("This label is underlined!" & ASCII.LF & "This one is underlined in 日本語の入用quite a funky fashion")); Set_Justify (Label, Justify_Left); Set_Pattern (Label, "_________________________ _ _________ _ _____ _ __" & " __ ___ ____ _____"); Add (Frame2, Label); Pack_Start (Vbox, Frame2, False, False, 0); Gtk_New (Frame2, "Markup Label"); Gtk_New (Label); Set_Markup (Label, ("" & "This label has markup!" & ASCII.LF & "You can make text bold italic " & "underline striken big. " & ASCII.LF & "You can also use mono spaced font" & " and write H2O " & "and " & ASCII.LF & "" & "y=裡xi" & "2 " & "+ 3" & " besides other things...")); Add (Frame2, Label); Pack_Start (Vbox, Frame2, False, False, 0); Show_All (Frame); end Run; end Create_Label;

Alphabetical Index