Class: Iup::ColorBar
Overview
Displays a palette of colors from which the user can select a primary and secondary color.
Example
The following example sets up a default set of colors in a 2-column layout,
responding to color selections by calling redraw which updates an associated
display (not given here):
Iup::ColorBar.new do |b|
# the following settings define the display
b.rastersize = '70x'
b. = 'vertical'
b.num_parts = 2
b.show_secondary = 'yes'
b.preview_size = 60
# this call back responds to single-click color selections by updating display
b.select_cb = ->(idx, type){
case type
when Iup::IUP_PRIMARY
canvas.foreground = b.cell(idx)
when Iup::IUP_SECONDARY
canvas.background = b.cell(idx)
end
canvas.redraw
Iup::DEFAULT
}
# this call back responds to double-click color selections by updating display
b.cell_cb = ->(idx){
canvas.foreground cell(idx)
canvas.redraw
Iup::DEFAULT
}
# updates display with a switch between primary and secondary colors
b.switch_cb = ->(prim_cell, sec_cell){
fg_colour = canvas.foreground
canvas.foreground = canvas.background
canvas.background = fg_colour
canvas.redraw
Iup::DEFAULT
}
end
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#cell ⇒ Object
:call-seq: bar.cell(n) bar.cell(n, val).
-
#cell_cb=(callback) ⇒ Object
--.
-
#count ⇒ Object
:attr_reader: count Same as #num_cells.
-
#extended_cb=(callback) ⇒ Object
--.
-
#initialize {|_self| ... } ⇒ ColorBar
constructor
Creates a new colorbar instance.
-
#num_cells ⇒ Object
:attr: num_cells Contains the number of cells, defaults to 16.
-
#num_parts ⇒ Object
:attr: num_parts The number of lines or columns, defaults to 1.
-
#orientation ⇒ Object
:attr: orientation 'horizontal' / 'vertical'.
-
#preview_size ⇒ Object
:attr: preview_size Size of preview area in pixels.
-
#primary_cell ⇒ Object
:attr: primary_cell Index of the primary cell, defaults to 0 (black).
-
#secondary_cell ⇒ Object
:attr: secondary_cell Index of the secondary cell, defaults to 15 (white).
-
#select_cb=(callback) ⇒ Object
--.
-
#shadowed ⇒ Object
:attr: shadowed Controls 3D effect of color cells.
-
#show_preview ⇒ Object
:attr: show_preview Flag to show preview area or not, values 'yes' / 'no'.
-
#show_secondary ⇒ Object
:attr: show_secondary Whether to allow the selection of a secondary color, values 'no' / 'yes'.
-
#squared ⇒ Object
:attr: squared Controls aspect ratio of color cells.
-
#switch_cb=(callback) ⇒ Object
--.
Methods inherited from Canvas
#action=, #activate, #arc, #background, #background=, #backopacity, #backopacity=, #begin_block, #border, #box, #canfocus, #chord, #clear, #cursor, #deactivate, #drawsize, #end_block, #expand, #fillmode, #fillmode=, #focus_cb=, #font, #foreground, #foreground=, #hatch, #hatch=, #init, #interiorstyle, #interiorstyle=, #keypress_cb=, #kill, #line, #linecap, #linecap=, #linejoin, #linejoin=, #linestyle, #linestyle=, #linewidth, #linewidth=, #mark, #marksize, #marksize=, #marktype, #marktype=, #motion_cb=, #nativefont=, #padding, #pathset, #pixel, #position, #rastersize, #rectangle, #redraw, #resize_cb=, #screenposition, #sector, #stipple, #text, #textalignment, #textalignment=, #textorientation, #textorientation=, #tip, #vectortext, #vectortext_charsize, #vectortext_charsize=, #vectortext_direction, #vectortext_fontsize, #vectortext_loadfont, #vectortext_size, #vertex, #viewport, #wheel_cb=, #window, #writemode, #writemode=
Methods included from ButtonCallback
Methods included from ScrollBarAttributes
#dx, #dx=, #dy, #dy=, #linex, #linex=, #liney, #liney=, #posx, #posx=, #posy, #posy=, #scroll_cb=, #scrollbar, #xautohide, #xmax, #xmax=, #xmin, #xmin=, #yautohide, #ymax, #ymax=, #ymin, #ymin=
Methods included from AttributeBuilders
#define_attribute, #define_id_attribute, #define_id_reader, #define_id_writer, #define_property_attribute, #define_property_reader, #define_property_writer, #define_reader, #define_writer
Methods included from DragDropAttributes
#dragbegin_cb=, #dragdata_cb=, #dragdatasize_cb=, #dragend_cb=, #dragsource, #dragsourcemove, #dragtypes, #dropdata_cb=, #dropmotion_cb=, #droptarget, #droptypes
Methods inherited from Widget
#active, #assign_handle, #bgcolor, #destroy, #enterwindow_cb=, #fgcolor, #font, #getfocus_cb=, #help_cb=, #k_any=, #killfocus_cb=, #leavewindow_cb=, #map_cb=, #maxsize, #minsize, #open_controls, #size, #unmap_cb=, #visible, #wid, #zorder
Methods included from CallbackSetter
Constructor Details
#initialize {|_self| ... } ⇒ ColorBar
Creates a new colorbar instance. If a block is given, the new instance is yielded to it.
50 51 52 53 54 55 56 |
# File 'lib/wrapped/colorbar.rb', line 50 def initialize open_controls @handle = ControlsLib.IupColorbar # run any provided block on instance, to set up further attributes yield self if block_given? end |
Instance Method Details
#cell ⇒ Object
:call-seq:
.cell(n)
.cell(n, val)
Access nth cell color, n in range 0 to num_cells-1.
66 |
# File 'lib/wrapped/colorbar.rb', line 66 define_id_attribute :cell |
#cell_cb=(callback) ⇒ Object
--
133 134 135 136 137 138 139 140 141 |
# File 'lib/wrapped/colorbar.rb', line 133 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 |
#count ⇒ Object
:attr_reader: count Same as #num_cells.
76 |
# File 'lib/wrapped/colorbar.rb', line 76 define_reader :count |
#extended_cb=(callback) ⇒ Object
--
152 153 154 155 156 157 158 159 160 |
# File 'lib/wrapped/colorbar.rb', line 152 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 |
#num_cells ⇒ Object
:attr: num_cells Contains the number of cells, defaults to 16.
71 |
# File 'lib/wrapped/colorbar.rb', line 71 define_attribute :num_cells |
#num_parts ⇒ Object
:attr: num_parts The number of lines or columns, defaults to 1.
81 |
# File 'lib/wrapped/colorbar.rb', line 81 define_attribute :num_parts |
#orientation ⇒ Object
:attr: orientation 'horizontal' / 'vertical'
86 |
# File 'lib/wrapped/colorbar.rb', line 86 define_attribute :orientation |
#preview_size ⇒ Object
:attr: preview_size Size of preview area in pixels.
91 |
# File 'lib/wrapped/colorbar.rb', line 91 define_attribute :preview_size |
#primary_cell ⇒ Object
:attr: primary_cell Index of the primary cell, defaults to 0 (black).
106 |
# File 'lib/wrapped/colorbar.rb', line 106 define_attribute :primary_cell |
#secondary_cell ⇒ Object
:attr: secondary_cell Index of the secondary cell, defaults to 15 (white).
111 |
# File 'lib/wrapped/colorbar.rb', line 111 define_attribute :secondary_cell |
#select_cb=(callback) ⇒ Object
--
172 173 174 175 176 177 178 179 180 |
# File 'lib/wrapped/colorbar.rb', line 172 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 |
#shadowed ⇒ Object
:attr: shadowed Controls 3D effect of color cells. Values 'yes' / 'no'.
121 |
# File 'lib/wrapped/colorbar.rb', line 121 define_attribute :shadowed |
#show_preview ⇒ Object
:attr: show_preview Flag to show preview area or not, values 'yes' / 'no'.
96 |
# File 'lib/wrapped/colorbar.rb', line 96 define_attribute :show_preview |
#show_secondary ⇒ Object
:attr: show_secondary Whether to allow the selection of a secondary color, values 'no' / 'yes'.
101 |
# File 'lib/wrapped/colorbar.rb', line 101 define_attribute :show_secondary |
#squared ⇒ Object
:attr: squared Controls aspect ratio of color cells. Values 'yes' / 'no'.
116 |
# File 'lib/wrapped/colorbar.rb', line 116 define_attribute :squared |
#switch_cb=(callback) ⇒ Object
--
192 193 194 195 196 197 198 199 200 |
# File 'lib/wrapped/colorbar.rb', line 192 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 |