Scrolling a field automatically
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 137
- Joined: Thu Jul 24, 2008 11:22 pm
Scrolling a field automatically
I want to scroll a field as I am adding data to it so that it always shows the last items added. I've tried using the vscroll command but the pixels change as the field gets more data added. I know there will be simple solution. Anyone care to enlighten me?
cheers
Glenn
cheers
Glenn
Re: Scrolling a field automatically
Hi Glenn,
Setting the vScroll of a field to a very large number will scroll it as far as it will currently go, given the text it contains. It’s perhaps best to give a specific example- if, every time the user moved their mouse into a field, you wanted it to scroll to the bottom and place the insertion point at the end, you could use:
... in the script of the field.
This example would be appropriate if you were manually adding text to the field. If you were adding text to the field using a script, and wanted to see successive additions of text as the script runs, you could periodically set the vScroll to a very large number, as above. So the above example illustrates the technique, which you can use according to your specific requirements. Perhaps this will work for you.
Edit: I've just noticed a comment in the Rev Dictionary, under "vScroll", which gives a slightly different approach. Adjusted to match my previous example, it is:
Regards,
Michael
Setting the vScroll of a field to a very large number will scroll it as far as it will currently go, given the text it contains. It’s perhaps best to give a specific example- if, every time the user moved their mouse into a field, you wanted it to scroll to the bottom and place the insertion point at the end, you could use:
Code: Select all
on mouseEnter
set the vScroll of me to 1000000
click at the loc of me
end mouseEnter
This example would be appropriate if you were manually adding text to the field. If you were adding text to the field using a script, and wanted to see successive additions of text as the script runs, you could periodically set the vScroll to a very large number, as above. So the above example illustrates the technique, which you can use according to your specific requirements. Perhaps this will work for you.
Edit: I've just noticed a comment in the Rev Dictionary, under "vScroll", which gives a slightly different approach. Adjusted to match my previous example, it is:
Code: Select all
on mouseEnter
set the vscroll of me to (the effective textheight of me) * (the number of lines in me)
click at the loc of me
end mouseEnter
Michael
Re: Scrolling a field automatically
When placed at the end of the handler, this code will also accomplish the desired result:
select the last line of fld"my Data"
Regards,
select the last line of fld"my Data"
Regards,
Ken
Re: Scrolling a field automatically
Hi all,
Indeed, Ken's “select the last line” is a good alternative, and I might also correct an oversight in my previous post- I had hoped to place the insertion point at the end of the field, ready for further typing. For this I used “click at the loc”, but this only works in the limited examples I tested.... correctly sets the insertion point, if this is desired. Using "on mouseEnter" is just for the purposes of the example.
Regards,
Michael
Indeed, Ken's “select the last line” is a good alternative, and I might also correct an oversight in my previous post- I had hoped to place the insertion point at the end of the field, ready for further typing. For this I used “click at the loc”, but this only works in the limited examples I tested.
Code: Select all
on mouseEnter
set the lockScreen to true
select the last line of me
select empty
focus on me
end mouseEnter
Regards,
Michael
Re: Scrolling a field automatically
Hi Michael,
From a script I always use the brute force "set the scoll of field "myField" to 1000000. Let the darn field figure out how far it can scroll. This has the advantage that anything that can scroll, like a group, can figure it out even if there is nothing to select to force the group to scroll it into sight.
If you want to give the user the insertion point at the end I would sayThis works also on a locked field, then obviously no insertion point.
regards
Bernd
From a script I always use the brute force "set the scoll of field "myField" to 1000000. Let the darn field figure out how far it can scroll. This has the advantage that anything that can scroll, like a group, can figure it out even if there is nothing to select to force the group to scroll it into sight.
If you want to give the user the insertion point at the end I would say
Code: Select all
on mouseEnter
select after char - 1 of me
end mouseEnter
regards
Bernd
Re: Scrolling a field automatically
Hi Michael,
I tried to calculate the max scroll of a field, it is ugly but seems to work. See why I said I liked the brute force way "set the scroll of myObject to 100000"
There are some formulas floating around for the max scroll something like: the formattedHeight - the height of the field - top and bottom margins. I found them close but not really exact. This is my attempt. If anybody finds it does not work I would shure be interested.
It used to be less important what the scroll was but with the option to code for the iPhone and all the momentum scrolling going on there it gets more interesting to control the scroll more precisely.
I append the stack for people who suffer from insomnia, it should put them to sleep right away.
regards
Bernd
I tried to calculate the max scroll of a field, it is ugly but seems to work. See why I said I liked the brute force way "set the scroll of myObject to 100000"
Code: Select all
on mouseUp
put the formattedHeight of field 1 into tFormat
put the height of field 1 into tHeight
put the borderwidth of field 1 into tBorder
-- it could have a horizontal scrollbar
if the hScrollbar of field 1 then add (scrollbarWidth of field 1 + 1) to tHeight
put 0 into fFocusCorr
put 0 into tBorderKorr
-- -- correct for focus and border shown/not shown
put 0 into fFocusCorr
if tBorder > 0 then
put 4 into tFocusCorr
put 10 into tBorderKorr
else -- borderwidth = 0
put 5 into tBorderKorr
end if
-- if traversalOn is true / focus on/off
if traversalOn of field 1 then
if (showFocusBorder of field 1) and the focusedObject = the long id of field 1 and tBorder > 0 then subtract 4 from tFocusCorr
end if
put tFormat - tHeight - tBorderKorr + tFocusCorr into tSum
set the scroll of field 1 to tSum
end mouseUp
It used to be less important what the scroll was but with the option to code for the iPhone and all the momentum scrolling going on there it gets more interesting to control the scroll more precisely.
I append the stack for people who suffer from insomnia, it should put them to sleep right away.

regards
Bernd
- Attachments
-
- MaxScrollOfField-2.rev.zip
- (3.04 KiB) Downloaded 319 times
Re: Scrolling a field automatically
Having prepared this stack, I thought I might as well post it, although it was a little while ago. It explores the calculation of maximum required scroll, which can depend on border settings, the presence of a horizontal scroll bar, and, on non-Windows platforms, whether the field has the focus, and thus a focus border around it.
Regards,
Michael
Regards,
Michael
- Attachments
-
- MaximumScrollExperiment.zip
- (12.87 KiB) Downloaded 315 times
Re: Scrolling a field automatically
Hi Michael,
thanks for posting this. It is a very thorough walk through of the different things that influence the max scroll. Rev changed (at least on a Mac) in version 4.5 when going to Livecode, the way the focusedBorder is taken into account. It makes no more difference for the max scroll.
I like the display of the fonts in their native appearance.
regards
Bernd
thanks for posting this. It is a very thorough walk through of the different things that influence the max scroll. Rev changed (at least on a Mac) in version 4.5 when going to Livecode, the way the focusedBorder is taken into account. It makes no more difference for the max scroll.
I like the display of the fonts in their native appearance.
regards
Bernd
Re: Scrolling a field automatically
Hi Bernd,
While it was interesting to push the exploration to some sort of conclusion, and contribute to the available cures for insomnia, the eventual handler CalculateMaxScroll was the sort I’m not very comfortable with. I always think of such handlers, with lots of little conditions to conform to the specifics of the Rev version being used, as being very “version unstable”. When I see a group of odd conditions like that, a warning bell goes off in my head. It's the sort of handler you write to keep a project progressing, with the idea of replacing it at a later date. I’m not that surprised to hear a more recent version of LiveCode does things a little differently, removing the need for special treatment of the focus border on the MacOS. Still, it was an interesting exercise.
Regards,
Michael
While it was interesting to push the exploration to some sort of conclusion, and contribute to the available cures for insomnia, the eventual handler CalculateMaxScroll was the sort I’m not very comfortable with. I always think of such handlers, with lots of little conditions to conform to the specifics of the Rev version being used, as being very “version unstable”. When I see a group of odd conditions like that, a warning bell goes off in my head. It's the sort of handler you write to keep a project progressing, with the idea of replacing it at a later date. I’m not that surprised to hear a more recent version of LiveCode does things a little differently, removing the need for special treatment of the focus border on the MacOS. Still, it was an interesting exercise.
Regards,
Michael
Re: Scrolling a field automatically
Hi Michael,

I liked the population of the field with the fontnames and actually displaying the font name in font. It was a little slow. The other day I was doing something for the iPhone and it turned out that manipulating the htmlText was quite fast.
(I wanted to have the first word of a line in bold, the rest of the line plain, this for a long list > 300 lines)
I tried this on the font populating routine.
have a look.
regards
I totally agree. I felt uncomfortable with this code also. Guess why I preferred the brute force methodWhen I see a group of odd conditions like that, a warning bell goes off in my head

I liked the population of the field with the fontnames and actually displaying the font name in font. It was a little slow. The other day I was doing something for the iPhone and it turned out that manipulating the htmlText was quite fast.
(I wanted to have the first word of a line in bold, the rest of the line plain, this for a long list > 300 lines)
I tried this on the font populating routine.
have a look.
regards
- Attachments
-
- populate font list.rev.zip
- (4.67 KiB) Downloaded 330 times
Re: Scrolling a field automatically
Hi Bernd,
Excellent! Before looking at your stack, I couldn’t resist having a go myself, with your mention of htmlText a very big hint. Here’s what I came up with:... all in all, putting the list into a variable the building a new variable explicitly specifying the htmlText is definitely the way to go. I can see how this technique will be useful in a range of circumstances, so I’m very glad you mentioned it.
Edit: It's worth noting that the repeat form you used:
... has the advantage that it allows you to single out specific line/s to apply changes to, which can be very useful indeed.
Regards,
Michael
Excellent! Before looking at your stack, I couldn’t resist having a go myself, with your mention of htmlText a very big hint. Here’s what I came up with:
Code: Select all
on mouseUp
put the fontNames into fontList
sort fontList
repeat for each line n in fontList
put "<p><font face=""e&n"e&">"&n&"</font></p>"&return after newFontList
end repeat
delete char - 1 in newFontList
set the htmlText of fld "fontList" to newFontList
end mouseUp
Edit: It's worth noting that the repeat form you used:
Code: Select all
repeat with i = 1 to the number of lines of tData
Regards,
Michael