[cells-devel] Scrollable celtk widgets

Andy Chambers achambers.home at googlemail.com
Sat Dec 19 20:58:55 UTC 2009


One annoying limitation of tk widgets is that only text and canvas
support the commands required for
scrollbars.  So I made the `mk-scrollee' macro.  Used in conjunction
with a new type of canvas item
I created `window-item', we can wrap any tk window in a canvas so that
it can be scrolled.

I tried making :scroll-region a rule where the dimensions are derived
from the wrapped window but got
an assertion error in tk-create-event-handler-ex.  Is that because
it's trying to get the dimensions of a
widget that's not been created yet?  How could I get around this?

As always, feel free to import this stuff into celtk/cello if you want.

Cheers,
Andy

(deftk window-item (item)
  ()
  (:tk-spec window
   -anchor
   -height
   -width
   -state
   -tags
   -window
   ))

(defmacro mk-scrollee ((&key (height 500)
			     (width 500)) &body body)
  "wraps any tk window inside a canvas so that it can be scrolled"
  `(make-kid 'canvas
    :scroll-region (list 0 0 ,width ,height)
    :gridding "-row 0 -column 0 -sticky news"
    :kids (c? (the-kids
	       , at body
	       (mk-window-item
		:coords (list 0 0)
		:window (c? (path (kid1 .parent)))
		:anchor 'nw
		:height (c? (height (kid1 .parent)))
		:width (c? (width (kid1 .parent))))))))

;;; Usage
(run-celtk-window 'window
  :kids (c? (the-kids
  (mk-scroller
   :packing (c?pack-self "-side top -fill both -expand 1")
   :canvas (c? (mk-scrollee (:height 1000
                             :width 500)
		 (mk-stack ()
		   (loop for i from 0 to 30
		      collect (mk-label :text (format nil "hi ~a" i))))))))))

-- 
----
Andy Chambers
Formedix Ltd




More information about the cells-devel mailing list