Class: Iup::List
- Includes:
- ButtonCallback, DragDropAttributes
- Defined in:
- lib/wrapped/list.rb
Overview
A dynamic control presenting a list of options to the user. The list may be visible, or a hidden, drop-down list. Optionally, items may be editable.
Example
(1) Simple list, responding to double-click selection:
Iup::List.new do |l|
l.item(1, "Java")
l.item(2, "Ruby")
l.item(3, "Scheme")
l.spacing = 4
l.size = "80x100"
l.dblclick_cb = ->(index, text) {
puts "DBL CLICK ON #{index} with #{text}"
Iup::DEFAULT
}
end
(2) Dropdown list, responding to changes in value:
Iup::List.new do |l|
l.item(1, "Java")
l.item(2, "Ruby")
l.item(3, "Scheme")
l.spacing = 4
l.dropdown = 'yes'
l.valuechanged_cb = ->{
puts "New value index is #{l.value}, text is #{l.item(l.value)}"
Iup::DEFAULT
}
end
Note that the C implementation of Iup’s list is 1-indexed: this is preserved in the wrapped version, for consistency.
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#action=(callback) ⇒ Object
–.
-
#append ⇒ Object
:attr_writer: append (with editbox set) appends given string to end of list.
-
#appenditem(text, image = nil) ⇒ Object
Adds given item to end of list.
-
#autohide ⇒ Object
:attr: autohide If set, scrollbars are only shown if necessary, values ‘yes’ / ‘no’.
-
#canfocus ⇒ Object
:attr: canfocus If set, the control can gain focus, values ‘yes’ / ‘no’.
-
#caret ⇒ Object
:attr: caret (with editbox set) ‘col’, in single-line mode, or ‘lin,col’ in multi-line mode.
-
#caret_cb=(callback) ⇒ Object
–.
-
#caretpos ⇒ Object
:attr: caretpos (with editbox set) Index of character of the insertion point.
-
#clipboard ⇒ Object
:attr_writer: clipboard (with editbox set) ‘clear’ / ‘copy’ / ‘cut’ / ‘paste’.
-
#count ⇒ Object
:attr_reader: count Returns the number of items in the list.
-
#dblclick_cb=(callback) ⇒ Object
–.
-
#dragdrop_cb=(callback) ⇒ Object
–.
-
#dragdroplist ⇒ Object
:attr: dragdroplist If yes, enables drag and drop between lists: ‘yes’ / ‘no’.
-
#dropdown ⇒ Object
:attr: dropdown ‘yes’ / ‘no’, if set, only the selected item is visible.
-
#dropdown_cb=(callback) ⇒ Object
–.
-
#dropfilestarget ⇒ Object
:attr: dropfilestarget Enable or disable the drop of files: ‘no’ / ‘yes’.
-
#edit_cb=(callback) ⇒ Object
–.
-
#editbox ⇒ Object
:attr: editbox ‘yes’ / ‘no’, if set adds an editable box to the list.
-
#expand ⇒ Object
:attr: expand Allows list to fill available space in indicated direction.
-
#initialize {|_self| ... } ⇒ List
constructor
Creates a new instance.
-
#insert ⇒ Object
:attr_writer: insert (with editbox set) Places a given string at current caret position, overwriting any current selection.
-
#insertitem(index, text, image = nil) ⇒ Object
Insert item at given index.
-
#item(index, text = nil, image = nil) ⇒ Object
:call-seq: list.item(index) # retrieves item list.item(index, text) # sets text list.item(index, text, image) # sets text and image .
-
#mask ⇒ Object
:attr: mask (with editbox set) Defines a mask to filter text input.
-
#motion_cb=(callback) ⇒ Object
–.
-
#multiple ⇒ Object
:attr: multiple If set, allows selection of multiple items: values ‘yes’ / ‘no’.
-
#multiselect_cb=(callback) ⇒ Object
–.
-
#nc ⇒ Object
:attr: nc (with editbox set) Maximum number of characters allowed for keyboard input (0 allows an indefinite number).
-
#padding ⇒ Object
:attr: padding (with editbox set) Margin in x and y directions, value as “mxn”.
-
#position ⇒ Object
:attr_reader: position returns position in pixels within client window as “x,y”.
-
#rastersize ⇒ Object
:attr: rastersize Size of the list, in pixels, value as “widthxheight”.
-
#readonly ⇒ Object
:attr: readonly (with editbox set) If set, prevents the user changing contents: values ‘yes’ / ‘no’.
-
#removeitem(item) ⇒ Object
Removes given item from the list: *
list- index of item to remove (1-indexed), or ‘all’, to remove all items. -
#screenposition ⇒ Object
:attr_reader: screenposition returns position in pixels on screen as “x,y”.
-
#scrollbar ⇒ Object
:attr: scrollbar When in multiline mode, enables a scrollbar.
-
#scrollto ⇒ Object
:attr_writer: scrollto (with editbox set) ‘col’ Scrolls to make given column number visible, in single-line mode.
-
#scrolltopos ⇒ Object
:attr_writer: scrolltopos (with editbox set) Scrolls to make character ‘number’ visible.
-
#selectedtext ⇒ Object
:attr: selectedtext (with editbox set) Reads or overwrites the current selection.
-
#selection ⇒ Object
:attr: selection (with editbox set) Selects text as ‘col1:col2’ (single-line) / ‘lin1,col1:lin2,col2’ (multi-line) / ‘all’ / ‘none’.
-
#selectionpos ⇒ Object
:attr: selectionpos (with editbox set) Selects text between character positions: ‘pos1:pos2’ / ‘all’ / ‘none’.
-
#showdragdrop ⇒ Object
:attr: showdragdrop If set, enables internal drag/drop: values ‘yes’ / ‘no’.
-
#showdropdown ⇒ Object
:attr_writer: showdropdown Shows the dropdown list, if dropdown=yes.
-
#sort ⇒ Object
:attr: sort Forces items to be sorted alphabetically.
-
#spacing ⇒ Object
:attr: spacing Space between items, value as a number.
-
#tip ⇒ Object
:attr: tip Tooltip string.
-
#value ⇒ Object
–.
-
#value=(val) ⇒ Object
:nodoc:.
-
#valuechanged_cb=(callback) ⇒ Object
–.
-
#visiblecolumns ⇒ Object
:attr: visiblecolumns The minimum number of visible columns, defaults to 5.
-
#visiblelines ⇒ Object
:attr: visiblelines The minimum number of visible lines, when dropdown=no.
Methods included from ButtonCallback
Methods included from DragDropAttributes
#dragbegin_cb=, #dragdata_cb=, #dragdatasize_cb=, #dragend_cb=, #dragsource, #dragsourcemove, #dragtypes, #dropdata_cb=, #dropmotion_cb=, #droptarget, #droptypes
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 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| ... } ⇒ List
Creates a new instance. If a block is given, the new instance is yielded to it.
71 72 73 74 75 76 |
# File 'lib/wrapped/list.rb', line 71 def initialize @handle = IupLib.IupList(nil) # run any provided block on instance, to set up further attributes yield self if block_given? end |
Instance Method Details
#action=(callback) ⇒ Object
–
392 393 394 395 396 397 398 399 400 |
# File 'lib/wrapped/list.rb', line 392 def action= callback unless callback.arity == 3 raise ArgumentError, 'action callback must take 3 arguments: (text, item, state)' end cb = Proc.new do |ih, text, item, state| callback.call text, item, state end define_callback cb, 'ACTION', :sii_i end |
#append ⇒ Object
:attr_writer: append (with editbox set) appends given string to end of list.
83 |
# File 'lib/wrapped/list.rb', line 83 define_writer :append |
#appenditem(text, image = nil) ⇒ Object
Adds given item to end of list.
-
text- required text label -
image- optional image reference / name.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/wrapped/list.rb', line 88 def appenditem(text, image=nil) IupLib.IupSetAttribute(@handle, 'APPENDITEM', text) case image when NilClass ; when String IupLib.SetAttibute(@handle, "IMAGE#{count}", image) when ImageWidget image_name = IupLib.IupGetName(name).first if image_name.nil? or image_name.empty? image_name = SecureRandom.uuid image.assign_handle image_name end IupLib.IupSetAttribute(@handle, "IMAGE#{count}", image_name) end end |
#autohide ⇒ Object
:attr: autohide If set, scrollbars are only shown if necessary, values ‘yes’ / ‘no’.
108 |
# File 'lib/wrapped/list.rb', line 108 define_attribute :autohide |
#canfocus ⇒ Object
:attr: canfocus If set, the control can gain focus, values ‘yes’ / ‘no’.
113 |
# File 'lib/wrapped/list.rb', line 113 define_attribute :canfocus |
#caret ⇒ Object
:attr: caret (with editbox set) ‘col’, in single-line mode, or ‘lin,col’ in multi-line mode.
118 |
# File 'lib/wrapped/list.rb', line 118 define_attribute :caret |
#caret_cb=(callback) ⇒ Object
–
414 415 416 417 418 419 420 421 422 |
# File 'lib/wrapped/list.rb', line 414 def caret_cb= callback unless callback.arity == 3 raise ArgumentError, 'caret_cb callback must take 3 arguments: (line, column, position)' end cb = Proc.new do |ih, lin, col, pos| callback.call lin, col, pos end define_callback cb, 'CARET_CB', :iii_i end |
#caretpos ⇒ Object
:attr: caretpos (with editbox set) Index of character of the insertion point.
123 |
# File 'lib/wrapped/list.rb', line 123 define_attribute :caretpos |
#clipboard ⇒ Object
:attr_writer: clipboard (with editbox set) ‘clear’ / ‘copy’ / ‘cut’ / ‘paste’. Access the clipboard with the current selection.
129 |
# File 'lib/wrapped/list.rb', line 129 define_writer :clipboard |
#count ⇒ Object
:attr_reader: count Returns the number of items in the list.
134 |
# File 'lib/wrapped/list.rb', line 134 define_reader :count |
#dblclick_cb=(callback) ⇒ Object
–
433 434 435 436 437 438 439 440 441 |
# File 'lib/wrapped/list.rb', line 433 def dblclick_cb= callback unless callback.arity == 2 raise ArgumentError, 'dblclick_cb callback must take 2 arguments: index, text' end cb = Proc.new do |ih, index, text| callback.call index, text end define_callback cb, 'DBLCLICK_CB', :is_i end |
#dragdrop_cb=(callback) ⇒ Object
–
456 457 458 459 460 461 462 463 464 |
# File 'lib/wrapped/list.rb', line 456 def dragdrop_cb= callback unless callback.arity == 4 raise ArgumentError, 'dragdrop_cb callback must take 4 arguments: (drag_id, drop_id, isshift, iscontrol)' end cb = Proc.new do |ih, drag_id, drop_id, isshift, iscontrol| callback.call drag_id.to_i, drop_id.to_i, (isshift != 0), (iscontrol != 0) end define_callback cb, 'DRAGDROP_CB', :iiii_i end |
#dragdroplist ⇒ Object
:attr: dragdroplist If yes, enables drag and drop between lists: ‘yes’ / ‘no’.
139 |
# File 'lib/wrapped/list.rb', line 139 define_attribute :dragdroplist |
#dropdown ⇒ Object
:attr: dropdown ‘yes’ / ‘no’, if set, only the selected item is visible.
151 |
# File 'lib/wrapped/list.rb', line 151 define_attribute :dropdown |
#dropdown_cb=(callback) ⇒ Object
–
474 475 476 477 478 479 480 481 482 |
# File 'lib/wrapped/list.rb', line 474 def dropdown_cb= callback unless callback.arity == 1 raise ArgumentError, 'dropdown_cb callback must take 1 argument, shown' end cb = Proc.new do |ih, state| callback.call (state == 1) end define_callback cb, 'DROPDOWN_CB', :i_i end |
#dropfilestarget ⇒ Object
:attr: dropfilestarget Enable or disable the drop of files: ‘no’ / ‘yes’. Automatically set to ‘yes’ if dropfiles_cb is defined when list is mapped.
146 |
# File 'lib/wrapped/list.rb', line 146 define_attribute :dropfilestarget |
#edit_cb=(callback) ⇒ Object
–
494 495 496 497 498 499 500 501 502 |
# File 'lib/wrapped/list.rb', line 494 def edit_cb= callback unless callback.arity == 2 raise ArgumentError, 'edit_cb callback must take 2 arguments: (character, new_value)' end cb = Proc.new do |ih, c, text| callback.call c, text end define_callback cb, 'EDIT_CB', :is_i end |
#editbox ⇒ Object
:attr: editbox ‘yes’ / ‘no’, if set adds an editable box to the list.
156 |
# File 'lib/wrapped/list.rb', line 156 define_attribute :editbox |
#expand ⇒ Object
:attr: expand Allows list to fill available space in indicated direction. Values ‘no’ / ‘horizontal’ / ‘vertical’ / ‘yes’.
162 |
# File 'lib/wrapped/list.rb', line 162 define_attribute :expand |
#insert ⇒ Object
:attr_writer: insert (with editbox set) Places a given string at current caret position, overwriting any current selection.
168 |
# File 'lib/wrapped/list.rb', line 168 define_writer :insert |
#insertitem(index, text, image = nil) ⇒ Object
Insert item at given index.
-
index- index to place item (1-indexed) -
text- required text label -
image- optional image reference / name.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/wrapped/list.rb', line 174 def insertitem(index, text, image=nil) IupLib.IupSetAttribute @handle, "INSERTITEM#{index}", text case image when NilClass ; when String IupLib.IupSetAttibute @handle, "IMAGE#{index}", image when ImageWidget image_name = IupLib.IupGetName(name).first if image_name.nil? or image_name.empty? image_name = SecureRandom.uuid image.assign_handle image_name end IupLib.IupSetAttribute @handle, "IMAGE#{index}", image_name end end |
#item(index, text = nil, image = nil) ⇒ Object
:call-seq:
list.item(index) # retrieves item
list.item(index, text) # sets text
list.item(index, text, image) # sets text and image
Accesses given index position.
-
index- index of item (1-indexed) -
text- text label (nilto retrieve) -
image- optional image reference / name.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/wrapped/list.rb', line 200 def item(index, text=nil, image=nil) if text.nil? IupLib.IupGetAttribute(@handle, index.to_s).first else IupLib.IupSetAttribute(@handle, index.to_s, text) case image when NilClass ; when String IupLib.IupSetAttribute(@handle, "IMAGE#{index}", image) when ImageWidget IupLib.IupSetAttributeHandle(@handle, "IMAGE#{index}", image.handle) end text end end |
#mask ⇒ Object
:attr: mask (with editbox set) Defines a mask to filter text input. See pre-defined masks.
221 |
# File 'lib/wrapped/list.rb', line 221 define_attribute :mask |
#motion_cb=(callback) ⇒ Object
–
513 514 515 516 517 518 519 520 521 |
# File 'lib/wrapped/list.rb', line 513 def motion_cb= callback unless callback.arity == 3 raise ArgumentError, 'motion_cb callback must take 3 arguments: (x, y, state)' end cb = Proc.new do |ih, x, y, state| callback.call x, y, state end define_callback cb, 'MOTION_CB', :iis_i end |
#multiple ⇒ Object
:attr: multiple If set, allows selection of multiple items: values ‘yes’ / ‘no’. Only available if editbox = dropdown = no.
227 |
# File 'lib/wrapped/list.rb', line 227 define_attribute :multiple |
#multiselect_cb=(callback) ⇒ Object
–
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 |
# File 'lib/wrapped/list.rb', line 532 def multiselect_cb= callback unless callback.arity == 2 raise ArgumentError, 'multiselect_cb callback must take 2 arguments, the array of selected and array of deselected items' end cb = Proc.new do |ih, val_ptr| val = FFI::Pointer.new(val_ptr).read_string selected = [] deselected = [] val.split('').each_with_index do |item, index| selected << index+1 if item == '+' deselected << index+1 if item == '-' end callback.call selected, deselected end define_callback cb, 'MULTISELECT_CB', :s_i end |
#nc ⇒ Object
:attr: nc (with editbox set) Maximum number of characters allowed for keyboard input (0 allows an indefinite number).
233 |
# File 'lib/wrapped/list.rb', line 233 define_attribute :nc |
#padding ⇒ Object
:attr: padding (with editbox set) Margin in x and y directions, value as “mxn”.
238 |
# File 'lib/wrapped/list.rb', line 238 define_attribute :padding |
#position ⇒ Object
:attr_reader: position returns position in pixels within client window as “x,y”.
243 |
# File 'lib/wrapped/list.rb', line 243 define_reader :position |
#rastersize ⇒ Object
:attr: rastersize Size of the list, in pixels, value as “widthxheight”.
248 |
# File 'lib/wrapped/list.rb', line 248 define_attribute :rastersize |
#readonly ⇒ Object
:attr: readonly (with editbox set) If set, prevents the user changing contents: values ‘yes’ / ‘no’.
254 |
# File 'lib/wrapped/list.rb', line 254 define_attribute :readonly |
#removeitem(item) ⇒ Object
Removes given item from the list:
-
list- index of item to remove (1-indexed), or ‘all’, to remove all items.
258 259 260 |
# File 'lib/wrapped/list.rb', line 258 def removeitem item IupLib.IupSetAttribute(@handle, "REMOVEITEM", item.to_s) end |
#screenposition ⇒ Object
:attr_reader: screenposition returns position in pixels on screen as “x,y”.
265 |
# File 'lib/wrapped/list.rb', line 265 define_reader :screenposition |
#scrollbar ⇒ Object
:attr: scrollbar When in multiline mode, enables a scrollbar. Values ‘vertical’ / ‘horizontal’ / ‘yes’ / ‘no’.
271 |
# File 'lib/wrapped/list.rb', line 271 define_attribute :scrollbar |
#scrollto ⇒ Object
:attr_writer: scrollto (with editbox set) ‘col’ Scrolls to make given column number visible, in single-line mode. ‘lin/col’ Scrolls to make line and column number visible, in multi-line mode.
279 |
# File 'lib/wrapped/list.rb', line 279 define_writer :scrollto |
#scrolltopos ⇒ Object
:attr_writer: scrolltopos (with editbox set) Scrolls to make character ‘number’ visible.
284 |
# File 'lib/wrapped/list.rb', line 284 define_writer :scrolltopos |
#selectedtext ⇒ Object
:attr: selectedtext (with editbox set) Reads or overwrites the current selection. Does nothing if no text is selected.
290 |
# File 'lib/wrapped/list.rb', line 290 define_attribute :selectedtext |
#selection ⇒ Object
:attr: selection (with editbox set) Selects text as ‘col1:col2’ (single-line) / ‘lin1,col1:lin2,col2’ (multi-line) / ‘all’ / ‘none’.
296 |
# File 'lib/wrapped/list.rb', line 296 define_attribute :selection |
#selectionpos ⇒ Object
:attr: selectionpos (with editbox set) Selects text between character positions: ‘pos1:pos2’ / ‘all’ / ‘none’.
302 |
# File 'lib/wrapped/list.rb', line 302 define_attribute :selectionpos |
#showdragdrop ⇒ Object
:attr: showdragdrop If set, enables internal drag/drop: values ‘yes’ / ‘no’.
307 |
# File 'lib/wrapped/list.rb', line 307 define_attribute :showdragdrop |
#showdropdown ⇒ Object
:attr_writer: showdropdown Shows the dropdown list, if dropdown=yes.
312 |
# File 'lib/wrapped/list.rb', line 312 define_writer :showdropdown |
#sort ⇒ Object
:attr: sort Forces items to be sorted alphabetically. Insert/append operations will ignore the index number.
320 |
# File 'lib/wrapped/list.rb', line 320 define_attribute :sort |
#spacing ⇒ Object
:attr: spacing Space between items, value as a number.
325 |
# File 'lib/wrapped/list.rb', line 325 define_attribute :spacing |
#tip ⇒ Object
:attr: tip Tooltip string.
330 |
# File 'lib/wrapped/list.rb', line 330 define_attribute :tip |
#value ⇒ Object
–
341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/wrapped/list.rb', line 341 def value item_str = IupLib.IupGetAttribute(@handle, 'VALUE').first if multiple == 'YES' result = [] item_str.split('').each_with_index do |item, index| result << index+1 if item == '+' end return result else return item_str end end |
#value=(val) ⇒ Object
:nodoc:
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/wrapped/list.rb', line 354 def value= val # :nodoc: if multiple == 'YES' result = "" count.to_i.times do |i| if val.include?(i+1) result << '+' else result << '-' end end IupLib.IupSetAttribute(@handle, 'VALUE', result) else IupLib.IupSetAttribute(@handle, 'VALUE', val.to_s) end end |
#valuechanged_cb=(callback) ⇒ Object
–
556 557 558 559 560 561 562 563 564 |
# File 'lib/wrapped/list.rb', line 556 def valuechanged_cb= callback unless callback.arity.zero? raise ArgumentError, 'valuechanged_cb callback must take 0 arguments' end cb = Proc.new do |ih| callback.call end define_callback cb, 'VALUECHANGED_CB', :plain end |
#visiblecolumns ⇒ Object
:attr: visiblecolumns The minimum number of visible columns, defaults to 5.
373 |
# File 'lib/wrapped/list.rb', line 373 define_attribute :visiblecolumns |
#visiblelines ⇒ Object
:attr: visiblelines The minimum number of visible lines, when dropdown=no.
378 |
# File 'lib/wrapped/list.rb', line 378 define_attribute :visiblelines |