Class: Iup::Dial
- Includes:
- ButtonCallback
- Defined in:
- lib/wrapped/dial.rb
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#button_press_cb(callback) ⇒ Object
Called when the user presses the left mouse button over the dial.
-
#button_release_cb(callback) ⇒ Object
Called when the user releases the left mouse button after pressing it over the dial.
-
#initialize(orientation = 'horizontal', &block) ⇒ Dial
constructor
A new instance of Dial.
-
#mousemove_cb(callback) ⇒ Object
Called each time the user moves the dial with the mouse button pressed.
- #value(val = nil) ⇒ Object
-
#valuechanged_cb(callback) ⇒ Object
Called after the value was interactively changed by the user.
Methods included from ButtonCallback
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 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 CallbackSetter
Constructor Details
#initialize(orientation = 'horizontal', &block) ⇒ Dial
Returns a new instance of Dial.
5 6 7 8 9 10 11 |
# File 'lib/wrapped/dial.rb', line 5 def initialize orientation = 'horizontal', &block open_controls @handle = ControlsLib.IupDial orientation # run any provided block on instance, to set up further attributes self.instance_eval &block if block_given? end |
Instance Method Details
#button_press_cb(callback) ⇒ Object
Called when the user presses the left mouse button over the dial. The angle here is always zero, except for the circular dial. Callback is a 1-argument function: (angle)
39 40 41 42 43 44 45 46 47 |
# File 'lib/wrapped/dial.rb', line 39 def callback unless callback.arity == 1 raise ArgumentError, 'button_press_cb callback must take 1 argument: (angle)' end cb = Proc.new do |ih, angle| callback.call angle end define_callback cb, 'BUTTON_PRESS_CB', :d_i end |
#button_release_cb(callback) ⇒ Object
Called when the user releases the left mouse button after pressing it over the dial. The angle here is always zero, except for the circular dial. Callback is a 1-argument function: (angle)
52 53 54 55 56 57 58 59 60 |
# File 'lib/wrapped/dial.rb', line 52 def callback unless callback.arity == 1 raise ArgumentError, 'button_release_cb callback must take 1 argument: (angle)' end cb = Proc.new do |ih, angle| callback.call angle end define_callback cb, 'BUTTON_RELEASE_CB', :d_i end |
#mousemove_cb(callback) ⇒ Object
Called each time the user moves the dial with the mouse button pressed. The angle the dial rotated since it was initialized is passed as a parameter. Callback is a 1-argument function: (angle)
65 66 67 68 69 70 71 72 73 |
# File 'lib/wrapped/dial.rb', line 65 def mousemove_cb callback unless callback.arity == 1 raise ArgumentError, 'mousemove_cb callback must take 1 argument: (angle)' end cb = Proc.new do |ih, angle| callback.call angle end define_callback cb, 'MOUSEMOVE_CB', :d_i end |
#value(val = nil) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/wrapped/dial.rb', line 23 def value val=nil if val.nil? result = IupLib.IupGetAttribute(@handle, 'VALUE').first result.to_f else IupLib.IupSetAttribute @handle, 'VALUE', val.to_s end end |
#valuechanged_cb(callback) ⇒ Object
Called after the value was interactively changed by the user. Called when the selection is changed or when the text is edited.
77 78 79 80 81 82 83 84 85 |
# File 'lib/wrapped/dial.rb', line 77 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 |