CFFI wrapper for the Nuklear IM GUI library with liballegro backend, to be used with cl-liballegro.
Nuklear is minimal immediate-mode graphical user interface toolkit. To use it alongside liballegro, you have to write some amount of glue code. This library brings both Nuklear itself and that glue code to Common Lisp, so you can just plug it in and have some nice minimal GUI in your cl-liballegro-powered application.
(ql:quickload :cl-liballegro-nuklear) in your Lisp.
Note: upon loading this library with asdf, the corresponding foreign library is automatically built (
allegro_nuklear.dll on Windows,
liballegro_nuklear.so on more sane operating systems), so you'll have to have compiler toolchain and liballegro dev files installed on your machine.
Currently tested to work on following OSes:
- Windows (using MinGW64 and
seh-dynamicvariant of official liballegro binaries)
- MacOS (using Homebrew version of liballegro)
...and on following Lisp compilers:
(ql:quickload '(:cl-liballegro :cl-liballegro-nuklear :float-features)) (cffi:defcallback main :int ((argc :int) (argv :pointer)) (al:init) (al:init-primitives-addon) (al:init-image-addon) (al:init-font-addon) (al:init-ttf-addon) (al:install-mouse) (let ((display (al:create-display 800 600)) (queue (al:create-event-queue))) (al:register-event-source queue (al:get-display-event-source display)) (al:register-event-source queue (al:get-mouse-event-source)) (cffi:with-foreign-object (ev '(:union al:event)) (loop :with font := (nk:allegro-font-create-from-file "Roboto-Regular.ttf" 12 0) :with ctx := (nk:allegro-init font display 800 600) :do (let ((get-event (al:wait-for-event-timed queue ev 0.06))) (when (and get-event (eq (cffi:foreign-slot-value ev '(:union al:event) 'al::type) :display-close)) (loop-finish)) (nk:input-begin ctx) (loop :while get-event :do (nk:allegro-handle-event ev) (setf get-event (al:get-next-event queue ev))) (nk:input-end ctx) (unless (zerop (nk:begin ctx "Demo" '(nk::w 100f0 nk::h 100f0) 0)) (nk:layout-row-static ctx 30f0 80 1) (unless (zerop (nk:button-label ctx "button")) (format t "button pressed~%")) (nk:end ctx) (nk:allegro-render) (al:flip-display))) :finally (nk:allegro-font-del font) (nk:allegro-shutdown) (al:destroy-display display) (al:destroy-event-queue queue) (return 0))))) (float-features:with-float-traps-masked (:divide-by-zero :invalid :inexact :overflow :underflow) (al:run-main 0 (cffi:null-pointer) (cffi:callback main)))
See example.lisp for more involved example.
nk:prog is renamed to
nk:prog- because of obvious
There's also lispy interface making library interaction more idiomatic of CL. See docstrings in lispy.lisp for documentation.
- bodge-nuklear, which depends on nuklear-blob is other CFFI wrapper for Nuklear. It does not include glue code for liballegro, but designed to work with OpenGL-based cl-bodge game framework.
Merge requests are welcome. For major changes, please open an issue first to discuss what you would like to change.