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.
(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
Attributes
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”.
Enables the control to gain focus. Values ‘yes’ / ‘no’.
Allows button to fill available space in indicated direction. Values ‘no’ / ‘horizontal’ / ‘vertical’ / ‘yes’.
Position of image relative to text. Values ‘left’ / ‘right’ / ‘top’ / ‘bottom’/
If set, shows button borders even if impress defined. Values ‘yes’ / ‘no’.
Margin in x and y directions, value as “mxn”.
Returns position in pixels within client window as “x,y”.
Size of the button, in pixels, value as “widthxheight”.
Returns position in pixels on screen as “x,y”.
Space between image and text, value as a number.
Tooltip string.
Displayed on the button as a text label.
Public Class Methods
Source
# 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
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 toaction.
Callbacks
Attributes
Sets action called when the button 1 (usually left) is selected. Callback must respond to call and take no arguments.