First I realize this is in alpha so if the answer is the layout mangier is not working fully that is fine. I just want to know how this is supposed to work.
I have created a top level layout mangier that is vertical. inside it I have put a layout mangier that is horizontal and has an label and edit box and separately inside the top level under the first one I have put in a list box. Then finally I put another horizontal layout mangier under the list box that has 3 buttons.
So I think what I should get is a row with label and edit box and a second row with the list box and a third row with 3 buttons. If I understand it correctly it should grow the list box to be as long as my edit box and label together. Then finally make the buttons at the bottom all the same length of the longest row.
If that is how it is supposed to work it is not. My list box is not the same length as the edit box let alone the edit box and label together.
Can you take a look at this and tell me what I should be doing to line these controls up in this dialog?
(defclass fruit-events (gfw:event-dispatcher) ())
(defmethod gfw:event-close ((disp fruit-events) (dlg gfw:dialog)) (call-next-method) (let ((ownerp (gfw:owner dlg))) (gfs:dispose dlg) (unless ownerp (gfw:shutdown 0)))) (defun fruit-basket () (gfw:startup "Fruit basket" (lambda () (let* ((dlg (make-instance 'gfw:dialog :owner nil :dispatcher (make-instance 'fruit-events) :layout (make-instance 'gfw:flow-layout :margins 8 :spacing 8 :style '(:vertical)) :style :modeless :text "Fruit basket LISP demonstration")) ; (edit-disp (make-instance 'edit-control-events)) (top-panel (make-instance 'gfw:panel :layout (make-instance 'gfw:flow-layout :spacing 4 :style '(:vertical)) :parent dlg)) (inner-panel (make-instance 'gfw:panel :layout (make-instance 'gfw:flow-layout :spacing 4) :parent top-panel)) (fruit-list (make-instance 'gfw:list-box ;:callback (fruit-list-callback) :parent top-panel)) (fruit-label (make-instance 'gfw:label :text "Enter fruit:" :parent inner-panel)) (fruit-edit (make-instance 'gfw:edit :text "1234567890123456789012345" :parent inner-panel)) (btn-panel (make-instance 'gfw:panel :layout (make-instance 'gfw:flow-layout :spacing 4) :parent top-panel )) (btn-add (make-instance 'gfw:button :callback (lambda (disp btn ) (declare (ignore disp btn)) (gfw:append-item fruit-list (gfw:text fruit-edit ) nil nil) (setf (gfw:text fruit-edit) "") (gfw:give-focus fruit-edit)) :style '(:default-button) :text "Add" :parent btn-panel)) (btn-remove (make-instance 'gfw:button :callback (lambda (disp btn) (declare (ignore disp btn)) (gfw:delete-selection fruit-list) (gfw:give-focus fruit-edit)) :style '(:default-button) :text "Remove" :parent btn-panel)) (btn-exit (make-instance 'gfw:button :callback (lambda (disp btn) (declare (ignore disp btn)) (let ((ownerp (gfw:owner dlg))) (gfs:dispose dlg) (unless ownerp (gfw:shutdown 0)))) :style '(:cancel-button) :text "Exit" :parent btn-panel)))
(declare (ignore fruit-label btn-add btn-remove btn-exit)) (gfw:pack dlg) (setf (gfw:minimum-size dlg) (gfs:make-size :width 300 :height 200 )) (setf (gfw:text fruit-edit) "") (gfw:show dlg t) dlg))))
On 9/9/07, Ken Perry whistler@blinksoft.com wrote:
First I realize this is in alpha so if the answer is the layout mangier is not working fully that is fine. I just want to know how this is supposed to work.
You are right in two ways -- the whole thing needs much more functionality, and there are bugs.
If that is how it is supposed to work it is not. My list box is not the same length as the edit box let alone the edit box and label together.
Can you take a look at this and tell me what I should be doing to line these controls up in this dialog?
I got something closer to what I think you were intending. My revised version of your code is here:
http://lispwidgets.net/fruit2.lisp
Note that I used an in-package form at the top of the file, which you may want to remove.
I changed the dialog's layout to be a border-layout. The top-panel containing the fruit label and the edit control are placed in the top region of the layout. The inner-panel containing the list-box is placed in the center region. The btn-panel is placed in the bottom region. These placements are accomplished using the setf function for gfw:layout-attribute.
There is a bug in border-layout where spacing is not allocated to the center region, so I had to cheat by setting a top-margin value for the inner-layout.
The list-box is sized by a combination of setting a minimum-size on the list-box and using a heap-layout for the inner-panel.
I got the buttons to be equal widths by including the :normalize style for the btn-layout. This exercise revealed a second bug, which is that I had to also include the :horizontal style keyword explicitly, when in fact it should be the default anyway.
I realize that you had wanted the buttons to fill the available space, but there is a limitation of the layout management system in that I don't currently provide a way to get multiple children to fill the available width (or height). The heap-layout sort of works that way, but it's designed for just one visible child at a time. Also, I don't currently provide a way to right-justify or bottom-justify child elements within a panel. There are several possible ways to provide these behaviors, but I haven't decided which way to go yet. But this is why the buttons are still aligned left in the btn-panel.
By the way, you had the :default-button style set on two of the buttons. I changed it to just be the add button, but one or the other is fine.
The general strategy for packing dialogs (and top-level windows) is to allow child panels and controls to be sized according to their preferred sizes, or set minimum or maximum sizes on them, and let the size of the container be determined by that. You don't want to explicitly set a size on the dialog for the scenario you are trying to achieve.
Sorry for the long-winded reply, but there is one more comment I should make. I totally understand that part of the issue here is the difficulty in figuring how to use the layout managers. Obviously I understand them, having written the code, but for new folks it's not necessarily clear how it all fits together. This is something I will improve over time, with better examples and also better documentation. Not to mention bug fixes :-)
graphic-forms-devel@common-lisp.net