Exemplo n.º 1
0
            public Size Measure(float width, float height)
            {
                var finalSize = Size.Zero;

                for (var i = 0; i < _views.Length; i++)
                {
                    var size = _scope.Measure(ref _views[i], width, height);

                    if (size.Width > finalSize.Width)
                    {
                        finalSize.Width = size.Width;
                    }

                    finalSize.Height += _spacing;
                    finalSize.Height += size.Width;
                }

                finalSize.Height -= _spacing;

                return(finalSize);
            }
Exemplo n.º 2
0
        protected override Windows.Foundation.Size MeasureOverride(Windows.Foundation.Size availableSize)
        {
            var scope = new LayoutScope <UIElement>(LayoutAdapter.Instance);
            var root  = LayoutHandler?.Invoke(scope);

            if (root != null)
            {
                var size = scope.Measure(root.Value, (float)availableSize.Width, (float)availableSize.Height);

                return(new Windows.Foundation.Size(size.Width, size.Height));
            }

            return(base.MeasureOverride(availableSize));
        }
Exemplo n.º 3
0
            private void MeasureColumns(float width, float height)
            {
                var columns     = (GridColumnDefinition[])_grid.Columns;
                var unknownSize = width - _grid.KnownWidth;

                for (var i = 0; i < columns.Length; i++)
                {
                    _columnWidths[i] = (columns[i].Type == GridUnitType.Pixel) ? columns[i].Width : 0;
                }

                for (var span = 1; span <= _maxColumnSpan; span++)
                {
                    for (var cursor = 0; cursor <= columns.Length - span; cursor++)
                    {
                        var lastUnknownCursor = -1;

                        for (var i = cursor + span - 1; i >= cursor; i--)
                        {
                            if (columns[i].Type != GridUnitType.Pixel)
                            {
                                lastUnknownCursor = i;
                                break;
                            }
                        }

                        if (lastUnknownCursor == -1)
                        {
                            continue;
                        }

                        var measureSize = _columnWidths[cursor];

                        for (var i = cursor + 1; i < cursor + span; i++)
                        {
                            measureSize += _columnWidths[i];
                        }

                        measureSize += unknownSize;

                        var spanSize = 0.0f;

                        for (var i = 0; i < _views.Length; i++)
                        {
                            if (_views[i].ColumnSpan == span && _views[i].Column == cursor)
                            {
                                var size = _scope.Measure(ref _views[i].View, measureSize, height);

                                if (size.Width > spanSize)
                                {
                                    spanSize = size.Width;
                                }
                            }
                        }

                        if (spanSize > 0)
                        {
                            for (var i = cursor; i < cursor + span; i++)
                            {
                                if (i != lastUnknownCursor)
                                {
                                    spanSize -= _columnWidths[i];
                                }
                            }

                            var original = _columnWidths[lastUnknownCursor];

                            _columnWidths[lastUnknownCursor] = spanSize;

                            unknownSize -= (spanSize - original);
                        }
                    }
                }
            }