Tutorial 2

This commit is contained in:
David Botton 2021-01-06 01:33:29 -05:00
parent d2fdc58a40
commit 69d0589089
2 changed files with 35 additions and 1 deletions

34
tutorial/02-tutorial.lisp Normal file
View file

@ -0,0 +1,34 @@
(defpackage #:clog-user
(:use #:cl #:clog)
(:export start-tutorial))
(in-package :clog-user)
(defun on-new-window (body)
"On-new-window handler."
;; Give your app a name that apears in the browser tab/window
(setf (title (html-document body)) "Tutorial 2")
;; The CLOG-body object gives you access to a number of other CLOG-Objects
;;
;; (html-document body) is the CLOG-Document object
;; (window body) is the CLOG-Window object
;; (location body) is the CLOG-Location object
;; (navigator body) is the CLOG-Navigator object
(let ((hello-element
(create-child body "<h1>Hello World! (click me!)</h1>")))
(let ((x 0)) ; A closure - each call to on-new-window will
(set-on-click hello-element ; create a different version of this closer.
(lambda ()
(incf x)
(dotimes (n x)
(create-child body
(format nil "<p>Clicked ~A times.</p>" x))))))))
(defun start-tutorial ()
"Start turtorial."
(initialize #'on-new-window)
(open-browser))