[comp.windows.news] question about liteitem.ps

marantz@aramis.rutgers.edu (Roy Marantz) (04/07/88)

I'm trying to define items (ala liteitem) that are "self-sizing".  By
that I mean I want to define some part of the item (say a label) and
have the rest of the item scale itself appropriately.  Anyway I tried
to get TextItem to behave this way and have had no luck.  Does anyone
understand enough about how TextItem works to give me some clues?  I
hoped that issuing a "/reshape self send" in the right place would
cause a TextItem to redo its shape, but this doesn't seem to work.
TextItem /reshape created a /new LiteText object each time it is
called and this makes it "context sensitive".  Any ideas?  Can anyone
explain the linkage between a TextItem and LiteText, LabeledItem, and
Item?  There is alot of context that is not documented and the code
seems alittle obscure.  What else is new :-)  Thanks for any help or
pointers.

Roy
-- 
uucp:   {ames, cbosgd, harvard, moss}!aramis.rutgers.edu!marantz
arpa:   marantz@aramis.rutgers.edu

don@BRILLIG.UMD.EDU (Don Hopkins) (04/08/88)

   Date: 7 Apr 88 00:00:00 GMT
   From: aramis.rutgers.edu!marantz@rutgers.edu  (Roy Marantz)

   I'm trying to define items (ala liteitem) that are "self-sizing".  By
   that I mean I want to define some part of the item (say a label) and
   have the rest of the item scale itself appropriately.  Anyway I tried
   to get TextItem to behave this way and have had no luck.  Does anyone
   understand enough about how TextItem works to give me some clues?  I
   hoped that issuing a "/reshape self send" in the right place would
   cause a TextItem to redo its shape, but this doesn't seem to work.
   TextItem /reshape created a /new LiteText object each time it is
   called and this makes it "context sensitive".  Any ideas?  Can anyone
   explain the linkage between a TextItem and LiteText, LabeledItem, and
   Item?  There is alot of context that is not documented and the code
   seems alittle obscure.  What else is new :-)  Thanks for any help or
   pointers.

   Roy
   -- 
   uucp:   {ames, cbosgd, harvard, moss}!aramis.rutgers.edu!marantz
   arpa:   marantz@aramis.rutgers.edu

(I've been playing around with Items recently, and here is an attempt
to rationalize some of what I've learned ...)

Class LabeledItem has methods called /AdjustItemSize and
/CalcObj&LabelXY, which are used by various subclass's /reshape
method. (It doesn't use them itsself.)

These items have a Label and an Object, and a method for determining
the /LabelSize ( - => LabelWidth LabelHeight ), and (sometimes) the
/ObjectSize ( - => ObjectHeight ObjectWidth ).

/AdjustItemSize makes sure the item's at least big enough to hold both
the Label and the Object. (The size depends on the ObjectLoc, which
can be /Right, /Left, /Top, or /Bottom, and determines where the Object
is positioned relative to the Label.)

/CalcObj&LabelXY lays the Label and the Object out in the Item, using
ItemBorder and ItemGap, and vertically or horizontally centers them
next to each other in the Object according to ObjectLoc.

For example, TextItem's /reshape method does the following:

% ItemWidth and ItemHeight are set from the values passed to /reshape. 
% The Object has been given some initial size in ObjectWidth, ObjectHeight. 
% Make sure the ItemWidth and ItemHeight are at least large enough to hold
% both the Label and the Object, with borders and a gap.
% (The Item won't be made any smaller, just enlarged if necessary.)
        AdjustItemSize
% Expand ObjectWidth so it's as wide as will fit in this item.
        /ObjectWidth ItemWidth 2 ItemBorder mul sub def
% If the object is beside the label, narrow it down by the label width and gap!
        ObjectLoc /Right eq ObjectLoc /Left eq or {
            /ObjectWidth ObjectWidth LabelWidth sub ItemGap sub def
        } if
% Lay out the Label and the Object, so they're centered appropriatly
% in the item.
        CalcObj&LabelXY

If you /reshape one of these items to some large size, wider that the
ItemObject's minimum width, it will expand horizontally to fill the
space. If you wanted, you could make it expand the ObjectHeight to use
all available vertical space, as well. (If ObjectLoc's /Top or
/Bottom, then don't forget to subtract LabelHeight and ItemGap!) If
you /reshape it smaller than it wants to be (the initial object size)
in either dimension, it will grow appropriatly. Look at
various Items' /reshape methods to see how they set up initial
(minimum) values for ObjectWidth and ObjectHeight.  Your /PaintItem
method, or whatever it calls to paint the Object, should look at
ObjectX, ObjectY, ObjectWidth, and ObjectHeight, and scale its
graphics into that space.

I hope this is of some use to you! 

	-Don