class Iup::Toggle

A Toggle control is a control that can have two or three states. The toggle control will display some text or an image.

Attributes

alignment

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

canfocus

Enables the control to gain focus. Values 'yes' / 'no'.

expand

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

flat

If set, hides the control's border until mouse enters the button area. Values 'yes' / 'no'.

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 when inactive.

impress

Sets the image to display when pressed.

padding

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

position

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

radio

read-only Returns 'yes' / 'no' if toggle within a radio control.

rastersize

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

screenposition

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

three_state

'no' / 'yes', 3-state only for text labels

tip

Tooltip string.

title

text to display.

value

'on' / 'off' / 'toggle' / 'notdef' (for 3-state toggles).

Public Class Methods

new(title=nil, arg='', &block) click to toggle source

Creates an instance of a Toggle control.

title

optional text to display

arg

optional name of action to perform when state changed

block

optional block to set up attributes.

# File lib/wrapped/toggle.rb, line 39
def initialize title=nil, arg='', &block
  @handle = IupLib.IupToggle title, arg

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

Public Instance Methods

action(callback) click to toggle source

Action generated when the toggle's state (on/off) was changed. action takes a 1-argument callback, the argument indicating the state change. state_change == 1 if state changed to “on” state_change == 0 if state changed to “off”

# File lib/wrapped/toggle.rb, line 76
def action callback
  unless callback.arity == 1 
    raise ArgumentError, 'action callback must take 1 argument, the state_change'
  end
  cb = Proc.new do |ih, state_change|
    callback.call state_change.to_i
  end
  define_callback cb, 'ACTION', :i_i
end
valuechanged_cb(callback) click to toggle source

Called after the value was interactively changed by the user.

# File lib/wrapped/toggle.rb, line 87
def valuechanged_cb callback
  unless callback.arity.zero?
    raise ArgumentError, 'valuechanged_cb callback must take 0 arguments'
  end
  cb = Proc.new do |ih|
    callback.call
  end
  define_callback cb, 'VALUECHANGED_CB', :plain
end