Page 1 of 1

Problem with 1st try at a scroller

Posted: Mon Apr 01, 2013 7:46 pm
by Gene
Hi - I've puzzled over this until the screen is starting to go blank in front of my eyes and I can't seem to figure out what is going on, so I'm hoping someone can give me a tip. I think that the answer is staring me in the face, but i can't pull it out.

To initially get started with creating a scroller I downloaded a tutorial that works just great - except that it I can't seem to change the position of the field and scroll area without the scroller refusing to display the first few lines of the text.

"Out of the box", the example has the text field positioned in the upper left hand corner of the screen. I have tried numerous ways to move it down and toward the center, as would be a more typical situation. When it first displays, the top of the text within the field is visible, but as soon as the scroller is activated, it will scroll down and back up again, but now clipping the first few lines.

I've been testing this on the Android simulator and a device, but I thought that this is a more general question than for just the Android forum.

Here is the code, cut and pasted from the example. The only thing I change is the position of the text field and the scroll area object when I run into trouble.

Thanks in advance for any advice.

Code: Select all

local sScrollerID

on preOpenCard
   local tScrollerRect, tContentRect
   
   // Only create a scroller on a mobile device
   if environment() is not "mobile" then exit preOpenCard
   
   // Set the area of the scroller
   put the rect of group "scrollArea" into tScrollerRect
   
   // Set the are of the content to be scrolled
   put the left of field "lorem",the top of field "lorem",the right of field "lorem",the formattedHeight of field "lorem" into tContentRect
   
   // Create the scroller control
   mobileControlCreate "scroller", "loremScroll"
   put the result into sScrollerID
   
   // Set the properties of the scroller
   mobileControlSet "loremScroll", "rect", tScrollerRect
   mobileControlSet "loremScroll", "contentRect", tContentRect
   mobileControlSet "loremScroll", "visible", true
   mobileControlSet "loremScroll", "scrollingEnabled", true
   mobileControlSet "loremScroll", "vIndicator", true
   mobileControlSet "loremScroll", "vscroll", 0
end preOpenCard

on closeCard
   // Delete the scroller
   if environment() is not "mobile" then exit closeCard
   mobileControlDelete sScrollerID
end closeCard

on scrollerDidScroll hOffset, vOffset
   // When the user scrolls move the displayed content
   set the vScroll of group "scrollArea" to vOffset
end scrollerDidScroll

Re: Problem with 1st try at a scroller

Posted: Tue Apr 02, 2013 11:24 am
by bn
Hi Gene,

the contentRect is relative to the scrollerRect. I.e. the topLeft of the contentRect is 0,0

instead of
put the left of field "lorem",the top of field "lorem",the right of field "lorem",the formattedHeight of field "lorem" into tContentRect
try

Code: Select all

put 0,0,the width of field "lorem",the formattedHeight of field "lorem" into tContentRect
it should work.
Kind regards
Bernd

Re: Problem with 1st try at a scroller

Posted: Tue Apr 02, 2013 4:48 pm
by Gene
Thank you Bernd! Your solution works perfectly.

After I tried your code and tested on my device, I went back to the original lesson and reread it. Sure enough, a similar line of code was embedded in the text as a possible substitute for the line in question. Duh, I had missed that altogether. It appears that maybe I should learn to read English before continuing on trying to learn more programming. For possible benefit to others here is a quote of the alternate line of code from the example:

"-nb, if you experience hidden text in your field after a scroll please replace the above script with :
put 0,0,(the formattedWidth of group "scrollArea"),(the formattedHeight of group "scrollArea") into tContentRect -"

Also, if anyone else reads this, the entire lesson on how to create a scroller is found at: http://lessons.runrev.com/s/lessons/m/4 ... ll-a-field

Your explanation below drives at the heart of the matter, and is worth remembering for the future.
the contentRect is relative to the scrollerRect. I.e. the topLeft of the contentRect is 0,0
Thanks again for your time and effort.

Cheers - Gene