vindarel / lisp-journey

Discovering the Common Lisp ecosystem. https://lisp-journey.gitlab.io/
2 stars 0 forks source link

blog/gui-programming-in-common-lisp-part-5-of-5-nuklear/ #38

Open utterances-bot opened 5 months ago

utterances-bot commented 5 months ago

GUI Programming in Common Lisp, part 5/5: Nuklear - Lisp journey

Nuklear is a small immediate-mode GUI toolkit: Nuklear is a minimal-state, immediate-mode graphical user interface toolkit written in ANSI C and licensed under public domain. It was designed as a simple embeddable user interface for application and does not have any dependencies, a default render backend or OS window/input handling but instead provides a highly modular, library-based approach, with simple input state for input and draw commands describing primitive shapes as output.

https://lisp-journey.gitlab.io/blog/gui-programming-in-common-lisp-part-5-of-5-nuklear/

backforeground commented 5 months ago

The complete example:

(ql:quickload :bodge-ui-window)

(defpackage :bodge-ui-window-test
  (:use :cl :bodge-ui :bodge-host))
(in-package :bodge-ui-window-test)

(defpanel (main-panel
            (:title "Hello Bodge UI")
            (:origin 200 50)
            (:width 400) (:height 400)
            (:options :movable :resizable
                      :minimizable :scrollable
                      :closable))

  (label :text "Nested widgets:")
  (horizontal-layout
   (radio-group
    (radio :label "Option 1")
    (radio :label "Option 2" :activated t))
   (vertical-layout
    (check-box :label "Check 1" :width 100)
    (check-box :label "Check 2"))
   (vertical-layout
    (label :text "Awesomely" :align :left)
    (label :text "Stacked" :align :centered)
    (label :text "Labels" :align :right)))
  (label :text "Expand by width:")
  (horizontal-layout
   (button :label "Dynamic")
   (button :label "Min-Width" :width 80)
   (button :label "Fixed-Width" :expandable nil :width 100))
  )

(defparameter *window-width* 800)
(defparameter *window-height* 600)

;; Define main window
(defclass main-window (bodge-ui-window:ui-window) ()
  (:default-initargs
   :title "Bodge UI Window Example"
   :width *window-width*
   :height *window-height*
   :panels '(main-panel)
   :floating t
   :opengl-version #+bodge-gl2 '(2 1)
                   #-bodge-gl2 '(3 3)))

(defun run ()
  (bodge-host:open-window (make-instance 'main-window)))

(run)