class Iup::Widget
This class provides shared functionality across all widgets in the IUP library.
Every widget has a handle, which is often a C pointer:
p Iup::Button.new.handle # => #<FFI::Pointer address=0x0000647e530e6a80>
The Widget class provides attributes supporting appearance, including whether the widget is active, its size, font and color, and its position in the z-order list (where widgets are overlapping, and the top one is visible).
Some common callbacks are also found in this class, responding to:
-
map/unmap, where the native interface elements are created. Some child widgets require their parent to be mapped first.
-
focus events.
-
keyboard/mouse events.
Example
The following code creates a button with large red text, which reports when the mouse moves over the button and any key is pressed:
Iup::mainloop do btn = Iup::Button.new("hello") do it.fgcolor = "255 0 0" it.font = "Times, Bold 18" it.enterwindow_cb = ->{ puts "on button" } it.leavewindow_cb = ->{ puts "off button" } it.k_any = ->(k){ puts "Key #{k.chr}" } end Iup::Dialog.new(btn).show end
Attributes
Enables or prevents user interaction. Typically, a widget will appear greyed-out when inactive. Values ‘yes’ / ‘no’.
Specify RGB values for background color, as “r g b”.
Specify RGB values for foreground color, as “r g b”.
Sets the widget’s font, using a font description as “<font face>, <font styles> <font size>”, e.g. “Times, Bold 14”. For portability, the fonts Courier, Helvetica and Times are always mapped to appropriate native system fonts.
Unique reference to widget.
Maximum size of widget, value as “widthxheight”.
Minimum size of widget, value as “widthxheight”.
Size of the widget, in character units, value as “widthxheight”.
Shows or hides the widget. Values ‘yes’ / ‘no’.
Native widget identifier.
Alters z-order, values as ‘top’ / ‘bottom’.
Public Instance Methods
Source
# File lib/wrapped/widget.rb, line 47 def assign_handle name IupLib.IupSetHandle(name, @handle) end
Sets the internal handle name for this widget.
Source
# File lib/wrapped/widget.rb, line 120 def destroy IupLib.IupDestroy @handle end
When no longer required, call destroy to have the C backend reclaim the widget.
Source
# File lib/wrapped/widget.rb, line 54 def open_controls unless @@controlslib ControlsLib.IupControlsOpen @@controlslib = true end end
Ensure the controls library is opened
Callbacks
Attributes
Action generated when the mouse enters the widget. Callback must respond to call and take no arguments.
Action generated when a widget is given keyboard focus. Callback must respond to call and take no arguments.
Action generated when the user presses F1 at a control. Callback must respond to call and take no arguments.
Action generated when a keyboard event occurs. Callback must respond to call and takes 1-argument: (key)
-
key- the character that is pressed, see Key definitions.
Action generated when a widget loses keyboard focus. Callback must respond to call and take no arguments.
Action generated when the mouse leaves the widget. Callback must respond to call and take no arguments.
Called right after a widget is mapped and its layout updated. Callback must respond to call and take no arguments.
Called right before a widget is unmapped. Callback must respond to call and take no arguments.