Page 1 of 1

Changing Field Width to Length of String

Posted: Tue May 17, 2016 5:12 am
by RossG
I have a field of width x.
I have a comma-delimited string of width x + 20.
How can I change the field width to accommodate the string?
The width of the string will depend on the numbers.
Perhaps a fixed-width font (if there is such a thing) would help.
Does the string have a width?

Re: Changing Field Width to Length of String

Posted: Tue May 17, 2016 5:56 am
by dunbarx
Hi.

Check out the "formattedWidth" in the dictionary.

Craig Newman

Re: Changing Field Width to Length of String

Posted: Thu Jun 09, 2016 3:51 am
by RossG
Craig
formattedWidth doesn't give a consistent result
when divided by the number of items - close but
not exact.

I'll use a graphic with width 10px X number of items.

Re: Changing Field Width to Length of String

Posted: Thu Jun 09, 2016 4:50 am
by dunbarx
I cannot think what you have going on. If I place a bunch of text in a field, that text being wider than the field itself so that it runs off the right side, and then (pseudo)

Code: Select all

set the width of that field to the formattedWidth of that field
All is right with the world. What are you seeing?

Craig

Re: Changing Field Width to Length of String

Posted: Thu Jun 09, 2016 6:50 am
by bn
Hi Ross,

If I understand correctly what you are trying to do
Perhaps a fixed-width font (if there is such a thing) would help.
yes there are monospaced fonts, on Mac this is e.g. Courier or Monaco. If you have only singel digit numbers or fore each item the same number of digits for your items than it should work.
Does the string have a width?
look at measureText in the dictionary. It gives you the rect of a string.

Kind regards
Bernd

Re: Changing Field Width to Length of String

Posted: Thu Jun 09, 2016 1:48 pm
by dunbarx
Bernd.

What am I missing with suggesting the formattedWidth? The OP simply wants the field to adjust itself to be able to display a string of any length.

Or at least I think he does. Calculating the width of text by counting the number of chars of a monospaced font surely would work, but seems like a roundabout way to do so, and then limits your font options somewhat, er, drastically.

Craig

Re: Changing Field Width to Length of String

Posted: Fri Jun 10, 2016 12:15 am
by RossG
What I want to do is bar-graph the fields by the number of items.
Since some have single-digit numbers and some don't just the
digit count (formattedWidth ?) won't give the right answer.

It was just an idea since I have the item count for each
field available so no trouble to use that to change the
width of a graphic.

Thank you gentlemen for your help.