forked from rabbibotton/clog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
21-tutorial.lisp
73 lines (63 loc) · 3.44 KB
/
21-tutorial.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
;;;; It this tutorial we will create a Common Lisp CLOG version of the
;;;; plugin from the previous two tutorials.
;;; First we will create a package for our component
(defpackage #:clog-drop-list
(:use #:cl #:clog)
(:export clog-drop-list
create-drop-list
drop-root))
(in-package :clog-drop-list)
;;; Next we will use the clog-unordered-list as the base for our new
;;; class clog-drop-list and allow access to the "drop-root" for
;;; list items to be children of.
(defclass clog-drop-list (clog-unordered-list)
((drop-root :accessor drop-root))
(:documentation "CLOG Drop List object - a collapsible list component"))
(defgeneric drop-root (clog-drop-list)
(:documentation "Accessor for the drop list root, create clog-list-items
on the drop-root."))
(defgeneric create-drop-list (clog-obj &key content class html-id auto-place)
(:documentation "Create a drop-list with CONTENT as the top of tree."))
(defmethod create-drop-list ((obj clog-obj) &key (content "")
(class nil)
(html-id nil)
(auto-place t))
(let* ((new-obj (create-unordered-list obj :class class
:html-id html-id
:auto-place auto-place))
(header (create-list-item new-obj :content content)))
(change-class new-obj 'clog-drop-list)
(setf (drop-root new-obj) (create-unordered-list header))
(set-on-mouse-down header
(lambda (obj data)
(declare (ignore obj data))
(if (hiddenp (drop-root new-obj))
(setf (hiddenp (drop-root new-obj)) nil)
(setf (hiddenp (drop-root new-obj)) t)))
:cancel-event t) ; prevent event bubble up tree
new-obj))
(defpackage #:clog-tut-21
(:use #:cl #:clog)
(:export start-tutorial))
(in-package :clog-tut-21)
(defun on-new-window (body)
(let* ((drop-list (clog-drop-list:create-drop-list body :content "Top of tree"))
(item (create-list-item (clog-drop-list:drop-root drop-list) :content "Item 1"))
(item (create-list-item (clog-drop-list:drop-root drop-list) :content "Item 2"))
(item (create-list-item (clog-drop-list:drop-root drop-list) :content "Item 3"))
(item (create-list-item (clog-drop-list:drop-root drop-list) :content "Item 4"))
(drop-list2 (clog-drop-list:create-drop-list item :content "Another Drop"))
(item (create-list-item (clog-drop-list:drop-root drop-list2) :content "Item 1"))
(item (create-list-item (clog-drop-list:drop-root drop-list2) :content "Item 2"))
(drop-list3 (clog-drop-list:create-drop-list item :content "Hidden Drop"))
(item (create-list-item (clog-drop-list:drop-root drop-list3) :content "Item 1"))
(item (create-list-item (clog-drop-list:drop-root drop-list3) :content "Item 2"))
(drop-list4 (clog-drop-list:create-drop-list drop-list :content "One more Drop"))
(item (create-list-item (clog-drop-list:drop-root drop-list4) :content "Item 1"))
(item (create-list-item (clog-drop-list:drop-root drop-list4) :content "Item 2")))
(declare (ignore item))
(setf (hiddenp (clog-drop-list:drop-root drop-list3)) t)))
(defun start-tutorial ()
"Start tutorial."
(initialize 'on-new-window)
(open-browser))