Keeping the scrollbar at the bottom of a field

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Keeping the scrollbar at the bottom of a field

Post by gyroscope » Sun May 18, 2008 8:00 pm

Hi, I have a button which adds one or more lines of type at a time to a field. When the scrollbar of the field becomes active, I would like the scrollbar slide to always appear at the bottom of the field so that the last text entry can be seen.

The only two properties which I can find which seem relevant to solving this problem are endValue and vScroll; however after experimenting with these, I am still having no luck...

So is there a neat bit of scripting that I could put into the button that would keep the scrollbar slide at the bottom, so as to always show the last text entry?

I'd appreciate any help or advice here, please!

:)

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Mon May 19, 2008 12:30 pm

Try this:

Code: Select all

on mouseUp
  -- do your thing
  -- now ensure itthe field scrolls to the bottom
  set the vScroll of field "MyField" to the formattedHeight of field "MyField"
end mouseUp
Hope this helped,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon May 19, 2008 1:42 pm

Dear Gyroscope,

The maximum scroll equals:

Code: Select all

the formattedHeight of fld x - the height of fld x - the margins of fld x - the textHeight of fld x
provided that the margins are an integer and the fixedLineHeight of the field is true. If the margins are no integer, you probably need to use item 4 of the margins. If the fixedLineHeight is not true, you need to find a way to figure out the height of the last line of your field. Also, the dontWrap of your field has to be set to true.

This is a nice way to do it:

Code: Select all

getProp maxScroll
  if word 1 of the name of the target is "field" then
  return (the formattedHeight of the target - the height of the target - the margins of the target - the textHeight of the target)
  else return empty
end maxScroll
(untested, but should work)

Now, if you have this script at stack level or in a library, you can call this property using:

Code: Select all

put the maxScroll of fld x
set the vScroll of fld x to the maxScroll of fld x
The first line should return an integer, the second should set the scroll of a field to the largest possible value.

Best regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Mon May 19, 2008 9:31 pm

Hi Jan

Thank you very much, that is perfect for my project needs at the moment, and it works a treat!


Hi Mark

Thank you also for your comprehensive coding; as it happens, I needed to be able to find out the maximum scroll of a text field for my third project so this has solved another problem I was going to post at some later time...

:)
Last edited by gyroscope on Tue May 20, 2008 11:04 am, edited 1 time in total.

Nonsanity
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 86
Joined: Thu May 17, 2007 9:15 pm
Contact:

Post by Nonsanity » Mon May 19, 2008 9:36 pm

I've always just used:

Code: Select all

set the vscroll of fld x to 100000
I suppose that could fail in extreme cases, but I've never run across such a one, and I've been using this trick since the late 80's with HyperCard (less the V in vscroll).
~ Nonsanity
~ Chris Innanen

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Tue May 20, 2008 11:03 am

Hi Nonsanity, thanks for the info; I did try that (with a few other figures as well) but unfortunately kept getting an error message (or it didn't seem to do anything with 100000). But if it works for you, that's good!

:)

Garrett
Posts: 386
Joined: Sat Apr 08, 2006 8:15 am
Contact:

Post by Garrett » Tue May 20, 2008 6:55 pm

Or if by chance the field is acting as a list box, you can do this:

Code: Select all

set the hilitedLine of field "fList" to the number of lines of field "fList"
That would highlight the last line and cause it to scroll to the point that the last line is fully visible.

* fList being the name of field. Use whatever name your field is of course.

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Tue May 20, 2008 7:01 pm

I'm certain I'm going to find that useful at some point, thank you Garrett!

:)

bjb007
Posts: 313
Joined: Fri Dec 28, 2007 4:56 am

Keeping the scrollbar at the bottom of a field

Post by bjb007 » Fri Aug 15, 2008 6:18 am

And set the highlight (sorry, Hilite)
color to the field background.
Life is just a bowl of cherries.

Post Reply