Class: Iup::ColorBar

Inherits:
Widget show all
Defined in:
lib/wrapped/colourbar.rb

Overview

Colour bar

Instance Attribute Summary

Attributes inherited from Widget

#handle

Instance Method Summary collapse

Methods inherited from Widget

#assign_handle, #enterwindow_cb, #getfocus_cb, #help_cb, #k_any, #killfocus_cb, #leavewindow_cb, #map_cb, #open_controls, #unmap_cb

Methods included from AttributeBuilders

#define_attribute, #define_id_attribute, #define_id_readonly, #define_id_writeonly, #define_property_attribute, #define_property_writeonly, #define_readonly, #define_writeonly

Methods included from CallbackSetter

#define_callback

Constructor Details

#initialize(&block) ⇒ ColorBar

Returns a new instance of ColorBar.



6
7
8
9
10
11
12
# 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

Instance Method Details

#cell_cb(callback) ⇒ Object

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.



42
43
44
45
46
47
48
49
50
# 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) ⇒ Object

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



54
55
56
57
58
59
60
61
62
# 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) ⇒ Object

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).



68
69
70
71
72
73
74
75
76
# 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) ⇒ Object

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.



81
82
83
84
85
86
87
88
89
# 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