public override void ArrangeChildren(Widget widget) { ArrangementValid = true; var cells = GetCellArray(widget.Nodes); if (cells == null) { return; } var availableWidth = widget.ContentWidth - (ColCount - 1) * ColSpacing; var availableHeight = widget.ContentHeight - (RowCount - 1) * RowSpacing; var cols = LinearAllocator.Allocate(availableWidth, CalcColConstraints(widget, cells), roundSizes: true); var rows = LinearAllocator.Allocate(availableHeight, CalcRowConstraints(widget, cells), roundSizes: true); // Layout each cell var p = new Vector2(0, widget.Padding.Top); DebugRectangles.Clear(); for (int i = 0; i < RowCount; i++) { p.X = widget.Padding.Left; for (int j = 0; j < ColCount; j++) { var c = cells[i, j]; if (c == null) { p.X += cols[j]; continue; } var colSpan = GetColSpan(c, i, j); var size = Vector2.Zero; for (int u = 0; u < colSpan; u++) { size.X += cols[j + u] + (u > 0 ? ColSpacing : 0); } var rowSpan = GetRowSpan(c, i, j); for (int u = 0; u < rowSpan; u++) { size.Y += rows[i + u] + (u > 0 ? RowSpacing : 0); } var align = GetCellData(c, i, j).Alignment; LayoutWidgetWithinCell(c, p, size, align, DebugRectangles); p.X += cols[j] + ColSpacing; } p.Y += rows[i] + RowSpacing; } }
public override void ArrangeChildren(Widget widget) { ArrangementValid = true; var widgets = GetChildren(widget); if (widgets.Count == 0) { return; } var constraints = new LinearAllocator.Constraints[widgets.Count]; int i = 0; foreach (var child in widgets) { constraints[i++] = new LinearAllocator.Constraints { MinSize = child.EffectiveMinSize.X, MaxSize = child.EffectiveMaxSize.X, Stretch = (child.LayoutCell ?? CellDefaults).StretchX }; } var availableWidth = Math.Max(0, widget.ContentWidth - (widgets.Count - 1) * Spacing); var sizes = LinearAllocator.Allocate(availableWidth, constraints, roundSizes: true); i = 0; DebugRectangles.Clear(); var position = widget.Padding.LeftTop; foreach (var child in widgets) { var size = new Vector2(sizes[i], widget.ContentHeight); var align = (child.LayoutCell ?? CellDefaults).Alignment; LayoutWidgetWithinCell(child, position, size, align, DebugRectangles); position.X += size.X + Spacing; i++; } }
public override void ArrangeChildren(Widget widget) { ArrangementValid = true; var widgets = GetChildren(widget); if (widgets.Count == 0) { return; } DebugRectangles.Clear(); List <Widget>[] lines = new List <Widget> [splitIndices.Count - 1]; float[] maxLineHeights = new float[splitIndices.Count - 1]; for (int j = 0; j < splitIndices.Count - 1; j++) { int i0 = splitIndices[j]; int i1 = splitIndices[j + 1]; lines[j] = widgets.GetRange(i0, i1 - i0); maxLineHeights[j] = lines[j].Max((w) => w.EffectiveMinSize.Y); } var availableHeight = Math.Max(0, widget.ContentHeight - (lines.Length - 1) * Spacing); float dy = 0.0f; for (int j = 0; j < splitIndices.Count - 1; j++) { int i0 = splitIndices[j]; int i1 = splitIndices[j + 1]; var constraints = new LinearAllocator.Constraints[i1 - i0]; var line = lines[j]; var maxLineHeight = maxLineHeights[j]; var availableWidth = Math.Max(0, widget.ContentWidth - (line.Count - 1) * Spacing); int i = 0; foreach (var w in line) { constraints[i++] = new LinearAllocator.Constraints { MinSize = w.EffectiveMinSize.X, MaxSize = w.EffectiveMaxSize.X, Stretch = (w.LayoutCell ?? LayoutCell.Default).StretchX }; } var sizes = LinearAllocator.Allocate(availableWidth, constraints, roundSizes: true); i = 0; float justifyDx = 0.0f; if (RowAlignment == HAlignment.Justify) { justifyDx = (availableWidth - sizes.Sum(size => size)) / (line.Count + 1); } if (ColumnAlignment == VAlignment.Justify) { var justifyDy = (availableHeight - maxLineHeights.Sum(h => h)) / (lines.Length + 1); dy += justifyDy; } var position = new Vector2(widget.Padding.Left, widget.Padding.Top + dy); foreach (var w in line) { position.X += justifyDx; var height = (w.LayoutCell ?? LayoutCell.Default).Stretch.Y == 0.0f ? w.EffectiveMinSize.Y : maxLineHeight; var size = new Vector2(sizes[i], height); var align = (w.LayoutCell ?? LayoutCell.Default).Alignment; LayoutWidgetWithinCell(w, position, size, align, DebugRectangles); position.X += size.X + Spacing; i++; } dy += maxLineHeight + Spacing; } }