Is the Text Field good enough for this ?

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
liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm
Location: down under

Is the Text Field good enough for this ?

Post by liveme » Sun Mar 21, 2021 9:27 pm

Hi ppl,

I'm willing to use a simple text fld to display an article content on both, Desktop and Mobile App...

Facts : due to the monitor size, on the desktop a content could be displayed as a 10 lines article.
(with X numbers of characters per line - *I do not define myself that number, LC probably does it somehow)
...on the Mobile though, I suspect it would use more lines due to readable font size...and smaller field size...

Question : if I was to count the number of lines at saving time : would the LC count function register a number of 10 lines for the Desktop versions, while it could register a number of more than 10 lines on the Mobile version ?
I would like to keep track of that number of lines, but with "equal results", whereas its beeing displayed and saved from a larger or smaller screen user, is that even possible ?
How would you treat that otherwise ?

PS: I've seen there is a formated text function, hence the question about the "field text" use instead...
*I already have records on the total number of characters for the content... but I'm now looking for "some" number of lines :roll: :roll: if doable...
graciasss ! :lol:

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9647
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Is the Text Field good enough for this ?

Post by dunbarx » Mon Mar 22, 2021 12:20 am

Hi.

I do not develop for mobile.

But if you ask LC for the number of lines in a field, you will get one answer, regardless of which platform you build for.

So your question, I think, is all about displaying data, not getting field properties. Formatting for different screen sizes is its own task, and others will chime in on the special things required to do that for mobile devices.

I am not sure this is helpful.

Craig

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm
Location: down under

Re: Is the Text Field good enough for this ?

Post by liveme » Mon Mar 22, 2021 4:51 am

I have not built the app to test it on mobile yet.

but let's take this example, if I would ask some kids to writte a line poems, some using PC, tablets or a mobile to do so,
I would need to find a way to count those 5 lines. In a console/terminal window - if I remember - a line is aprox. 80 char.
Its fine for me if LC does count 80 chars or so per lines, as long as it does it whatever screen's size it (wrapping text as it has to be depending the device) it will display the content on...
So I guess a better question would be :
- Does LC uses a predifined numbers of char per line, no matter whatever screen size the content displays on ?
:idea: :?:

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Is the Text Field good enough for this ?

Post by AxWald » Mon Mar 22, 2021 9:43 am

Hi,
liveme wrote:
Mon Mar 22, 2021 4:51 am
Does LC uses a predifined numbers of char per line, no matter whatever screen size the content displays on ?
No. Depending on the property "dontWrap" it will:
- either not wrap at all (means part of the text may "vanish" at the right),
- or wrap at the edge of the field, keeping words together.

Text width can differ a lot on different platforms, even if the same font is available.

A way to get some numbers:

Code: Select all

on mouseUp
   lock screen
   put the text of fld "1_fld" into mySave
   put "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890 " & CR into fld "1_fld"
   get the formattedwidth of line 1 of fld "1_fld"
   put mySave into fld "1_fld"
   unlock screen
   --  now we have the measure:
   answer "Field width: " & the width of fld "1_fld" & CR & \
         "Text width: " & it
end mouseUp
  • Make a field "1_fld", and a button. Copy the button script, and klick. Adjust field width to match text width.
  • Now attach mobile, use "Development/Test".
  • Click button on mobile, and use the resulting values to calculate & adjust "textSize" for mobile.
Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm
Location: down under

Re: Is the Text Field good enough for this ?

Post by liveme » Mon Mar 22, 2021 10:43 am

Uiihhh :shock: ...okay, thks I 'll test that next...
not a straghtforward sol to this it seems....hmm...I'll see.maybe I can make my own - theorical equivalent line counts,
counting char/80char per line instead. As if the input fld was a paper page with a fix number of char..and all lines content being added in sequence....
Or maybe auto-split a content at input time... some average system anyway.
Tks for the lights ! :wink:

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3999
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Is the Text Field good enough for this ?

Post by bn » Mon Mar 22, 2021 10:52 am

liveme wrote:
Mon Mar 22, 2021 4:51 am
I have not built the app to test it on mobile yet.

but let's take this example, if I would ask some kids to writte a line poems, some using PC, tablets or a mobile to do so,
I would need to find a way to count those 5 lines.
:idea: :?:
If I understand correctly you want to make sure there are 5 lines, regardless of wrapping due to different width of fields.

I that case the "number of lines of field x" will always be the same because for LC a line is terminated by a return.
If you want to know the _apparent_ number of lines of a text field that has wrapped lines you can use the formattedText and ask for the number of lines of the formatted text. You can do this in a variable.

Code: Select all

put the formattedText of field 1 into tVar
put the number of lines of tVar
be aware though that formattedText puts a return after each _apparent_ line to do its "thing". That means the number of chars of the field and the formattedText of the field can differ due to the added returns.

Kind regards
Bernd

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm
Location: down under

Re: Is the Text Field good enough for this ?

Post by liveme » Mon Mar 22, 2021 11:13 am

Thanks Bernd, yes thats exactly what I was hopping to do...
I dont know yet what would the implication be with this extra "return symbol" on each lines...
might be problematic later down the road...I will think about it more...
tks a lot
:wink:

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9647
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Is the Text Field good enough for this ?

Post by dunbarx » Mon Mar 22, 2021 2:30 pm

Hi.

Be aware that when clearing the "dontWrap" property, LC will only break lines where spaces (ASCII 32) are embedded. Otherwise, a long run-on string of chars will still continue out of the right side of the field. You might play with this for a minute; it takes a little practice...

Craig

andresdt
Posts: 146
Joined: Fri Aug 16, 2019 7:51 pm

Re: Is the Text Field good enough for this ?

Post by andresdt » Mon Mar 22, 2021 3:03 pm

Hi, try to use segment and / or paragraph instead of counting the lines.
If you can ask the children to write their poems and count the segments. In this way, you will not have to take into account the number of lines that each poem has, or on which platform it was written.

dontWrap to true

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm
Location: down under

Re: Is the Text Field good enough for this ?

Post by liveme » Mon Mar 22, 2021 7:30 pm

thks Guys, lots of unexplored ways for that still in LC !

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”