(SOLVED) Text overflow.

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
AGC studios
Posts: 21
Joined: Thu Apr 23, 2020 1:49 pm

(SOLVED) Text overflow.

Post by AGC studios » Mon Jun 08, 2020 1:18 pm

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 😊
Last edited by AGC studios on Tue Jun 09, 2020 10:45 am, edited 1 time in total.

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

Re: Text overflow.

Post by jmburnod » Mon Jun 08, 2020 1:25 pm

Hi,
If i understand you correctly, the formattedWidth should be useful in this case
Best regards
Jean-Marc
https://alternatic.ch

AGC studios
Posts: 21
Joined: Thu Apr 23, 2020 1:49 pm

Re: Text overflow.

Post by AGC studios » Mon Jun 08, 2020 1:31 pm

Thanks, I will look into it. :D

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

Re: Text overflow.

Post by dunbarx » Mon Jun 08, 2020 2:47 pm

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

AGC studios
Posts: 21
Joined: Thu Apr 23, 2020 1:49 pm

Re: Text overflow.

Post by AGC studios » Mon Jun 08, 2020 3:07 pm

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

AGC studios
Posts: 21
Joined: Thu Apr 23, 2020 1:49 pm

Re: Text overflow.

Post by AGC studios » Mon Jun 08, 2020 3:25 pm

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

AGC studios
Posts: 21
Joined: Thu Apr 23, 2020 1:49 pm

Re: Text overflow.

Post by AGC studios » Mon Jun 08, 2020 4:45 pm

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

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

Re: Text overflow.

Post by jmburnod » Mon Jun 08, 2020 5:53 pm

So, I have a new problem...
Please one problem by post. This make search easier and Klaus glad
Best
Jean-Marc
https://alternatic.ch

AGC studios
Posts: 21
Joined: Thu Apr 23, 2020 1:49 pm

Re: Text overflow.

Post by AGC studios » Mon Jun 08, 2020 5:59 pm

Ok, thought it might be better this way... fewer threads... ill move it.

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

Re: Text overflow.

Post by dunbarx » Tue Jun 09, 2020 4:26 am

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

AGC studios
Posts: 21
Joined: Thu Apr 23, 2020 1:49 pm

Re: Text overflow.

Post by AGC studios » Tue Jun 09, 2020 6:34 am

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.

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Text overflow. :Solved

Post by bogs » Tue Jun 09, 2020 10:20 am

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...
Image

Post Reply