On Tuesday 27 January 2004 1:25 am, Steve Wampler wrote:
> On Mon, 2004-01-26 at 08:42, Steve Wampler wrote:
> > On Mon, Jan 26, 2004 at 08:29:58AM -0700, Steve Wampler wrote:
> > > Does anyone have any code for figuring out the 'size' (x,y bounds)
> > > of a string before it is displayed in a component?
> >
> > Ah, reading the "Graphics Programming in Icon", I've found
> > the WAttrib("ascent"), WAttrib("descent"), and WAttrib("leading")
> > calls.  That should be sufficent, along with TextWidth() to
> > do the above.
>
> Ok, apparently I lied.  Nothing is easy, even
> after finding WAttrib(w, "height") and
> WAttrib(w, "leading")...
>
> TextWidth() and WAttrib() require the window as
> a parameter - but apparently there is no window
> associated with a _Dialog while it is being setup()
> (window value is &null), so I can't get use the
> above after all...
>
> Now, I *think* I can get around this by estimating
> the width using the 'width' (maximum character width)
> of the font, but how do I get the font during
> _Dialog setup()?
>
> Is there another way?
>
> Thanks!
> Steve

Hi Steve

This is possible by use of a temporary "hidden" window.

If "s" is the string to be displayed in "label", you could override the 
component_setup() in the dialog to do the following :-

   method component_setup()
      local win, width

      # Setup the label and other components
      self.setup()

      win := (WOpen ! (["canvas=hidden"] ||| self.attribs)) |  
                             fatal("couldn't open window")
      width := TextWidth(win, s)
      WClose(win)

      label.set_label(s)
      set_attribs("size=" || (width + 50) || ",140")
   end


Hope this helps,


R



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to