Class: Iup::ScrollBox
- Includes:
- ButtonCallback, DragDropAttributes, ScrollBarAttributes
- Defined in:
- lib/wrapped/scrollbox.rb
Overview
A container holding a single child widget, enabling that child widget to be scrolled.
Attributes
- border
-
Set to show a border around the scrollbox. Values ‘yes’ / ‘no’.
- canfocus
-
Always ‘no’ - control cannot gain focus.
- clientoffset
-
read-only, returns current offset of box in its client as “widthxheight”.
- clientsize
-
read-only, returns current size of box as “widthxheight”.
- cursor
-
Name of the mouse shape / cursor for the scrollbox.
- drawsize
-
Size of drawing area in pixels, as “widthxheight”.
- expand
-
Allows container to fill available space in indicated direction. Values ‘no’ / ‘horizontal’ / ‘vertical’ / ‘yes’.
- padding
-
Margin in x and y directions in pixels, value as “mxn”.
- position
-
read-only returns position in pixels within client window as “x,y”.
- rastersize
-
Size of the container, in pixels, value as “widthxheight”.
- screenposition
-
read-only returns position in pixels on screen as “x,y”.
- scrollbar
-
Selects ‘no’ / ‘horizontal’ / ‘vertical’ / ‘yes’ (for both) scrollbars.
- tip
-
Tooltip string.
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#action(callback) ⇒ Object
Action generated when the scrollbar needs to be redrawn.
-
#focus_cb(callback) ⇒ Object
Called when the scrollbar gets or loses the keyboard focus.
-
#initialize(child, &block) ⇒ ScrollBox
constructor
Creates a new instance of the container.
-
#keypress_cb(callback) ⇒ Object
Action generated when a key is pressed or released.
-
#motion_cb(callback) ⇒ Object
Action generated when the mouse is moved.
-
#resize_cb(callback) ⇒ Object
Action generated when the scrollbar size is changed.
-
#wheel_cb(callback) ⇒ Object
Action generated when the mouse wheel is rotated.
Methods included from ButtonCallback
Methods included from ScrollBarAttributes
#dx, #dy, #linex, #liney, #posx, #posy, #scroll_cb, #xmax, #xmin, #ymax, #ymin
Methods included from AttributeBuilders
#define_attribute, #define_id_attribute, #define_id_readonly, #define_id_writeonly, #define_property_attribute, #define_property_writeonly, #define_readonly, #define_writeonly
Methods included from DragDropAttributes
#dragbegin_cb, #dragdata_cb, #dragdatasize_cb, #dragend_cb, #dropdata_cb, #dropmotion_cb
Methods inherited from Widget
#assign_handle, #enterwindow_cb, #getfocus_cb, #help_cb, #k_any, #killfocus_cb, #leavewindow_cb, #map_cb, #open_controls, #unmap_cb
Methods included from CallbackSetter
Constructor Details
#initialize(child, &block) ⇒ ScrollBox
Creates a new instance of the container.
- child
-
a child widget
- block
-
optional block to set up attributes
33 34 35 36 37 38 |
# File 'lib/wrapped/scrollbox.rb', line 33 def initialize child, &block @handle = IupLib.IupScrollBox child.handle # run any provided block on instance, to set up further attributes self.instance_eval &block if block_given? end |
Instance Method Details
#action(callback) ⇒ Object
Action generated when the scrollbar needs to be redrawn. action takes a callback which accepts 2 arguments (posx, posy). posx, posy are the position of the horizontal and vertical thumbs of the scrollbar.
60 61 62 63 64 65 66 67 68 |
# File 'lib/wrapped/scrollbox.rb', line 60 def action callback unless callback.arity == 2 raise ArgumentError, 'action must take 2 arguments: (posx, posy)' end cb = Proc.new do |ih, posx, posy| callback.call posx, posy end define_callback cb, 'ACTION', :ff_i end |
#focus_cb(callback) ⇒ Object
Called when the scrollbar gets or loses the keyboard focus. Callback takes a single parameter: (focus)
- focus
-
non-zero if canvas gaining focus, else zero.
75 76 77 78 79 80 81 82 83 |
# File 'lib/wrapped/scrollbox.rb', line 75 def focus_cb callback unless callback.arity == 1 raise ArgumentError, 'focus_cb callback must take 1 argument, the focus' end cb = Proc.new do |ih, focus| callback.call focus end define_callback cb, 'FOCUS_CB', :i_i end |
#keypress_cb(callback) ⇒ Object
Action generated when a key is pressed or released. keypress_cb takes a 2-argument callback: (character, pressed). pressed == 1 if key is pressed, pressed == 0 if key is released.
89 90 91 92 93 94 95 96 97 |
# File 'lib/wrapped/scrollbox.rb', line 89 def keypress_cb callback unless callback.arity == 2 raise ArgumentError, 'keypress_cb callback must take 2 arguments: (char, press)' end cb = Proc.new do |ih, char, press| callback.call char, press end define_callback cb, 'KEYPRESS_CB', :ii_i end |
#motion_cb(callback) ⇒ Object
Action generated when the mouse is moved. Callback takes 3 arguments: (x, y, state)
- x
-
x position of mouse
- y
-
y position of mouse
- state
-
status of mouse buttons and certain keyboard keys at the moment the event was generated.
– TODO: include functions, as in button_cb
107 108 109 110 111 112 113 114 115 |
# File 'lib/wrapped/scrollbox.rb', line 107 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 |
#resize_cb(callback) ⇒ Object
Action generated when the scrollbar size is changed. resize_cb a 2-argument callback: (width, height).
- width
-
internal width of canvas (client width)
- height
-
internal height of canvas (client height)
121 122 123 124 125 126 127 128 129 |
# File 'lib/wrapped/scrollbox.rb', line 121 def resize_cb callback unless callback.arity == 2 raise ArgumentError, 'resize_cb callback must take 2 arguments: (width, height)' end cb = Proc.new do |ih, width, height| callback.call width, height end define_callback cb, 'RESIZE_CB', :ii_i end |
#wheel_cb(callback) ⇒ Object
Action generated when the mouse wheel is rotated. wheel_cb a 4-argument callback: (delta, x, y, status).
- delta
-
the amount the wheel was rotated in notches.
- x, y
-
position in the canvas where the event has occurred, in pixels.
- status
-
status of mouse buttons and certain keyboard keys at the moment the event was generated.
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/wrapped/scrollbox.rb', line 136 def wheel_cb callback unless callback.arity == 4 raise ArgumentError, 'wheel_cb callback must take 4 arguments: (delta, x, y, status)' end cb = Proc.new do |ih, delta, x, y, status_ptr| status = FFI::Pointer.new(status_ptr).read_string callback.call delta, x, y, status end define_callback cb, 'WHEEL_CB', :fiis_i end |