Esempio n. 1
0
        protected override Rectangle CalculateChildBounds(UiView view)
        {
            Point size             = view.ComputeSize(Bounds.Width, Bounds.Height);
            PositionParameters pos = view.PositionParameters;

            Rectangle childRect = new Rectangle(0, 0, size.X, size.Y);

            int posX = pos.X.Compute(Bounds.Width);
            int posY = pos.Y.Compute(Bounds.Height);

            switch (pos.HorizontalAlignment)
            {
            case HorizontalAlignment.Center:
                childRect.X = posX - size.X / 2;
                break;

            case HorizontalAlignment.Left:
                childRect.X = posX;
                break;

            case HorizontalAlignment.Right:
                childRect.X = posX - size.X;
                break;

            case HorizontalAlignment.Stretch:
                childRect.X     = 0;
                childRect.Width = Bounds.Width;
                break;
            }

            switch (pos.VerticalAlignment)
            {
            case VerticalAlignment.Center:
                childRect.Y = posY - size.Y / 2;
                break;

            case VerticalAlignment.Top:
                childRect.Y = posY;
                break;

            case VerticalAlignment.Bottom:
                childRect.Y = posY - size.Y;
                break;

            case VerticalAlignment.Stretch:
                childRect.Y      = 0;
                childRect.Height = Bounds.Height;
                break;
            }

            Rectangle bounds = childRect;
            Point     offset = _scroller != null ? ScrollPosition : Point.Zero;

            bounds.X -= offset.X;
            bounds.Y -= offset.Y;

            return(bounds);
        }
Esempio n. 2
0
        protected override Rectangle CalculateChildBounds(UiView view)
        {
            Point size             = view.ComputeSize(Bounds.Width, Bounds.Height);
            PositionParameters pos = view.PositionParameters;

            Rectangle childRect = new Rectangle(0, 0, size.X, size.Y);

            int posX = pos.X.Compute(Bounds.Width);
            int posY = pos.Y.Compute(Bounds.Height);

            switch (pos.HorizontalAlignment)
            {
            case HorizontalAlignment.Center:
                childRect.X = posX - size.X / 2;
                break;

            case HorizontalAlignment.Left:
                childRect.X = posX;
                break;

            case HorizontalAlignment.Right:
                childRect.X = posX - size.X;
                break;

            case HorizontalAlignment.Stretch:
                childRect.X     = 0;
                childRect.Width = Bounds.Width;
                break;
            }

            switch (pos.VerticalAlignment)
            {
            case VerticalAlignment.Center:
                childRect.Y = posY - size.Y / 2;
                break;

            case VerticalAlignment.Top:
                childRect.Y = posY;
                break;

            case VerticalAlignment.Bottom:
                childRect.Y = posY - size.Y;
                break;

            case VerticalAlignment.Stretch:
                childRect.Y      = 0;
                childRect.Height = Bounds.Height;
                break;
            }

            pos.Margin.RepairRect(ref childRect, Bounds.Width, Bounds.Height);
            return(childRect);
        }
Esempio n. 3
0
        protected override Rectangle CalculateChildBounds(UiView view)
        {
            Rectangle childBounds = Bounds;

            int index = _tempChildren.IndexOf(view);

            if (index < 0)
            {
                return(new Rectangle(100000, 10000, 100, 100));
            }

            if (index == 0)
            {
                _currentWrapMax = 0;
                _currentWrapPos = Padding;

                _currentSize = 0;
            }

            PositionParameters parameters = _tempChildren[index].PositionParameters;

            int width  = Bounds.Width;
            int height = Bounds.Height;

            if (_vertical)
            {
                Point size = view.ComputeSize(width, height);

                if (view.PositionParameters.Height.IsRest)
                {
                    int restParts = Math.Max(_restParts, 1);

                    size.Y = _rest * view.PositionParameters.Height.Rest / restParts;
                    size.Y = Math.Max(view.MinSize.Y, size.Y);
                }

                int posX = Padding + parameters.Margin.Left;

                if (!_wrap)
                {
                    switch (parameters.HorizontalAlignment)
                    {
                    case HorizontalAlignment.Center:
                        posX = (width - size.X) / 2;
                        break;

                    case HorizontalAlignment.Right:
                        posX = width - Padding - parameters.Margin.Right - size.X;
                        break;

                    case HorizontalAlignment.Stretch:
                        size.X = width - Padding * 2 - parameters.Margin.Width;
                        break;
                    }
                }

                int pos = Padding;

                if (index > 0)
                {
                    pos = _tempChildren[index - 1].Bounds.Bottom + _tempChildren[index - 1].PositionParameters.Margin.Bottom + Spacing;

                    if (_wrap)
                    {
                        posX = _currentWrapPos + view.Margin.Left;

                        _currentSize = Math.Max(pos, _currentSize);

                        if (pos + size.Y > Math.Ceiling(Bounds.Height + UiUnit.Unit))
                        {
                            pos = Padding;

                            _currentWrapPos = _currentWrapMax + Spacing;

                            int right = _currentWrapPos;
                            posX = right + parameters.Margin.Left;
                        }
                    }
                }

                childBounds.X     = posX;
                childBounds.Width = size.X;

                childBounds.Y      = pos + parameters.Margin.Top;
                childBounds.Height = size.Y;

                _currentWrapMax = Math.Max(_currentWrapMax, childBounds.Right + view.Margin.Right);
                _currentSize    = Math.Max(childBounds.Bottom + Padding, _currentSize);
            }
            else
            {
                Point size = view.ComputeSize(width, height);

                if (view.PositionParameters.Width.IsRest)
                {
                    int restParts = Math.Max(_restParts, 1);

                    size.X = _rest * view.PositionParameters.Width.Rest / restParts;
                    size.X = Math.Max(view.MinSize.X, size.X);
                }

                int posY = Padding + parameters.Margin.Top;

                if (!_wrap)
                {
                    switch (parameters.VerticalAlignment)
                    {
                    case VerticalAlignment.Center:
                        posY = (height - size.Y) / 2;
                        break;

                    case VerticalAlignment.Bottom:
                        posY = height - Padding - parameters.Margin.Bottom - size.Y;
                        break;

                    case VerticalAlignment.Stretch:
                        size.Y = height - Padding * 2 - parameters.Margin.Height;
                        break;
                    }
                }

                int pos = Padding;

                if (index > 0)
                {
                    pos = _tempChildren[index - 1].Bounds.Right + _tempChildren[index - 1].PositionParameters.Margin.Right + Spacing;

                    if (_wrap)
                    {
                        posY = _currentWrapPos + view.Margin.Top;

                        if (pos + size.X > Math.Ceiling(Bounds.Width + UiUnit.Unit))
                        {
                            pos = Padding;

                            _currentWrapPos = _currentWrapMax + Spacing;

                            int bottom = _currentWrapPos;
                            posY = bottom + parameters.Margin.Top;
                        }
                    }
                }

                childBounds.X     = pos + parameters.Margin.Left;
                childBounds.Width = size.X;

                childBounds.Y      = posY;
                childBounds.Height = size.Y;

                _currentWrapMax = Math.Max(_currentWrapMax, childBounds.Bottom + view.Margin.Bottom);
                _currentSize    = Math.Max(childBounds.Right + Padding, _currentSize);
            }

            _updateBounds |= view.Bounds != childBounds;

            return(childBounds);
        }