public override void Layout(ViewLayoutContext context)
{
Debug.Assert(context != null);
// Validate incoming reference
if (context == null) throw new ArgumentNullException("context");
// We take on all the available display area
ClientRectangle = context.DisplayRectangle;
// Ensure that the correct number of children are created
SyncChildren();
// Is there anything to layout?
if (Count > 0)
{
// Reduce the client area by the requested padding before the internal children
Rectangle displayRect = CommonHelper.ApplyPadding(Orientation.Horizontal, ClientRectangle, _padding);
// Get size of the first child, assume all others are same size
Size itemSize = this[0].GetPreferredSize(context);
// Starting position for first item
Point nextPoint = displayRect.Location;
for (int i = 0; i < Count; i++)
{
// Find rectangle for the child
context.DisplayRectangle = new Rectangle(nextPoint, itemSize);
// Layout the child
this[i].Layout(context);
// Move to next position across
nextPoint.X += itemSize.Width;
// Do we need to move to next line?
if (((i + 1) % _lineItems) == 0)
{
nextPoint.X = displayRect.X;
nextPoint.Y += itemSize.Height;
}
}
}
// Put back the original display value now we have finished
context.DisplayRectangle = ClientRectangle;
}