Class: Iup::Toggle
- Includes:
- ImageAttributes
- Defined in:
- lib/wrapped/toggle.rb
Overview
A Toggle control is a control that can have two or three states. The toggle control will display some text or an image.
Attributes
- alignment
-
Sets the horizontal and vertical alignment. The value is a string “horizontal:vertical”, with options ALEFT, ACENTER, ARIGHT or none.
- canfocus
-
Enables the control to gain focus. Values ‘yes’ / ‘no’.
- expand
-
Allows control to fill available space in indicated direction. Values ‘no’ / ‘horizontal’ / ‘vertical’ / ‘yes’.
- flat
-
If set, hides the control’s border until mouse enters the button area. Values ‘yes’ / ‘no’.
- image
-
Sets the image to display. This can be an actual image object, or the name of an image.
- iminactive
-
Sets the image to display when inactive.
- impress
-
Sets the image to display when pressed.
- padding
-
Margin in x and y directions, value as “mxn”.
- position
-
read-only returns position in pixels within client window as “x,y”.
- radio
-
read-only Returns ‘yes’ / ‘no’ if toggle within a radio control.
- rastersize
-
Size of the control, in pixels, value as “widthxheight”.
- screenposition
-
read-only returns position in pixels on screen as “x,y”.
- three_state
-
‘no’ / ‘yes’, 3-state only for text labels
- tip
-
Tooltip string.
- title
-
text to display.
- value
-
‘on’ / ‘off’ / ‘toggle’ / ‘notdef’ (for 3-state toggles).
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#action(callback) ⇒ Object
Action generated when the toggle’s state (on/off) was changed.
-
#initialize(title = nil, arg = '', &block) ⇒ Toggle
constructor
Creates an instance of a Toggle control.
-
#three_state(val = nil) ⇒ Object
:nodoc:.
-
#valuechanged_cb(callback) ⇒ Object
Called after the value was interactively changed by the user.
Methods included from ImageAttributes
Methods included from AttributeReference
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(title = nil, arg = '', &block) ⇒ Toggle
Creates an instance of a Toggle control.
- title
-
optional text to display
- arg
-
optional name of action to perform when state changed
- block
-
optional block to set up attributes.
39 40 41 42 43 44 |
# File 'lib/wrapped/toggle.rb', line 39 def initialize title=nil, arg='', &block @handle = IupLib.IupToggle title, arg # 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 toggle’s state (on/off) was changed. action takes a 1-argument callback, the argument indicating the state change. state_change == 1 if state changed to “on” state_change == 0 if state changed to “off”
76 77 78 79 80 81 82 83 84 |
# File 'lib/wrapped/toggle.rb', line 76 def action callback unless callback.arity == 1 raise ArgumentError, 'action callback must take 1 argument, the state_change' end cb = Proc.new do |ih, state_change| callback.call state_change.to_i end define_callback cb, 'ACTION', :i_i end |
#three_state(val = nil) ⇒ Object
:nodoc:
61 62 63 64 65 66 67 |
# File 'lib/wrapped/toggle.rb', line 61 def three_state val=nil # :nodoc: if val.nil? IupLib.IupGetAttribute(@handle, '3STATE').first else IupLib.IupGetAttribute(@handle, '3STATE', val).first end end |
#valuechanged_cb(callback) ⇒ Object
Called after the value was interactively changed by the user.
87 88 89 90 91 92 93 94 95 |
# File 'lib/wrapped/toggle.rb', line 87 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 |