prime31/UIToolkit — Issue #43: Relative positioning broken?
Author: nsxdavid
Created: 2011-11-27 09:07:31+00:00
State: open

Seems as if the latest refactoring in commit 5f18bc818b2c848f28ec6c3fa57066df2403e849 has broken the relative positioning.

In short, it looks like IPositionablePositioningExtensions.cs: refreshPositions is just wrong now.

// Get anchor info
UIAnchorInfo anchorInfo = sprite.anchorInfo;

// Get parent anchor position
Vector3 position = parentAnchorPosition(anchorInfo.ParentUIObject, anchorInfo.ParentUIyAnchor, anchorInfo.ParentUIxAnchor);

Say the screen width is 320. If there is no parent, this would move a Right Anchored object to X of 320.
Then:

// Add position offset
if (anchorInfo.UIPrecision == UIPrecision.Percentage)
{
position.x += UIRelative.xPercentFrom(anchorInfo.UIxAnchor, anchorInfo.OffsetX);
position.y -= UIRelative.yPercentFrom(anchorInfo.UIyAnchor, anchorInfo.OffsetY);
}

This causes it to move it another 320 to the right so 640, becaues UIRelative.xPercentFrom() does this:

// Get inital offset
float offset = Screen.width * percentOffset;

// If anchor is right the offset is flipped
if( anchor == UIxAnchor.Right )
{
offset = Screen.width - offset;
}
return offset;

So with screen width of 320, 320 * 0 is 0, but because of Anchor.Right, that's 320-0, or 320. Which gets added and thus 640.

Anyway, anything anchored to the right or bottom of the screen is being thrown off screen.