public void BakeAtLocation(BakedLayout inProgressLayout) { int nestingLevel = 0; AddNodeToLayout(inProgressLayout, Point.Zero, this.rootNode, nestingLevel); BakeGroup(inProgressLayout, this.rootNode, Point.Zero, nestingLevel); }
public void AddNodeToLayout(BakedLayout inProgressLayout, Point position, LayoutNode node, int nestingLevel) { if (node.IsBakable) { inProgressLayout.Add(node, new BakedLayoutNode(position, this.measurer.GetMeasuredSize(node.Size), nestingLevel)); } }
public BakedLayout Bake() { if (!this.rootNode.Size.IsMeasurableAlong(Orientation.Horizontal) || !this.rootNode.Size.IsMeasurableAlong(Orientation.Vertical)) { throw new ImpossibleLayoutException("Root node is not a constant size"); } var bakedLayout = new BakedLayout(this.rootNode); BakeAtLocation(bakedLayout); return(bakedLayout); }
public BakedFlowLayout(BakedLayout bakedLayout, RawFlowLayout rawFlowLayout) { this.bakedLayout = bakedLayout; this.rawFlowLayout = rawFlowLayout; this.rows = new BakedRow[this.rawFlowLayout.RowCount]; for (int rowIndex = 0; rowIndex < this.rawFlowLayout.RowCount; rowIndex++) { var rowItems = this.rawFlowLayout.GetItemNodes(rowIndex); this.rows[rowIndex] = new BakedRow(bakedLayout, this.rawFlowLayout.GetRowName(rowIndex), this.rawFlowLayout.GetRowUsedSpace(rowIndex), rowItems); } UsedSpace = CalculateUsedSpace(); }
private void BakeGroup(BakedLayout inProgressLayout, LayoutNode parentNode, Point parentNodeLocation, int parentNestingLevel) { var isVertical = parentNode.Orientation == Orientation.Vertical; var groupSize = this.measurer.GetMeasuredSize(parentNode.Size); int remainingAlongSize = GetRemainingAlongSizeFromEasyNodes(parentNode, groupSize); var perpendicularStretchSize = isVertical ? groupSize.X - parentNode.Margin.X * 2 : groupSize.Y - parentNode.Margin.Y * 2; HandleStretchedNodes(parentNode, remainingAlongSize, perpendicularStretchSize); // Place elements PlaceAndBakeMeasuredElements(inProgressLayout, parentNode, parentNodeLocation, parentNestingLevel + 1); }
private void PlaceAndBakeMeasuredElements(BakedLayout inProgressLayout, LayoutNode parentNode, Point parentNodeLocation, int currentNestingLevel) { var parentSize = this.measurer.GetMeasuredSize(parentNode.Size); var nextPosition = parentNodeLocation + parentNode.Alignment.GetRelativePositionOfElement(parentSize, CalculateTotalUsedSpace(parentNode)) + parentNode.Alignment.AddPostionDeltaFromMargin(parentNode.Margin) ; foreach (var child in parentNode.Children) { var alignmentOffset = parentNode.Alignment.GetRelativePositionOfElement(CalculateTotalUsedSpace(parentNode), this.measurer.GetMeasuredSize(child.Size)).WithJustAxisValue(parentNode.Orientation.Opposite().ToAxis()); var childPosition = nextPosition + alignmentOffset; AddNodeToLayout(inProgressLayout, childPosition, child, currentNestingLevel); nextPosition += parentNode.Orientation.GetPointForAlongAxis(this.measurer.MeasureEdgeOfNode(child, parentNode.Orientation) + parentNode.Padding); if (child.HasChildren) { BakeGroup(inProgressLayout, child, childPosition, currentNestingLevel); } } }
public BakedRow(BakedLayout bakedLayout, string rowName, Point rowUsedSpace, LayoutNode[] itemNodes) { this.rowUsedSpace = rowUsedSpace; this.rowNode = bakedLayout.GetNode(rowName); this.itemNodes = bakedLayout.GetDirectChildrenOfNode(rowName); }