class Iup::ColorBar
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.expand = '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
Attributes
Contains the number of cells, defaults to 16.
The number of lines or columns, defaults to 1.
‘horizontal’ / ‘vertical’
Size of preview area in pixels.
Index of the primary cell, defaults to 0 (black).
Index of the secondary cell, defaults to 15 (white).
Controls 3D effect of color cells. Values ‘yes’ / ‘no’.
Flag to show preview area or not, values ‘yes’ / ‘no’.
Whether to allow the selection of a secondary color, values ‘no’ / ‘yes’.
Controls aspect ratio of color cells. Values ‘yes’ / ‘no’.
Public Class Methods
Source
# 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
Creates a new colorbar instance. If a block is given, the new instance is yielded to it.
Public Instance Methods
Source
# File lib/wrapped/colorbar.rb, line 66 define_id_attribute :cell
Access nth cell color, n in range 0 to num_cells-1.
Callbacks
Attributes
Callback called when the user double clicks a color cell to change its value. Callback must respond to call and is a 1-argument function: (cell_index),
-
cell_index- index of clicked cell, between 0 and num_cells-1.
Returns a new color (as a string), or nil if no change.
Callback called when the user right click a cell with the Shift key pressed Callback must respond to call is a 1-argument function: (cell_index).
-
cell_index- index of clicked cell, between 0 and num_cells-1.
If returns Iup::DEFAULT, cell is redrawn; if returns Iup::IGNORE, cell is not redrawn.
Callback called when a color is selected. The primary color is selected with the left mouse button, and, if present, secondary is selected with the right mouse button. Callback must respond to call and is a 2-argument function: (cell_index, type):
-
cell_index- index of selected color -
type- of color, see type constants
Callback 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 must respond to call and takes 2 arguments: (prim_cell, sec_cell):
-
prim_cell- index of primary cell -
sec_cell- index of secondary cell