class Iup::Matrix
An interactive control, used to display a matrix or grid of strings on a canvas. The API documentation can only hint at the use of this control. For more information see Tecgraf’s documentation on IupMatrix.
Example
matrix =Iup::Matrix.new do |m| m.numlin = 3 m.numcol = 3 m.set(0, 1, "Country") m.set(0, 2, "Capital") m.set(0, 3, "Population") m.set(1, 1, "England") m.set(1, 2, "London") m.set(1, 3, "58,620,100") m.set(2, 1, "Scotland") m.set(2, 2, "Edinburgh") m.set(2, 3, "5,546,900") m.set(3, 1, "Wales") m.set(3, 2, "Cardiff") m.set(3, 3, "3,186,600") m.readonly = "yes" end dlg = Iup::Dialog.new(matrix) do |d| d.title = "Matrix Example" end.map dlg.show
Note that the dialog must be mapped before being shown, to correctly display the matrix.
Public Class Methods
Source
# File lib/wrapped/matrix.rb, line 41 def initialize open_controls @handle = ControlsLib.IupMatrix "" # run any provided block on instance, to set up further attributes yield self if block_given? end
Creates a new instance. If a block is given, the new instance is yielded to it.
Public Instance Methods
Source
# File lib/wrapped/matrix.rb, line 53 def get(lin, col) IupLib.IupGetAttribute(@handle, "#{lin}:#{col}").first end
Get value of cell:
-
lin- line number of cell -
col- column number of cell
Returns string value of cell (lin, col).
Source
# File lib/wrapped/matrix.rb, line 61 def set(lin, col, value) IupLib.IupSetAttribute(@handle, "#{lin}:#{col}", value.to_s) end
Set value of cell:
-
lin- line number of cell -
col- column number of cell -
value- new value for cell
Action attributes
Attributes
Forces line/column sizes so the matrix visible fits in the current displayed size.
Public Instance Methods
Source
# File lib/wrapped/matrix.rb, line 361 def redraw IupLib.IupSetAttribute(@handle, 'redraw', 'all') end
Instructs matrix of data change, and that it must redraw itself. Value can be:
-
‘all’ - redraw the whole matrix
-
‘Ld’ - redraws line d
-
‘Ld1-d2’ - redraws lines d1 to d2
-
‘Cd’ - redraws column c
-
‘Cd1-d2’ - redraws columns d1 to d2
Callbacks
Attributes
Callback called when a keyboard event occurs. Callback must respond to call and takes 5 arguments: (key, lin, col, edition, value)
-
key- identifier of pressed key, see Key definitions -
lin- line of selected cell -
col- column of selected cell -
edition- is 1 if in edit mode, or 0 otherwise -
value- varies with edit mode: can be current value, string with key character, or “”.
Returns Iup::Default to validate the key, Iup::Ignore to ignore, Iup::Continue forwards the key, or identifier of the key to be treated
Callback called when any mouse button is pressed over a cell. Callback must respond to call and takes 3 arguments: (lin, col, status)
-
lin- line of selected cell -
col- column of selected cell -
status- of mouse buttons and some keyboard keys.
Return Iup::IGNORE to avoid refresh of display, or Iup::DEFAULT.
Callback called when a column is interactively resized. Callback must respond to call and takes 1 argument: (col)
-
col- column being resized
Return Iup::IGNORE to avoid refresh of display, or Iup::DEFAULT.
Callback called when matrix cell is selected, matrix gets focus etc. Callback must respond to call and takes 2 arguments: (lin, col)
-
lin- line of selected cell -
col- column of selected cell
Callback called when cell is no longer current cell, matrix loses focus etc. Callback must respond to call and takes 2 arguments: (lin, col)
-
lin- line of selected cell -
col- column of selected cell
Callback called when mouse has moved over the matrix. Callback must respond to call and takes 2 arguments: (lin, col)
-
lin- line of current mouse position -
col- column of current mouse position
Callback called when any mouse button is released over a cell. Callback must respond to call and takes 3 arguments: (lin, col, status)
-
lin- line of selected cell -
col- column of selected cell -
status- of mouse buttons and some keyboard keys.
Return Iup::IGNORE to avoid refresh of display, or Iup::DEFAULT.
Callback called after the element size has been updated, but before the cells are refreshed. Callback must respond to call and takes 2 arguments: (width, height)
-
width- of internal area in pixels -
height- of internal area in pixels
Callback called when matrix is scrolled. Callback must respond to call and takes 2 arguments: (lin, col)
-
lin- line of cell currently in top-left corner -
col- column of cell currently in top-left corner
Callback called to retrieve value of a cell. Callback must respond to call and takes 2 arguments: (lin, col)
-
lin- line of cell -
col- column of cell
Canvas attributes
Attributes
Changed to ‘no’, cf. Iup::Canvas#border.
Changed to ‘yes’, cf. Iup::Canvas#scrollbar.
Cell attributes
Public Instance Methods
Source
# File lib/wrapped/matrix.rb, line 169 def bgcolor_cell(col, lin, color) IupLib.IupSetAttribute(@handle, "BGCOLOR#{lin}:#{col}", color) end
Sets the background color of a cell:
-
col- column to change -
lin- line to change -
color- color in ‘r g b’ format
Source
# File lib/wrapped/matrix.rb, line 154 def bgcolor_column(col, color) IupLib.IupSetAttribute(@handle, "BGCOLOR*:#{col}", color) end
Sets the background color of a column:
-
col- column to change -
color- color in ‘r g b’ format
Source
# File lib/wrapped/matrix.rb, line 161 def bgcolor_line(lin, color) IupLib.IupSetAttribute(@handle, "BGCOLOR#{lin}:*", color) end
Sets the background color of a line:
-
lin- line to change -
color- color in ‘r g b’ format
Source
# File lib/wrapped/matrix.rb, line 191 def fgcolor_cell(col, lin, color) IupLib.IupSetAttribute(@handle, "FGCOLOR#{lin}:#{col}", color) end
Sets the foreground color of a cell:
-
col- column to change -
lin- line to change -
color- color in ‘r g b’ format
Source
# File lib/wrapped/matrix.rb, line 176 def fgcolor_column(col, color) IupLib.IupSetAttribute(@handle, "FGCOLOR*:#{col}", color) end
Sets the foreground color of a column:
-
col- column to change -
color- color in ‘r g b’ format
Source
# File lib/wrapped/matrix.rb, line 183 def fgcolor_line(lin, color) IupLib.IupSetAttribute(@handle, "FGCOLOR#{lin}:*", color) end
Sets the foreground color of a line:
-
lin- line to change -
color- color in ‘r g b’ format
Source
# File lib/wrapped/matrix.rb, line 213 def font_cell(col, lin, font) IupLib.IupSetAttribute(@handle, "FONT#{lin}:#{col}", font) end
Sets the font of a cell:
-
col- column to change -
lin- line to change -
font- font
Source
# File lib/wrapped/matrix.rb, line 198 def font_column(col, font) IupLib.IupSetAttribute(@handle, "FONT*:#{col}", font) end
Sets the font of a column:
-
col- column to change -
font- font
Column size attributes
Attributes
Default width of column in SIZE units, default value is 80.
Public Instance Methods
Source
# File lib/wrapped/matrix.rb, line 265 def mincolwidth(n, size) IupLib.IupSetAttribute(@handle, "MINCOLWIDTH#{n}", size.to_s) end
Defines minimum column width in SIZE units.
-
n- column number -
size- new size of column n
Source
# File lib/wrapped/matrix.rb, line 246 def rasterwidth(n, num_pixels) IupLib.IupSetAttribute(@handle, "RASTERWIDTH#{n}", num_pixels.to_s) end
Defines column width in pixels.
-
n- column number -
num_pixels- new width of column n
Source
# File lib/wrapped/matrix.rb, line 253 def width(n, size) IupLib.IupSetAttribute(@handle, "WIDTH#{n}", size.to_s) end
Defines column width in SIZE units
-
n- column number -
size- new size of column n
General attributes
Attributes
Defines the mouse shape / cursor for the matrix. Available cursors are shown in the Tecgraf documentation.
Allows container to fill available space in indicated direction. Values ‘no’ / ‘horizontal’ / ‘vertical’ / ‘yes’.
Removes 3D appearance from matrix, values ‘yes’ / ‘no’.
Enables flat scrollbars, values ‘yes’ / ‘no’.
Defines current cell, in format “L:C” - default “1:1”.
Controls display of focus mark when drawing matrix. Values ‘yes’ / ‘no’.
Overlay color for selected cells.
Scroll visible area to given cell: “L:C” format, use a “*” for L or C to scroll to a column or line.
Defines drag offset of origin: if changed, change origin too.
Returns position in pixels within client window as “x,y”.
Size of the container, in pixels, value as “widthxheight”.
Disable editing of cells. Values ‘yes’ / ‘no’.
Returns position in pixels on screen as “x,y”.
Tooltip string.
Line size attributes
Attributes
Default height of line in SIZE units, default value is 8.
Public Instance Methods
Source
# File lib/wrapped/matrix.rb, line 274 def height(n, size) IupLib.IupSetAttribute(@handle, "HEIGHT#{n}", size.to_s) end
Defines line height in SIZE units:
-
n- line number -
size- new size of line n
Source
# File lib/wrapped/matrix.rb, line 286 def rasterheight(n, num_pixels) IupLib.IupSetAttribute(@handle, "RASTERHEIGHT#{n}", num_pixels.to_s) end
Defines line height in pixels:
-
n- line number -
num_pixels- new length of line n
Number of cells attributes
Attributes
Adds a new column to matrix after the given column.
Adds a new line to matrix after the given line.
Removes the given column from the matrix.
Removes the given line from the matrix.
Makes the non-scrollable lines/columns appear like the title line/column, values ‘yes’ / ‘no’.
Defines the number of columns in the matrix, must be an integer.
Specifies the number of visible columns to include in calculating the Natural size.
Defines the number of lines in the matrix, must be an integer.
Number of columns that are non-scrollable, not counting the title column.
Specifies the number of visible lines to include in calculating the Natural size.
Size attributes
Attributes
Limits expansion to the largest size where all cells are visible.
Dynamically resize the column while dragging, values ‘yes’ / ‘no’.
Allows column widths to be adjusted manually by users, values ‘yes’ / ‘no’.
If set, defines cell size based on the title size. Values ‘yes’ / ‘no’.