[cells-devel] [CELTK] A "grid" widget
Andy Chambers
achambers.home at googlemail.com
Mon Jul 27 23:19:07 UTC 2009
I came across the need for a "grid" widget in celtk. It's really just
a macro "mk-grid"
that lets you compose a grid as a set of rows with a function to make
each row. The
function should take two arguments; the first is the row object for
the row that is
currently being created, the second is the row-number so that you can
use it in the
:gridding slot. I've not used it in anger yet so it may evolve a bit
yet but I'll post any
updates as they come.
Usage would be as follows:
(celtk::run-celtk-window 'window
:kids (c? (the-kids
(mk-stack (:packing (c?pack-self))
(mk-grid
:gridding '(:columns ("-weight {1}" "-weight {0}")
:rows ("-weight {1}" "-weight {0}"))
:rows '(car cdr)
:row-factory (lambda (row row-num)
(list
(mk-label :text (format nil "~a: " row)
:gridding (format nil
"-row ~a -column 1 -padx 30 -sticky nw"
row-num))
(mk-label :text (format nil "~a" (with-output-to-string (s)
(describe row s)))
:gridding (format nil
"-row ~a -column 2" row-num)))))))))
diff --git a/frame.lisp b/frame.lisp
index 3f5b2b2..37d6e4e 100644
--- a/frame.lisp
+++ b/frame.lisp
@@ -42,6 +42,32 @@ See the Lisp Lesser GNU Public License for more details.
(defmd stack-mixin (inline-mixin)
:packing-side 'top)
+;--- g r i d s ----------------------------------------------
+
+(defmd grid (grid-manager frame)
+ (rows)
+ (row-factory)
+ (kids (c? (the-kids
+ (loop for row in (^rows)
+ for row-num from 0
+ collect (funcall (^row-factory)
+ row
+ row-num))))))
+
+(defobserver .kids ((self grid))
+ (when new-value
+ (loop for k in new-value
+ when (gridding k)
+ do (tk-format `(:grid ,k)
+ (format nil "grid ~a ~a"
+ (path k)
+ (gridding k))))))
+
+(defmacro mk-grid (&rest initargs)
+ `(make-instance 'grid
+ , at initargs
+ :fm-parent *parent*))
+
;--- f r a m e --------------------------------------------------
diff --git a/packages.lisp b/packages.lisp
index 5318b8c..e0b0cc9 100644
--- a/packages.lisp
+++ b/packages.lisp
@@ -48,6 +48,8 @@
#:entry
#:mk-entry
#:text
+
+ #:mk-grid
#:frame-stack
#:frame-row
--
----
Andy Chambers
Formedix Ltd
More information about the cells-devel
mailing list