the number of ACTUAL lines in a field?

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
thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 383
Joined: Mon Mar 01, 2010 7:13 pm
Contact:

the number of ACTUAL lines in a field?

Post by thatkeith » Fri Mar 21, 2014 1:31 pm

I know I can get the lines of a field, which tells me how many return-delimited chunks of text there are. But is there a way to determine the 'effective' lines of a field? Say I have one string with no returns in the middle, but it's long enough to linewrap into three 'effective', visual lines. (A bit like this post!) Can I find this out through scripting?
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 383
Joined: Mon Mar 01, 2010 7:13 pm
Contact:

Re: the number of ACTUAL lines in a field?

Post by thatkeith » Fri Mar 21, 2014 1:55 pm

Replying to my own question *again*... :D

Seems that the textHeightSum tells me the total height of the lines of text in pixels. Finding the 'effective textHeight' of the field tells me the line spacing, I can work out the number of visual lines from that, with a bit of sanity checking to CMA. :wink:
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

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

Re: the number of ACTUAL lines in a field?

Post by dunbarx » Fri Mar 21, 2014 1:58 pm

Not sure if this will help, but look here:

http://lessons.runrev.com/s/lessons/m/2 ... -wrap-text

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 383
Joined: Mon Mar 01, 2010 7:13 pm
Contact:

Re: the number of ACTUAL lines in a field?

Post by thatkeith » Fri Mar 21, 2014 2:01 pm

That's not quite what I was playing towards (a more accurate phrase than "working towards") but it's a great example for a related process. Thanks!
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: the number of ACTUAL lines in a field?

Post by bn » Fri Mar 21, 2014 2:29 pm

Hi Keith,

isn't the formattedText what you are looking for?

Suppose you have text in a field that has it dontWrap set to false, i.e. the text wraps. You want to know how many visual lines are in the field

Code: Select all

put the formattedText of field "x" into tTemp
put the number of lines of tTemp
or I am not getting it.

Kind regards
Bernd

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

Re: the number of ACTUAL lines in a field?

Post by dunbarx » Fri Mar 21, 2014 2:47 pm

Rereading your original post (why is there always time to do that but never time to do so in the first place?) Bernd's suggestion is just what you wanted. He gets it.

Craig

thatkeith
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 383
Joined: Mon Mar 01, 2010 7:13 pm
Contact:

Re: the number of ACTUAL lines in a field?

Post by thatkeith » Sat Mar 22, 2014 5:00 pm

Of course it's an easy one-liner too, no two-step process needed:

Code: Select all

put the number of lines of the formattedText of field "blurb"
Thanks!
Technical Writer, Meta
University Lecturer
Technical Editor, MacUser (1996-2015)
360 VR media specialist

Post Reply