[ruby-gnome2-doc-cvs] [Hiki] update - Gtk::Label

Back to archive index

ruby-****@lists***** ruby-****@lists*****
2003年 4月 23日 (水) 16:20:24 JST


-------------------------
REMOTE_ADDR = 61.204.181.66
REMOTE_HOST = 
-------------------------

-------------------------
= class Gtk::Label
The Gtk::Label widget displays a small amount of text. As the name implies, most labels are used to label another widget such as a Gtk::Button, a Gtk::MenuItem, or a Gtk::OptionMenu.

=== 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 Gtk::Label.new(text, true) or Gtk::Label.set_text(text, true).

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 Gtk::Label#mnemonic_widget=. Here's a simple example where the label is inside a button: 


  # Pressing Alt+H will activate this button
  button = Gtk::Button.new
  label = Gtk::Label.new("_Hello", true)
  button.add(label)


There's a convenience function to create buttons with a mnemonic label already inside: 

  # Pressing Alt+H will activate this button
  button = Gtk::Button.new("_Hello")

To create a mnemonic for a widget alongside the label, such as a Gtk::Entry, you have to point the label at the entry with Gtk::Label#mnemonic_widget=: 

  # Pressing Alt+H will focus the entry
  entry = Gtk::Entry.new
  label = Gtk::Label.new("_Hello", true)
  label.mnemonic_widget = 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: 

  label = Gtk::Label.new
  label.set_markup("<small>Small text</small>")

(See complete documentation of available tags in the Pango manual.)

The markup passed to Gtk::Label#set_markup() must be valid; for example, literal </>/& characters must be escaped as &lt;, &gt;, and &amp;. If you pass text obtained from the user, file, or a network to Gtk::Label#set_markup(), you'll want to escape it with GLib::Markup.escape_text(not implemented yet).

Markup strings are just a convenient way to set the Pango::AttrList on a label; Gtk::Label#set_attributes() may be a simpler way to set attributes in some cases. Be careful though; Pango::AttrList tends to cause internationalization problems, unless you're applying attributes to the entire string. 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 Gtk::Label#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 Gtk::Label#wrap=.

Gtk::Label#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 Gtk::Misc#set_alignment.

== super class
* ((<Gtk::Misc>))

== class methods
--- Gtk::Label.new(str = nil, mnemonic = false)
    Creates a new label with the given text inside it. 
    If mnemonic = true and 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 Gtk::Label#mnemonic_widget=.
    If Gtk::Label#mnemonic_widget= is not called, then the first activatable ancestor of the Gtk::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.
str : The text of the label,  
Returns : the new GtkLabel 

    * str: The text of the label
    * mnemonic: true if mnemonic characters are underlined with an '_' in front of the mnemonic character
    * Returns: the new Gtk::Label 

== public instance methods
--- attributes
    Gets the list of style attributes to apply to the text of the label.
    * Returns: the list of style attributes(Pango::AttrList)
--- attributes=(attrs)
    Sets a Pango::AttrList; the attributes in the list are applied to the label text. The attributes set with this method will be ignored if Gtk::Label#use_underline? or Gtk::Label#use_markup? is true.
    * attrs : a Pango::AttrList 
    * Returns: attrs
--- set_attributes(attrs)
    Same as attributes=.
    * attrs : a Pango::AttrList 
    * Returns: self

--- text
    Fetches the text from a label widget, as displayed on the screen. This does not include any embedded underlines indicating mnemonics or Pango markup. (See Gtk::Label#label)
    * Returns : the text in the label widget. This is the internal string used by the label, and must not be modified. 

--- set_text(str, mnemonic = false)
    Sets the text within the GtkLabel widget. It overwrites any text that was there before. 
    This will also clear any previously set mnemonic accelerators.
    If mnemonic = true and 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 Gtk::Label#mnemonic_widget=.
    * str: The text you want to set. 
    * mnemonic: true if mnemonic characters are underlined with an '_' in front of the mnemonic character
    * Returns: self

--- set_markup(str, mnemonic = false)
    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.
    If mnemonic = true and 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 Gtk::Label#mnemonic_widget=.
    * str: a markup string (see Pango markup format)
    * mnemonic: true if mnemonic characters are underlined with an '_' in front of the mnemonic character
    * Returns: self

--- pattern=(pattern)
    The pattern of underlines you want under the existing text within the Gtk::Label widget. For example if the current text of the label says "FooBarBaz" passing a pattern of "___   ___" will underline "Foo" and "Baz" but not "Bar".
    * pattern: The pattern as described above.  
    * Returns: pattern
--- set_pattern(pattern)
    Same as pattern=.
    * pattern: The pattern as described above.  
    * Returns: pattern

--- cursor_position
    Gets the current position of the insertion cursor in chars.
    * Returns: the current position

--- justify
    Returns the justification of the label. See Gtk::Label#justify=.
    * Returns: ((<GtkJustification|Gtk#GtkJustification>))
--- justify=(jtype)
    Sets the alignment of the lines in the text of the label relative to each other. Gtk::JUSTIFY_LEFT is the default value when the widget is first created with Gtk::Label.new. If you instead want to set the alignment of the label as a whole, use Gtk::Misc#alignment= instead. Gtk::Label#justify= has no effect on labels containing only a single line.
    * jtype: a ((<GtkJustification|Gtk#GtkJustification>))
    * Returns: jtype
--- set_justify(jtype)
    Same as justify=.
    * jtype: a ((<GtkJustification|Gtk#GtkJustification>))
    * Returns: self

--- label
    Fetches the text from a label widget including any embedded underlines indicating mnemonics and Pango markup. (See Gtk::Label#text).
    * Returns: the text of the label widget. This string is owned by the widget and must not be modified or freed. 
--- label=(str)
    Sets the text of the label. The label is interpreted as including embedded underlines and/or Pango markup depending on the values of Gtk::Label#use_underline? and Gtk::Label#use_markup?.
    * str: the new text to set for the label
    * Returns: str
--- set_label(str)
    Same as label=.
    * str: the new text to set for the label
    * Returns: self

--- 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 Gtk::Label#layout_offsets. The returned layout is owned by the label so need not be freed by the caller.
    * Returns: the Pango::Layout for this label 

--- layout_offsets
    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 Gtk::EventBox to receive the events, and pack the label inside it, since labels are a Gtk::Widget::NO_WINDOW widget. Remember when using the Pango::Layout functions you need to convert to and from pixels using Pango.pixels or Pango::SCALE.    * x: location to store X offset of layout, or nil
    * y: location to store Y offset of layout, or nil

--- mnemonic_keyval
    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::Keyval::GDK_VoidSymbol.
    * Returns: GDK keyval usable for accelerators, or Gdk::Keyval::GDK_VoidSymbol 

--- mnemonic_widget
    Retrieves the target of the mnemonic (keyboard shortcut) of this label. See Gtk::Label#mnemonic_widget=.
    * Returns: the target of the label's mnemonic, or nil if none has been set and the default algorithm will be used. 
--- mnemonic_widget=(widget)
    If the label has been set so that it has an mnemonic key (using i.e. Gtk::Label#set_markup, Gtk::Label#set_text, Gtk::Label.new 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 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 function.
    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.
    * widget: the target Gtk::Widget  
    * Returns: widget
--- set_mnemonic_widget(widget)
    Same as mnemonic_widget=.
    * widget: the target Gtk::Widget  
    * Returns: self

--- selectable?
    Gets the value set by Gtk::Label#selectable=.
    * Returns: true if the user can copy text from the label 
--- selectable=(setting)
    Selectable labels allow the user to select text from the label, for copy-and-paste.
    * setting: true to allow selecting text in the label 
    * Returns: setting
--- set_selectable(setting)
    Same as selectable=.
    * setting: true to allow selecting text in the label 
    * Returns: self

--- select_region
    
--- selection_bound
--- selection_bounds
    Gets the selected range of characters in the label, returning true if there's a selection.
    * Returns: [start, end] or nil
       * start: return location for start of selection, as a character offset 
       * end: return location for end of selection, as a character offset 

--- use_markup?
    Returns whether the label's text is interpreted as marked up with the Pango text markup language. See Gtk::Label#use_markup=.
    * Returns: true if the label's text will be parsed for markup. 
--- use_markup=(setting)
    Sets whether the text of the label contains markup in Pango's text markup language. See Gtk::Labelset_markup.
    * setting: true if the label's text should be parsed for markup
    * Returns: setting
--- set_use_markup(setting)
    Same as use_markup=.
    * setting: true if the label's text should be parsed for markup
    * Returns: self

--- use_underline?
    Returns whether an embedded underline in the label indicates a mnemonic. See Gtk::Label#use_underline=.
    * Returns: true whether an embedded underline in the label indicates the mnemonic accelerator keys. --- use_underline=(setting)
    If true, an underline in the text indicates the next character should be used for the mnemonic accelerator key.
    * setting: true if underlines in the text indicate mnemonics 
    * Returns: setting
--- set_use_underline(setting)
    Same as use_underline=.
    * setting: true if underlines in the text indicate mnemonics 
    * Returns: setting

--- wrap?
    Returns whether it toggles line wrapping within the Gtk::Label widget or not.
    * Returns: true if it toggles line wrapping.
--- wrap=(wrap)
    Toggles line wrapping within the Gtk::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.
    * wrap: the setting
    * Returns: wrap
--- set_wrap(wrap)
    Same as wrap=.
    * wrap: the setting
    * Returns: self

== signals
--- copy-clipboard: self
     * self: Gtk::Label
--- move-cursor: self
     * self: Gtk::Label
--- populate-popup: self
     * self: Gtk::Label
     * arg1: Gtk::Menu

((<Masao>))




ruby-gnome2-cvs メーリングリストの案内
Back to archive index