Class: Iup::Button
- Includes:
- ButtonCallback, ImageAttributes
- Defined in:
- lib/wrapped/button.rb
Overview
A button can display some text, an image, or both. When clicked, a specified action function is called. The action should return Iup::DEFAULT, or, if the button should exit the application, Iup::CLOSE.
(1) A button with some text and an action
Iup::Button.new('click me', ->{
puts 'clicked'
Iup::DEFAULT
})
(2) A button with an image stored in img and action specified by a separate method; some padding around the image within the button.
def click_fn
puts 'clicked'
Iup::DEFAULT
end
Iup:Button.new('', ->{ click_fn }) do |b|
b.image = img
b.padding = '50x20'
end
(3) A button with text and image, image placed above text. The text contains an & before the “x”, so the action can be triggered using ALT+x, and closes the application.
Iup::Button.new('e&xit', ->{ puts 'exit'; Iup::CLOSE }) do |b|
b.image = img
b.imageposition = 'top'
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 button to fill available space in indicated direction.
-
#flat ⇒ Object
:attr: alignment Sets the horizontal and vertical alignment.
-
#imageposition ⇒ Object
:attr: imageposition Position of image relative to text.
-
#impressborder ⇒ Object
:attr: impressborder If set, shows button borders even if impress defined.
-
#initialize(title = '', callback = nil) {|_self| ... } ⇒ Button
constructor
Creates an instance of a button.
-
#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”.
-
#rastersize ⇒ Object
:attr: rastersize Size of the button, in pixels, value as “widthxheight”.
-
#screenposition ⇒ Object
:attr_reader: screenposition Returns position in pixels on screen as “x,y”.
-
#spacing ⇒ Object
:attr: spacing Space between image and text, value as a number.
-
#tip ⇒ Object
:attr: tip Tooltip string.
-
#title ⇒ Object
:attr: title Displayed on the button as a text label.
Methods included from ButtonCallback
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 = '', callback = nil) {|_self| ... } ⇒ Button
Creates an instance of a button. If a block is given, the new instance is yielded to it.
-
title- the text to display on the button. -
callback- procedure to call when button is left-clicked, passed to #action.
45 46 47 48 49 50 51 52 |
# File 'lib/wrapped/button.rb', line 45 def initialize(title='', callback = nil) @handle = IupLib.IupButton(title, nil) self.action = callback unless callback.nil? # run any provided block on instance, to set up further attributes yield self if block_given? end |
Instance Method Details
#action=(callback) ⇒ Object
–
139 140 141 142 143 144 145 146 147 |
# File 'lib/wrapped/button.rb', line 139 def action= callback unless callback.arity.zero? raise ArgumentError, 'action must take 0 arguments' end cb = Proc.new do |ih| callback.call end define_callback(cb, 'ACTION', :plain) 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”.
63 |
# File 'lib/wrapped/button.rb', line 63 define_attribute :alignment |
#canfocus ⇒ Object
:attr: canfocus Enables the control to gain focus. Values ‘yes’ / ‘no’.
68 |
# File 'lib/wrapped/button.rb', line 68 define_attribute :canfocus |
#expand ⇒ Object
:attr: expand Allows button to fill available space in indicated direction. Values ‘no’ / ‘horizontal’ / ‘vertical’ / ‘yes’.
74 |
# File 'lib/wrapped/button.rb', line 74 define_attribute :expand |
#flat ⇒ Object
:attr: alignment Sets the horizontal and vertical alignment. The value is a string “horizontal:vertical”, with options ALEFT, ACENTER, ARIGHT or none.
81 |
# File 'lib/wrapped/button.rb', line 81 define_attribute :flat |
#imageposition ⇒ Object
:attr: imageposition Position of image relative to text. Values ‘left’ / ‘right’ / ‘top’ / ‘bottom’/
93 |
# File 'lib/wrapped/button.rb', line 93 define_attribute :imageposition |
#impressborder ⇒ Object
:attr: impressborder If set, shows button borders even if impress defined. Values ‘yes’ / ‘no’.
87 |
# File 'lib/wrapped/button.rb', line 87 define_attribute :impressborder |
#padding ⇒ Object
:attr: padding Margin in x and y directions, value as “mxn”.
98 |
# File 'lib/wrapped/button.rb', line 98 define_attribute :padding |
#position ⇒ Object
:attr_reader: position Returns position in pixels within client window as “x,y”.
103 |
# File 'lib/wrapped/button.rb', line 103 define_reader :position |
#rastersize ⇒ Object
:attr: rastersize Size of the button, in pixels, value as “widthxheight”.
108 |
# File 'lib/wrapped/button.rb', line 108 define_attribute :rastersize |
#screenposition ⇒ Object
:attr_reader: screenposition Returns position in pixels on screen as “x,y”.
113 |
# File 'lib/wrapped/button.rb', line 113 define_reader :screenposition |
#spacing ⇒ Object
:attr: spacing Space between image and text, value as a number.
118 |
# File 'lib/wrapped/button.rb', line 118 define_attribute :spacing |
#tip ⇒ Object
:attr: tip Tooltip string.
123 |
# File 'lib/wrapped/button.rb', line 123 define_attribute :tip |
#title ⇒ Object
:attr: title Displayed on the button as a text label.
128 |
# File 'lib/wrapped/button.rb', line 128 define_attribute :title |