Script to resize text to fit text box?

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
cmhjon
Posts: 191
Joined: Tue Aug 04, 2015 11:55 am

Script to resize text to fit text box?

Post by cmhjon » Thu Aug 06, 2020 6:09 pm

Hi all,

I am looking for a way (via script) to look at some text in a text box and ensure the text box is wide enough to fully show all text characters within and if not decrease the text size accordingly. In this case, text boxes will contain a decimal measurement in inches. A text box could contain:

x
x.x
x.xx
x.xxx
x.xxxx
etc.

(x is a number of course)

Just figure the width based on the longest possible text string for all text boxes you say? That's great but then I run the risk of overlapping text between two neighboring text boxes.

A script is preferable but I am open to other ideas.

Thank you,
Jon :)

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: Script to resize text to fit text box?

Post by stam » Thu Aug 06, 2020 6:32 pm

Hi cmhjon,

haven't tested it but think the formattedWidth would do it?
i.e.

Code: Select all

set the width of field 1 to the formattedWidth of field 1

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Script to resize text to fit text box?

Post by jmburnod » Thu Aug 06, 2020 6:33 pm

Hi Jon,
Here is a thread probably useful for you
viewtopic.php?f=7&t=30996&hilit=textsize+formattedwidth
Best regards
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10319
Joined: Wed May 06, 2009 2:28 pm

Re: Script to resize text to fit text box?

Post by dunbarx » Thu Aug 06, 2020 8:53 pm

Hi.

There have been several threads on this topic.

When you mention changing the textSize in certain cases, does that mean that there is a maximum allowable width for the field? If not, then setting the formattedWidth, as stam posted, should be fine. If so, however, and this was discussed as well, you may not want to reduce the textSize beyond what is reasonable for the user to read. It is not good practice anyway, as users are not expecting this sort of action.

So what are your limitations, if any?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10319
Joined: Wed May 06, 2009 2:28 pm

Re: Script to resize text to fit text box?

Post by dunbarx » Thu Aug 06, 2020 9:29 pm

I found the discussion about a similar topic:
viewtopic.php?f=9&t=34247&p=192845&hili ... th#p192845

Craig

Post Reply