Class: Iup::Toggle
- Includes:
- ImageAttributes
- Defined in:
- lib/wrapped/toggle.rb
Overview
A control that can have two or three states, and displays either some text or an image.
Example
(1) with text label
Iup::Toggle.new('click to change')
(2) with a standard image, reporting changes to value
Iup::Toggle.new do |t|
t.image = "IUP_MessageHelp"
t.valuechanged_cb = ->{ puts "button 1 state #{toggle1.value}" }
end
Instance Attribute Summary
Attributes inherited from Widget
Instance Method Summary collapse
-
#action=(callback) ⇒ Object
–.
-
#alignment ⇒ Object
:attr: alignment Sets the horizontal and vertical alignment.
-
#canfocus ⇒ Object
:attr: canfocus Enables the control to gain focus.
-
#expand ⇒ Object
:attr: expand Allows control to fill available space in indicated direction.
-
#flat ⇒ Object
:attr: flat If set, hides the control’s border until mouse enters the button area.
-
#initialize(title = nil) {|_self| ... } ⇒ Toggle
constructor
Creates a new instance.
-
#padding ⇒ Object
:attr: padding Margin in x and y directions, value as “mxn”.
-
#position ⇒ Object
:attr_reader: position Returns position in pixels within client window as “x,y”.
-
#radio ⇒ Object
:attr_reader: radio Returns ‘yes’ / ‘no’, if toggle is within a radio control.
-
#rastersize ⇒ Object
:attr: rastersize Size of the control, in pixels, value as “widthxheight”.
-
#screenposition ⇒ Object
:attr_reader: screenposition returns position in pixels on screen as “x,y”.
-
#three_state ⇒ Object
–.
-
#three_state=(val) ⇒ Object
:nodoc:.
-
#tip ⇒ Object
:attr: tip Tooltip string.
-
#title ⇒ Object
:attr: title text to display.
-
#value ⇒ Object
:attr: value Toggle’s state, value one of ‘on’ / ‘off’ / ‘toggle’ / ‘notdef’ (for 3-state toggles).
-
#valuechanged_cb=(callback) ⇒ Object
–.
Methods included from ImageAttributes
#image, #image=, #iminactive, #iminactive=, #impress, #impress=
Methods included from AttributeReference
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 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 included from CallbackSetter
Constructor Details
#initialize(title = nil) {|_self| ... } ⇒ Toggle
Creates a new instance. If a block is given, the new instance is yielded to it.
-
title- optional text to display
25 26 27 28 29 30 |
# File 'lib/wrapped/toggle.rb', line 25 def initialize(title=nil) @handle = IupLib.IupToggle(title, '') # run any provided block on instance, to set up further attributes yield self if block_given? end |
Instance Method Details
#action=(callback) ⇒ Object
–
123 124 125 126 127 128 129 130 131 |
# File 'lib/wrapped/toggle.rb', line 123 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 |
#alignment ⇒ Object
:attr: alignment Sets the horizontal and vertical alignment. The value is a string “horizontal:vertical”, with horizontal options ALEFT, ACENTER, ARIGHT and vertical options ATOP, ACENTER, ABOTTOM. Partial values also accepted, e.g. “ARIGHT”, “:ATOP”.
41 |
# File 'lib/wrapped/toggle.rb', line 41 define_attribute :alignment |
#canfocus ⇒ Object
:attr: canfocus Enables the control to gain focus. Values ‘yes’ / ‘no’.
46 |
# File 'lib/wrapped/toggle.rb', line 46 define_attribute :canfocus |
#expand ⇒ Object
:attr: expand Allows control to fill available space in indicated direction. Values ‘no’ / ‘horizontal’ / ‘vertical’ / ‘yes’.
52 |
# File 'lib/wrapped/toggle.rb', line 52 define_attribute :expand |
#flat ⇒ Object
:attr: flat If set, hides the control’s border until mouse enters the button area. Values ‘yes’ / ‘no’.
58 |
# File 'lib/wrapped/toggle.rb', line 58 define_attribute :flat |
#padding ⇒ Object
:attr: padding Margin in x and y directions, value as “mxn”.
63 |
# File 'lib/wrapped/toggle.rb', line 63 define_attribute :padding |
#position ⇒ Object
:attr_reader: position Returns position in pixels within client window as “x,y”.
68 |
# File 'lib/wrapped/toggle.rb', line 68 define_reader :position |
#radio ⇒ Object
:attr_reader: radio Returns ‘yes’ / ‘no’, if toggle is within a radio control.
73 |
# File 'lib/wrapped/toggle.rb', line 73 define_reader :radio |
#rastersize ⇒ Object
:attr: rastersize Size of the control, in pixels, value as “widthxheight”.
78 |
# File 'lib/wrapped/toggle.rb', line 78 define_attribute :rastersize |
#screenposition ⇒ Object
:attr_reader: screenposition returns position in pixels on screen as “x,y”.
83 |
# File 'lib/wrapped/toggle.rb', line 83 define_reader :screenposition |
#three_state ⇒ Object
–
90 91 92 |
# File 'lib/wrapped/toggle.rb', line 90 def three_state IupLib.IupGetAttribute(@handle, '3STATE').first end |
#three_state=(val) ⇒ Object
:nodoc:
94 95 96 |
# File 'lib/wrapped/toggle.rb', line 94 def three_state= val # :nodoc: IupLib.IupGetAttribute(@handle, '3STATE', val).first end |
#tip ⇒ Object
:attr: tip Tooltip string.
101 |
# File 'lib/wrapped/toggle.rb', line 101 define_attribute :tip |
#title ⇒ Object
:attr: title text to display.
106 |
# File 'lib/wrapped/toggle.rb', line 106 define_attribute :title |
#value ⇒ Object
:attr: value Toggle’s state, value one of ‘on’ / ‘off’ / ‘toggle’ / ‘notdef’ (for 3-state toggles).
112 |
# File 'lib/wrapped/toggle.rb', line 112 define_attribute :value |
#valuechanged_cb=(callback) ⇒ Object
–
139 140 141 142 143 144 145 146 147 |
# File 'lib/wrapped/toggle.rb', line 139 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 |