Lisp HUG Maillist Archive

Push-button & Menu

Hi, I have a problem with the creation of a push-button.
In the following code If you press “item-1” a push-button  (button1) is created
in a different area from the pinboard-layout. 
I want  to create this push-button in the pinboard-layout. 

Thanks in advance

(capi:define-interface interface-2 ()
  ()
  (:panes
   (output-pane-1
    capi:output-pane))
  (:layouts
   (column-layout-1
    capi:column-layout
    '(row-layout-1))
   (row-layout-1
    capi:row-layout
    '(output-pane-1 pinboard-layout-1))
   (pinboard-layout-1
    capi:pinboard-layout
    ()))
  (:menu-bar menu-1)
  (:menus
   (menu-1
    "Menu-1"
    (("Item-1"
      :callback 'f1)
     "Item-2")))
  (:default-initargs
   :best-height 280
   :best-width 300
   :layout 'column-layout-1
   :title "Interface-3"))

(defun f1(data interface)

(let ((button1 (make-instance 'capi:push-button

                              :text "button1"

                              ;:internal-border 20

                              :visible-min-width 200)))
 (capi:contain (make-instance 'capi:push-button-panel

                           :items (list button1)

                           :layout-args '(:x-gap 30)))))




 (capi:display (make-instance 'interface-2))



Re: Push-button & Menu

On Thursday 28 May 2009 10:33:55 am Foteini Grivokostopoulou wrote:

>

> Hi, I have a problem with the creation of a push-button.

Change f1 to be:

(defun f1(data interface)

(let ((button1 (make-instance 'capi:push-button

:text "button1"

;:internal-border 20

:visible-min-width 200)))

(setf (capi:layout-description (slot-value interface 'pinboard-layout-1))

(list (make-instance 'capi:push-button-panel

:items (list button1)

:layout-args '(:x-gap 30)

:x 30

:y 100)))))

Your version of f1 used capi:contain, which opens a new window (a "container" for testing purposes).

Capi layouts have a (list) field called a "description", accessible with the function capi:layout-description. The items managed by the layout must be in the description list. Normally you would stick items into the description using the '( ... ) arguments in the capi:define-interface macro, but that adds them statically (you could use capi:hide-pane / show-pane to turn them off/on), but, in your example code you seemed to want to add a button dynamically, hence, you have to alter the description dynamically.

(You should be able to use capi:manipulate-pinboard to change the description, but when I tried it, it complained that push-button-panel is not a pinboard-object.)

Note that, for this simple example, you don't even need the push-button-panel, you can just add an :x and :y to the button1 and throw it directly into the description list.

In general, if you are laying out a GUI, try using the other layout helper classes, like row-layout, column-layout, grid-layout, etc. They automagically pack your items together and handle resizing of the gui, whereas a pinboard layout will not reposition your button if your resize. Same deal with those classes - if you really need to add/remove buttons dynamically, you do it by altering their capi:layout-description's.

pt

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