Calculating normalized horizontal position based on container size with fixed item size

Hi,

I’m building a little list of items inside a ScrollRect and would like to jump to any of them giving an index.

Based on inspector my items are 56x56 and the container has a width of 932. As an example I have tried to jump to an item manually (5th item in this example) just by setting normalizedHorizontalPostion to (556)/932. But this seems not quite right. If I set the Content rect position to -556 it shows my item at correct position (in the inspector) but when i try to set this through the scrollrect normalized horizontal position I can see in the inspector that the container is not jumping to the expected position.

Is there anything I am missing? Must I have any other internal screen rect or container rect position variables into account for this?.

Cheers.

This is untested:

w = visible area of scrollrect
mW = 932; //total width of scroll rect
pos = (itemcount - 1)*56; //0 indexed, hence 1st item should read (1-1)*56 = 0

return ((Mathf.Clamp(pos+w/2f, w/2f, mW - w/2f)-w/2f)/(mW-w))

Maybe that will work, if the scroll bar interpolates linearly I believe it should!