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

Re: Table widgets



In article <7tq4n8$j37$1@nntp.itservices.ubc.ca>,
  nilsj@unixg.ubc.ca (Nils Johnson) wrote:
> I have two questions about the WIDGET_TABLE command. I am trying to
> create a read-only table as part of a larger widget. It's not too
> hard to get something going, but...
>
> 1. There is a funny "gap" on the right and bottom sides of the table.
> What is the reason for this extra space, and is there any way to get
> rid of it?
>
> 2. I would like to set the column widths so that no text is cut off.
> Is there a relatively easy way to determine the number of pixels (or
> inches, or centimeters) a given string will take on the screen? Or
> is there some other slick way?
>
> Nils
>

(Before I start this may be the second time this post appears because I
wasn't sure whether my news feed was working so I posted it again via
Deja.)

Anyway the problem and the answer to 2 is yes. Now I've found this to
be an extremely accurate method, and if I I
understand what you're trying yo do then tihs should work . As I read
it,
you're trying to get the columns to automatically size by not just the
the
title (as IDL does automatically) but also by what's in the columns, so
the
maximum width.

Essentially you're going to use a dynamic resizing label widget to
calculate the width of the strings on the screen. So first we set this
up

base = Widget_Base(MAP=0)
label = Widget_Label(base, /DYNAMIC_RESIZE, VALUE='')

For a particular column, find out the strLen() of the longest column
value
or column title, i.e. on average the widest. Of course one of the other
column values might be slightly wider on screen if the max strLen() one
is
composed entirely of llllllllllll and a shorter one is all wwwwwww. But
in
practice it works out fine.

Now we set the label's value to this string we have found which is the
longest:

Widget_Control, label, SET_VALUE=longString

..and then we find out the width of this label:

width = (Widget_Info(label, /GEOMETRY)).scr_xsize

If you then add on about 20 pixels or so for safety (you can tell I'm
doing
engineering at Uni). After you've repeated this for all columns you
have an
array which can be used for

Widget_Control, tableID, SET_COLUMN_WIDTHS=[width1, width2......]

I hope this helps. It took me a little while to work this out when I
had to
do it, but I think you'll find that it works quite effectively,
provided I
understood what you were wanting correctly. The IDL table widget is not
good
but can be caressed into doing vaguely what you want it to.


Cheers,

Phil Aldis

reply to:
philaldis@yahoo.com


Sent via Deja.com http://www.deja.com/
Before you buy.