Exemplo n.º 1
0
        private LinearAllocator.Constraints[] CalcRowConstraints(Widget widget, Widget[,] cells)
        {
            var rows = new LinearAllocator.Constraints[RowCount];

            for (int i = 0; i < RowCount; i++)
            {
                rows[i] = new LinearAllocator.Constraints {
                    MaxSize = float.PositiveInfinity
                };
            }
            for (int i = 0; i < RowCount; i++)
            {
                for (int j = 0; j < ColCount; j++)
                {
                    var c = cells[i, j];
                    if (c != null)
                    {
                        rows[i].Stretch = Math.Max(rows[i].Stretch, GetCellData(c, i, j).StretchY);
                        int   s  = GetRowSpan(c, i, j);
                        float mn = c.EffectiveMinSize.Y;
                        float mx = c.EffectiveMaxSize.Y;
                        if (s > 1)
                        {
                            mn /= s;
                            mx /= s;
                        }
                        // Distribute constraints evenly
                        for (int u = i; u < s + i; u++)
                        {
                            rows[u].MinSize = Math.Max(rows[u].MinSize, mn);
                            rows[u].MaxSize = Math.Max(rows[u].MaxSize, mx);
                        }
                    }
                }
            }
            return(rows);
        }
Exemplo n.º 2
0
        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++;
            }
        }
Exemplo n.º 3
0
        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;
            }
        }