Fitting text in a field.

Moderators: LCNeil, heatherlaine, kevinmiller, elanorb

Post Reply
elanorb
Livecode Staff Member
Livecode Staff Member
Posts: 516
Joined: Fri Feb 24, 2006 9:45 am

Fitting text in a field.

Post by elanorb » Thu Mar 27, 2014 1:01 pm

Hi

In yesterday's webinar somebody asked about ensuring text fits in a field. There are 2 ways to do this, you can resize the field to fit the text or resize the text to fit the field.
textResize.PNG
In this example the code for the "Resize field" button is

Code: Select all

on mouseUp
   set the height of field 2 to the formattedHeight of field 2
   set the width of field 2 to the formattedWidth of field 2
end mouseUp
The code for the "Resize text" button is

Code: Select all

on mouseUp
   local tTextSize
   
   put the effective textSize of field 3 into tTextSize
   repeat until the formattedWidth of field 3 <= the width of field 3
      subtract 1 from tTextSize
      set the textSize of field 3 to tTextSize
   end repeat
end mouseUp
I hope that is helpful.

Kind regards

Elanor
Elanor Buchanan
Software Developer
LiveCode

jim1001
Posts: 143
Joined: Fri Jan 29, 2016 6:25 pm

Re: Fitting text in a field.

Post by jim1001 » Fri May 06, 2016 6:46 pm

Hi Elanor,

In the LiveCode 7.1.3 IDE there is a “Fit content” button on the “Size & Position” options for a field. I couldn’t find the equivalent in LiveCode 8.0.0. Anyhow I found that even when I used “Fit content” when using the 7.1.3 IDE on Windows, if I put the app onto a mobile device the text was often the wrong size for the field (although it looked right in the IDE).

I was wondering is it not worth laying out everything to look right in a Windows IDE if you’re going to deploy on mobile? Should all laying out be done with code as you’ve done?

On a slightly different theme is there anywhere I can see what all the options do in the Property Inspector pages? So far I’ve just been picking up scraps here and there and playing around. Couldn’t see much explanation in the User Guide.

Apologies for throwing a lot in here. It was getting late on a Friday…

Thanks,
Jim

Ps: is it you doing the Application Building course videos?

elanorb
Livecode Staff Member
Livecode Staff Member
Posts: 516
Joined: Fri Feb 24, 2006 9:45 am

Re: Fitting text in a field.

Post by elanorb » Thu May 12, 2016 5:54 pm

Hi Jim

Unfortunately you have run into a common and tricky problem, I would advise designing with some tolerances in mind and perhaps using the default fonts.

I think the most important thing is to decide whether you want to make your controls larger, where you need to, to fit the text, or make the text smaller to fit in your controls. In both cases you will either need to do some coding or test your app on the platforms you are interested in building for to find values that work cross platform.

It may be that you can just set the font size depending on the platform and that will be enough

Code: Select all

on preOpenCard
   switch the platform 
      case "Win32"
         set the textSize of me to 14
         break         
      case "MacOS"
         set the textSize of me to 12
         break
      case "Linux"
         set the textSize of me to 16
         break
      case "iphone"
           set the textSize of me to 14
         break
      case "android"
           set the textSize of me to 10`
         break
end preOpenCard
Regarding the missing "Fit content" button, this is a known issue and has been reported as a bug here

http://quality.livecode.com/show_bug.cgi?id=17618

You can add yourself to the CC list if you want to get updates when the status of the bug changes.

As far as properties in the Property Inspector go there isn't a list anywhere, but you can find all the properties in the Dictionary by using the filter in the left pane, and selecting the "property" type. The Dictionary entries explain each property in more detail.

As for the ABC videos some are me and some are Georgia, Georgia is English and I am Scottish, if you can tell which is which :)

I hope that helps.

Kind regards

Elanor
Elanor Buchanan
Software Developer
LiveCode

elanorb
Livecode Staff Member
Livecode Staff Member
Posts: 516
Joined: Fri Feb 24, 2006 9:45 am

Re: Fitting text in a field.

Post by elanorb » Thu May 12, 2016 5:58 pm

Just a quick follow up, if you want the properties for a particular control type they are all listed under the Dictionary entry for the control. So the "button" entry has a list of all the properties and messages that apply to buttons.
Elanor Buchanan
Software Developer
LiveCode

jim1001
Posts: 143
Joined: Fri Jan 29, 2016 6:25 pm

Re: Fitting text in a field.

Post by jim1001 » Fri May 13, 2016 11:24 am

Elanor,

Many thanks for the very helpful answer. Fortunately I’m only coding for one specific Android device at the moment. I had actually had got all the sizes right by trial & error in LC 7.13. Then when I used LC 8 to install the app everything was out again :-(

I’ve added myself to the bug update list - though as you imply & I’ve found, “Fit content” appeared to work in the Windows IDE but then things didn’t fit on the Android device.

Is the MobGUI extension any use for this kind of thing? I’m not sure if it’s still supported anyhow. Maybe it’s overkill for my current requirements but could be useful in the future.

I had a look at the dictionary entry for “button” and most of the properties are there as you said - thanks. I spotted some omissions so if I have the time & inclination could submit some doc bugs. Then again...

The videos have definitely been in Scottish :wink:
They are very clear & well explained, even reassuring! My only problem is remembering where I saw this or that so I’ve taken to compiling an index.

Thanks again,
Jim

Post Reply

Return to “idea2app and Coding School”