Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

ScrollViewWidget.numChildren returns 3 instead of actual children count?
Started by yvrnrbx Jun 02 2019 11:55 PM

2 replies to this topic
scrollviewwidget numchildren
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

yvrnrbx

[GLOBAL: userInfoPane.html]
yvrnrbx
  • Observer

  • 3 posts
  • Corona SDK

Hello,

 

I was making an app for browsing names (humans) and I was stopped by an inaccurate result of numChildren for ScrollViewWidget. It always returns 3 even if the object doesn't even have children or if children is more than 3. Is it a bug or am I doing something wrong?

 

Here's my code:

local widget = require("widget")
local backgroundPlayer = require("background")
local objectSize = {x = 90,y = 90}
local letters = {"A","B","C","D","E","F","G","I","H","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}
local letterSelectionGroup = display.newGroup()
local fontReallyBig = native.newFont("SinkinSans-200XLight.ttf",60)
local fontBig = native.newFont("SinkinSans-300Light.ttf",35)
local fontNormal = native.newFont("SinkinSans-300Light.ttf",20)
local scrollViewGuideOptions = {
	x = 100,
	y = display.contentHeight/2,
	width = 300,
	height = display.contentHeight,
	horizontalScrollDisabled = true,
	friction = 0.7,
	scrollHeight = 3200,
	hideBackground = true
}
local scrollViewInteractiveOptions = {
	x = 100,
	y = display.contentHeight/2,
	width = 300,
	height = display.contentHeight,
	horizontalScrollDisabled = true,
	friction = 0.7,
	scrollHeight = 3200,
	hideBackground = true,
	isLocked = true
}
local scrollViewBackground = {
	x = 100,
	y = display.contentHeight/2,
	width = 300,
	height = display.contentHeight,
	fillColor = {1,1,1}
}
local mainScrollView = widget.newScrollView(scrollViewGuideOptions)
local interactiveScroll = widget.newScrollView(scrollViewInteractiveOptions)
local mSV_Background = display.newRect(scrollViewGuideOptions.x,scrollViewGuideOptions.y,scrollViewGuideOptions.width,scrollViewGuideOptions.height)
local rectBG = display.newRect(0,0,display.contentWidth,display.contentHeight)
rectBG.anchorX = 0
rectBG.anchorY = 0


mSV_Background:setFillColor(1,1,1,0.4)
mSV_Background.anchorX = 0
mainScrollView.anchorX = 0
mainScrollView:toFront()
--local fontSmall = native.newFont("SinkinSans-200XLight.ttf",12)
--local fontTiny = native.newFont("SinkinSans-200XLight.ttf",8)
local letterIcons = {}
backgroundPlayer:PlayBackground()
rectBG:toBack()
--mainScrollView
for i = -2,#letters+2 do
	local options = {
	x = mainScrollView.width/2,
	y = 100+(150*i),
	width = mainScrollView.width,
	height = 00,
	font = fontReallyBig,
	text = letters[i],
	fontSize = 80,
	align = "center"
	}
	local options2 = {
	x = mainScrollView.width/2,
	y = 100+(200*i),
	width = mainScrollView.width,
	height = 200,
	}
	if letters[i] ~= nil then
		local newText = display.newText(options)
		mainScrollView:insert(newText)
		newText:setFillColor(0,0,0,0.8)
	else
		local newRect = display.newRect(options2.x,options2.y,options2.width,options2.height)
		newRect:setFillColor(1,0.8,0.8,0.4)
		mainScrollView:insert(newRect)
	end
	
	
	
	
end
mainScrollView:setScrollHeight(mainScrollView.numChildren*200)--100+(200*#letters)+300 -- Here

print(mainScrollView.numChildren*200)
print(mainScrollView.numChildren)

I am unable to set the ScrollView's scrollHeight correctly because of the wrong result.

 

Any help is welcome.

 



[TOPIC: post.html]
#2

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,085 posts
  • Corona SDK

Scrollview is not a group so that will not work.  You can get access to the items if you dig around a bit.

 

But simply count the items as you add them then you know how many items are in the scrollview.


  • yvrnrbx likes this

[TOPIC: post.html]
#3

yvrnrbx

[GLOBAL: userInfoPane.html]
yvrnrbx
  • Observer

  • 3 posts
  • Corona SDK

Well thanks about that.

 

The wiki told me though that the ScrollViewWidget inherits methods and properties from GroupObject but I'll ignore that instead for now.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: scrollviewwidget, numchildren