Lisp HUG Maillist Archive

Dynamic layout and control counts in CAPI

Hi,

Using CAPI, I want to create a panel which contains a number spinner at the top and below it, a number of drop-down menus dynamically equal to the number in the spinner. Is there an easy way to do this in CAPI? The only languages I know that I've seen to do this well are a few functional reactive ones; is there a nice way for doing this in LISP?

Mark

Re: Dynamic layout and control counts in CAPI

Unable to parse email body. Email id is 13353

Re: Dynamic layout and control counts in CAPI

I shall study that, but it looks really good. Thanks very much!

Mark


On Tue, May 12, 2015 at 1:20 PM, Dave Fox <davef@lispworks.com> wrote:

 > Using CAPI, I want to create a panel which contains a number spinner at the
 > top and below it, a number of drop-down menus dynamically equal to the
 > number in the spinner. Is there an easy way to do this in CAPI? The only
 > languages I know that I've seen to do this well are a few functional
 > reactive ones; is there a nice way for doing this in LISP?

Something like this?

----------------------------------------------------------------------
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defpackage "MY-PACKAGE" (:use "CAPI") (:add-use-defaults))
  )

(in-package "MY-PACKAGE")

(define-interface mark ()
  ((start :initform 1)
    (end :initform 3)
    (dropdowns :initform (make-hash-table)))
  (:panes
   (text-input-range-1
    text-input-range
    :start start
    :end end
    :callback 'set-dropdowns
    :callback-type :interface-data
    :title "Select number of dropdowns:"))
  (:layouts
   (column-layout-1
    column-layout
    '(text-input-range-1 column-of-dropdowns))
   (column-of-dropdowns
    column-layout
    ()))
  (:default-initargs
   :layout 'column-layout-1
   :title "Mark"
   ))

(defun get-dropdown (self i)
  (with-slots (dropdowns) self
    (or (gethash i dropdowns)
        (setf (gethash i dropdowns)
              (make-instance 'text-input-choice
                             :items (loop for j from (char-code #\A) to (char-code #\Z)
                                          collect (format nil "~D-~A" i (code-char j))))))))

(defun get-dropdowns (self start end)
  (loop for i from start below end
        collect
        (get-dropdown self i)))

(defmethod interface-display :before ((self mark))
  (with-slots (column-of-dropdowns start end) self
    (setf (layout-description column-of-dropdowns)
          (get-dropdowns self start (1- end)))))

(defun set-dropdowns (self item)
  (with-slots (column-of-dropdowns start) self
    (setf (layout-description column-of-dropdowns)
          (get-dropdowns self start (+ start item)))))

; (display (make-instance 'mark))
----------------------------------------------------------------------


--
Dave Fox
LispWorks Ltd
http://www.lispworks.com/

Registered Office: St John's Innovation Centre, Cowley Road, Cambridge CB4 0WS
Registered in England: No. 5114963
EC VAT ID: GB 833329531


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