Haskell bindings to the libui C library.
GPLv3
Haskell bindings to the libui
C library.
The library is currently only an FFI wrapper.
Useful top-level modules are:
Graphics.LibUI
Graphics.LibUI.OSX
They export general and OSX specific functionality in raw C and "wrapped"
Haskell APIs. Currently implemented for OSX only are wrappers for Webkit and a
partial wrapper to Mapviews, both of which have examples. This should go back to
upstream libui
once it's solid.
Important
This package needs some splitting and cleaning-up, as well as some more work,
but the bits exposed by Graphics.LibUI.FFI
(Graphics.LibUI.FFI.Wrapped
,
Graphics.LibUI.FFI.Raw
& OSX variants) should be ok to use.
They aren't used in anything serious right now. You'd be courageous to do it.
import Graphics.LibUI
main = do
uiInit
wn <- uiNewWindow "Haskell on GUIs" 220 100 True
btn <- uiNewButton "Click me"
wn `setChild` btn
wn `setMargined` True
uiShow wn
uiMain
You can run this example with:
git clone https://github.com/beijaflor-io/haskell-libui
cd haskell-libui
make READMEExample
./READMEExample
There're several examples on the examples
directory. The Simple...
examples
only use the Graphics.LibUI.FFI
part of the library and are what you want to
look at first.
The ReactiveBanana...
examples are playgrounds for showing how you could wrap
the callback based API with FRP without much work.
apps/markd
is an example application (currently only working on OSX), which
previews how a file is rendered by pandoc
.
Graphics.LibUI.FFI.Raw
libui
names prefixed with c_
Graphics.LibUI.FFI.Wrapped
uiControl
typeexamples
and Graphics.LibUI.Types
and
Graphics.LibUI.MonadUI
MonadUI
shouldn't wrap IO actions, but abstract commands:
data UI = UI [UIControl]
class MonadUI m b where runUI :: UI -> m b
instance MonadUI IO CUIControl where runUI = toCUIControlIO
The aim of Graphics.LibUI.Types
and friends is to end-up with code that looks
like:
runUILoop do
menu "File" [ "Open"
, "Save"
, UIMenuItemQuit
]
void $ window "libui Control Gallery" 640 300 True $
void $ tabs $ do
tab "Basic Controls" $ do
hbox $
button "Button"
checkbox "Checkbox"
label "This is a label. Right now, labels can only span one line."
void $ group "Entries" $
form [ formItem "Entry" (entry "")
, formItem "Entry" (entry "")
, formItem "Search Entry" (searchEntry "")
]
tab "Basic Controls" $ hbox $ do
void $ group "Numbers" (return ())
void $ group "Lists" (return ())
tab "Data Choosers" mempty
Tested on OSX, Fedora and Ubuntu 14.04. A Vagrantfile is available.
This code is published under the GPLv3 license