public override void UpdateLayout(List <Component> componentList, AssortedWidgets.Util.Position origin, AssortedWidgets.Util.Size area) { List <Component> .Enumerator clEnum = componentList.GetEnumerator(); for (int i = 0; i < rowCount; ++i) { for (int e = 0; e < columnCount; ++e) { if (clEnum.MoveNext()) { alignment[i][e].component = clEnum.Current; Size perfectSize = clEnum.Current.GetPreferedSize(); alignment[i][e].width = perfectSize.width; alignment[i][e].height = perfectSize.height; alignment[i][e].HStyle = ((IElement)clEnum.Current).HorizontalStyle; alignment[i][e].VStyle = ((IElement)clEnum.Current).VerticalStyle; } else { alignment[i][e].component = null; alignment[i][e].width = 0; alignment[i][e].height = 0; alignment[i][e].HStyle = EElementStyle.Fit; alignment[i][e].VStyle = EElementStyle.Fit; } } } OneLineInfo[] columnInfo = new OneLineInfo[columnCount]; for (int e = 0; e < columnCount; ++e) { columnInfo[e].miniSize = 0; columnInfo[e].isStretch = false; for (int i = 0; i < rowCount; ++i) { if (alignment[i][e].HStyle == EElementStyle.Stretch) { columnInfo[e].isStretch = true; } columnInfo[e].miniSize = Math.Max(columnInfo[e].miniSize, alignment[i][e].width); } } OneLineInfo[] rowInfo = new OneLineInfo[rowCount]; for (int i = 0; i < rowCount; ++i) { rowInfo[i].miniSize = 0; rowInfo[i].isStretch = false; for (int e = 0; e < columnCount; ++e) { if (alignment[i][e].VStyle == EElementStyle.Stretch) { rowInfo[i].isStretch = true; } rowInfo[i].miniSize = Math.Max(rowInfo[i].miniSize, alignment[i][e].height); } } int widthAvailable = (int)(area.width - (columnCount - 1) * Spacer - Left - Right); uint stretchSegment = 0; for (int e = 0; e < columnCount; ++e) { if (columnInfo[e].isStretch) { ++stretchSegment; } else { widthAvailable -= (int)columnInfo[e].miniSize; } } if (widthAvailable > 0) { if (stretchSegment > 0) { uint averageWidth = (uint)widthAvailable / stretchSegment; for (int e = 0; e < columnCount; ++e) { if (columnInfo[e].isStretch) { columnInfo[e].miniSize = Math.Max(columnInfo[e].miniSize, averageWidth); } } } else { uint averageAppend = (uint)widthAvailable / columnCount; for (int e = 0; e < columnCount; ++e) { columnInfo[e].miniSize += averageAppend; } } } int heightAvailable = (int)(area.height - Top - Bottom - (rowCount - 1) * Spacer); stretchSegment = 0; for (int i = 0; i < rowCount; ++i) { if (rowInfo[i].isStretch) { ++stretchSegment; } else { heightAvailable -= (int)rowInfo[i].miniSize; } } if (heightAvailable > 0) { if (stretchSegment > 0) { uint averageHeight = (uint)heightAvailable / stretchSegment; for (int i = 0; i < rowCount; ++i) { if (rowInfo[i].isStretch) { rowInfo[i].miniSize = Math.Max(rowInfo[i].miniSize, averageHeight); } } } else { uint averageAppend = (uint)heightAvailable / rowCount; for (int i = 0; i < rowCount; ++i) { rowInfo[i].miniSize += averageAppend; } } } int tempX = (int)Left + origin.X; int tempY = (int)Top + origin.Y; for (int i = 0; i < rowCount; ++i) { for (int e = 0; e < columnCount; ++e) { Position CPosition = new Position(tempX, tempY); Size Carea = new Size(columnInfo[e].miniSize, rowInfo[i].miniSize); OrderComponent((uint)i, (uint)e, CPosition, Carea); tempX += (int)(columnInfo[e].miniSize + Spacer); } tempX = (int)Left + origin.X; tempY += (int)(Spacer + rowInfo[i].miniSize); } }
public override void UpdateLayout(List<Component> componentList, AssortedWidgets.Util.Position origin, AssortedWidgets.Util.Size area) { List<Component>.Enumerator clEnum = componentList.GetEnumerator(); for (int i = 0; i < rowCount; ++i) { for (int e = 0; e < columnCount; ++e) { if (clEnum.MoveNext()) { alignment[i][e].component = clEnum.Current; Size perfectSize = clEnum.Current.GetPreferedSize(); alignment[i][e].width = perfectSize.width; alignment[i][e].height = perfectSize.height; alignment[i][e].HStyle = ((IElement)clEnum.Current).HorizontalStyle; alignment[i][e].VStyle = ((IElement)clEnum.Current).VerticalStyle; } else { alignment[i][e].component = null; alignment[i][e].width = 0; alignment[i][e].height = 0; alignment[i][e].HStyle = EElementStyle.Fit; alignment[i][e].VStyle = EElementStyle.Fit; } } } OneLineInfo[] columnInfo = new OneLineInfo[columnCount]; for (int e = 0; e < columnCount; ++e) { columnInfo[e].miniSize = 0; columnInfo[e].isStretch = false; for (int i = 0; i < rowCount; ++i) { if (alignment[i][e].HStyle == EElementStyle.Stretch) { columnInfo[e].isStretch = true; } columnInfo[e].miniSize = Math.Max(columnInfo[e].miniSize, alignment[i][e].width); } } OneLineInfo[] rowInfo = new OneLineInfo[rowCount]; for (int i = 0; i < rowCount; ++i) { rowInfo[i].miniSize = 0; rowInfo[i].isStretch = false; for (int e = 0; e < columnCount; ++e) { if (alignment[i][e].VStyle == EElementStyle.Stretch) { rowInfo[i].isStretch = true; } rowInfo[i].miniSize = Math.Max(rowInfo[i].miniSize, alignment[i][e].height); } } int widthAvailable = (int)(area.width - (columnCount - 1) * Spacer - Left - Right); uint stretchSegment = 0; for (int e = 0; e < columnCount; ++e) { if (columnInfo[e].isStretch) { ++stretchSegment; } else { widthAvailable -= (int)columnInfo[e].miniSize; } } if (widthAvailable > 0) { if (stretchSegment > 0) { uint averageWidth = (uint)widthAvailable / stretchSegment; for (int e = 0; e < columnCount; ++e) { if (columnInfo[e].isStretch) { columnInfo[e].miniSize = Math.Max(columnInfo[e].miniSize, averageWidth); } } } else { uint averageAppend = (uint)widthAvailable / columnCount; for (int e = 0; e < columnCount; ++e) { columnInfo[e].miniSize += averageAppend; } } } int heightAvailable = (int)(area.height - Top - Bottom - (rowCount - 1) * Spacer); stretchSegment = 0; for (int i = 0; i < rowCount; ++i) { if (rowInfo[i].isStretch) { ++stretchSegment; } else { heightAvailable -= (int)rowInfo[i].miniSize; } } if (heightAvailable > 0) { if (stretchSegment > 0) { uint averageHeight = (uint)heightAvailable / stretchSegment; for (int i = 0; i < rowCount; ++i) { if (rowInfo[i].isStretch) { rowInfo[i].miniSize = Math.Max(rowInfo[i].miniSize, averageHeight); } } } else { uint averageAppend = (uint)heightAvailable / rowCount; for (int i = 0; i < rowCount; ++i) { rowInfo[i].miniSize += averageAppend; } } } int tempX = (int)Left + origin.X; int tempY = (int)Top + origin.Y; for (int i = 0; i < rowCount; ++i) { for (int e = 0; e < columnCount; ++e) { Position CPosition = new Position(tempX, tempY); Size Carea = new Size(columnInfo[e].miniSize, rowInfo[i].miniSize); OrderComponent((uint)i, (uint)e, CPosition, Carea); tempX += (int)(columnInfo[e].miniSize + Spacer); } tempX = (int)Left + origin.X; tempY += (int)(Spacer + rowInfo[i].miniSize); } }