mirror of
https://github.com/rabbibotton/clog.git
synced 2025-12-06 02:30:42 -08:00
Tutorial 6
This commit is contained in:
parent
6d8467caf4
commit
964e76536a
3 changed files with 42 additions and 2 deletions
|
|
@ -147,12 +147,11 @@ window."))
|
|||
(defmethod y-offset ((obj clog-window))
|
||||
(query obj "pageYOffset"))
|
||||
|
||||
|
||||
(defgeneric set-y-offset (clog-window value))
|
||||
|
||||
(defmethod set-y-offset ((obj clog-window) value)
|
||||
(execute obj "pageYOffset" value))
|
||||
(defsetf y-offset set-y-offsett)
|
||||
(defsetf y-offset set-y-offset)
|
||||
|
||||
;;;;;;;;;
|
||||
;; top ;;
|
||||
|
|
|
|||
40
tutorial/06-tutorial.lisp
Normal file
40
tutorial/06-tutorial.lisp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
(defpackage #:clog-user
|
||||
(:use #:cl #:clog)
|
||||
(:export start-tutorial))
|
||||
|
||||
(in-package :clog-user)
|
||||
|
||||
(defun my-on-click (obj)
|
||||
(print "Event thread started") ; Every click will add a thread
|
||||
(unless (connection-data-item obj "isRunning") ; So we toggle a connection-data-item
|
||||
(setf (connection-data-item obj "isRunning") t) ; in order to turn on and off the flashing.
|
||||
(setf (text obj) "(click me to stop!)")
|
||||
|
||||
;; When looping in an event or thread always check if the connection is still
|
||||
;; valid to close down the event or thread.
|
||||
(loop
|
||||
(if (and (validp obj) (connection-data-item obj "isRunning"))
|
||||
(progn
|
||||
(setf (color obj) "green")
|
||||
(sleep 0.3)
|
||||
(setf (color obj) "red")
|
||||
(sleep 0.3))
|
||||
(return))))
|
||||
(setf (connection-data-item obj "isRunning") nil)
|
||||
(setf (text obj) "(click me to start!)")
|
||||
(setf (color obj) "black")
|
||||
(print "Event thread stopped"))
|
||||
|
||||
(defun on-new-window (body)
|
||||
"On-new-window handler."
|
||||
|
||||
(setf (title (html-document body)) "Tutorial 6")
|
||||
|
||||
(set-on-click (create-child body "<h1>(click me to start!)</h1>")
|
||||
#'my-on-click))
|
||||
|
||||
(defun start-tutorial ()
|
||||
"Start turtorial."
|
||||
|
||||
(initialize #'on-new-window)
|
||||
(open-browser))
|
||||
|
|
@ -38,3 +38,4 @@ Tutorial Summary
|
|||
03-tutorial.lisp - Events fire in parallel
|
||||
05-tutorial.lisp - The event target, reusing event handlers
|
||||
05-tutorial.lisp - Using connection-data-item
|
||||
06-tutorial.lisp - Tasking and events
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue