This issue/question is still out there. Can we please have someone from CL clarify what the scrollWidth, scrollHeight are supposed to do? Thank you.
width and height are the visible area of the scrollView. scrollWidth and scrollHeight are supposed to set the limits of how big the overall scroll area is. Since scrollView’s are implemented as display.newGroups() which are by definition infinite in size, if we don’t set a limit, you could scroll for ever. These numbers are supposed to form an artificial bounds on the group.
Now I’ve not looked at the code for this, but it seems to me that it would be a desirable feature that if your content doesn’t fill the maximum set with scrollWidth and scrollHeight, then you would not want to scroll empty space, so it may artificially limit to the actual bounds of the group upto a max of scrollWidth/scrollHeight.
Is it not behaving this way?
Rob
I have been trying to understand this well by varying the width values of text vs scrollWidth using the ScrollView sample app from the CL samples and it is somehow not playing right. Try it.
Try scrollWidth = display.contentWidth * 2,
and display.contentWidth * 3 for the display.newText putting up the lotsOfText. You would expect to have a wide body of text which is scrollable up to twice the screen width right?
Then try scrollWidth = display.contentWidth * 3,
and display.contentWidth * 2 for the display.newText …
Something is definitely not adding up. Need more experimentation to nail it down.
Rob, did you have a chance to try this simple test? Give it a whirl if you have 5 minutes. You will see the inconsistency. Thanks
local scrollview = widget.newScrollView { top = 0, left = 0, width = display.contentWidth , height = display.contentHeight, scrollWidth = display.contentWidth \* 2, scrollHeight = 2000, listener = scrollListener, horizontalScrollDisabled = true, hideScrollBar = false, }
The width and height are the area of the screen
where you want the scrollView to be constrained within, i.e. the
viewPort of the scrollView. Setting the width to contentWidth * 2 makes
no sense since since you can’t see an area that big. Setting the
height to 2000 is the same issue if your contentHeight is < 2000 then
there is no scrolling. The scrollWidth and scrollHeight is the
maximum area that can be scrolled. If the scrollWidth is less that
width or scrollHeight is less than height then there isn’t anything to
scroll. I would expect that you would almost always have scrollWidth
and scrollHeight greater than width and height. The exception is if
you are only scrolling in one direction, in which case the direction
that’s not scrolling would be the same. In this case you have
horizontalScrolling disabled, so it’s pointless to make scrollWidth
greater than width.
The code above worked the way I expect it too once I made the width and height something that fits in the content area.
Rob
Did you have a chance to try the experiment I suggested using the CL Sample ScrollView with Lorem Ipsum text in it?
If you set scrollWidth to be contentWidth * 2 and the display.newText width to be also contentWidth * 2 you would expect this to nicely show 1/2 of the text on the initial screen and then allow you to scroll horizontally to see the rest right? What you see looks like the attached image. Definitely something wrong here but I don’t know if its a bug or our lack of understanding of these parameters.
Kindly help us understand if latter is the case. Thanks much!!!
Kerem can you post your sample code and I’ll take a look.
Rob
Sure. Here it is. It is the CL ScrollView sample so I just played with the scrollWidth and the width of display.newText for the long text. This makes a good platform to investigare the scrollWidth impact vis a vis content width. Thanks for your attention.
-- -- Abstract: Scroll View sample app -- -- Version: 2.0 -- -- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license -- Copyright (C) 2010 Corona Labs Inc. All Rights Reserved. -- -- Demonstrates how to make text and graphics move up and down on touch, -- or scroll, using the widget libraries scrollView methods. -- -- Supports Graphics 2.0 ------------------------------------------------------------ display.setStatusBar( display.HiddenStatusBar ) local widget = require( "widget" ) -- Our ScrollView listener local function scrollListener( event ) local phase = event.phase local direction = event.direction if "began" == phase then --print( "Began" ) elseif "moved" == phase then --print( "Moved" ) elseif "ended" == phase then --print( "Ended" ) end -- If the scrollView has reached it's scroll limit if event.limitReached then if "up" == direction then print( "Reached Top Limit" ) elseif "down" == direction then print( "Reached Bottom Limit" ) elseif "left" == direction then print( "Reached Left Limit" ) elseif "right" == direction then print( "Reached Right Limit" ) end end return true end -- Create a ScrollView local scrollView = widget.newScrollView { left = 0, top = 0, width = display.contentWidth, height = display.contentHeight, scrollWidth = display.contentWidth \* 2, bottomPadding = 50, id = "onBottom", horizontalScrollDisabled = false, verticalScrollDisabled = false, listener = scrollListener, } --Create a text object for the scrollViews title local titleText = display.newText("Move Up to Scroll", display.contentCenterX, 48, native.systemFontBold, 16) titleText:setFillColor( 0 ) -- insert the text object into the created display group scrollView:insert( titleText ) --Create a large text string local lotsOfText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur imperdiet consectetur euismod. Phasellus non ipsum vel eros vestibulum consequat. Integer convallis quam id urna tristique eu viverra risus eleifend.\n\nAenean suscipit placerat venenatis. Pellentesque faucibus venenatis eleifend. Nam lorem felis, rhoncus vel rutrum quis, tincidunt in sapien. Proin eu elit tortor. Nam ut mauris pellentesque justo vulputate convallis eu vitae metus. Praesent mauris eros, hendrerit ac convallis vel, cursus quis sem. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque fermentum, dui in vehicula dapibus, lorem nisi placerat turpis, quis gravida elit lectus eget nibh. Mauris molestie auctor facilisis.\n\nCurabitur lorem mi, molestie eget tincidunt quis, blandit a libero. Cras a lorem sed purus gravida rhoncus. Cras vel risus dolor, at accumsan nisi. Morbi sit amet sem purus, ut tempor mauris.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur imperdiet consectetur euismod. Phasellus non ipsum vel eros vestibulum consequat. Integer convallis quam id urna tristique eu viverra risus eleifend.\n\nAenean suscipit placerat venenatis. Pellentesque faucibus venenatis eleifend. Nam lorem felis, rhoncus vel rutrum quis, tincidunt in sapien. Proin eu elit tortor. Nam ut mauris pellentesque justo vulputate convallis eu vitae metus. Praesent mauris eros, hendrerit ac convallis vel, cursus quis sem. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque fermentum, dui in vehicula dapibus, lorem nisi placerat turpis, quis gravida elit lectus eget nibh. Mauris molestie auctor facilisis.\n\nCurabitur lorem mi, molestie eget tincidunt quis, blandit a libero. Cras a lorem sed purus gravida rhoncus. Cras vel risus dolor, at accumsan nisi. Morbi sit amet sem purus, ut tempor mauris. " --Create a text object containing the large text string and insert it into the scrollView local lotsOfTextObject = display.newText( lotsOfText, display.contentCenterX, 0, display.contentWidth \* 2, 0, "Helvetica", 14) lotsOfTextObject:setFillColor( 0 ) lotsOfTextObject.anchorY = 0.0 -- Top --------------------------------lotsOfTextObject:setReferencePoint( display.TopCenterReferencePoint ) lotsOfTextObject.y = titleText.y + titleText.contentHeight + 10 scrollView:insert( lotsOfTextObject )
Hi Rob,
Any chance to try this out? Thanks for your efforts.
Regards,
Kerem
yeah something definitely fishy about the scrollView. Especially when in the documentation it states that scrollWidth and scrollHeight are required but corona never seems to use them in most of their tutorials.
Furthermore, scrollWidth (and probably scrollHeight) doesn’t really work properly (or i should say not in a particulary friendly way) but as someone mentioned the scrollView api code is probably reducing it based on the actual contents of the scrollView, which yeah does make scrollWidth/scrollHeight redundant.
Can we somehow tweak the scrollView widget api somewhere so it will do what we want and not what it is doing right now?
yeah something definitely fishy about the scrollView. Especially when in the documentation it states that scrollWidth and scrollHeight are required but corona never seems to use them in most of their tutorials.
Furthermore, scrollWidth (and probably scrollHeight) doesn’t really work properly (or i should say not in a particulary friendly way) but as someone mentioned the scrollView api code is probably reducing it based on the actual contents of the scrollView, which yeah does make scrollWidth/scrollHeight redundant.
Can we somehow tweak the scrollView widget api somewhere so it will do what we want and not what it is doing right now?
poke poke poke…
So are scrollWidth and scrollHeight required or not?
The docs say they are, but I have yet to find values that make any difference in my code. Taking them out makes no difference, so how is it that they are required?
Jay
I’m trying to get an answer.
Rob
Well, more than half a year ago I posted a simple test above ( in this very thread) with code as well and I thought it exhibited the inconsistency well but alas… I think this one fell through the cracks.
The scrollView’s scrollWidth and scrollHeight are kind of the initial maximum size. As things are added that grows the scrollView the values of scrollWidth and scrollHeight will grow with the actual size.
Its used to calculate the scrolling limits. You can always use the setScrollHeight, setScrollWidth methods to reset the area if you’ve added something that caused it limits to change.
The parameters are not actually required. If you do not provide them they default to the set width and height.
Rob
Rob, thanks for tracking that down and getting us the “official” word.
Jay
poke poke poke…
So are scrollWidth and scrollHeight required or not?
The docs say they are, but I have yet to find values that make any difference in my code. Taking them out makes no difference, so how is it that they are required?
Jay
I’m trying to get an answer.
Rob
Well, more than half a year ago I posted a simple test above ( in this very thread) with code as well and I thought it exhibited the inconsistency well but alas… I think this one fell through the cracks.
The scrollView’s scrollWidth and scrollHeight are kind of the initial maximum size. As things are added that grows the scrollView the values of scrollWidth and scrollHeight will grow with the actual size.
Its used to calculate the scrolling limits. You can always use the setScrollHeight, setScrollWidth methods to reset the area if you’ve added something that caused it limits to change.
The parameters are not actually required. If you do not provide them they default to the set width and height.
Rob