[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Popup Menus



I have a question about the view-default-size method on popup menus.
Here's what it is, from the library directory:

(defmethod view-default-size ((menu pop-up-menu))
  (let* ((the-font (view-font menu))
         (item-display (slot-value menu 'item-display))
         (max-menu-width (max 20 (if (stringp item-display)
                                   (string-width
                                    (or item-display "")
                                    the-font)
                                   0))))
    (setf (dialog-item-width-correction menu)
          (+ (if (equal "" (dialog-item-text menu)) 9 18)
             (dolist (m (menu-items menu) max-menu-width)
               (when (> (setq m (string-width (menu-item-title m)
                                              the-font))
                        max-menu-width)
                 (setq max-menu-width m)))))
    (add-points #@(19 4)
                (call-next-method))))

This doesn't seem to come out right, when I try it. I wrote this one
which seems right as far as I can see:

(defmethod view-default-size ((menu pop-up-menu))
  (let* ((font (view-font menu))
         (item-widths (mapcar #'(lambda (menu-item)
                                  (string-width (menu-item-title
menu-item) font))
                              (menu-items menu)))
         (title-width (string-width (menu-title menu) font))
         (width-spacing-correction 35)
        (height-spacing-correction 4))
    (multiple-value-bind (ascent descent max-width leading) (font-info font)
      (declare (ignore max-width))
      (make-point (+ width-spacing-correction (apply #'max item-widths)
                     title-width)
                  (+ height-spacing-correction leading ascent descent)))))

I didn't really test it much with different fonts, seeing as how the
menu itself is going to be in Chicago 12. Am I missing something here?

What's the #@(19 4) in the original for?
__________________________________________________________________________
Robby Findler                                               robby+@cmu.edu
Carnegie Mellon University    Pittsburgh, PA                (412) 681-4552