Auto Scrolling Field

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
mickpitkin92
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 226
Joined: Tue Jun 30, 2009 11:15 pm
Location: North East England, United Kingdom

Auto Scrolling Field

Post by mickpitkin92 » Sat Aug 03, 2013 10:33 am

Now I hate to ask this because it is probably one of the basics, but is there anyway I can make a field automatically scroll down to show a new line when it is full? Effectively, something like booting OS X in Single User Mode and seeing each action the OS does as it is starting up.

Kind regards.
Currently working on the Nix Operating System, an operating system that runs atop of Windows and Mac with the goal of providing an alternative to those systems without having to leave them whilst providing the features of a standard OS.

andrewferguson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 179
Joined: Wed Apr 10, 2013 5:09 pm

Re: Auto Scrolling Field

Post by andrewferguson » Sat Aug 03, 2013 10:53 am

Hi,
I'm not sure about automatic, but

Code: Select all

--in this example the field is called "field", and the size of each line is 50 pixels
set the vScroll of field "field" to the number of lines of field "field" * 50
should scroll the text down to the last line.

Andrew

shaosean
Posts: 827
Joined: Thu Nov 04, 2010 7:53 am

Re: Auto Scrolling Field

Post by shaosean » Sat Aug 03, 2013 11:38 am

If you set the fixedLineHeight property to TRUE and set the textSize property to a font size you like, you can use the above code without hardcoding a value (the 50 in the code above)..

Code: Select all

--in this example the field is called "field"
set the vScroll of field "field" to the number of lines of field "field" * (the textHeight of field "field")
See the textHeight property (this is automatically updated when you change the textSize AND the fixedLineHeight is set to TRUE)..

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

Re: Auto Scrolling Field

Post by bn » Sat Aug 03, 2013 11:53 am

Hi Mick,

what I do if I want a scrolling text field to scroll to the bottom is to set the vScroll of the textfield to a ridiciously high number like 100000. Lazy but works.

This will scroll to the last line.

Kind regards

Bernd

mickpitkin92
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 226
Joined: Tue Jun 30, 2009 11:15 pm
Location: North East England, United Kingdom

Re: Auto Scrolling Field

Post by mickpitkin92 » Sat Aug 03, 2013 1:36 pm

Well gents, these are all fantastic ideas, in terms of making it automatic, writing to the field will be implemented as a function anyways and so the automatic stuff will be handled by the function anyways. I'll let you know which is best when I get a chance.
Currently working on the Nix Operating System, an operating system that runs atop of Windows and Mac with the goal of providing an alternative to those systems without having to leave them whilst providing the features of a standard OS.

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

Re: Auto Scrolling Field

Post by bn » Sat Aug 03, 2013 1:50 pm

Hi Mick,
Well gents
you should include Shao, she deserves a big thanks for all her support on this forum and this thread. :)

Kind regards

Bernd

mickpitkin92
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 226
Joined: Tue Jun 30, 2009 11:15 pm
Location: North East England, United Kingdom

Re: Auto Scrolling Field

Post by mickpitkin92 » Sat Aug 03, 2013 2:05 pm

Wut? I thought with the Sean thing, oh Jesus.

I am so sorry Shao. I didn't realize. >_<
Currently working on the Nix Operating System, an operating system that runs atop of Windows and Mac with the goal of providing an alternative to those systems without having to leave them whilst providing the features of a standard OS.

mickpitkin92
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 226
Joined: Tue Jun 30, 2009 11:15 pm
Location: North East England, United Kingdom

Re: Auto Scrolling Field

Post by mickpitkin92 » Sat Aug 03, 2013 6:58 pm

So guys, I had a little try of this just now and unfortunately the ones that Shaosean and Andrew suggested, don't work, at least not in 6.1 they don't. Luckily enough, I stumbled upon a little gem in the hints section of the Dictionary for VScroll.

Code: Select all

Set The VScroll Of Field 1 To (The Effective TextHeight Of Field 1) * (The Number Of Lines In Field 1)
Thanks go to kspieldenner@lifetouch.com who posted it back in 2010, nonetheless, when I get round to the contributors list, you three shall find yourselves on the list, along with a huge amount of other people who have helped me over the years. I just need to get round to finishing my software. :D
Currently working on the Nix Operating System, an operating system that runs atop of Windows and Mac with the goal of providing an alternative to those systems without having to leave them whilst providing the features of a standard OS.

andrewferguson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 179
Joined: Wed Apr 10, 2013 5:09 pm

Re: Auto Scrolling Field

Post by andrewferguson » Sat Aug 03, 2013 7:48 pm

mickpitkin92 wrote:unfortunately the ones that Shaosean and Andrew suggested, don't work, at least not in 6.1 they don't.
Don't work? It worked for me in 6.1

Andrew

mickpitkin92
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 226
Joined: Tue Jun 30, 2009 11:15 pm
Location: North East England, United Kingdom

Re: Auto Scrolling Field

Post by mickpitkin92 » Sat Aug 03, 2013 8:06 pm

Doesn't work for some reason, not sure why.
Currently working on the Nix Operating System, an operating system that runs atop of Windows and Mac with the goal of providing an alternative to those systems without having to leave them whilst providing the features of a standard OS.

andrewferguson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 179
Joined: Wed Apr 10, 2013 5:09 pm

Re: Auto Scrolling Field

Post by andrewferguson » Sat Aug 03, 2013 8:34 pm

Maybe it is not working because you have text that is wrapped to make it look like more than one line but actually is only a small number of lines.

If that is the case then the code you found, or the idea by Bernd would be best.

Andrew

KurtR
LiveCode Member
LiveCode Member
Posts: 6
Joined: Mon Dec 05, 2011 5:34 pm

Re: Auto Scrolling Field

Post by KurtR » Mon Jul 10, 2017 9:12 pm

Newbie here... This thread helped me solve a scrolling problem, but I found a tweak that makes this a little simpler. You can use the textHeightSum property of a field to determine its height/size, then just subtract from that to set the scroll position where you want. So no tracking or calculation of numbers of rows, etc. Here is an example:

Code: Select all

on scrollMe
   set the vScroll of field "myTextBox" to (the textHeightSum of field "myTextBox")  - 100
end scrollMe
In this example, I am using a font size of 12, and I experimented to find that 100 was the right number of pixels to subtract (or close to that). I use parenthesis for code clarity only, probably not needed. This custom handler positions the scroll at the last line of text. With other font sizes you might need a larger number of pixels to subtract. Anyway, I like the elegance of this approach, and use it a lot to create the look of a console feed in a field.

So, after every time I add text to myTextBox, I just run the command scrollMe, and that keeps everything looking like a console feed.

Post Reply

Return to “Talking LiveCode”