public void setPositionParams(PositionParams positionParams) { this.positionParams = positionParams; }
private static Bounds calcualteChildRect(Rect parentRect, SizeParams sizeParams, PositionParams positionParams, Rect contentRect) { Bounds bounds = new Bounds(); int childWidth = 0; if (sizeParams.Width == WRAP_CONTENTS) { childWidth = (int)contentRect.Width; } else if (sizeParams.WidthPercent != FILL && sizeParams.WidthPercent != MATCH_PARENT) { childWidth = (int)(parentRect.Width * sizeParams.WidthPercent / 100.0f); } else if (sizeParams.Width == MATCH_PARENT) { childWidth = (int)parentRect.Width; } else if (sizeParams.Width >= 0) { childWidth = (int)sizeParams.Width; } else { childWidth = (int)parentRect.Width; } int childHeight = 0; if (sizeParams.Height == WRAP_CONTENTS) { childHeight = (int)contentRect.Height; } else if (sizeParams.HeightPercent != FILL && sizeParams.HeightPercent != MATCH_PARENT) { childHeight = (int)(parentRect.Height * sizeParams.HeightPercent / 100.0f); } else if (sizeParams.Height == MATCH_PARENT) { childHeight = (int)parentRect.Height; } else if (sizeParams.Height >= 0) { childHeight = (int)sizeParams.Height; } else { childHeight = (int)parentRect.Height; } int childXPos; if (positionParams.xPos == CENTER) { childXPos = (int)parentRect.Left + (int)((parentRect.Width / 2.0f) - childWidth / 2); } else { childXPos = (int)parentRect.Left + (int)positionParams.xPos; } int childYPos; if (positionParams.yPos == CENTER) { childYPos = (int)parentRect.Top + (int)((parentRect.Height / 2.0f) - childHeight / 2); } else { childYPos = (int)parentRect.Top + (int)positionParams.yPos; } bounds.rect = new Rect(childXPos, childYPos, childWidth, childHeight); return(bounds); }