Page 1 of 1
Scroll string into view, Dontwrap set to FALSE [Solved]
Posted: Thu Nov 23, 2017 10:51 am
by ittarter
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!
Re: Scroll string into view, Dontwrap set to FALSE
Posted: Thu Nov 23, 2017 5:22 pm
by jacque
Check the formattedText entry in the dictionary. That can give you the actual visual lines.
Re: Scroll string into view, Dontwrap set to FALSE
Posted: Thu Nov 23, 2017 7:17 pm
by dunbarx
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
Re: Scroll string into view, Dontwrap set to FALSE
Posted: Thu Nov 23, 2017 8:01 pm
by jmburnod
Hi Craig,
It seems we have to use "effective textheight".
The textheight in LC 8 is empty
Best
Jean-Marc
Re: Scroll string into view, Dontwrap set to FALSE
Posted: Fri Nov 24, 2017 11:25 am
by ittarter
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
Re: Scroll string into view, Dontwrap set to FALSE [Solved]
Posted: Fri Nov 24, 2017 6:12 pm
by jacque
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.
Re: Scroll string into view, Dontwrap set to FALSE [Solved]
Posted: Fri Nov 24, 2017 7:06 pm
by bn
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
Re: Scroll string into view, Dontwrap set to FALSE [Solved]
Posted: Sat Nov 25, 2017 11:58 am
by jmburnod
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
Re: Scroll string into view, Dontwrap set to FALSE [Solved]
Posted: Sat Nov 25, 2017 12:35 pm
by bn
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
Re: Scroll string into view, Dontwrap set to FALSE [Solved]
Posted: Sat Nov 25, 2017 8:50 pm
by ittarter
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.
Re: Scroll string into view, Dontwrap set to FALSE [Solved]
Posted: Sat Nov 25, 2017 8:52 pm
by ittarter
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!
Re: Scroll string into view, Dontwrap set to FALSE [Solved]
Posted: Sun Nov 26, 2017 2:09 pm
by jmburnod
Thanks again Bernd and Jacqueline (who I didn't read with attention)
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
Re: Scroll string into view, Dontwrap set to FALSE [Solved]
Posted: Sun Nov 26, 2017 2:23 pm
by bn
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