Esempio n. 1
0
 public static LayoutNode Spacer(Point size)
 {
     return(new LayoutNode(false, LayoutNodeName.Nameless, LayoutSize.Pixels(size),
                           /*Ignored params:*/
                           Orientation.Horizontal,
                           LayoutStyle.Empty,
                           null));
 }
Esempio n. 2
0
 public static LayoutNode NamelessLeaf(LayoutSize size)
 {
     return(new LayoutNode(true, LayoutNodeName.Nameless, size,
                           /*Ignored params:*/
                           Orientation.Horizontal,
                           LayoutStyle.Empty,
                           null));
 }
Esempio n. 3
0
 public static LayoutNode Leaf(string name, LayoutSize size)
 {
     return(new LayoutNode(true, name, size,
                           /*Ignored params:*/
                           Orientation.Horizontal,
                           LayoutStyle.Empty,
                           null));
 }
Esempio n. 4
0
 public void ConsumeInstruction(FlowLayoutInstruction instruction)
 {
     if (instruction == FlowLayoutInstruction.Linebreak)
     {
         if (HasRoomForAnotherRow(LayoutNode.NamelessLeaf(LayoutSize.Pixels(0, 0))))
         {
             AddNewRow();
         }
     }
 }
Esempio n. 5
0
 public static RawLayout OrientedParent(Orientation orientation, string name, LayoutSize size, LayoutStyle style, params LayoutNode[] children)
 {
     if (orientation == Orientation.Horizontal)
     {
         return(HorizontalParent(name, size, style, children));
     }
     else
     {
         return(VerticalParent(name, size, style, children));
     }
 }
Esempio n. 6
0
 internal RawFlowLayout(string name, LayoutSize size, LayoutStyle workableAreaStyle, Orientation orientation, FlowLayoutStyle style, FlowLayoutRows rows) : base(
         LayoutNode.OneOffParent(name, size, workableAreaStyle,
                                 LayoutNode.OrientedParent(orientation.Opposite(), "rows", LayoutSize.Pixels(rows.UsedSize), new LayoutStyle(padding: style.PaddingBetweenRows),
                                                           rows.GetLayoutNodesOfEachRow()
                                                           )
                                 ))
 {
     this.orientation  = orientation;
     this.rowNodes     = rows.GetLayoutNodesOfEachRow();
     this.rowUsedSpace = rows.GetUsedSpaceOfEachRow();
 }
Esempio n. 7
0
 /// <summary>
 /// This is only called by the static constructor methods. Most constructors ignore everything past "size"
 /// </summary>
 private LayoutNode(bool isBakable, LayoutNodeName name, LayoutSize size, Orientation orientation, LayoutStyle style, LayoutNode[] children)
 {
     IsBakable   = isBakable;
     Name        = name;
     Size        = size;
     Orientation = orientation;
     if (children != null)
     {
         Children = children;
     }
     Style = style;
 }
Esempio n. 8
0
        private static LayoutSize FlexParentSize(Orientation orientation, FlexLayoutStyle style, LayoutNode[] children)
        {
            var totalPadding             = (children.Length - 1) * style.InnerStyle.Padding;
            var totalAlongMargin         = style.InnerStyle.Margin.AxisValue(orientation.ToAxis()) * 2;
            var totalPerpendicularMargin = style.InnerStyle.Margin.AxisValue(orientation.Opposite().ToAxis()) * 2;

            var measuredAlongSize        = 0;
            var largestPerpendicularSize = 0;

            foreach (var child in children)
            {
                measuredAlongSize       += child.Size.GetValueFromOrientation(orientation).ActualSize;
                largestPerpendicularSize = Math.Max(largestPerpendicularSize, child.Size.GetValueFromOrientation(orientation.Opposite()).ActualSize);
            }

            var alongSize         = measuredAlongSize + totalAlongMargin + totalPadding;
            var perpendicularSize = largestPerpendicularSize + totalPerpendicularMargin;


            if (style.MinAlongSize.HasValue)
            {
                alongSize = Math.Max(alongSize, style.MinAlongSize.Value);
            }

            if (style.MinPerpendicularSize.HasValue)
            {
                perpendicularSize = Math.Max(perpendicularSize, style.MinPerpendicularSize.Value);
            }

            if (orientation == Orientation.Horizontal)
            {
                return(LayoutSize.Pixels(alongSize, perpendicularSize));
            }
            else
            {
                return(LayoutSize.Pixels(perpendicularSize, alongSize));
            }
        }
Esempio n. 9
0
        private static RawFlowLayout OrientedFlowParent(Orientation orientation, string name, LayoutSize size, FlowLayoutStyle style, params LayoutNodeOrInstruction[] children)
        {
            var workableAreaStyle = new LayoutStyle(margin: style.Margin, alignment: style.Alignment);

            var workableArea = LayoutNode.NamelessOneOffParent(size, workableAreaStyle, LayoutNode.Leaf("workableArea", LayoutSize.StretchedBoth())).Bake().GetNode("workableArea");
            var rows         = new FlowLayoutRows(workableArea.Size, style, orientation);

            foreach (var item in children)
            {
                if (item.IsLayoutNode)
                {
                    if (!rows.CanFitItemPerpendicular(item))
                    {
                        break;
                    }

                    if (rows.CanFitItemAlongCurrentRow(item))
                    {
                        rows.AddItemToCurrentRow(item);
                    }
                    else
                    {
                        rows.CreateNextRowAndAdd(item);
                    }
                }
                else if (item.IsInstruction)
                {
                    rows.ConsumeInstruction(item);
                }
            }

            return(new RawFlowLayout(name, size, workableAreaStyle, orientation, style, rows));
        }
Esempio n. 10
0
 public static RawFlowLayout VerticalFlowParent(string name, LayoutSize size, FlowLayoutStyle style, params LayoutNodeOrInstruction[] children)
 {
     return(OrientedFlowParent(Orientation.Vertical, name, size, style, children));
 }
Esempio n. 11
0
 public static RawLayout OneOffParent(string name, LayoutSize size, LayoutStyle style, LayoutNode child)
 {
     // Horizontal/Vertical does not matter here
     return(HorizontalParent(name, size, style, child));
 }
Esempio n. 12
0
 public static RawLayout NamelessOneOffParent(LayoutSize size, LayoutStyle style, LayoutNode child)
 {
     // Horizontal/Vertical does not matter here
     return(HorizontalParent("root", size, style, child));
 }
Esempio n. 13
0
 public static LayoutNode NamelessHorizontalParent(LayoutSize size, LayoutStyle style, params LayoutNode[] children)
 {
     return(new RawLayout(new LayoutNode(true, LayoutNodeName.Nameless, size, Orientation.Horizontal, style, children)));
 }
Esempio n. 14
0
 public static LayoutNode StretchedSpacer()
 {
     return(new LayoutNode(false, LayoutNodeName.Nameless, LayoutSize.StretchedBoth(), Orientation.Horizontal, LayoutStyle.Empty, null));
 }
Esempio n. 15
0
 /// <summary>
 /// Returns a LayoutNode just like this one with the same children, only resized
 /// </summary>
 /// <param name="newSize"></param>
 /// <returns></returns>
 public RawLayout GetResized(Point newSize)
 {
     return(new RawLayout(new LayoutNode(IsBakable, Name, LayoutSize.Pixels(newSize.X, newSize.Y), Orientation, Style, Children)));
 }
Esempio n. 16
0
 public static RawLayout HorizontalParent(string name, LayoutSize size, LayoutStyle style, params LayoutNode[] children)
 {
     return(new RawLayout(new LayoutNode(true, name, size, Orientation.Horizontal, style, children)));
 }
Esempio n. 17
0
        public LayoutNode GetLayoutNode(string rowNodeName)
        {
            var size = Orientation.GetPointFromAlongPerpendicular(AvailableAlongSize, UsedPerpendicularSize);

            return(LayoutNode.OrientedParent(Orientation, rowNodeName, LayoutSize.Pixels(size), RowStyle, Content.ToArray()));
        }
Esempio n. 18
0
 public Point GetMeasuredSize(LayoutSize size)
 {
     return(new Point(MeasureEdge(size.Width), MeasureEdge(size.Height)));
 }