Scrolling a field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Scrolling a field
Hello,
I need to scroll a field to a specified line number, since all lines have different heights, I can't use vscroll property, and hilitedline doesn't work.
What property should I use?
I need to scroll a field to a specified line number, since all lines have different heights, I can't use vscroll property, and hilitedline doesn't work.
What property should I use?
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Scrolling a field
Hi Max,
Just an idea.
If it possible to use a "find in fld" command, LC sets automaticaly the vScroll
Best regards
Jean-Marc
Just an idea.
If it possible to use a "find in fld" command, LC sets automaticaly the vScroll
Best regards
Jean-Marc
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Scrolling a field
Hi.
Very interesting.
Jean-Marc's idea works to a point, but in a test I made, the foundLine always appears as the third line in the scrolled field (LC 6.5). If the foundText is within the visible portion of the top "screen" of the field, it simple boxes that text of course.
I made a small scrolling test field, about 150 pixels tall, with a few dozen lines in it and ran this:
So when finding a line of text low down in the field, the boxed foundLine is always the third line showing. I am sure this can be used to advantage, since the textHeight of the two lines above the foundLine are known, and the scroll of the field is known after the find (pseudo):
But this seems clunky, even as kluges go, and I am not sure how reliable that third line thingie is. Anyone can make this work, but is there a more grown-up way to set the scroll to so the foundline is always at the top?
Craig Newman
Very interesting.
Jean-Marc's idea works to a point, but in a test I made, the foundLine always appears as the third line in the scrolled field (LC 6.5). If the foundText is within the visible portion of the top "screen" of the field, it simple boxes that text of course.
I made a small scrolling test field, about 150 pixels tall, with a few dozen lines in it and ran this:
Code: Select all
on mouseUp
repeat with y = 1 to the number of lines of fld 1
set the textSize of line y of fld 1 to random(20) + 6
end repeat
end mouseUp
Code: Select all
find the text
put the scroll of the field into tScroll
put the sum of the textHeights of the two lines above the foundLine into tOffset
set the scroll of the field to tScroll - tOffset
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 7266
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Scrolling a field
Try "select line x of fld y"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Scrolling a field
This works, sort of:
Jacque, selecting a line does not bring it to the top. And the above does not quite work, since the scroll is not well set. An array would be more compact. We need another way, or a new property, "the scrollLine"
Craig
Code: Select all
on mouseUp
repeat with y = 1 to the number of lines of fld 1
put y && the textsize of line y of fld 1 into line y of tData
end repeat
ask "what line # ?"
put it into tLine
repeat with y = 1 to tLine
add word 2 of line y of tData to tScroll
end repeat
set the scroll of fld 1 to tScroll
end mouseUp
Craig
Re: Scrolling a field
Ok, I get this idea, it works, but it can be very improved. Image to reach the X line:
########CODE#######
#14 is the standard line height
put 0 into totv
repeat with i=1 to x
put the textSize of line i of field 1 into temp
if temp is empty or temp is "mixed" then
put 14 into temp
end if
put totv + temp into totv
end repeat
put totv - (the height of field 1) into totv
if totv > 0 then
set the vscroll of field 1 to totv
end if
#####END OF CODE#####
########CODE#######
#14 is the standard line height
put 0 into totv
repeat with i=1 to x
put the textSize of line i of field 1 into temp
if temp is empty or temp is "mixed" then
put 14 into temp
end if
put totv + temp into totv
end repeat
put totv - (the height of field 1) into totv
if totv > 0 then
set the vscroll of field 1 to totv
end if
#####END OF CODE#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Scrolling a field
Hi.
I guess that "x" is the line number sought?
This still places the line at the bottom. And still has my issue, the scroll is not well set.
Craig
I guess that "x" is the line number sought?
This still places the line at the bottom. And still has my issue, the scroll is not well set.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7266
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Scrolling a field
I'll test it when I get back to my Mac, but I'm pretty sure select used to work. If not, get the formattedheight of line 1 to x and use that.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Scrolling a field
Jacque.
It seems that if the scroll starts out less than the desired scroll, the selectedLine is set at the bottom of the field. If greater, the scroll is set at the top. If in the middle, no movement.
Craig
It seems that if the scroll starts out less than the desired scroll, the selectedLine is set at the bottom of the field. If greater, the scroll is set at the top. If in the middle, no movement.
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7266
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Scrolling a field
If the field has listbehavior, this seems to work:
Code: Select all
on doScroll pNum
put the formattedheight of line 1 to pNum of fld 1 into tScroll
set the scroll of fld 1 to tScroll -- can overshoot a bit
set the hilitedline of fld 1 to pNum -- corrects it
end doScroll
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Scrolling a field
Yes, list behavior seems to possess its own discipline, greater than in ordinary fields.
I do not know if there is enough interest, assuming a reliable method is not forthcoming, to propose a new property, like "scrollLine", or whatever. Oddly, in the use-list, a very similar question came up just today.
I only threw together a solution because I was more interested in the fact that setting the selectedLine (and the scroll) works differently depending on the current scroll setting, whether greater or less than the desired value. So there are a couple of ancillary issues that are open right now...
Craig
I do not know if there is enough interest, assuming a reliable method is not forthcoming, to propose a new property, like "scrollLine", or whatever. Oddly, in the use-list, a very similar question came up just today.
I only threw together a solution because I was more interested in the fact that setting the selectedLine (and the scroll) works differently depending on the current scroll setting, whether greater or less than the desired value. So there are a couple of ancillary issues that are open right now...
Craig
-
- VIP Livecode Opensource Backer
- Posts: 474
- Joined: Thu Sep 04, 2008 6:23 am
- Location: Melbourne Australia
Re: Scrolling a field
To scroll a field so that a desired line (line linenum) sits at the top of the field I use the following:
Code: Select all
set the lockscreen to true
--scroll section to line linenum where "linenum is the number of the line
--to sit at the top of the field
select line -1 of field "TextToScroll"
select line linenum of field "TextToScroll"
set the lockscreen to false
Re: Scrolling a field
Good idea Jacque & jameshale!
I use this now:
########CODE#######
put the formattedheight of line 1 to X of field "testo" into totv
put totv - (the formattedHeight of line X of field "testo") into totv
set the vscroll of field "testo" to totv
#####END OF CODE#####
I use this now:
########CODE#######
put the formattedheight of line 1 to X of field "testo" into totv
put totv - (the formattedHeight of line X of field "testo") into totv
set the vscroll of field "testo" to totv
#####END OF CODE#####
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Scrolling a field
Hi.
The OP wanted to set the top of the visible field by finding text in that field, and to boot, the textSize of each line was different. The trick is to finely tune that. Try this. Make a new field, fairly small. In a button:
Some of your stuff, some other stuff. Thoughts?
Craig
The OP wanted to set the top of the visible field by finding text in that field, and to boot, the textSize of each line was different. The trick is to finely tune that. Try this. Make a new field, fairly small. In a button:
Code: Select all
on mouseUp
lock screen
repeat with y = 1 to 100
put y into line y of last fld
set the textSize of line y of last fld to random(20) + 6
end repeat
find "55" in last fld
put word 2 of the foundLine into tLine
--scroll section to line linenum where "linenum is the number of the line
--to sit at the top of the field
select line -1 of last field
select line tLine of last field
set the lockscreen to false
end mouseUp
Craig
Re: Scrolling a field
A few of the solutions in the thread don't take into account a bug in livecode where the spaceabove and space below properties are not taken into account. Specifically (put the formattedHeight of line 1 to tLOS of fld 1 into tScroll) is a problem and it has been reported.
Here is my generalized solution to position a line at the top, center or bottom of a field.
Here is my generalized solution to position a line at the top, center or bottom of a field.
Code: Select all
on __positionLineinFld pline, obj, pWhere
/* __positionLineinFld Fields
Syntax:
__positionLineinFld linenbr,long_ID_of_Field,["Top"\"Center"\"Bottom"]
Examples:
__positionLineinFld 20,the long ID of fld "foo"
__positionLineinFld 20,the long ID of fld "foo", "Center"
Description:
Sets the scroll of a field so the line specified is in the specifed
location within the visiable field. Both fixed and non-fixed line
heights are supported.
Source:
Michael Doub with a special thanks to James Hale for his help.
__positionLineinFld */
set the lockscreen to true
put the height of obj into tFieldHeight
put 0 into tScroll
if pline > 1 then
repeat with x = 1 to pLine
-- put x,\
-- the spacebelow of line x-1 of obj,\
-- the spaceabove of line x of obj ,\
-- the formattedheight of line x of obj,\
-- tScroll & return after msg
Add the spacebelow of line x-1 of obj to tScroll
Add the spaceabove of line x of obj to tScroll
Add the formattedheight of line x of obj to tScroll
end repeat
else
set the vscroll of obj to 0
end if
switch pWhere
case "Top"
subtract the formattedheight of line pline of obj from tScroll
break
case "Center"
subtract (tFieldHeight / 2) from tScroll
subtract (the formattedheight of line pline of obj /2) from tScroll
subtract the spaceabove of line pline of obj from tScroll
add the topmargin of obj to tScroll
break
case "Bottom"
subtract the formattedheight of line pline of obj from tScroll
-- tScroll is now the top of the line
select line -1 of obj
select line pLine of obj
select empty
put the scroll of obj into bScroll -- this is the top of the last wrapped line
put the formattedheight of line pline of obj -(bScroll - tScroll) into lastLineHeight
Add lastLineHeight to bScroll
subtract tFieldHeight from bScroll
add the bottommargin of obj to bScroll
set the vscroll of obj to trunc(bScroll)
put bScroll into tScroll
break
default
put tScroll - the formattedheight of line pline of obj into tScroll
end switch
set the vscroll of obj to trunc(tScroll)
-- put the vscroll of obj after msg
set the lockscreen to false
end __positionLineinFld