How to know if a text will fit on a label field?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
How to know if a text will fit on a label field?
Hi experienced developers, I have this "fixed width, height" label field to which before setting its contents (at run time) I would like to know if the text is going to fit on it.
In other words I would like to avoid to set the contents to a text that will imply that the user will need need to scroll the field in order to be able to read it.
The text could have variable length and line breaks...
I can't figure out how to handle it.
Hope I made myself clear.
Thanks
In other words I would like to avoid to set the contents to a text that will imply that the user will need need to scroll the field in order to be able to read it.
The text could have variable length and line breaks...
I can't figure out how to handle it.
Hope I made myself clear.
Thanks
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question
Re: How to know if a text will fit on a label field?
Hi Simon,
Not sure i understand you correctly.
I you need to display all the text in a field with width fixe, you may use formattedHeight
To know if you can display your text in your fld:
A quick and dirty way to resize the fld:
Best regards
Jean-Marc
Not sure i understand you correctly.
I you need to display all the text in a field with width fixe, you may use formattedHeight
To know if you can display your text in your fld:
Code: Select all
put the height of fld "myField" >= ((the formattedHeight of fld "myField") + (the margins of fld "myField"))
Code: Select all
...
lock screen
put the topleft of fld "myField" into tTL
set the height of fld "myField" to ((the formattedHeight of fld "myField") + (the margins of fld "myField"))
set the topleft of fld "myField" to tTL
...
Jean-Marc
https://alternatic.ch
Re: How to know if a text will fit on a label field?
Hi Simon,
what Jean-Marc said does also apply to buttons, so this worked fine in my little test:
Width of button -> 82 px
Label of button -> Button, very loooooooooong
Script:
Et voila, it fits (new width 149 px)! 
what Jean-Marc said does also apply to buttons, so this worked fine in my little test:
Width of button -> 82 px
Label of button -> Button, very loooooooooong
Script:
Code: Select all
on mouseUp pMouseButton
set the width of me to the formattedwidth of me
end mouseUp

-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Re: How to know if a text will fit on a label field?
Jean-Marc & Klaus, instead of resizing the object what I want to do is to resize its contents in case it doesn't fit. Your answer will certainly help to achieve my goal.
Many thanks!
Many thanks!
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question
Re: How to know if a text will fit on a label field?
Try something like this. make two fields. Put a lot of text into fld 2, so that it will not fit into fld 1. Put this in a button script;
Craig
Code: Select all
on mouseUp
put the height of fld 1 into origHeight
put fld 2 into fld 1
repeat until the formattedHeight of fld 1 <= origHeight
set the textSize of fld 1 to the textSize of fld 1 - 1
end repeat
end mouseUp
-
- VIP Livecode Opensource Backer
- Posts: 10057
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: How to know if a text will fit on a label field?
There was a thread about this on the use-livecode list recently:simon.schvartzman wrote: ↑Fri Oct 25, 2019 5:21 pmJean-Marc & Klaus, instead of resizing the object what I want to do is to resize its contents in case it doesn't fit. Your answer will certainly help to achieve my goal.
https://www.mail-archive.com/use-liveco ... 04277.html
One thing that didn't come up there was what happens when the text is so long that reducing it to fit the object impairs readability.
But if that's not a need for your situation, the solutions offered toward the end of the thread may be helpful.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 665
- Joined: Tue Jul 29, 2014 12:52 am
Re: How to know if a text will fit on a label field?
Many thanks Richard!
Simon
________________________________________
To ";" or not to ";" that is the question
________________________________________
To ";" or not to ";" that is the question