Changing Field Width to Length of String

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Changing Field Width to Length of String

Post 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?
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Changing Field Width to Length of String

Post by dunbarx »

Hi.

Check out the "formattedWidth" in the dictionary.

Craig Newman
RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Changing Field Width to Length of String

Post 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.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Changing Field Width to Length of String

Post 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
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Changing Field Width to Length of String

Post 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
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Changing Field Width to Length of String

Post 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
RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: Changing Field Width to Length of String

Post 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.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Post Reply