Class: Iup::Matrix

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

Overview

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.

Instance Attribute Summary

Attributes inherited from Widget

#handle

Instance Method Summary collapse

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 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 CallbackSetter

#define_callback

Constructor Details

#initialize {|_self| ... } ⇒ Matrix

Creates a new instance. If a block is given, the new instance is yielded to it.

Yields:

  • (_self)

Yield Parameters:

  • _self (Iup::Matrix)

    the object that the method was called on



41
42
43
44
45
46
47
# 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

Instance Method Details

#action_cb=(callback) ⇒ Object



398
399
400
401
402
403
404
405
406
# File 'lib/wrapped/matrix.rb', line 398

def action_cb= callback
  unless callback.arity == 5
    raise ArgumentError, 'action_cb callback must take 5 arguments: (key, lin, col, edition, value)'
  end
  cb = Proc.new do |ih, key, lin, col, edition, value|
    callback.call key, lin, col, edition, value
  end
  define_callback cb, 'ACTION_CB', :i_s
end

#addcolObject

:attr_writer: addcol Adds a new column to matrix after the given column.



295
# File 'lib/wrapped/matrix.rb', line 295

define_writer :addcol

#addlinObject

:attr_writer: addlin Adds a new line to matrix after the given line.



300
# File 'lib/wrapped/matrix.rb', line 300

define_writer :addlin

#bgcolor_cell(col, lin, color) ⇒ Object

Sets the background color of a cell:

  • col - column to change

  • lin - line to change

  • color - color in ‘r g b’ format



169
170
171
# File 'lib/wrapped/matrix.rb', line 169

def bgcolor_cell(col, lin, color)
  IupLib.IupSetAttribute(@handle, "BGCOLOR#{lin}:#{col}", color)
end

#bgcolor_column(col, color) ⇒ Object

Sets the background color of a column:

  • col - column to change

  • color - color in ‘r g b’ format



154
155
156
# File 'lib/wrapped/matrix.rb', line 154

def bgcolor_column(col, color)
  IupLib.IupSetAttribute(@handle, "BGCOLOR*:#{col}", color)
end

#bgcolor_line(lin, font) ⇒ Object

Sets the font of a line:

  • lin - line to change

  • font - font



161
162
163
# File 'lib/wrapped/matrix.rb', line 161

def bgcolor_line(lin, color)
  IupLib.IupSetAttribute(@handle, "BGCOLOR#{lin}:*", color)
end

#borderObject

:attr: border Changed to ‘no’, cf. Iup::Canvas#border.



376
# File 'lib/wrapped/matrix.rb', line 376

define_attribute :border

#click_cb=(callback) ⇒ Object



418
419
420
421
422
423
424
425
426
# File 'lib/wrapped/matrix.rb', line 418

def click_cb= callback
  unless callback.arity == 3
    raise ArgumentError, 'click_cb callback must take 3 arguments: (lin, col, status)'
  end
  cb = Proc.new do |ih, lin, col, status|
    callback.call lin, col, status
  end
  define_callback cb, 'CLICK_CB', :i_s
end

#colresize_cb=(callback) ⇒ Object



436
437
438
439
440
441
442
443
444
# File 'lib/wrapped/matrix.rb', line 436

def colresize_cb= callback
  unless callback.arity == 1
    raise ArgumentError, 'colresize_cb callback must take 1 argument: (col)'
  end
  cb = Proc.new do |ih, col|
    callback.call col
  end
  define_callback cb, 'COLRESIZE_CB', :i_s
end

#cursorObject

:attr: cursor Defines the mouse shape / cursor for the matrix. Available cursors are shown in the Tecgraf documentation.



74
# File 'lib/wrapped/matrix.rb', line 74

define_attribute :cursor

#delcolObject

:attr_writer: delcol Removes the given column from the matrix.



305
# File 'lib/wrapped/matrix.rb', line 305

define_writer :delcol

#dellinObject

:attr_writer: dellin Removes the given line from the matrix.



310
# File 'lib/wrapped/matrix.rb', line 310

define_writer :dellin

#enteritem_cb=(callback) ⇒ Object



511
512
513
514
515
516
517
518
519
# File 'lib/wrapped/matrix.rb', line 511

def enteritem_cb= callback
  unless callback.arity == 2
    raise ArgumentError, 'enteritem_cb callback must take 2 arguments: (lin, col)'
  end
  cb = Proc.new do |ih, lin, col|
    callback.call lin, col
  end
  define_callback cb, 'ENTERITEM_CB', :i_s
end

#expandObject

:attr: expand Allows container to fill available space in indicated direction. Values ‘no’ / ‘horizontal’ / ‘vertical’ / ‘yes’.



127
# File 'lib/wrapped/matrix.rb', line 127

define_attribute :expand

#fgcolor_cell(col, lin, color) ⇒ Object

Sets the foreground color of a cell:

  • col - column to change

  • lin - line to change

  • color - color in ‘r g b’ format



191
192
193
# File 'lib/wrapped/matrix.rb', line 191

def fgcolor_cell(col, lin, color)
  IupLib.IupSetAttribute(@handle, "FGCOLOR#{lin}:#{col}", color)
end

#fgcolor_column(col, color) ⇒ Object

Sets the foreground color of a column:

  • col - column to change

  • color - color in ‘r g b’ format



176
177
178
# File 'lib/wrapped/matrix.rb', line 176

def fgcolor_column(col, color)
  IupLib.IupSetAttribute(@handle, "FGCOLOR*:#{col}", color)
end

#fgcolor_line(lin, color) ⇒ Object

Sets the foreground color of a line:

  • lin - line to change

  • color - color in ‘r g b’ format



183
184
185
# File 'lib/wrapped/matrix.rb', line 183

def fgcolor_line(lin, color)
  IupLib.IupSetAttribute(@handle, "FGCOLOR#{lin}:*", color)
end

#fittosizeObject

:attr_writer: fittosize Forces line/column sizes so the matrix visible fits in the current displayed size.



369
# File 'lib/wrapped/matrix.rb', line 369

define_writer :fittosize

#flatObject

:attr: flat Removes 3D appearance from matrix, values ‘yes’ / ‘no’.



84
# File 'lib/wrapped/matrix.rb', line 84

define_attribute :flat

#flatscrollbarObject

:attr: flatscrollbar Enables flat scrollbars, values ‘yes’ / ‘no’.



89
# File 'lib/wrapped/matrix.rb', line 89

define_attribute :flatscrollbar

#focuscellObject

:attr: focuscell Defines current cell, in format “L:C” - default “1:1”.



79
# File 'lib/wrapped/matrix.rb', line 79

define_attribute :focuscell

#font_cell(col, lin, font) ⇒ Object

Sets the font of a cell:

  • col - column to change

  • lin - line to change

  • font - font



213
214
215
# File 'lib/wrapped/matrix.rb', line 213

def font_cell(col, lin, font)
  IupLib.IupSetAttribute(@handle, "FONT#{lin}:#{col}", font)
end

#font_column(col, font) ⇒ Object

Sets the font of a column:

  • col - column to change

  • font - font



198
199
200
# File 'lib/wrapped/matrix.rb', line 198

def font_column(col, font)
  IupLib.IupSetAttribute(@handle, "FONT*:#{col}", font)
end

#get(lin, col) ⇒ Object

Get value of cell:

  • lin - line number of cell

  • col - column number of cell

Returns string value of cell (lin, col).



53
54
55
# File 'lib/wrapped/matrix.rb', line 53

def get(lin, col)
  IupLib.IupGetAttribute(@handle, "#{lin}:#{col}").first
end

#height(n, size) ⇒ Object

Defines line height in SIZE units:

  • n - line number

  • size - new size of line n



274
275
276
# File 'lib/wrapped/matrix.rb', line 274

def height(n, size)
  IupLib.IupSetAttribute(@handle, "HEIGHT#{n}", size.to_s)
end

#heightdefObject

:attr: height Default height of line in SIZE units, default value is 8.



281
# File 'lib/wrapped/matrix.rb', line 281

define_attribute :heightdef

#hiddentextmarksObject

:attr: hiddentextmarks Use a “…” or crop text when longer than cell, values ‘yes’ / ‘no’.



100
# File 'lib/wrapped/matrix.rb', line 100

define_attribute :hiddentextmarks

#hidefocusObject

:attr: hidefocus Controls display of focus mark when drawing matrix. Values ‘yes’ / ‘no’.



95
# File 'lib/wrapped/matrix.rb', line 95

define_attribute :hidefocus

#hlcolorObject

:attr: hlcolor Overlay color for selected cells.



105
# File 'lib/wrapped/matrix.rb', line 105

define_attribute :hlcolor

#leaveitem_cb=(callback) ⇒ Object



529
530
531
532
533
534
535
536
537
# File 'lib/wrapped/matrix.rb', line 529

def leaveitem_cb= callback
  unless callback.arity == 2
    raise ArgumentError, 'leaveitem_cb callback must take 2 arguments: (lin, col)'
  end
  cb = Proc.new do |ih, lin, col|
    callback.call lin, col
  end
  define_callback cb, 'LEAVEITEM_CB', :i_s
end

#limitexpandObject

:attr: limitexpand Limits expansion to the largest size where all cells are visible.



222
# File 'lib/wrapped/matrix.rb', line 222

define_attribute :limitexpand

#mincolwidth(n, size) ⇒ Object

Defines minimum column width in SIZE units.

  • n - column number

  • size - new size of column n



265
266
267
# File 'lib/wrapped/matrix.rb', line 265

def mincolwidth(n, size)
  IupLib.IupSetAttribute(@handle, "MINCOLWIDTH#{n}", size.to_s)
end

#mousemove_cb=(callback) ⇒ Object



493
494
495
496
497
498
499
500
501
# File 'lib/wrapped/matrix.rb', line 493

def mousemove_cb= callback
  unless callback.arity == 2
    raise ArgumentError, 'mousemove_cb callback must take 2 arguments: (lin, col)'
  end
  cb = Proc.new do |ih, lin, col|
    callback.call lin, col
  end
  define_callback cb, 'MOUSEMOVE_CB', :i_s
end

#noscrollastitleObject

:attr: noscrollastitle Makes the non-scrollable lines/columns appear like the title line/column, values ‘yes’ / ‘no’.



350
# File 'lib/wrapped/matrix.rb', line 350

define_attribute :noscrollastitle

#numcolObject

:attr: numcol Defines the number of columns in the matrix, must be an integer.



315
# File 'lib/wrapped/matrix.rb', line 315

define_attribute :numcol

#numcol_noscrollObject

:attr: numlin_noscroll Number of columns that are non-scrollable, not counting the title column.



327
# File 'lib/wrapped/matrix.rb', line 327

define_attribute :numcol_noscroll

#numcol_visibleObject

:attr: numcol_visible Specifies the number of visible columns to include in calculating the Natural size.



321
# File 'lib/wrapped/matrix.rb', line 321

define_attribute :numcol_visible

#numlinObject

:attr: numlin Defines the number of lines in the matrix, must be an integer.



332
# File 'lib/wrapped/matrix.rb', line 332

define_attribute :numlin

#numlin_noscrollObject

:attr: numlin_noscroll Number of lines that are non-scrollable, not counting the title line.



344
# File 'lib/wrapped/matrix.rb', line 344

define_attribute :numlin_noscroll

#numlin_visibleObject

:attr: numlin_visible Specifies the number of visible lines to include in calculating the Natural size.



338
# File 'lib/wrapped/matrix.rb', line 338

define_attribute :numlin_visible

#originObject

:attr_writer: origin Scroll visible area to given cell: “L:C” format, use a “*” for L or C to scroll to a column or line.



111
# File 'lib/wrapped/matrix.rb', line 111

define_writer :origin

#originoffsetObject

:attr: originoffset Defines drag offset of origin: if changed, change #origin too.



116
# File 'lib/wrapped/matrix.rb', line 116

define_attribute :originoffset

#positionObject

:attr_reader: position Returns position in pixels within client window as “x,y”.



132
# File 'lib/wrapped/matrix.rb', line 132

define_reader :position

#rasterheight(n, num_pixels) ⇒ Object

Defines line height in pixels:

  • n - line number

  • num_pixels - new length of line n



286
287
288
# File 'lib/wrapped/matrix.rb', line 286

def rasterheight(n, num_pixels)
  IupLib.IupSetAttribute(@handle, "RASTERHEIGHT#{n}", num_pixels.to_s)
end

#rastersizeObject

:attr: rastersize Size of the container, in pixels, value as “widthxheight”.



137
# File 'lib/wrapped/matrix.rb', line 137

define_attribute :rastersize

#rasterwidth(n, num_pixels) ⇒ Object

Defines column width in pixels.

  • n - column number

  • num_pixels - new width of column n



246
247
248
# File 'lib/wrapped/matrix.rb', line 246

def rasterwidth(n, num_pixels)
  IupLib.IupSetAttribute(@handle, "RASTERWIDTH#{n}", num_pixels.to_s)
end

#readonlyObject

:attr: readonly Disable editing of cells. Values ‘yes’ / ‘no’.



121
# File 'lib/wrapped/matrix.rb', line 121

define_attribute :readonly

#redrawObject

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



361
362
363
# File 'lib/wrapped/matrix.rb', line 361

def redraw
  IupLib.IupSetAttribute(@handle, 'redraw', 'all')
end

#release_cb=(callback) ⇒ Object



456
457
458
459
460
461
462
463
464
# File 'lib/wrapped/matrix.rb', line 456

def release_cb= callback
  unless callback.arity == 3
    raise ArgumentError, 'release_cb callback must take 3 arguments: (lin, col, status)'
  end
  cb = Proc.new do |ih, lin, col, status|
    callback.call lin, col, status
  end
  define_callback cb, 'RELEASE_CB', :i_s
end

#resizedragObject

:attr: resizedrag Dynamically resize the column while dragging, values ‘yes’ / ‘no’.



233
# File 'lib/wrapped/matrix.rb', line 233

define_attribute :resizedrag

#resizematrixObject

:attr: resizematrix Allows column widths to be adjusted manually by users, values ‘yes’ / ‘no’.



228
# File 'lib/wrapped/matrix.rb', line 228

define_attribute :resizematrix

#resizematrix_cb=(callback) ⇒ Object



475
476
477
478
479
480
481
482
483
# File 'lib/wrapped/matrix.rb', line 475

def resizematrix_cb= callback
  unless callback.arity == 2
    raise ArgumentError, 'resizematrix_cb callback must take 2 arguments: (width, height)'
  end
  cb = Proc.new do |ih, width, height|
    callback.call width, height
  end
  define_callback cb, 'RESIZEMATRIX_CB', :i_s
end

#screenpositionObject

:attr_reader: screenposition Returns position in pixels on screen as “x,y”.



142
# File 'lib/wrapped/matrix.rb', line 142

define_reader :screenposition

#scrollbarObject

:attr: scrollbar Changed to ‘yes’, cf. Iup::Canvas#scrollbar.



381
# File 'lib/wrapped/matrix.rb', line 381

define_attribute :scrollbar

#scrolltop_cb=(callback) ⇒ Object



547
548
549
550
551
552
553
554
555
# File 'lib/wrapped/matrix.rb', line 547

def scrolltop_cb= callback
  unless callback.arity == 2
    raise ArgumentError, 'scrolltop_cb callback must take 2 arguments: (lin, col)'
  end
  cb = Proc.new do |ih, lin, col|
    callback.call lin, col
  end
  define_callback cb, 'SCROLLTOP_CB', :i_s
end

#set(lin, col, value) ⇒ Object

Set value of cell:

  • lin - line number of cell

  • col - column number of cell

  • value - new value for cell



61
62
63
# File 'lib/wrapped/matrix.rb', line 61

def set(lin, col, value)
  IupLib.IupSetAttribute(@handle, "#{lin}:#{col}", value.to_s)
end

#tipObject

:attr: tip Tooltip string.



147
# File 'lib/wrapped/matrix.rb', line 147

define_attribute :tip

#usetitlesizeObject

:attr: usetitlesize If set, defines cell size based on the title size. Values ‘yes’ / ‘no’.



239
# File 'lib/wrapped/matrix.rb', line 239

define_attribute :usetitlesize

#value_cb=(callback) ⇒ Object



565
566
567
568
569
570
571
572
573
# File 'lib/wrapped/matrix.rb', line 565

def value_cb= callback
  unless callback.arity == 2
    raise ArgumentError, 'value_cb callback must take 2 arguments: (lin, col)'
  end
  cb = Proc.new do |ih, lin, col|
    callback.call lin, col
  end
  define_callback cb, 'VALUE_CB', :i_s
end

#width(n, size) ⇒ Object

Defines column width in SIZE units

  • n - column number

  • size - new size of column n



253
254
255
# File 'lib/wrapped/matrix.rb', line 253

def width(n, size)
  IupLib.IupSetAttribute(@handle, "WIDTH#{n}", size.to_s)
end

#widthdefObject

:attr: widthdef Default width of column in SIZE units, default value is 80.



260
# File 'lib/wrapped/matrix.rb', line 260

define_attribute :widthdef