class Iup::ColorBar

Colour bar

Public Class Methods

new(&block) click to toggle source
# File lib/wrapped/colourbar.rb, line 6
def initialize &block
  open_controls
  @handle = ControlsLib.IupColorbar

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

Public Instance Methods

cell_cb(callback) click to toggle source

Called when the user double clicks a color cell to change its value. Callback is a 1-argument function: (cell_index), returns a new colour (as a string), or nil if no change.

# File lib/wrapped/colourbar.rb, line 42
def cell_cb callback
  unless callback.arity == 1
    raise ArgumentError, 'cell_cb callback must take 1 argument: (cell_index)'
  end
  cb = Proc.new do |ih, cell_index|
    callback.call cell_index 
  end
  define_callback cb, 'CELL_CB', :i_s
end
extended_cb(callback) click to toggle source

Called when the user right click a cell with the Shift key pressed Callback is a 1-argument function: (cell_index).

# File lib/wrapped/colourbar.rb, line 54
def extended_cb callback
  unless callback.arity == 1
    raise ArgumentError, 'extended_cb callback must take 1 argument: (cell_index)'
  end
  cb = Proc.new do |ih, cell_index|
    callback.call cell_index 
  end
  define_callback cb, 'EXTENDED_CB', :i_i
end
select_cb(callback) click to toggle source

Called when a colour is selected. The primary colour is selected with the left mouse button, and if existent the secondary is selected with the right mouse button. Callback is a 2-argument function: (cell_index / type).

# File lib/wrapped/colourbar.rb, line 68
def select_cb callback
  unless callback.arity == 2
    raise ArgumentError, 'select_cb callback must take 2 arguments: (cell_index, type)'
  end
  cb = Proc.new do |ih, cell_index, type|
    callback.call cell_index, type 
  end
  define_callback cb, 'SELECT_CB', :ii_i
end
switch_cb(callback) click to toggle source

called when the user double clicks the preview area outside the preview cells to switch the primary and secondary selections. It is only called if SHOW_SECONDARY=YES. Callback takes 2 arguments: index of primary and secondary cells.

# File lib/wrapped/colourbar.rb, line 81
def switch_cb callback
  unless callback.arity == 2
    raise ArgumentError, 'switch_cb callback must take 2 arguments: (prim_cell, sec_cell)'
  end
  cb = Proc.new do |ih, cell_index, type|
    callback.call cell_index, type 
  end
  define_callback cb, 'SWITCH_CB', :ii_i
end