class Iup::Widget

Parent class for controls in the library.

Attributes

handle[R]

Unique reference to widget.

Public Instance Methods

assign_handle(name) click to toggle source

The C handle name for this widget

# File lib/wrapped/widget.rb, line 14
def assign_handle name
  IupLib.IupSetHandle name, @handle
end
enterwindow_cb(callback) click to toggle source

Action generated when the mouse enters the element

# File lib/wrapped/widget.rb, line 75
def enterwindow_cb callback
  unless callback.arity.zero?
    raise ArgumentError, 'enterwindow_cb callback must take 0 arguments'
  end
  cb = Proc.new do |ih|
    callback.call
  end
  define_callback cb, 'ENTERWINDOW_CB', :plain
end
getfocus_cb(callback) click to toggle source

Action generated when an element is given keyboard focus

# File lib/wrapped/widget.rb, line 53
def getfocus_cb callback
  unless callback.arity.zero?
    raise ArgumentError, 'getfocus_cb callback must take 0 arguments'
  end
  cb = Proc.new do |ih|
    callback.call
  end
  define_callback cb, 'GETFOCUS_CB', :plain
end
help_cb(callback) click to toggle source

Action generated when the user presses F1 at a control

# File lib/wrapped/widget.rb, line 110
def help_cb callback
  unless callback.arity.zero?
    raise ArgumentError, 'help_cb callback must take 0 arguments'
  end
  cb = Proc.new do |ih|
    callback.call
  end
  define_callback cb, 'HELP_CB', :plain_v
end
k_any(callback) click to toggle source

Action generated when a keyboard event occurs. k_any takes a 1-argument callback, the argument being the character that is pressed.

# File lib/wrapped/widget.rb, line 99
def k_any callback
  unless callback.arity == 1
    raise ArgumentError, 'k_any callback must take 1 argument, a character'
  end
  cb = Proc.new do |ih, c|
    callback.call c
  end
  define_callback cb, 'K_ANY', :i_i
end
killfocus_cb(callback) click to toggle source

Action generated when an element loses keyboard focus

# File lib/wrapped/widget.rb, line 64
def killfocus_cb callback
  unless callback.arity.zero?
    raise ArgumentError, 'killfocus_cb callback must take 0 arguments'
  end
  cb = Proc.new do |ih|
    callback.call
  end
  define_callback cb, 'KILLFOCUS_CB', :plain
end
leavewindow_cb(callback) click to toggle source

Action generated when the mouse leaves the element

# File lib/wrapped/widget.rb, line 86
def leavewindow_cb callback
  unless callback.arity.zero?
    raise ArgumentError, 'leavewindow_cb callback must take 0 arguments'
  end
  cb = Proc.new do |ih|
    callback.call
  end
  define_callback cb, 'LEAVEWINDOW_CB', :plain
end
map_cb(callback) click to toggle source

Called right after an element is mapped and its layout updated

# File lib/wrapped/widget.rb, line 31
def map_cb callback
  unless callback.arity.zero?
    raise ArgumentError, 'map_cb callback must take 0 arguments'
  end
  cb = Proc.new do |ih|
    callback.call
  end
  define_callback cb, 'MAP_CB', :plain
end
open_controls() click to toggle source

Ensure the controls library is opened

# File lib/wrapped/widget.rb, line 21
def open_controls
  unless @@controlslib
    ControlsLib.IupControlsOpen
    @@controlslib = true
  end
end
unmap_cb(callback) click to toggle source

Called right before an element is unmapped

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

Private Instance Methods

widget_list(widgets) click to toggle source

given an array of widgets, convert into format widget1, :pointer, widget2, … , :pointer, nil

# File lib/wrapped/widget.rb, line 124
def widget_list widgets
  result = []

  widgets.each do |widget|
    result << widget.handle
    result << :pointer
  end

  result << nil

  return result
end