Class: Iup::Dial

Inherits:
Widget show all
Includes:
ButtonCallback
Defined in:
lib/wrapped/dial.rb

Instance Attribute Summary

Attributes inherited from Widget

#handle

Instance Method Summary collapse

Methods included from ButtonCallback

#button_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 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

#define_callback

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 button_press_cb 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 button_release_cb 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