Lisp HUG Maillist Archive

How to select menu-items, :selected-item-function vs. :selected-function

Hello LispWorkers,  I wonder if anyone can explain to me what's
happening in the following two pieces of code, one of which seems to
work, but the other doesn't.  In this simplified example, I'm
capi:contain'ing a capi:menu-component with 10 items whose data are
the integers 1 to 10.

In the first case, the menu-component has a :selected-item-function
that always returns 3, so the the menu-item whose datum is 3 is
selected is marked as selected when the component appears on screen.
This code works (LWM 6.0.1, OS X 10.5.8).

(flet ((make-item (i)
         (make-instance
          'capi:menu-item :data i)))
  (capi:contain
   (make-instance
    'capi:menu-component
    :interaction :single-selection
    :items-function
    #'(lambda (&rest args)
        (loop for i from 1 to 10 collect (make-item i)))
    :selected-item-function (constantly 3))))

In the second case, the menu-items have selected-functions, but such
that the only item whose selected-function will return true is the
menu-item whose datum is 3.  In this case the component has no
selected-item-function, of course.  This code doesn't work.

(flet ((make-item (i)
         (make-instance
          'capi:menu-item :data i
          :selected-function #'(lambda (&rest args)
                                 (declare (ignore args))
                                 (eql i 3)))))
  (capi:contain
   (make-instance
    'capi:menu-component
    :interaction :single-selection
    :items-function
    #'(lambda (&rest args)
        (loop for i from 1 to 10 collect (make-item i))))))

Does anyone know what's happening here?  Thanks in advance!

-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/


Re: How to select menu-items, :selected-item-function vs. :selected-function

I don't know the answer to your question, but you can work around by
choosing :multiple-selection for the :interaction argument (it works
normally). This doesn't change anything because all the items are tested
and, in any case, just one is eql to 3.

Best regards

Denis


Le 22/06/10 18:51, « [NOM] » <[ADRESSE]> a écrit :

> 
> Hello LispWorkers,  I wonder if anyone can explain to me what's
> happening in the following two pieces of code, one of which seems to
> work, but the other doesn't.  In this simplified example, I'm
> capi:contain'ing a capi:menu-component with 10 items whose data are
> the integers 1 to 10.
> 
> In the first case, the menu-component has a :selected-item-function
> that always returns 3, so the the menu-item whose datum is 3 is
> selected is marked as selected when the component appears on screen.
> This code works (LWM 6.0.1, OS X 10.5.8).
> 
> (flet ((make-item (i)
>          (make-instance
>           'capi:menu-item :data i)))
>   (capi:contain
>    (make-instance
>     'capi:menu-component
>     :interaction :single-selection
>     :items-function
>     #'(lambda (&rest args)
>         (loop for i from 1 to 10 collect (make-item i)))
>     :selected-item-function (constantly 3))))
> 
> In the second case, the menu-items have selected-functions, but such
> that the only item whose selected-function will return true is the
> menu-item whose datum is 3.  In this case the component has no
> selected-item-function, of course.  This code doesn't work.
> 
> (flet ((make-item (i)
>          (make-instance
>           'capi:menu-item :data i
>           :selected-function #'(lambda (&rest args)
>                                  (declare (ignore args))
>                                  (eql i 3)))))
>   (capi:contain
>    (make-instance
>     'capi:menu-component
>     :interaction :single-selection
>     :items-function
>     #'(lambda (&rest args)
>         (loop for i from 1 to 10 collect (make-item i))))))
> 
> Does anyone know what's happening here?  Thanks in advance!

-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgique

Tel : 32 (0)2 219 31 09
Mail :  denis.pousseur@gmail.com
-------------------------------------------------------



Updated at: 2020-12-10 08:39 UTC