Andy Chambers wrote:
On 11/2/07, Andy Chambers achambers.home@googlemail.com wrote:
(defmacro mk-expander ((&rest initargs) &rest kids) `(make-instance 'expander ,@initargs :fm-parent *parent* :expansion (c? (the-kids ,@kids)) :expanded (c-in nil) :kids (c? (the-kids (mk-button-ex ((^label) (setf (expanded (upper self expander)) (not (expanded (upper self expander)))))) (when (^expanded) (^expansion))))))
(defmacro mk-expander ((&rest initargs) &rest kids) `(make-instance 'expander ,@initargs :fm-parent *parent* :expansion (c? (lambda () (the-kids ,@kids))) :expanded (c-in nil) :kids (c? (the-kids (mk-button-ex ((^label) (setf (expanded (upper self expander)) (not (expanded (upper self expander)))))) (when (^expanded) (funcall (^expansion)))))))
wrapping the expansion rule inside a lambda works. This creates a new set of widgets each time the rule runs though. Is there some way of doing it without that?
There are two things you can do here. One is to look at the family-values class, which has a fancy mechanism for maintaining a list of kids based on the md-value slot, which would go back and forth between '(:expander) and '(:expander :expandee). Then the kids rule avoids forever generating the expander widget because it basically pairs widget kids against the md-value list and sees it can keep a kid (a big issue being that rules can see the last value calculated most supportedly via the .cache symbol macro).
The other approach makes the expandee simply /visible/ based on the parnets expanded value. This avoids creating/destroying/recreating what is often an expensive widget. My GUI classes also have a 'collapsed' slot which can be set to mirror the visible slot of an expandee, so you get the treeview effect where the expansion closes up and everything scrunches back over to conserve space.
I usually go with the latter.
Your second post came thru pretty fast after the first (seems like maybe the lists started working again?) so I did not get a chance to meditate on why the expander only worked thru one cycle. I did see some things I would do differently, but the above pretty much moves us a couple of squares ahead so let's stay where we are.
ken