Height of lines in a field with fixedLineHeight to false)

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
Fermin
Posts: 149
Joined: Fri Jun 05, 2015 10:44 pm

Height of lines in a field with fixedLineHeight to false)

Post by Fermin » Mon Jun 20, 2016 7:58 pm

Hi to all,

I need to scroll by line a field with Lyrics whose lines have different heights.
(FixedLineHeight to false / DontWrap to true)

I think the key is to find the height of each line ... but how do I get?
I plan to use a second field and textHeightSum function but does not seem to work well.
Any Idea, Please ?

Code: Select all

on mouseup
   /*160620-1925 ckaron: main field - ckClon: secondary field.*/
   set the vScroll of fld cKaron to 0
   repeat with theLine = 1 to 10 
      wait 120 ;  if the mouse is down then exit to top -- Time to see the effect and optional exit
      set the htmlText of fld ckClon to the htmlText of line theLine of fld ckaron -- Text with Styles
      put the textheightSum of fld ckClon into theHeight -- ¿Not seem to work this value?
      set the vScroll of fld cKaron to the vScroll of fld  cKaron + theHeight
   end repeat
end mouseup

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

Re: Height of lines in a field with fixedLineHeight to false

Post by dunbarx » Mon Jun 20, 2016 10:05 pm

Hi.

Not sure how you want to scroll. But make a scrolling field and a button. In the button script:

Code: Select all

on mouseUp
   repeat with y = 1 to 40
      put y & y & y &y into line y of fld 1
      set the textSize of line y of fld 1 to 12 + random(18)
   end repeat
end mouseUp
At any time you can:

Code: Select all

answer the textSize of line 6 of fld 1 --or whatever line
If you want to scroll to line 30, say, you would need to add all the textSizes of all the lines up to 30, and scroll to that value. So now how do you want to actually scroll? It would be fun to have each scroll "event" calculate the scroll of the current line and figure out what new scroll was required to perfectly display the next line.

Craig Newman

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

Re: Height of lines in a field with fixedLineHeight to false

Post by dunbarx » Mon Jun 20, 2016 10:25 pm

Hi again.

Rereading, I see that you do not have lines of different heights, but rather lines of different lengths, not wrapped. Or is that true? Are the lines of different heights AND lengths?

Craig

Fermin
Posts: 149
Joined: Fri Jun 05, 2015 10:44 pm

Re: Height of lines in a field with fixedLineHeight to false

Post by Fermin » Mon Jun 20, 2016 11:33 pm

I am preparing an application for creating text synchronized with music
I want an option with justified text (and random FontSizes of text)
but I need the distances to the scrolls with the FixedLineSize Set to false

I created a video to try to explain it better. It is the first time I put a video. I hope you can see it . Here is:

https://www.youtube.com/watch?v=wbpaZWa ... e=youtu.be


0:03 Normal mode (no justified)
0:45 Justified FixedLineSize TRUE. (the scroll fails)
0:50 FixedLineSize FALSE
0:51 FixedLineSize TRUE
0:53 Play whith FixedLineSize TRUE. The scroll jumps OK every 6 lines but the text is cut. No good
1:31 Play whith FixedLineSize FALSE. The text looks good but the scroll jumps late (2:05) because the height of the lines change.

Sorry. No sound ... because copyright, you know... :)

Fermin
Posts: 149
Joined: Fri Jun 05, 2015 10:44 pm

Re: Height of lines in a field with fixedLineHeight to false

Post by Fermin » Tue Jun 21, 2016 9:52 am

Thanks for your comments, Craig.

I understand the basis of the idea but can not get an accurate result

The problem is that the textSIZE does not work. I need height, the textHEIGHT but applied to each line and seems to LiveCode not allow that...

Code: Select all

on mouseUp
   lock screen
   repeat with y = 1 to 40
      put y & y & y &y into line y of fld theField
      put (12 + random(18)) into ts
      set the textSize of line y of fld theField to ts
   end repeat
   -- 
   put 16 into theVS -- A line to calculate
   repeat with z = 1 to theVS
      -- add (the textHeight of line z of fld theField) to tsTot -- Error: Object does not have this property
      -- add (the textSize of line z of fld theField) * 4/3 to tsTot -- Summa of ¿heights?
      add (the textSize of line z of fld theField) * 1 to tsTot -- Summa of sizes
   end repeat
   set the vScroll of fld theField to tsTot -- Approximate but not exact
end mouseUp

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Height of lines in a field with fixedLineHeight to false

Post by jacque » Tue Jun 21, 2016 9:33 pm

I think what you're looking for is the formattedHeight:

Code: Select all

get the formattedHeight of line 1 to 8 of fld "displayField"
This will give you the pixel offset to line 8. You may need to adjust by a few pixels to get the scroll you actually want; usually about a third of the textheight works.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Fermin
Posts: 149
Joined: Fri Jun 05, 2015 10:44 pm

Re: Height of lines in a field with fixedLineHeight to false

Post by Fermin » Tue Jun 21, 2016 11:55 pm

Thanks Jacque, you're right, in fact I am already using something similar (formattedTop ) to calculate the vertical scroll of each verse.

Code: Select all

on mouseup  --160621-2324
   lock screen
   put the number of lines of fld cKaron into nLins -- cKaron: Field with Lyrics
   set the vscroll of fld cKaron to 0 -- Important
   put "" into fld "almacol4" -- Field with future vertical verse positions
   repeat with a = 1 to nLins
      put the formattedTop of line a of fld cKAron into lineTop -- Absolute position 
      put the top of fld ckaron into campoTop
      put linetop - campotop into elScrol -- Relative (ok) position 
      put elScrol into line a of fld "almacol4" -- Saving positions
    end repeat
end mouseup
(The Formatted... family, great properties)
...and people on the forum, Great People

Post Reply