lispnik / iup

Common Lisp CFFI bindings to the IUP Portable User Interface library (pre-ALPHA)
Other
139 stars 7 forks source link

run main-loop on a thread #2

Open lispnik opened 5 years ago

lispnik commented 5 years ago

Would like to be able to interactively build a gui from the REPL like you can with CAPI. main-loop blocks until the last dialog is closed though. Main consideration is that UI operations should run on the UI thread, otherwise bad thing happen (just like in swing, and maybe others).

Idea sketch:

(iup:open) ;; initialize manual

(defvar *idle-queue* '())

(defun idle-callback () 
   ;; lock
   (dolist (func *idle-queue*) (funcall func)
   (setf *idle-queue* '()))

(with-gui-thread ()
   (setf (iup:attribute foo :title) "new title"))
;;; ...
(call-with-gui-thread (func)
   ;; lock idle queue 
   (push func *idle-queue*))

notes:

CL-USER> (in-package #:iup-user)
IUP-USER> (start-gui-thread)
IUP-USER> (setq dialog (dialog nil))
IUP-USER> (setq button (button :title "hi"))
IUP-USER> (show dialog)
IUP-USER> (iup:append dialog button)
IUP-USER> (setf (attribute button :title )"new title")