# Nim IUP Direct
const
libiupSONAME = "libiup.so"
IUP_CLOSE* = -3
IUP_CENTER* = cint(0x0000FFFF)
type
Ihandle = object
PIhandle* = ptr Ihandle
Icallback* = proc (a1: PIhandle): cint {.cdecl.}
proc btn_exit_cb(ih:PIhandle):cint {.cdecl.}=
return IUP_CLOSE
proc Open*(argc: var cint; argv: ptr cstringArray): cint {.cdecl, importc: "IupOpen", dynlib: libiupSONAME, discardable.}
proc Button*(title: cstring; action: cstring): PIhandle {.cdecl, importc: "IupButton", dynlib: libiupSONAME.}
proc Label*(title: cstring): PIhandle {.cdecl, importc: "IupLabel", dynlib: libiupSONAME.}
proc Vbox*(child: PIhandle): PIhandle {.varargs, cdecl, importc: "IupVbox", dynlib: libiupSONAME.}
proc Dialog*(child: PIhandle): PIhandle {.cdecl, importc: "IupDialog", dynlib: libiupSONAME.}
proc SetAttribute*(ih: PIhandle; name: cstring; value: cstring) {.cdecl, importc: "IupSetAttribute", dynlib: libiupSONAME.}
proc SetCallback*(ih: PIhandle; name: cstring; `func`: Icallback): Icallback {.cdecl, importc: "IupSetCallback", dynlib: libiupSONAME, discardable.}
proc ShowXY*(ih: PIhandle; x: cint; y: cint): cint {.cdecl, importc: "IupShowXY", dynlib: libiupSONAME, discardable.}
proc MainLoop*(): cint {.cdecl, importc: "IupMainLoop", dynlib: libiupSONAME, discardable.}
proc Close*() {.cdecl, importc: "IupClose", dynlib: libiupSONAME.}
var dlg, button, label, vbox: PIhandle
var argc:cint
var argv:ptr cstringArray
Open(argc, argv)
label = Label("Hello world from IUP.")
button = Button("OK", nil)
vbox = Vbox(label, button, nil)
SetAttribute(vbox, "ALIGNMENT", "ACENTER")
SetAttribute(vbox, "GAP", "10")
SetAttribute(vbox, "MARGIN", "10x10")
dlg = Dialog(vbox)
SetAttribute(dlg, "TITLE", "Ubuntu RPi")
SetCallback(button, "ACTION", btn_exit_cb)
ShowXY(dlg, IUP_CENTER, IUP_CENTER)
MainLoop()
Close()