Page 1 of 1

Negative vscroll for a group

Posted: Wed Oct 31, 2012 12:51 pm
by Adrian
Hi. I'm going round in circles trying to work out what I'm doing wrong and I'm hoping you can help.

I have a fairly straightforward multi-line text field (LiveCode one, not a native iOS one) on a card. It's in a Group and in PreOpenCard I wrap a Scroller around it. So far, so typical of things that work elsewhere. However, when the card appears in the simulator, it starts pretty much centred, rather than at the top. If I scroll I can get to the top and it bounces correctly on the first line, etc.

In ScrollerDidScroll I put the vscroll of the Group into a field for debugging. On opening, this shows as zero and as I scroll to the top it shows a negative number. The dictionary tells me it is always a positive integer :shock:

I call resize Stack from preOpenCard.

In Resize Stack I have (partial, for example):
set the rect of group "ListGroup" to 10,200,760,960
set the height of field "ListField" to the formattedHeight of field "ListField"
iPhoneControlSet sScrollerID, "rect", the rect of group "ListGroup"
iPhoneControlSet sScrollerID, "contentRect", the formattedrect of group "ListGroup"
set the vScroll of group "ListGroup" to 0
iPhoneControlSet sScrollerID, "vscroll", 0

ScrollerDidScroll is:
on scrollerDidScroll pOffsetX, pOffsetY
lock screen
set the vScroll of group "ListGroup" to pOffsetY - the top of group "ListGroup"
unlock screen
put the vscroll of group "ListGroup" into field "Vscroll"
end scrollerDidScroll


The field has around 1200 lines in it (retrieved from a database).

Does anyone have a pointer to why my scroller is starting in the middle, rather than the top?

Cheers,

Adrian


(P.S. can anyone point me to some documentation that goes into detail about scrollers, values of pOffsetX/Y, etc.? I always seem to have to do a lot of trial and error to get scrollers to line up properly and most of the examples I've seen have the scroller at the top of a card, so avoiding things like having to calculate the vscroll based on the top of the group. I've got this working in various apps, but I could do with the science, rather than blundering about!)

Re: Negative vscroll for a group

Posted: Wed Oct 31, 2012 1:51 pm
by bn
Hi Adrian,

after

Code: Select all

set the height of field "ListField" to the formattedHeight of field "ListField"
you should probably set the top of field "ListField" to the top of group "ListGroup".
If you don't you see the behavior you notice: Livecode changes sizes of an object from the location of the object by adding to top/bottom, Right/Left.
At least I hope that cures it...

Kind regards
Bernd

Re: Negative vscroll for a group

Posted: Wed Oct 31, 2012 3:11 pm
by Adrian
Ah, that's it. Thanks very much Bernd

Cheers,

Adrian