Scroll string into view, Dontwrap set to FALSE [Solved]

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
ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Scroll string into view, Dontwrap set to FALSE [Solved]

Post by ittarter » Thu Nov 23, 2017 10:51 am

Hello!

I have a field "response" with dontwrap set to FALSE (so the text wraps, double negatives always throw me for a bit of a loop)

I want to be able to scroll a certain string into view.

This is what I've got so far:

Code: Select all

put the lineindex of char (item 2 of tPos) of fld "response" into x
Set The VScroll Of Field "response" To x * (The effective TextHeight of Field "response")
Where tPos are two numbers, the first and last char number of the selected string (relative to the text of the whole field, e.g. 606,625 for chars 606 to 625 of the field).

The problem with this method is that it doesn't know how to take into account the multiple lines created by setting the DONTWRAP to false. So the vscroll is usually off (even a broken clock is right twice a day).

I've tried turning on/off fixedlineheight but it doesn't change anything.
I've tried making a ghost field to check the effective line height of only the lines in question. Surprise surprise, same result.

Any help would be much appreciated!
Last edited by ittarter on Fri Nov 24, 2017 11:26 am, edited 1 time in total.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Scroll string into view, Dontwrap set to FALSE

Post by jacque » Thu Nov 23, 2017 5:22 pm

Check the formattedText entry in the dictionary. That can give you the actual visual lines.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Scroll string into view, Dontwrap set to FALSE

Post by dunbarx » Thu Nov 23, 2017 7:17 pm

Hi.

What Jacque said. But the OP wants to do something like this, valid for a field where every line occupies a single physical line:

Code: Select all

set the scroll of fld 1 to ((the textHeight of fld 1 -1) * desiredLine) -  the textHeight of fld 1
I am not with LC right now, but more needs to be done to make that work with a field with dontWrap set to "false", and with long lines of text that wrap within the physical width

Craig Newman

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Scroll string into view, Dontwrap set to FALSE

Post by jmburnod » Thu Nov 23, 2017 8:01 pm

Hi Craig,
It seems we have to use "effective textheight".
The textheight in LC 8 is empty
Best
Jean-Marc
https://alternatic.ch

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: Scroll string into view, Dontwrap set to FALSE

Post by ittarter » Fri Nov 24, 2017 11:25 am

Thanks for your help, guys. Here's a solution using the formattedtext property.

Code: Select all

put the formattedtext of fld "response" into fld "ghost response" 
--fld "ghost response" is a necessary invisible field,
--since a variable sadly can't use the lineindex property (maybe there's another option here?)
put the lineindex of char tDesiredChar of fld "ghost response" into y
put The effective TextHeight Of Field "response" into x --necessary when dontwrap is false
Set The VScroll Of Field "response" To y * x - (the height of fld "response" / 2) 
--or just y * x if you want to scroll so that the string is at the very top of the field

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Scroll string into view, Dontwrap set to FALSE [Solved]

Post by jacque » Fri Nov 24, 2017 6:12 pm

That's pretty much what I had in mind. You could use lineOffset() instead of lineIndex if you don't want the invisible field.

BTW, the "effective" textHeight isn't required because of line wrap. Any property that isn't explicitly set in a control will inherit compatible properties from its owner. This is true not only for text properties but others as well, such as colors.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Scroll string into view, Dontwrap set to FALSE [Solved]

Post by bn » Fri Nov 24, 2017 7:06 pm

Hi,

here is a solution that does not need a second field. It supports different textsizes and does not depend on "fixed textHeight" but it is a bit more involved.

use scrollbar or button to play around with. It is a file in 5.5 format.

Kind regards

Bernd
Attachments
scroll to middle.livecode.zip
(1.82 KiB) Downloaded 143 times

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Scroll string into view, Dontwrap set to FALSE [Solved]

Post by jmburnod » Sat Nov 25, 2017 11:58 am

Hi All,
Is someone knows why i sometimes get this result ? (LC 8.1.6, 8.1.7)

Code: Select all

put (textHeight of fld 1 = empty) &&  (effective  textHeight of fld 1 = empty)
return "true false"
Best regards
Jean-Marc
https://alternatic.ch

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

Re: Scroll string into view, Dontwrap set to FALSE [Solved]

Post by bn » Sat Nov 25, 2017 12:35 pm

Hi Jean-Marc,
put (textHeight of fld 1 = empty) && (effective textHeight of fld 1 = empty)
this should happen when you do not set the textHeight of a field explicitly, then the textHeight is empty and the inherited textHeight (= effective textHeight) is not empty.

Try to set the textHeight of the field to some value and both should return false.

Kind regards
Bernd

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: Scroll string into view, Dontwrap set to FALSE [Solved]

Post by ittarter » Sat Nov 25, 2017 8:50 pm

jacque wrote:
Fri Nov 24, 2017 6:12 pm
That's pretty much what I had in mind. You could use lineOffset() instead of lineIndex if you don't want the invisible field.
The reason I used an invisible field was actually to use the formattedtext property.

I could also lock the screen, save the original text to a variable, apply the formattedtext to the original field, calculate the lineindex/lineoffset, then restore the original text to the field and unlock the screen. For reasons of losing the selectedtext and having to save that too, I opted to use an invisible field instead.

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: Scroll string into view, Dontwrap set to FALSE [Solved]

Post by ittarter » Sat Nov 25, 2017 8:52 pm

bn wrote:
Fri Nov 24, 2017 7:06 pm
here is a solution that does not need a second field. It supports different textsizes and does not depend on "fixed textHeight" but it is a bit more involved.

use scrollbar or button to play around with. It is a file in 5.5 format.
Interesting, I didn't know about the formattedRect property of a string in a field. Very nice solution!

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Scroll string into view, Dontwrap set to FALSE [Solved]

Post by jmburnod » Sun Nov 26, 2017 2:09 pm

Thanks again Bernd and Jacqueline (who I didn't read with attention) :oops:
use scrollbar or button to play around with. It is a file in 5.5 format.
Button works fine but I get a bad result when I clic on the grey line of the scroolbar of Bernd's stack "scroll to middle". Only two results, 121 or 1
Kind regards
Jean-Marc
https://alternatic.ch

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

Re: Scroll string into view, Dontwrap set to FALSE [Solved]

Post by bn » Sun Nov 26, 2017 2:23 pm

Hi Jean-Marc,

Button works fine but I get a bad result when I clic on the grey line of the scroolbar of Bernd's stack "scroll to middle". Only two results, 121 or 1
set the pageInc of the scroller to - 1 or - 2 or a similar value, then try again.

I did not test clicking in the grey line because it is just a demo stack to show interactively the code I used.

Kind regards
Bernd

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”