[mcclim-devel] [PATCH] Space layout calculation: make user-supplied options take precedence

Rudi Schlatte rudi at constantly.at
Sat Sep 24 12:46:35 UTC 2005


Hello,

I noticed that a text-field created with an explicit :width option  
nevertheless had a width calculated from its initial contents.  Fixed  
by the attached patch, which also introduces a fast path for the  
common case of no user-supplied options.

There's still work to be done in the layout code, e.g. the following  
code creates a frame 100px wide (I'd expect 500):

(define-application-frame textedit-frame () ()
   (:panes (edit :text-field :value "edit" :width 500))
   (:layouts (:default
                 (vertically (:min-width 1 :width 100 :max-width +fill+)
                   edit))))

Nevertheless, it's better than what's there currently, so I'll commit  
it shortly if there are no objections.

Cheers,

Rudi


Index: panes.lisp
===================================================================
RCS file: /project/mcclim/cvsroot/mcclim/panes.lisp,v
retrieving revision 1.155
diff -u -r1.155 panes.lisp
--- panes.lisp    29 Aug 2005 22:39:31 -0000    1.155
+++ panes.lisp    24 Sep 2005 12:37:08 -0000
@@ -538,63 +538,48 @@
(defun merge-one-option
      (pane foo user-foo user-min-foo user-max-foo min-foo max-foo)
-
+  ;; Some of the hair in the code below is because the user-supplied
+  ;; values need not be given in device units
-  ;; NOTE: The defaulting for :min-foo and :max-foo is different  
from MAKE-SPACE-REQUIREMENT.
-  ;;       MAKE-SPACE-REQUIREMENT has kind of &key foo (min-foo 0)  
(max-foo +fill+)
-  ;;       While user space requirements has &key foo (min-foo foo)  
(max-foo foo).
-  ;;       I as a user would pretty much expect the same behavior,  
therefore I'll take the
-  ;;       following route:
-  ;;       When the :foo option is given, I'll let MAKE-SPACE- 
REQUIREMENT decide.
-  ;;
-  ;; old code:
-  ;;
-  ;; ;; Then we resolve defaulting. sec 29.3.1 says:
-  ;; ;; | If either of the :max-width or :min-width options is not
-  ;; ;; | supplied, it defaults to the value of the :width option. If
-  ;; ;; | either of the :max-height or :min-height options is not
-  ;; ;; | supplied, it defaults to the value of the :height option.
-  ;; (setf user-max-foo  (or user-max-foo user-foo)
-  ;;       user-min-foo  (or user-min-foo user-foo))
-  ;;       --GB 2003-01-23
+  (cond
+    ((not (or user-min-foo user-max-foo user-foo))
+     ;; fast path
+     (values foo min-foo max-foo))
+    (t
+     ;; sec 29.3.1 says:
+     ;; | If either of the :max-width or :min-width options is not
+     ;; | supplied, it defaults to the value of the :width option. If
+     ;; | either of the :max-height or :min-height options is not
+     ;; | supplied, it defaults to the value of the :height option.
+     (setf user-min-foo (or user-min-foo user-foo min-foo)
+           user-max-foo (or user-max-foo user-foo max-foo))
-  (when (and (null user-max-foo) (not (null user-foo)))
-    (setf user-max-foo (space-requirement-max-width
-            (make-space-requirement
-             :width (spacing-value-to-device-units pane foo)))))
-  (when (and (null user-min-foo) (not (null user-foo)))
-    (setf user-min-foo (space-requirement-min-width
-            (make-space-requirement
-             :width (spacing-value-to-device-units pane foo)))))
-
-  ;; when the user has no idea about the preferred size just take the
-  ;; panes preferred size.
-  (setf user-foo (or user-foo foo))
-  (setf user-foo (spacing-value-to-device-units pane user-foo))
+     ;; when the user has no idea about the preferred size just take
+     ;; the panes preferred size.
+     (setf user-foo (or user-foo foo))
+     (setf user-foo (spacing-value-to-device-units pane user-foo))
-  ;; dito for min/max
-  (setf user-min-foo (or user-min-foo min-foo)
-    user-max-foo (or user-max-foo max-foo))
-
-  ;; | :max-width, :min-width, :max-height, and :min-height can
-  ;; | also be specified as a relative size by supplying a list of
-  ;; | the form (number :relative). In this case, the number
-  ;; | indicates the number of device units that the pane is
-  ;; | willing to stretch or shrink.
-  (labels ((resolve-relative (dimension sign base)
-         (if (and (consp dimension) (eq (car dimension) :relative))
-         (+ base (* sign (cadr dimension)))
-         (spacing-value-to-device-units pane dimension))))
-    (setf user-min-foo (and user-min-foo
-                (resolve-relative user-min-foo  -1 user-foo))
-      user-max-foo (and user-max-foo
-                (resolve-relative user-max-foo  +1 user-foo))))
-
-  ;; Now we have two space requirements which need to be 'merged'.
-  (setf min-foo (clamp user-min-foo min-foo max-foo)
-    max-foo (clamp user-max-foo min-foo max-foo)
-    foo     (clamp user-foo     min-foo max-foo))
-  (values foo min-foo max-foo))
+     ;; | :max-width, :min-width, :max-height, and :min-height can
+     ;; | also be specified as a relative size by supplying a list of
+     ;; | the form (number :relative). In this case, the number
+     ;; | indicates the number of device units that the pane is
+     ;; | willing to stretch or shrink.
+     (labels ((resolve-relative (dimension sign base)
+                (if (and (consp dimension) (eq (car  
dimension) :relative))
+                    (+ base (* sign (cadr dimension)))
+                    (spacing-value-to-device-units pane dimension))))
+       (setf user-min-foo (resolve-relative user-min-foo  -1 user-foo)
+             user-max-foo (resolve-relative user-max-foo  +1 user- 
foo)))
+
+     ;; again, user options take precedence
+     (setf min-foo (min min-foo user-min-foo)
+           max-foo (max max-foo user-max-foo))
+
+     ;; Now we have two space requirements which need to be 'merged'.
+     (setf min-foo (clamp user-min-foo min-foo max-foo)
+           max-foo (clamp user-max-foo min-foo max-foo)
+           foo     (clamp user-foo     min-foo max-foo))
+     (values foo min-foo max-foo))))
(defmethod merge-user-specified-options ((pane space-requirement- 
options-mixin)
                       sr)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
URL: <https://mailman.common-lisp.net/pipermail/mcclim-devel/attachments/20050924/80968339/attachment.sig>


More information about the mcclim-devel mailing list