class Iup::Button
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
.
# Example 1: A button with some text and an action Button.new 'click me', ->{ puts 'clicked' DEFAULT }
# Example 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' DEFAULT end Button.new '', ->{ click_fn } do image img padding '50x20' end
# Example 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. Button.new 'e&xit', ->{ puts 'exit'; CLOSE } do image img imageposition 'top' end
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 button to fill available space in indicated direction. Values 'no' / 'horizontal' / 'vertical' / 'yes'.
- flat
-
If set, hides the button's border until mouse enters the button area. Values 'yes' / 'no'.
- impressborder
-
If set, shows button borders even if impress defined. Values 'yes' / 'no'.
- imageposition
-
Position of image relative to text. Values 'left' / 'right' / 'top' / 'bottom'/
- padding
-
Margin in x and y directions, value as “mxn”.
- position
-
read-only returns position in pixels within client window as “x,y”.
- rastersize
-
Size of the button, in pixels, value as “widthxheight”.
- screenposition
-
read-only returns position in pixels on screen as “x,y”.
- spacing
-
Space between image and text, value as a number.
- tip
-
Tooltip string.
- title
-
Label
text displayed on the button.
Public Class Methods
Creates an instance of a button.
- title
-
the text to display on the button.
- callback
-
procedure to call when button is left-clicked.
- block
-
optional block to set up the button's attributes.
# File lib/wrapped/button.rb, line 66 def initialize title='', callback = nil, &block @handle = IupLib.IupButton title, nil action callback unless callback.nil? # run any provided block on instance, to set up further attributes self.instance_eval &block if block_given? end
Public Instance Methods
Action generated when the button 1 (usually left) is selected.
# File lib/wrapped/button.rb, line 95 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