Page 1 of 1

(SOLVED) Text overflow.

Posted: Mon Jun 08, 2020 1:18 pm
by AGC studios
Hi, so I looked around and didn’t find anything that can help me… so the problem is that I have an entry text field, and I would like that instead of the text overflowing it will get smaller(like the Microsoft calculator on Win 10.) I know how to make text smaller, but I don’t know how to detect if the text has “touched” or overflowed the border of the text field… thanks for your help, it is very much appreciated 😊

Re: Text overflow.

Posted: Mon Jun 08, 2020 1:25 pm
by jmburnod
Hi,
If i understand you correctly, the formattedWidth should be useful in this case
Best regards
Jean-Marc

Re: Text overflow.

Posted: Mon Jun 08, 2020 1:31 pm
by AGC studios
Thanks, I will look into it. :D

Re: Text overflow.

Posted: Mon Jun 08, 2020 2:47 pm
by dunbarx
Jean-Marc is certainly on the right track.

But is it that you want the textSize to diminish after each entry, so that the new text "fits" into the field? That would get out of hand rather quickly, no? You would want to do something like (untested):

Code: Select all

on textchanged
    if the formattedWidth of me > the width of me then set the texSize of me to (the textSize of me - 1)
end textchanged
This should diminish the textSize after each new character entry that exceeds the width of the field. But I do not think this a good idea.

Craig

Re: Text overflow.

Posted: Mon Jun 08, 2020 3:07 pm
by AGC studios
Yes, I looked into it and it worked! THANK YOU!

If anyone is interested in the code:

Code: Select all

on putTextIntoField
   
   if (the formattedWidth of field "textAreaField" + 30) > the width of field "textAreaField" ---the + 30 was because the text would somtimes overflow half(you would only see half of the last char)
   then
      set the textSize of field "textAreaField" to takeTextSizeDown() 
   end if
   
end putTextIntoField


function takeTextSizeDown
   put the textSize of field "textAreaField" into tTextSize
   put the number of chars of field "textAreaField" into tTextCharNum
   return tTextSize - (tTextSize / tTextCharNum) --- this way the size of the font is proportionate to the amount of text
end takeTextSizeDown

Re: Text overflow.

Posted: Mon Jun 08, 2020 3:25 pm
by AGC studios
That would get out of hand rather quickly, no?
Yes, I am now looking for a way to get the text to break(sorry about the wrong wording, I don't exactly know how to phrase it... the "enter") Not much luck...


Ps. sorry if this wasn't clear, and thanks for answering :D

Re: Text overflow.

Posted: Mon Jun 08, 2020 4:45 pm
by AGC studios
So, I have a new problem...

I'm trying to get a contact number using

Code: Select all

mobileGetContactData

Code: Select all

mobilePickData
But I cannot seem to be able to get the phone number but I can get the name... I looked at every thread and none of them seemed to have an answer... I hope they fixed it... (running LC 9.6 DP 4) (Android 9.0 Pie)
:( :(

here's my code:

Code: Select all

on mouseUp
   mobilePickContact 
   put the result into tID
   put mobileGetContactData (tID) into tData
   answer tData[phone]["mobile"]  -- I also tried    answer tData["mobile"] 
end mouseUp
this is for the first name

Code: Select all

on mouseUp
   mobilePickContact 
   put the result into tID
   put mobileGetContactData (tID) into tData
   answer tData ["firstname"]
end mouseUp

Re: Text overflow.

Posted: Mon Jun 08, 2020 5:53 pm
by jmburnod
So, I have a new problem...
Please one problem by post. This make search easier and Klaus glad
Best
Jean-Marc

Re: Text overflow.

Posted: Mon Jun 08, 2020 5:59 pm
by AGC studios
Ok, thought it might be better this way... fewer threads... ill move it.

Re: Text overflow.

Posted: Tue Jun 09, 2020 4:26 am
by dunbarx
I am now looking for a way to get the text to break
Do you mean "wrap", that is, automatically display a new line below the original for the newly added text? This is likely the best way, unless something in your app cannot support it. This is what the "dontWrap" property is for.

The original idea, to reduce the textSize when you ran out of room, might be acceptable for one or two characters, but probably not for more than that. And it really goes against good practice.

So what are you really trying to achieve?

Craig

Re: Text overflow.

Posted: Tue Jun 09, 2020 6:34 am
by AGC studios
Hi, yes so my code goes something like this:

If the text is too big and the text size is above 35 then it will make the text smaller.
If it is below 35 then it will add a "space" and the field will wrap.
and I only let a max. of 20 char.

Anyway, this part works(I don't know how to add the "solved" to the title.) my problem now is the contacts but that is in another thread.

Thank you everyone that answered.

Re: Text overflow. :Solved

Posted: Tue Jun 09, 2020 10:20 am
by bogs
To put 'Solved' on the title thread is no trick at all, you simply go to your first post, click on the Edit icon (the pencil), and in the 'Subject' box, append ": Solved" to it, like so -
aPic_solved.png
Put life's little problems to rest...