Giter Club home page Giter Club logo

cl-liballegro-nuklear's Introduction

cl-liballegro-nuklear

This is 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.

Screenshots

screenshot

Installation

Just execute (ql:quickload :cl-liballegro-nuklear) in your Lisp.

To get the latest version of the package, install Lucky Lambda Quicklisp distribution.

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:

...and on following Lisp compilers:

Usage

(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.

Note: nk:prog is renamed to nk:prog- because of obvious NAME-CONFLICT error.

There's also lispy interface making library interaction more idiomatic of CL. See docstrings in lispy.lisp for documentation.

Declarative interface

There's also declarative interface in separate package cl-liballegro-nuklear/declarative which allows you to define an anonymous function doing all required FFI calls and type conversions. To do that, use defwindow macro in the following fashion:

(uiop:add-package-local-nickname :ui :cl-liballegro-nuklear/declarative)

(setf *window*
      (ui:defwindow demo ()
          (:x 50 :y 50 :w 200 :h 200
           :flags (border movable))
        (ui:layout-row-static :height 30 :item-width 80 :columns 1)
        (ui:button-label "button"
          (format t "button pressed!~%"))))

;; then somewhere in your main loop
(funcall *window* nuklear-context)


;; another example:
(setf *window*
      (ui:defwindow loading (&key progress file)
          (:w display-width :h display-height
           :styles ((:item-color :window-fixed-background :r 20)))
        (declare (type alexandria:non-negative-fixnum progress))
        (ui:layout-space (:format :dynamic :height 54 :widget-count 1)
          (ui:layout-space-push :x 0.28 :y 6 :w 0.45 :h 1)
          (ui:styles ((:item-color :progress-normal :r 50 :g 50 :b 50)
                      (:item-color :progress-cursor-normal :g 50)
                      (:vec2 :progress-padding :x 0 :y 0))
            (ui:progress :current progress))
          (ui:label (format nil " Loading ~a..." file)))))

;; then somewhere in your main loop
(funcall *window* nuklear-context :progress 42 :file "some.file")

See declarative.lisp for details.

Games made using cl-liballegro-nuklear

Related projects

  • 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.

Contributing

Merge requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

cl-liballegro-nuklear's People

Contributors

lockie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.