changelog shortlog graph tags branches changeset file revisions annotate raw help

Mercurial > demo / ui.lisp

revision 12: c520966de7fa
parent 10: 79737134254d
     1.1--- a/ui.lisp	Sun May 14 21:27:04 2023 -0400
     1.2+++ b/ui.lisp	Mon May 15 21:40:24 2023 -0400
     1.3@@ -1,6 +1,29 @@
     1.4 (in-package :demo)
     1.5+
     1.6+(defparameter ui-server-port 8080)
     1.7+(defparameter ui-server-host "0.0.0.0")
     1.8+
     1.9+(defclass ui-element (clog-element) ()
    1.10+  (:documentation "UI Element Object."))
    1.11+
    1.12+(defgeneric create-ui-element (obj &key hidden class id mode)
    1.13+  (:documentation "Create a new ui-element as a child of OBJ."))
    1.14+(defmethod create-ui-element ((obj clog:clog-obj)
    1.15+			      &key (class nil)
    1.16+				(hidden nil)
    1.17+				(id nil)
    1.18+				(mode 'auto))
    1.19+  (let ((new (clog:create-div obj
    1.20+			      :class class
    1.21+			      :hidden hidden
    1.22+			      :id id
    1.23+			      :mode mode)))
    1.24+    (clog:set-geometry new :width 200 :height 100)
    1.25+    (change-class new 'ui-element)))
    1.26+			      
    1.27 (defun on-new-window (body)
    1.28   "Handle new window event."
    1.29+  (clog:debug-mode body)
    1.30   (let ((elt (clog:create-child body "<h1>foobar</h1>")))
    1.31     (clog:set-on-click
    1.32      elt
    1.33@@ -9,5 +32,12 @@
    1.34 
    1.35 (defun start-ui ()
    1.36   "Start the UI."
    1.37-  (clog:initialize #'on-new-window)
    1.38+  (clog:initialize #'on-new-window
    1.39+		   :extended-routing t
    1.40+		   :host ui-server-host
    1.41+		   :port ui-server-port)
    1.42   (clog:open-browser))
    1.43+
    1.44+(defun stop-ui ()
    1.45+  "Stop the UI."
    1.46+  (clog:shutdown))