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

word wrapping

I have an object called a "titled icon," which consists of an icon
and a static-text-dialog-item.  The function set-ti-size calculates the
length of the title in pixels and sets the size of the icon and
the title appropriately.

I'm using the set-view-size method for static-text-dialog-itemS to do
my word wrapping.  This is causing problems.  My calculation of how
many lines I need for the title is correct if there weren't
any wrapping.  A shorter title can sometimes take up more space,
depending on where things wrap.  How can I account for this?
For now, I've included a fudge factor of 1 extra line, but this
is causing lay out problems.


-- Amy

Here's the function:

(defun set-ti-size (my-titled-icon &key (extra-width 0))
  (with-slots (icon-size icon-title title-pointer) my-titled-icon
    (let* ((ti-font (view-font my-titled-icon))
           (icon-h (point-h icon-size))
           (icon-v (point-v icon-size))
           (ti-size-h (+ icon-h *ti-extra-horizontal-margin* extra-width))
           (width (string-width icon-title ti-font))
           (lines (+ (ceiling width ti-size-h) 1)) ; the 1 is a fudge factor
           (title-size-v   (* (line-height ti-font) lines))
           (ti-size-v  (+ icon-v *ti-icon-title-gap* title-size-v))
           (title-size (make-point ti-size-h title-size-v)))
      (set-view-size title-pointer title-size)
      (set-view-size my-titled-icon ti-size-h ti-size-v))))