Module: Iup

Defined in:
lib/wrapped/constants.rb,
lib/wrapped/val.rb,
lib/wrapped/dial.rb,
lib/wrapped/fill.rb,
lib/wrapped/hbox.rb,
lib/wrapped/link.rb,
lib/wrapped/list.rb,
lib/wrapped/menu.rb,
lib/wrapped/tabs.rb,
lib/wrapped/text.rb,
lib/wrapped/tree.rb,
lib/wrapped/vbox.rb,
lib/wrapped/zbox.rb,
lib/iup-ffi-plain.rb,
lib/wrapped/frame.rb,
lib/wrapped/image.rb,
lib/wrapped/label.rb,
lib/wrapped/radio.rb,
lib/wrapped/timer.rb,
lib/wrapped/button.rb,
lib/wrapped/canvas.rb,
lib/wrapped/dialog.rb,
lib/wrapped/matrix.rb,
lib/wrapped/toggle.rb,
lib/wrapped/widget.rb,
lib/wrapped/gridbox.rb,
lib/wrapped/submenu.rb,
lib/wrapped/colorbar.rb,
lib/wrapped/expander.rb,
lib/wrapped/menuitem.rb,
lib/wrapped/splitbox.rb,
lib/wrapped/scintilla.rb,
lib/wrapped/scrollbox.rb,
lib/wrapped/separator.rb,
lib/wrapped/filedialog.rb,
lib/wrapped/fontdialog.rb,
lib/wrapped/iup-global.rb,
lib/wrapped/stretchbox.rb,
lib/wrapped/colordialog.rb,
lib/wrapped/progressbar.rb,
lib/wrapped/messagedialog.rb,
lib/wrapped/background-box.rb,
lib/wrapped/progressdialog.rb,
lib/wrapped/callback-setter.rb,
lib/wrapped/image-attributes.rb,
lib/wrapped/common-attributes.rb,
lib/wrapped/attribute-builders.rb,
lib/wrapped/attribute-reference.rb,
lib/wrapped/drag-drop-attributes.rb,
lib/wrapped/dynamic-fill-methods.rb,
lib/wrapped/scrollbar-attributes.rb

Overview

Iup is the main module, in which all controls and widgets are named.

The module also provides constants and supporting methods.

Defined Under Namespace

Modules: AttributeBuilders, AttributeReference, ButtonCallback, CallbackSetter, DragDropAttributes, DynamicFillMethods, ImageAttributes, ScrollBarAttributes Classes: BackgroundBox, Button, Canvas, ColorBar, ColorDialog, Dial, Dialog, Expander, FileDialog, Fill, FontDialog, Frame, GridBox, HBox, Image, ImageRGB, ImageRGBA, ImageWidget, Label, Link, List, Matrix, Menu, MenuItem, MessageDialog, ProgressBar, ProgressDialog, Radio, Scintilla, ScrollBox, Separator, SplitBox, StretchBox, SubMenu, Tabs, Text, Timer, Toggle, Tree, VBox, Val, Widget, ZBox

Constant Summary collapse

IUP_LIBS =
case RbConfig::CONFIG['host_os']
when /linux|cygwin/
  library_path = File.join(library_base, "linux")
  [
    "gobject-2.0", "pango-1.0",
    File.join(library_path, 'libcd.so'),
    File.join(library_path, 'libim.so'),
    File.join(library_path, "libiup.so"),
    File.join(library_path, 'libiupcd.so'),
    File.join(library_path, 'libiupcontrols.so'),
    File.join(library_path, 'libiupim.so'),
    File.join(library_path, 'libiupimglib.so'),
    File.join(library_path, 'libiup_scintilla.so')
  ]
when /mswin|mingw/
  library_path = File.join(library_base, "windows")
  [
    File.join(library_path, "freetype6.dll"),
    File.join(library_path, "zlib1.dll"),
    File.join(library_path, 'cd.dll'),
    File.join(library_path, 'im.dll'),
    File.join(library_path, "iup.dll"),
    File.join(library_path, 'iupcd.dll'),
    File.join(library_path, 'iupcontrols.dll'),
    File.join(library_path, 'iupim.dll'),
    File.join(library_path, 'iupimglib.dll') #,
    #               File.join(library_path, 'iup_scintilla.dll')
  ]
else
  raise Exception, 
    'iup libraries not found this platform', 
    RbConfig::CONFIG['host_os']
end
IUP_PRIMARY =

Identifies color type as the primary color.

-1
# Identifies color type as the secondary color.
IUP_SECONDARY =

Identifies color type as the secondary color.

-2
IGNORE =

Used by some actions so that callback is ignored.

-1
# Continues with user interaction: this is the return value to use, if in
# doubt.
DEFAULT =

Continues with user interaction: this is the return value to use, if in doubt.

-2
# Calls +IupExitLoop+ on returning; in most cases, this closes the
# application.
CLOSE =

Calls IupExitLoop on returning; in most cases, this closes the application.

-3
# Used by some action to pass control to parent.
CONTINUE =

Used by some action to pass control to parent.

-4
CENTER =

To place at center of screen.

0xFFFF
LEFT =

To place at left border of screen.

0xFFFE
RIGHT =

To place at right border of screen.

0xFFFD
MOUSEPOS =

To center on the mouse cursor.

0xFFFC
CURRENT =

To center on the current dialog’s position.

0xFFFB
CENTERPARENT =

To center on the parent dialog.

0xFFFA
TOP =

To place at top border of screen.

LEFT
BOTTOM =

To place at bottom border of screen.

RIGHT
IUP_SHOW =

When shown

0
IUP_RESTORE =

When restored

1
IUP_MINIMIZE =

When minimized

2
IUP_MAXIMIZE =

When maximized

3
IUP_HIDE =

When hidden

4
BUTTON1 =

Left mouse button

'1'
BUTTON2 =

Middle mouse button

'2'
BUTTON3 =

Right mouse button

'3'
BUTTON4 =

Extra button

'4'
BUTTON5 =

Extra button

'5'
MASK_FLOAT =

:section: Masks

"[+/-]?(/d+/.?/d*|/./d+)"
MASK_UFLOAT =
"(/d+/.?/d*|/./d+)"
MASK_EFLOAT =
"[+/-]?(/d+/.?/d*|/./d+)([eE][+/-]?/d+)?"
MASK_INT =
"[+/-]?/d+"
MASK_UINT =
"/d+"
MASK_FLOATCOMMA =
"[+/-]?(/d+/,?/d*|/,/d+)"
MASK_UFLOATCOMMA =
"(/d+/,?/d*|/,/d+)"
K_SP =

:section: Key definitions

' '.ord
K_exclam =
'!'.ord
K_quotedbl =
"\"".ord
K_numbersign =
'#'.ord
K_dollar =
'$'.ord
K_percent =
'%'.ord
K_ampersand =
'&'.ord
K_apostrophe =
"\'".ord
K_parentleft =
'('.ord
K_parentright =
')'.ord
K_plus =
'+'.ord
K_comma =
','.ord
K_minus =
'-'.ord
K_period =
'.'.ord
K_slash =
'/'.ord
K_0 =
'0'.ord
K_1 =
'1'.ord
K_2 =
'2'.ord
K_3 =
'3'.ord
K_4 =
'4'.ord
K_5 =
'5'.ord
K_6 =
'6'.ord
K_7 =
'7'.ord
K_8 =
'8'.ord
K_9 =
'9'.ord
K_colon =
':'.ord
K_semicolon =
';'.ord
K_less =
'<'.ord
K_equal =
'='.ord
K_greater =
'>'.ord
K_question =
'?'.ord
K_at =
'@'.ord
K_A =
'A'.ord
K_B =
'B'.ord
K_C =
'C'.ord
K_D =
'D'.ord
K_E =
'E'.ord
K_F =
'F'.ord
K_G =
'G'.ord
K_H =
'H'.ord
K_I =
'I'.ord
K_J =
'J'.ord
K_K =
'K'.ord
K_L =
'L'.ord
K_M =
'M'.ord
K_N =
'N'.ord
K_O =
'O'.ord
K_P =
'P'.ord
K_Q =
'Q'.ord
K_R =
'R'.ord
K_S =
'S'.ord
K_T =
'T'.ord
K_U =
'U'.ord
K_V =
'V'.ord
K_W =
'W'.ord
K_X =
'X'.ord
K_Y =
'Y'.ord
K_Z =
'Z'.ord
K_bracketleft =
'['.ord
K_backslash =
"\\".ord
K_bracketright =
']'.ord
K_circum =
'^'.ord
K_underscore =
'_'.ord
K_grave =
'`'.ord
K_a =
'a'.ord
K_b =
'b'.ord
K_c =
'c'.ord
K_d =
'd'.ord
K_e =
'e'.ord
K_f =
'f'.ord
K_g =
'g'.ord
K_h =
'h'.ord
K_i =
'i'.ord
K_j =
'j'.ord
K_k =
'k'.ord
K_l =
'l'.ord
K_m =
'm'.ord
K_n =
'n'.ord
K_o =
'o'.ord
K_p =
'p'.ord
K_q =
'q'.ord
K_r =
'r'.ord
K_s =
's'.ord
K_t =
't'.ord
K_u =
'u'.ord
K_v =
'v'.ord
K_w =
'w'.ord
K_x =
'x'.ord
K_y =
'y'.ord
K_z =
'z'.ord
K_braceleft =
'{'.ord
K_bar =
'|'.ord
K_braceright =
'}'.ord
K_tilde =
'~'.ord
K_BS =
"\b".ord
K_TAB =
"\t".ord
K_LF =
"\n".ord
K_CR =
"\r".ord
K_PAUSE =
0xFF13
K_ESC =
0xFF1B
K_HOME =
0xFF50
K_LEFT =
0xFF51
K_UP =
0xFF52
K_RIGHT =
0xFF53
K_DOWN =
0xFF54
K_PGUP =
0xFF55
K_PGDN =
0xFF56
K_END =
0xFF57
K_MIDDLE =
0xFF0B
K_Print =
0xFF61
K_INS =
0xFF63
K_Menu =
0xFF67
K_DEL =
0xFFFF
K_F1 =
0xFFBE
K_F2 =
0xFFBF
K_F3 =
0xFFC0
K_F4 =
0xFFC1
K_F5 =
0xFFC2
K_F6 =
0xFFC3
K_F7 =
0xFFC4
K_F8 =
0xFFC5
K_F9 =
0xFFC6
K_F10 =
0xFFC7
K_F11 =
0xFFC8
K_F12 =
0xFFC9
K_LSHIFT =
0xFFE1
K_RSHIFT =
0xFFE2
K_LCTRL =
0xFFE3
K_RCTRL =
0xFFE4
K_LALT =
0xFFE9
K_RALT =
0xFFEA
K_NUM =
0xFF7F
K_SCROLL =
0xFF14
K_CAPS =
0xFFE5
IUP_SBUP =

Operation on vertical scrollbar - used in scroll_cb callback.

0
IUP_SBDN =

Operation on vertical scrollbar - used in scroll_cb callback.

1
IUP_SBPGUP =

Operation on vertical scrollbar - used in scroll_cb callback.

2
IUP_SBPGDN =

Operation on vertical scrollbar - used in scroll_cb callback.

3
IUP_SBPOSV =

Operation on vertical scrollbar - used in scroll_cb callback.

4
IUP_SBDRAGV =

Operation on vertical scrollbar - used in scroll_cb callback.

5
IUP_SBLEFT =

Operation on horizontal scrollbar - used in scroll_cb callback.

6
IUP_SBRIGHT =

Operation on horizontal scrollbar - used in scroll_cb callback.

7
IUP_SBPGLEFT =

Operation on horizontal scrollbar - used in scroll_cb callback.

8
IUP_SBPGRIGHT =

Operation on horizontal scrollbar - used in scroll_cb callback.

9
IUP_SBPOSH =

Operation on horizontal scrollbar - used in scroll_cb callback.

10
IUP_SBDRAGH =

Operation on horizontal scrollbar - used in scroll_cb callback.

11
CD_QUERY =

:section: CD library

-1
CD_RGB =

:section: CD bitmap type

0
CD_MAP =
1
CD_RGBA =
0x100
CD_IRED =

:section: CD bitmap data

0
CD_IGREEN =
1
CD_IBLUE =
2
CD_IALPHA =
3
CD_INDEX =
4
CD_COLORS =
5
CD_ERROR =

:section: CD status report

-1
CD_OK =
0
CD_CLIPOFF =

:section: CD clip mode

0
CD_CLIPAREA =
1
CD_CLIPPOLYGON =
2
CD_CLIPREGION =
3
CD_UNION =

:section: CD region combine mode

0
CD_INTERSECT =
1
CD_DIFFERENCE =
2
CD_NOTINTERSECT =
3
CD_FILL =

:section: CD polygon mode

0
CD_OPEN_LINES =
1
CD_CLOSED_LINES =
2
CD_CLIP =
3
CD_BEZIER =
4
CD_REGION =
5
CD_PATH =
6
CD_POLYCUSTOM =
10
CD_PATH_NEW =

:section: CD path action

0
CD_PATH_MOVETO =
1
CD_PATH_LINETO =
2
CD_PATH_ARC =
3
CD_PATH_CURVETO =
4
CD_PATH_CLOSE =
5
CD_PATH_FILL =
6
CD_PATH_STROKE =
7
CD_PATH_FILLSTROKE =
7
CD_PATH_CLIP =
8
CD_EVENODD =

:section: CD fill mode

0
CD_WINDING =
1
CD_MITER =

:section: CD line join

0
CD_BEVEL =
1
CD_ROUND =
2
CD_CAPFLAT =

:section: CD line cap

0
CD_CAPSQUARE =
1
CD_CAPROUND =
2
CD_OPAQUE =

:section: CD background opacity mode

0
CD_TRANSPARENT =
1
CD_REPLACE =

:section: CD write mode

0
CD_XOR =
1
CD_NOT_XOR =
2
CD_POLITE =

:section: CD color allocation mode (palette)

0
CD_FORCE =
1
CD_CONTINUOUS =

:section: CD line style

0
CD_DASHED =
1
CD_DOTTED =
2
CD_DASH_DOT =
3
CD_DASH_DOT_DOT =
4
CD_CUSTOM =
5
CD_PLUS =

:section: CD mark type

0
CD_STAR =
1
CD_CIRCLE =
2
CD_X =
3
CD_BOX =
4
CD_DIAMOND =
5
CD_HOLLOW_CIRCLE =
6
CD_HOLLOW_BOX =
7
CD_HOLLOW_DIAMOND =
8
CD_HORIZONTAL =

:section: CD hatch type

0
CD_VERTICAL =
1
CD_FDIAGONAL =
2
CD_BDIAGONAL =
3
CD_CROSS =
4
CD_DIAGCROSS =
5
CD_SOLID =

:section: CD interior style

0
CD_HATCH =
1
CD_STIPPLE =
2
CD_PATTERN =
3
CD_HOLLOW =
4
CD_NORTH =

:section: CD text alignment

0
CD_SOUTH =
1
CD_EAST =
2
CD_WEST =
3
CD_NORTH_EAST =
4
CD_NORTH_WEST =
5
CD_SOUTH_EAST =
6
CD_SOUTH_WEST =
7
CD_CENTER =
8
CD_BASE_LEFT =
9
CD_BASE_CENTER =
10
CD_BASE_RIGHT =
11
CD_PLAIN =

:section: CD text style

0
CD_BOLD =
1
CD_ITALIC =
2
CD_UNDERLINE =
4
CD_STRIKEOUT =
8
CD_BOLD_ITALIC =

compatibility name

(CD_BOLD|CD_ITALIC)
CD_SMALL =

:section: CD font sizes

8
CD_STANDARD =
12
CD_LARGE =
18
CD_CAP_NONE =

:section: CD context capabilities

0x00000000
CD_CAP_FLUSH =
0x00000001
CD_CAP_CLEAR =
0x00000002
CD_CAP_PLAY =
0x00000004
CD_CAP_YAXIS =
0x00000008
CD_CAP_CLIPAREA =
0x00000010
CD_CAP_CLIPPOLY =
0x00000020
CD_CAP_REGION =
0x00000040
CD_CAP_RECT =
0x00000080
CD_CAP_CHORD =
0x00000100
CD_CAP_IMAGERGB =
0x00000200
CD_CAP_IMAGERGBA =
0x00000400
CD_CAP_IMAGEMAP =
0x00000800
CD_CAP_GETIMAGERGB =
0x00001000
CD_CAP_IMAGESRV =
0x00002000
CD_CAP_BACKGROUND =
0x00004000
CD_CAP_BACKOPACITY =
0x00008000
CD_CAP_WRITEMODE =
0x00010000
CD_CAP_LINESTYLE =
0x00020000
CD_CAP_LINEWITH =
0x00040000
CD_CAP_FPRIMTIVES =
0x00080000
CD_CAP_HATCH =
0x00100000
CD_CAP_STIPPLE =
0x00200000
CD_CAP_PATTERN =
0x00400000
CD_CAP_FONT =
0x00800000
CD_CAP_FONTDIM =
0x01000000
CD_CAP_TEXTSIZE =
0x02000000
CD_CAP_TEXTORIENTATION =
0x04000000
CD_CAP_PALETTE =
0x08000000
CD_CAP_LINECAP =
0x10000000
CD_CAP_LINEJOIN =
0x20000000
CD_CAP_PATH =
0x40000000
CD_CAP_BEZIER =
0x80000000
CD_CAP_ALL =
0xFFFFFFFF
CD_SIM_NONE =

:section: CD simulation flags

0x0000
CD_SIM_LINE =
0x0001
CD_SIM_RECT =
0x0002
CD_SIM_BOX =
0x0004
CD_SIM_ARC =
0x0008
CD_SIM_SECTOR =
0x0010
CD_SIM_CHORD =
0x0020
CD_SIM_POLYLINE =
0x0040
CD_SIM_POLYGON =
0x0080
CD_SIM_TEXT =
0x0100
CD_SIM_ALL =
0xFFFF
CD_SIM_LINES =
(CD_SIM_LINE | CD_SIM_RECT | CD_SIM_ARC | CD_SIM_POLYLINE)
CD_SIM_FILLS =
(CD_SIM_BOX | CD_SIM_SECTOR | CD_SIM_CHORD | CD_SIM_POLYGON)
CD_RED =

:section: CD colors

0xFF0000
CD_DARK_RED =

255, 0, 0

0x800000
CD_GREEN =

128, 0, 0

0x00FF00
CD_DARK_GREEN =

0,255, 0

0x008000
CD_BLUE =

0,128, 0

0x0000FF
CD_DARK_BLUE =

0, 0,255

0x000080
CD_YELLOW =

0, 0,128

0xFFFF00
CD_DARK_YELLOW =

255,255, 0

0x808000
CD_MAGENTA =

128,128, 0

0xFF00FF
CD_DARK_MAGENTA =

255, 0,255

0x800080
CD_CYAN =

128, 0,128

0x00FFFF
CD_DARK_CYAN =

0,255,255

0x008080
CD_WHITE =

0,128,128

0xFFFFFF
CD_BLACK =

255,255,255

0x000000
CD_DARK_GRAY =

0, 0, 0

0x808080
CD_GRAY =

128,128,128

0xC0C0C0
CD_MM2PT =

milimeters to points (pt = CD_MM2PT * mm)

2.834645669
CD_RAD2DEG =

radians to degrees (deg = CD_RAD2DEG * rad)

57.295779513
CD_DEG2RAD =

degrees to radians (rad = CD_DEG2RAD * deg)

0.01745329252

Class Method Summary collapse

Class Method Details

.alarm(title, msg, button1, button2 = nil, button3 = nil) ⇒ Object

Creates and shows an AlarmDialog, returning the number of the button clicked.

  • title - the title of the dialog window

  • msg - the text to display within the dialog

  • button1 - label for the first button

  • button2 - label for the optional second button

  • button3 - label for the optional third button

Returns index of clicked button (1, 2 or 3).

result = Iup.alarm("Vegetable time", "Pick a vegetable", "cabbage", "carrots", "peas")

Also see: MessageDialog



17
18
19
# File 'lib/wrapped/messagedialog.rb', line 17

def self.alarm title, msg, button1, button2=nil, button3=nil
  IupLib.IupAlarm(title, msg, button1, button2, button3)
end

.get_color(x = 0, y = 0) ⇒ Object

Shows a modal dialog to select a color.

  • x, y - optional coordinates to place the dialog

Returns r/g/b triple of selected color, or nil if “cancel” clicked.

r, g, b = Iup.get_color(150, 150)

Also see: ColorDialog



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/wrapped/colordialog.rb', line 13

def self.get_color x=0, y=0
  r = FFI::MemoryPointer.new(:int, 1, 0)
  g = FFI::MemoryPointer.new(:int, 1, 0)
  b = FFI::MemoryPointer.new(:int, 1, 0)
  code = IupLib.IupGetColor x, y, r, g, b
  if code == 0
    return nil
  else
    return r.read_int, g.read_int, b.read_int
  end
end

.get_file(filter = '') ⇒ Object

Convenience function to show a modal dialog to select a filename.

  • filter - path + filter for files to show

Returns the status code and selected filename: status is an integer, 1 for new file, 0 for existing file/directory, or -1 for cancelled.

Also see: FileDialog

For example, select a filename ending in “.txt” from current directory.

code, file = Iup.get_file('./*.txt')


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wrapped/filedialog.rb', line 17

def self.get_file filter=''
  file = ' '*(256-filter.size) + filter
  code = IupLib.IupGetFile(file)
  case code
  when 0, 1
    filename = file[0...file.index("\0")]
    return code, filename
  else
    return code, ''
  end
end

.global(name, val = nil) ⇒ Object

Accesses the global variable ‘name’. Provide a value for ‘val’ to set the variable, or leave as nil to get the variable.



31
32
33
34
35
36
37
# File 'lib/wrapped/iup-global.rb', line 31

def self.global(name, val=nil)
  if val.nil?
    IupLib.IupGetGlobal(name).first
  else
    IupLib.IupSetGlobal(name, val)
  end
end

.idle(callback) ⇒ Object

Sets the idle_action



40
41
42
43
44
45
# File 'lib/wrapped/iup-global.rb', line 40

def self.idle callback
  unless callback.nil? or callback.arity.zero? 
    raise ArgumentError 'callback to idle must take no arguments'
  end
  IupLib.IupSetFunction('IDLE_ACTION', callback)
end

.listdialog(title, items) ⇒ Object

Convenience function to show a modal dialog to select an item from a list.

  • title - title for dialog

  • items - list of items (strings) to display

Returns selected item, or nil if cancel clicked.

selection = Iup.listdialog('select one', ['C', 'Java', 'Ruby', 'Scheme'])
puts "Return #{selection}"

Also see: List



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wrapped/list.rb', line 15

def self.listdialog(title, items)
  strptrs = []
  strptrs << nil
 
  items_ptr = FFI::MemoryPointer.new(:pointer, items.length)
  items.each_with_index do |item, i|
    items_ptr[i].put_pointer(0, FFI::MemoryPointer.from_string(item))
  end

  code = IupLib.IupListDialog(1, title, items.length, items_ptr, 1, 1, 10, nil)

  return (code == -1 ? nil : items[code])
end

.load_image(filename) ⇒ Object

Loads an image from file, returning an ImageWidget instance.

  • filename - name of image file

Raises RuntimeError if no file of given filename exists.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/wrapped/image.rb', line 6

def self.load_image filename
  if File.exist?(filename)
    handle = ImLib.IupLoadImage(filename)
    puts handle # TODO - broken?
    image = ImageWidget.new
    image.handle = handle

    return image
  else
    raise RuntimeError, "File does not exist", filename
  end
end

.mainloopObject

All IUP GUI code must be called via a block passed to this method, as in this minimal example.

Iup.mainloop do

  label = Iup::Label.new("Hello World!")

  Iup::Dialog.new label do |d|
    d.title = ' ... from IUP'
    d.size = '150x50'
  end.show
end


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wrapped/iup-global.rb', line 16

def self.mainloop 
  begin
    IupLib.IupOpen(0, nil)
    ImgLib.IupImageLibOpen()

    yield
    IupLib.IupMainLoop
  ensure
    IupLib.IupClose
  end
end

.message(title, value) ⇒ Object

Convenience function to show a MessageDialog with given title and displayed message value. This is an “information” dialog, with a single button labelled “ok”.

Iup.message("About", <<MSG)
    My Ruby Application

   Date: January 2026
MSG

Also see: MessageDialog



33
34
35
# File 'lib/wrapped/messagedialog.rb', line 33

def self.message(title, value)
  IupLib.IupMessage(title, value)
end