class Iup::Label

A Label is a a static control. It can display some text or an image, or act as a separator.

The following example (see “examples/label.rb”) displays three labels:

  1. a label with some text given in blue, a large font, and center aligned.

  2. a label as a horizontal separator.

  3. a label using an image.

labeltext = <<-END
This label has the following attributes set:
BGCOLOR = 255 255 0
FGCOLOR = 0 0 255
FONT = 'Courier, Normal 14'
ALIGNMENT = ACENTER
END

lbl = Label.new labeltext  do                    # <1>
  bgcolor '255 255 0'
  fgcolor '0 0 255'
  font 'Courier, Normal 14'
  alignment 'ACENTER'
end

lbl_explain = Label.new 'The label on the right has the image of a star'
lbl_star = Label.new do                          # <2>
  image img_star # reference to an image
end

separator = Label.new do                         # <3>
  separator 'HORIZONTAL' 
end

Dialog.new(VBox.new(lbl, separator, HBox.new(lbl_explain, lbl_star))) do
  title 'IupLabel Example'
end.show
  1. A label with text, modifying the attributes of the text.

  2. A label with an image.

  3. A label which acts as an horizontal separator.

Attributes

alignment

Sets the horizontal and vertical alignment. The value is a string “horizontal:vertical”, with options ALEFT, ACENTER, ARIGHT or none.

ellipsis

If set, adds “…” to the text if there is inadequate space, values 'yes' / 'no'.

expand

Allows label to fill available space in indicated direction. Values 'no' / 'horizontal' / 'vertical' / 'yes'.

image

Sets the image to display. This can be an actual image object, or the name of an image.

iminactive

Sets the image to display wihen inactive.

padding

Margin in x and y directions, value as “mxn”.

position

read-only returns position in pixels within client window as “x,y”.

rastersize

Size of the label, in pixels, value as “widthxheight”.

separator

'horizontal' / 'vertical', makes line into a line separator.

screenposition

read-only returns position in pixels on screen as “x,y”.

spacing

Space between image and text, value as a number.

tip

Tooltip string.

title

text to display (unless label has an image or is a separator).

Public Class Methods

new(text=nil, &block) click to toggle source

Creates an instance of a label.

text

optional text to use for label.

block

optional block to set label's attributes.

# File lib/wrapped/label.rb, line 74
def initialize text=nil, &block
  @handle = IupLib.IupLabel text

  # run any provided block on instance, to set up further attributes
  self.instance_eval &block if block_given?
end