iup-ffi 0.13.0-x86_64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/LICENCE.md +21 -0
  3. data/README.md +139 -0
  4. data/lib/iup-ffi-plain.rb +51 -0
  5. data/lib/iup-ffi.rb +70 -0
  6. data/lib/library/linux/libcd.so +0 -0
  7. data/lib/library/linux/libim.so +0 -0
  8. data/lib/library/linux/libiup.so +0 -0
  9. data/lib/library/linux/libiup_scintilla.so +0 -0
  10. data/lib/library/linux/libiupcd.so +0 -0
  11. data/lib/library/linux/libiupcontrols.so +0 -0
  12. data/lib/library/linux/libiupim.so +0 -0
  13. data/lib/library/linux/libiupimglib.so +0 -0
  14. data/lib/plain/iupcdlib.rb +158 -0
  15. data/lib/plain/iupcontrolslib.rb +28 -0
  16. data/lib/plain/iupimglib.rb +15 -0
  17. data/lib/plain/iupimlib.rb +18 -0
  18. data/lib/plain/iuplib.rb +354 -0
  19. data/lib/plain/scintilla-lib.rb +17 -0
  20. data/lib/wrapped/attribute-builders.rb +93 -0
  21. data/lib/wrapped/attribute-reference.rb +27 -0
  22. data/lib/wrapped/background-box.rb +37 -0
  23. data/lib/wrapped/button.rb +152 -0
  24. data/lib/wrapped/callback-setter.rb +78 -0
  25. data/lib/wrapped/canvas.rb +698 -0
  26. data/lib/wrapped/colorbar.rb +212 -0
  27. data/lib/wrapped/colordialog.rb +121 -0
  28. data/lib/wrapped/common-attributes.rb +34 -0
  29. data/lib/wrapped/constants.rb +504 -0
  30. data/lib/wrapped/dial.rb +129 -0
  31. data/lib/wrapped/dialog.rb +309 -0
  32. data/lib/wrapped/drag-drop-attributes.rb +98 -0
  33. data/lib/wrapped/dynamic-fill-methods.rb +22 -0
  34. data/lib/wrapped/expander.rb +128 -0
  35. data/lib/wrapped/filedialog.rb +168 -0
  36. data/lib/wrapped/fill.rb +29 -0
  37. data/lib/wrapped/fontdialog.rb +71 -0
  38. data/lib/wrapped/frame.rb +70 -0
  39. data/lib/wrapped/gridbox.rb +188 -0
  40. data/lib/wrapped/hbox.rb +90 -0
  41. data/lib/wrapped/image-attributes.rb +58 -0
  42. data/lib/wrapped/image.rb +178 -0
  43. data/lib/wrapped/iup-global.rb +46 -0
  44. data/lib/wrapped/label.rb +110 -0
  45. data/lib/wrapped/link.rb +54 -0
  46. data/lib/wrapped/list.rb +567 -0
  47. data/lib/wrapped/matrix.rb +575 -0
  48. data/lib/wrapped/menu.rb +91 -0
  49. data/lib/wrapped/menuitem.rb +150 -0
  50. data/lib/wrapped/messagedialog.rb +127 -0
  51. data/lib/wrapped/progressbar.rb +91 -0
  52. data/lib/wrapped/progressdialog.rb +85 -0
  53. data/lib/wrapped/radio.rb +74 -0
  54. data/lib/wrapped/scintilla.rb +1112 -0
  55. data/lib/wrapped/scrollbar-attributes.rb +178 -0
  56. data/lib/wrapped/scrollbox.rb +40 -0
  57. data/lib/wrapped/separator.rb +24 -0
  58. data/lib/wrapped/splitbox.rb +114 -0
  59. data/lib/wrapped/stretchbox.rb +70 -0
  60. data/lib/wrapped/submenu.rb +58 -0
  61. data/lib/wrapped/tabs.rb +223 -0
  62. data/lib/wrapped/text.rb +382 -0
  63. data/lib/wrapped/timer.rb +82 -0
  64. data/lib/wrapped/toggle.rb +150 -0
  65. data/lib/wrapped/tree.rb +612 -0
  66. data/lib/wrapped/val.rb +162 -0
  67. data/lib/wrapped/vbox.rb +93 -0
  68. data/lib/wrapped/widget.rb +282 -0
  69. data/lib/wrapped/zbox.rb +80 -0
  70. metadata +131 -0
@@ -0,0 +1,575 @@
1
+ module Iup
2
+
3
+ # An interactive control, used to display a matrix or grid of strings on
4
+ # a canvas. The API documentation
5
+ # can only hint at the use of this control. For more information see
6
+ # Tecgraf's documentation on
7
+ # {IupMatrix}[https://www.tecgraf.puc-rio.br/iup/en/ctrl/iupmatrix.html].
8
+ #
9
+ # === Example
10
+ #
11
+ # matrix =Iup::Matrix.new do |m|
12
+ # m.numlin = 3
13
+ # m.numcol = 3
14
+ # m.set(0, 1, "Country")
15
+ # m.set(0, 2, "Capital")
16
+ # m.set(0, 3, "Population")
17
+ # m.set(1, 1, "England")
18
+ # m.set(1, 2, "London")
19
+ # m.set(1, 3, "58,620,100")
20
+ # m.set(2, 1, "Scotland")
21
+ # m.set(2, 2, "Edinburgh")
22
+ # m.set(2, 3, "5,546,900")
23
+ # m.set(3, 1, "Wales")
24
+ # m.set(3, 2, "Cardiff")
25
+ # m.set(3, 3, "3,186,600")
26
+ # m.readonly = "yes"
27
+ # end
28
+ #
29
+ # dlg = Iup::Dialog.new(matrix) do |d|
30
+ # d.title = "Matrix Example"
31
+ # end.map
32
+ #
33
+ # dlg.show
34
+ #
35
+ # Note that the dialog must be mapped before being shown, to
36
+ # correctly display the matrix.
37
+ #
38
+ class Matrix < Iup::Widget
39
+ # Creates a new instance.
40
+ # If a block is given, the new instance is yielded to it.
41
+ def initialize
42
+ open_controls
43
+ @handle = ControlsLib.IupMatrix ""
44
+
45
+ # run any provided block on instance, to set up further attributes
46
+ yield self if block_given?
47
+ end
48
+
49
+ # Get value of cell:
50
+ # * +lin+ - line number of cell
51
+ # * +col+ - column number of cell
52
+ # Returns string value of cell (lin, col).
53
+ def get(lin, col)
54
+ IupLib.IupGetAttribute(@handle, "#{lin}:#{col}").first
55
+ end
56
+
57
+ # Set value of cell:
58
+ # * +lin+ - line number of cell
59
+ # * +col+ - column number of cell
60
+ # * +value+ - new value for cell
61
+ def set(lin, col, value)
62
+ IupLib.IupSetAttribute(@handle, "#{lin}:#{col}", value.to_s)
63
+ end
64
+
65
+ # -- attributes
66
+
67
+ # :section: General attributes
68
+
69
+ ##
70
+ # :attr: cursor
71
+ # Defines the mouse shape / cursor for the matrix.
72
+ # Available cursors are shown in the
73
+ # {Tecgraf documentation}[http://www.tecgraf.puc-rio.br/iup/en/attrib/iup_cursor.html].
74
+ define_attribute :cursor
75
+
76
+ ##
77
+ # :attr: focuscell
78
+ # Defines current cell, in format "L:C" - default "1:1".
79
+ define_attribute :focuscell
80
+
81
+ ##
82
+ # :attr: flat
83
+ # Removes 3D appearance from matrix, values 'yes' / 'no'.
84
+ define_attribute :flat
85
+
86
+ ##
87
+ # :attr: flatscrollbar
88
+ # Enables flat scrollbars, values 'yes' / 'no'.
89
+ define_attribute :flatscrollbar
90
+
91
+ ##
92
+ # :attr: hidefocus
93
+ # Controls display of focus mark when drawing matrix.
94
+ # Values 'yes' / 'no'.
95
+ define_attribute :hidefocus
96
+
97
+ ##
98
+ # :attr: hiddentextmarks
99
+ # Use a "..." or crop text when longer than cell, values 'yes' / 'no'.
100
+ define_attribute :hiddentextmarks
101
+
102
+ ##
103
+ # :attr: hlcolor
104
+ # Overlay color for selected cells.
105
+ define_attribute :hlcolor
106
+
107
+ ##
108
+ # :attr_writer: origin
109
+ # Scroll visible area to given cell: "L:C" format, use a "*"
110
+ # for L or C to scroll to a column or line.
111
+ define_writer :origin
112
+
113
+ ##
114
+ # :attr: originoffset
115
+ # Defines drag offset of origin: if changed, change #origin too.
116
+ define_attribute :originoffset
117
+
118
+ ##
119
+ # :attr: readonly
120
+ # Disable editing of cells. Values 'yes' / 'no'.
121
+ define_attribute :readonly
122
+
123
+ ##
124
+ # :attr: expand
125
+ # Allows container to fill available space in indicated direction.
126
+ # Values 'no' / 'horizontal' / 'vertical' / 'yes'.
127
+ define_attribute :expand
128
+
129
+ ##
130
+ # :attr_reader: position
131
+ # Returns position in pixels within client window as "x,y".
132
+ define_reader :position
133
+
134
+ ##
135
+ # :attr: rastersize
136
+ # Size of the container, in pixels, value as "widthxheight".
137
+ define_attribute :rastersize
138
+
139
+ ##
140
+ # :attr_reader: screenposition
141
+ # Returns position in pixels on screen as "x,y".
142
+ define_reader :screenposition
143
+
144
+ ##
145
+ # :attr: tip
146
+ # Tooltip string.
147
+ define_attribute :tip
148
+
149
+ # :section: Cell attributes
150
+
151
+ # Sets the background color of a column:
152
+ # * +col+ - column to change
153
+ # * +color+ - color in 'r g b' format
154
+ def bgcolor_column(col, color)
155
+ IupLib.IupSetAttribute(@handle, "BGCOLOR*:#{col}", color)
156
+ end
157
+
158
+ # Sets the background color of a line:
159
+ # * +lin+ - line to change
160
+ # * +color+ - color in 'r g b' format
161
+ def bgcolor_line(lin, color)
162
+ IupLib.IupSetAttribute(@handle, "BGCOLOR#{lin}:*", color)
163
+ end
164
+
165
+ # Sets the background color of a cell:
166
+ # * +col+ - column to change
167
+ # * +lin+ - line to change
168
+ # * +color+ - color in 'r g b' format
169
+ def bgcolor_cell(col, lin, color)
170
+ IupLib.IupSetAttribute(@handle, "BGCOLOR#{lin}:#{col}", color)
171
+ end
172
+
173
+ # Sets the foreground color of a column:
174
+ # * +col+ - column to change
175
+ # * +color+ - color in 'r g b' format
176
+ def fgcolor_column(col, color)
177
+ IupLib.IupSetAttribute(@handle, "FGCOLOR*:#{col}", color)
178
+ end
179
+
180
+ # Sets the foreground color of a line:
181
+ # * +lin+ - line to change
182
+ # * +color+ - color in 'r g b' format
183
+ def fgcolor_line(lin, color)
184
+ IupLib.IupSetAttribute(@handle, "FGCOLOR#{lin}:*", color)
185
+ end
186
+
187
+ # Sets the foreground color of a cell:
188
+ # * +col+ - column to change
189
+ # * +lin+ - line to change
190
+ # * +color+ - color in 'r g b' format
191
+ def fgcolor_cell(col, lin, color)
192
+ IupLib.IupSetAttribute(@handle, "FGCOLOR#{lin}:#{col}", color)
193
+ end
194
+
195
+ # Sets the font of a column:
196
+ # * +col+ - column to change
197
+ # * +font+ - font
198
+ def font_column(col, font)
199
+ IupLib.IupSetAttribute(@handle, "FONT*:#{col}", font)
200
+ end
201
+
202
+ # Sets the font of a line:
203
+ # * +lin+ - line to change
204
+ # * +font+ - font
205
+ def bgcolor_line(lin, font)
206
+ IupLib.IupSetAttribute(@handle, "FONT#{lin}:*", font)
207
+ end
208
+
209
+ # Sets the font of a cell:
210
+ # * +col+ - column to change
211
+ # * +lin+ - line to change
212
+ # * +font+ - font
213
+ def font_cell(col, lin, font)
214
+ IupLib.IupSetAttribute(@handle, "FONT#{lin}:#{col}", font)
215
+ end
216
+
217
+ # :section: Size attributes
218
+
219
+ ##
220
+ # :attr: limitexpand
221
+ # Limits expansion to the largest size where all cells are visible.
222
+ define_attribute :limitexpand
223
+
224
+ ##
225
+ # :attr: resizematrix
226
+ # Allows column widths to be adjusted manually by users, values
227
+ # 'yes' / 'no'.
228
+ define_attribute :resizematrix
229
+
230
+ ##
231
+ # :attr: resizedrag
232
+ # Dynamically resize the column while dragging, values 'yes' / 'no'.
233
+ define_attribute :resizedrag
234
+
235
+ ##
236
+ # :attr: usetitlesize
237
+ # If set, defines cell size based on the title size.
238
+ # Values 'yes' / 'no'.
239
+ define_attribute :usetitlesize
240
+
241
+ # :section: Column size attributes
242
+
243
+ # Defines column width in pixels.
244
+ # * +n+ - column number
245
+ # * +num_pixels+ - new width of column n
246
+ def rasterwidth(n, num_pixels)
247
+ IupLib.IupSetAttribute(@handle, "RASTERWIDTH#{n}", num_pixels.to_s)
248
+ end
249
+
250
+ # Defines column width in SIZE units
251
+ # * +n+ - column number
252
+ # * +size+ - new size of column n
253
+ def width(n, size)
254
+ IupLib.IupSetAttribute(@handle, "WIDTH#{n}", size.to_s)
255
+ end
256
+
257
+ ##
258
+ # :attr: widthdef
259
+ # Default width of column in SIZE units, default value is 80.
260
+ define_attribute :widthdef
261
+
262
+ # Defines minimum column width in SIZE units.
263
+ # * +n+ - column number
264
+ # * +size+ - new size of column n
265
+ def mincolwidth(n, size)
266
+ IupLib.IupSetAttribute(@handle, "MINCOLWIDTH#{n}", size.to_s)
267
+ end
268
+
269
+ # :section: Line size attributes
270
+
271
+ # Defines line height in SIZE units:
272
+ # * +n+ - line number
273
+ # * +size+ - new size of line n
274
+ def height(n, size)
275
+ IupLib.IupSetAttribute(@handle, "HEIGHT#{n}", size.to_s)
276
+ end
277
+
278
+ ##
279
+ # :attr: height
280
+ # Default height of line in SIZE units, default value is 8.
281
+ define_attribute :heightdef
282
+
283
+ # Defines line height in pixels:
284
+ # * +n+ - line number
285
+ # * +num_pixels+ - new length of line n
286
+ def rasterheight(n, num_pixels)
287
+ IupLib.IupSetAttribute(@handle, "RASTERHEIGHT#{n}", num_pixels.to_s)
288
+ end
289
+
290
+ # :section: Number of cells attributes
291
+
292
+ ##
293
+ # :attr_writer: addcol
294
+ # Adds a new column to matrix after the given column.
295
+ define_writer :addcol
296
+
297
+ ##
298
+ # :attr_writer: addlin
299
+ # Adds a new line to matrix after the given line.
300
+ define_writer :addlin
301
+
302
+ ##
303
+ # :attr_writer: delcol
304
+ # Removes the given column from the matrix.
305
+ define_writer :delcol
306
+
307
+ ##
308
+ # :attr_writer: dellin
309
+ # Removes the given line from the matrix.
310
+ define_writer :dellin
311
+
312
+ ##
313
+ # :attr: numcol
314
+ # Defines the number of columns in the matrix, must be an integer.
315
+ define_attribute :numcol
316
+
317
+ ##
318
+ # :attr: numcol_visible
319
+ # Specifies the number of visible columns to include in calculating the
320
+ # Natural size.
321
+ define_attribute :numcol_visible
322
+
323
+ ##
324
+ # :attr: numlin_noscroll
325
+ # Number of columns that are non-scrollable, not counting the title
326
+ # column.
327
+ define_attribute :numcol_noscroll
328
+
329
+ ##
330
+ # :attr: numlin
331
+ # Defines the number of lines in the matrix, must be an integer.
332
+ define_attribute :numlin
333
+
334
+ ##
335
+ # :attr: numlin_visible
336
+ # Specifies the number of visible lines to include in calculating the
337
+ # Natural size.
338
+ define_attribute :numlin_visible
339
+
340
+ ##
341
+ # :attr: numlin_noscroll
342
+ # Number of lines that are non-scrollable, not counting the title
343
+ # line.
344
+ define_attribute :numlin_noscroll
345
+
346
+ ##
347
+ # :attr: noscrollastitle
348
+ # Makes the non-scrollable lines/columns appear like the title line/column,
349
+ # values 'yes' / 'no'.
350
+ define_attribute :noscrollastitle
351
+
352
+ # :section: Action attributes
353
+
354
+ # Instructs matrix of data change, and that it must redraw itself.
355
+ # Value can be:
356
+ # * 'all' - redraw the whole matrix
357
+ # * 'Ld' - redraws line d
358
+ # * 'Ld1-d2' - redraws lines d1 to d2
359
+ # * 'Cd' - redraws column c
360
+ # * 'Cd1-d2' - redraws columns d1 to d2
361
+ def redraw
362
+ IupLib.IupSetAttribute(@handle, 'redraw', 'all')
363
+ end
364
+
365
+ ##
366
+ # :attr_writer: fittosize
367
+ # Forces line/column sizes so the matrix visible fits in
368
+ # the current displayed size.
369
+ define_writer :fittosize
370
+
371
+ # :section: Canvas attributes
372
+
373
+ ##
374
+ # :attr: border
375
+ # Changed to 'no', cf. Iup::Canvas#border.
376
+ define_attribute :border
377
+
378
+ ##
379
+ # :attr: scrollbar
380
+ # Changed to 'yes', cf. Iup::Canvas#scrollbar.
381
+ define_attribute :scrollbar
382
+
383
+ # :section: Callbacks
384
+
385
+ ##
386
+ # :attr_writer: action_cb
387
+ # Callback called when a keyboard event occurs.
388
+ # Callback must respond to +call+ and takes 5 arguments: (key, lin, col, edition, value)
389
+ # * +key+ - identifier of pressed key, see {Key definitions}[../Iup.html#Key+definitions]
390
+ # * +lin+ - line of selected cell
391
+ # * +col+ - column of selected cell
392
+ # * +edition+ - is 1 if in edit mode, or 0 otherwise
393
+ # * +value+ - varies with edit mode: can be current value, string with key character, or "".
394
+ # Returns Iup::Default to validate the key, Iup::Ignore to ignore,
395
+ # Iup::Continue forwards the key, or identifier of the key to be treated
396
+
397
+ # --
398
+ def action_cb= callback
399
+ unless callback.arity == 5
400
+ raise ArgumentError, 'action_cb callback must take 5 arguments: (key, lin, col, edition, value)'
401
+ end
402
+ cb = Proc.new do |ih, key, lin, col, edition, value|
403
+ callback.call key, lin, col, edition, value
404
+ end
405
+ define_callback cb, 'ACTION_CB', :i_s
406
+ end
407
+
408
+ ##
409
+ # :attr_writer: click_cb
410
+ # Callback called when any mouse button is pressed over a cell.
411
+ # Callback must respond to +call+ and takes 3 arguments: (lin, col, status)
412
+ # * +lin+ - line of selected cell
413
+ # * +col+ - column of selected cell
414
+ # * +status+ - of mouse buttons and some keyboard keys.
415
+ # Return Iup::IGNORE to avoid refresh of display, or Iup::DEFAULT.
416
+
417
+ # --
418
+ def click_cb= callback
419
+ unless callback.arity == 3
420
+ raise ArgumentError, 'click_cb callback must take 3 arguments: (lin, col, status)'
421
+ end
422
+ cb = Proc.new do |ih, lin, col, status|
423
+ callback.call lin, col, status
424
+ end
425
+ define_callback cb, 'CLICK_CB', :i_s
426
+ end
427
+
428
+ ##
429
+ # :attr_writer: colresize_cb
430
+ # Callback called when a column is interactively resized.
431
+ # Callback must respond to +call+ and takes 1 argument: (col)
432
+ # * +col+ - column being resized
433
+ # Return Iup::IGNORE to avoid refresh of display, or Iup::DEFAULT.
434
+
435
+ # --
436
+ def colresize_cb= callback
437
+ unless callback.arity == 1
438
+ raise ArgumentError, 'colresize_cb callback must take 1 argument: (col)'
439
+ end
440
+ cb = Proc.new do |ih, col|
441
+ callback.call col
442
+ end
443
+ define_callback cb, 'COLRESIZE_CB', :i_s
444
+ end
445
+
446
+ ##
447
+ # :attr_writer: release_cb
448
+ # Callback called when any mouse button is released over a cell.
449
+ # Callback must respond to +call+ and takes 3 arguments: (lin, col, status)
450
+ # * +lin+ - line of selected cell
451
+ # * +col+ - column of selected cell
452
+ # * +status+ - of mouse buttons and some keyboard keys.
453
+ # Return Iup::IGNORE to avoid refresh of display, or Iup::DEFAULT.
454
+
455
+ # --
456
+ def release_cb= callback
457
+ unless callback.arity == 3
458
+ raise ArgumentError, 'release_cb callback must take 3 arguments: (lin, col, status)'
459
+ end
460
+ cb = Proc.new do |ih, lin, col, status|
461
+ callback.call lin, col, status
462
+ end
463
+ define_callback cb, 'RELEASE_CB', :i_s
464
+ end
465
+
466
+ ##
467
+ # :attr_writer: resizematrix_cb
468
+ # Callback called after the element size has been updated, but
469
+ # before the cells are refreshed.
470
+ # Callback must respond to +call+ and takes 2 arguments: (width, height)
471
+ # * +width+ - of internal area in pixels
472
+ # * +height+ - of internal area in pixels
473
+
474
+ # --
475
+ def resizematrix_cb= callback
476
+ unless callback.arity == 2
477
+ raise ArgumentError, 'resizematrix_cb callback must take 2 arguments: (width, height)'
478
+ end
479
+ cb = Proc.new do |ih, width, height|
480
+ callback.call width, height
481
+ end
482
+ define_callback cb, 'RESIZEMATRIX_CB', :i_s
483
+ end
484
+
485
+ ##
486
+ # :attr_writer: mousemove_cb
487
+ # Callback called when mouse has moved over the matrix.
488
+ # Callback must respond to +call+ and takes 2 arguments: (lin, col)
489
+ # * +lin+ - line of current mouse position
490
+ # * +col+ - column of current mouse position
491
+
492
+ # --
493
+ def mousemove_cb= callback
494
+ unless callback.arity == 2
495
+ raise ArgumentError, 'mousemove_cb callback must take 2 arguments: (lin, col)'
496
+ end
497
+ cb = Proc.new do |ih, lin, col|
498
+ callback.call lin, col
499
+ end
500
+ define_callback cb, 'MOUSEMOVE_CB', :i_s
501
+ end
502
+
503
+ ##
504
+ # :attr_writer: enteritem_cb
505
+ # Callback called when matrix cell is selected, matrix gets focus etc.
506
+ # Callback must respond to +call+ and takes 2 arguments: (lin, col)
507
+ # * +lin+ - line of selected cell
508
+ # * +col+ - column of selected cell
509
+
510
+ # --
511
+ def enteritem_cb= callback
512
+ unless callback.arity == 2
513
+ raise ArgumentError, 'enteritem_cb callback must take 2 arguments: (lin, col)'
514
+ end
515
+ cb = Proc.new do |ih, lin, col|
516
+ callback.call lin, col
517
+ end
518
+ define_callback cb, 'ENTERITEM_CB', :i_s
519
+ end
520
+
521
+ ##
522
+ # :attr_writer: leaveitem_cb
523
+ # Callback called when cell is no longer current cell, matrix loses focus etc.
524
+ # Callback must respond to +call+ and takes 2 arguments: (lin, col)
525
+ # * +lin+ - line of selected cell
526
+ # * +col+ - column of selected cell
527
+
528
+ # --
529
+ def leaveitem_cb= callback
530
+ unless callback.arity == 2
531
+ raise ArgumentError, 'leaveitem_cb callback must take 2 arguments: (lin, col)'
532
+ end
533
+ cb = Proc.new do |ih, lin, col|
534
+ callback.call lin, col
535
+ end
536
+ define_callback cb, 'LEAVEITEM_CB', :i_s
537
+ end
538
+
539
+ ##
540
+ # :attr_writer: scrolltop_cb
541
+ # Callback called when matrix is scrolled.
542
+ # Callback must respond to +call+ and takes 2 arguments: (lin, col)
543
+ # * +lin+ - line of cell currently in top-left corner
544
+ # * +col+ - column of cell currently in top-left corner
545
+
546
+ # --
547
+ def scrolltop_cb= callback
548
+ unless callback.arity == 2
549
+ raise ArgumentError, 'scrolltop_cb callback must take 2 arguments: (lin, col)'
550
+ end
551
+ cb = Proc.new do |ih, lin, col|
552
+ callback.call lin, col
553
+ end
554
+ define_callback cb, 'SCROLLTOP_CB', :i_s
555
+ end
556
+
557
+ ##
558
+ # :attr_writer: value_cb
559
+ # Callback called to retrieve value of a cell.
560
+ # Callback must respond to +call+ and takes 2 arguments: (lin, col)
561
+ # * +lin+ - line of cell
562
+ # * +col+ - column of cell
563
+
564
+ # --
565
+ def value_cb= callback
566
+ unless callback.arity == 2
567
+ raise ArgumentError, 'value_cb callback must take 2 arguments: (lin, col)'
568
+ end
569
+ cb = Proc.new do |ih, lin, col|
570
+ callback.call lin, col
571
+ end
572
+ define_callback cb, 'VALUE_CB', :i_s
573
+ end
574
+ end
575
+ end
@@ -0,0 +1,91 @@
1
+ module Iup
2
+
3
+ # A menu is a collection of menu items, submenus, and separators.
4
+ # It is usually placed within a Dialog, or launched from an
5
+ # action, using +popup+.
6
+ #
7
+ # This widget basically acts as a container for other menu
8
+ # widgets, but setting the +radio+ attribute makes those other
9
+ # widgets act as a radio group.
10
+ #
11
+ # === Example
12
+ #
13
+ # The following example creates open, save and exit menu items, and places
14
+ # them onto a menu. The save menu item is initially inactive. Notice
15
+ # the use of a separator, and how a SubMenu adds a clickable title to the
16
+ # file menu.
17
+ #
18
+ # item_open = Iup::MenuItem.new('Open')
19
+ # item_save = Iup::MenuItem.new('Save') do |i|
20
+ # i.active = 'NO'
21
+ # end
22
+ # item_exit = Iup::MenuItem.new('Exit', ->{ Iup::CLOSE })
23
+ # file_menu = Iup::Menu.new(
24
+ # item_open, item_save,
25
+ # Iup::Separator.new,
26
+ # item_exit)
27
+ # menu = Iup::Menu.new(Iup::SubMenu.new('File', file_menu))
28
+ #
29
+ # See also: MenuItem, Separator, SubMenu
30
+ #
31
+ class Menu < Iup::Widget
32
+
33
+ # Creates instance of a menu for given menu widgets.
34
+ # If a block is given, the new instance is yielded to it.
35
+ #
36
+ # * +widgets+ - one or more menu items, sub menus or separators.
37
+ #
38
+ def initialize *widgets
39
+ @handle = IupLib.IupMenu *widget_list(widgets)
40
+
41
+ # run any provided block on instance, to set up further attributes
42
+ yield self if block_given?
43
+ end
44
+
45
+ # -- attributes
46
+
47
+ ##
48
+ # :attr: radio
49
+ # If set, makes children act as a radio group. Values 'yes' / 'no'.
50
+ define_attribute :radio
51
+
52
+ ##
53
+ # :attr_reader: wid
54
+ # Native widget identifier.
55
+ define_reader :wid
56
+
57
+ # :section: Callbacks
58
+
59
+ ##
60
+ # :attr_writer: open_cb
61
+ # Callback called just before the menu is opened.
62
+ # Callback must respond to +call+ and take no arguments.
63
+
64
+ # --
65
+ def open_cb= callback
66
+ unless callback.arity.zero?
67
+ raise ArgumentError, 'open callback must take 0 arguments'
68
+ end
69
+ cb = Proc.new do |ih|
70
+ callback.call
71
+ end
72
+ define_callback cb, 'OPEN_CB', :plain
73
+ end
74
+
75
+ ##
76
+ # :attr_writer: menuclose_cb
77
+ # Callback called just after the menu is closed.
78
+ # Callback must respond to +call+ and take no arguments.
79
+
80
+ # --
81
+ def menuclose_cb= callback
82
+ unless callback.arity.zero?
83
+ raise ArgumentError, 'menuclose callback must take 0 arguments'
84
+ end
85
+ cb = Proc.new do |ih|
86
+ callback.call
87
+ end
88
+ define_callback cb, 'MENUCLOSE_CB', :plain
89
+ end
90
+ end
91
+ end