Ejemplo n.º 1
0
        protected override void Render()
        {
            var alignment = State.Alignment;

            using (var render = _mapper.CreateRender())
            {
                RenderChild(render, State.FirstChild, alignment);
                RenderChild(render, State.SecondChild, alignment);
            }
        }
Ejemplo n.º 2
0
        protected override void Render()
        {
            var children   = State.Children;
            var crossAxis  = State.CrossAxisAlignment;
            var mainAxis   = State.MainAxisAlignment;
            var columnSize = State.InnerSize;

            var alignX = crossAxis == CrossAxisAlignment.Start ? Alignment.TopLeft.X
                : crossAxis == CrossAxisAlignment.End ? Alignment.TopRight.X
                : Alignment.Center.X;

            var alignY = mainAxis == MainAxisAlignment.Start ? Alignment.TopCenter.Y
                : mainAxis == MainAxisAlignment.End ? Alignment.BottomCenter.Y
                : Alignment.Center.Y;

            var offsetMultiplierY = mainAxis == MainAxisAlignment.Start ? 0
                : mainAxis == MainAxisAlignment.End ? 1f
                : 0.5f;

            var childAlignment = new Alignment(alignX, alignY);
            var corner         = childAlignment.WithTop();
            var cornerPosition = new Vector2(0, -columnSize.Height * offsetMultiplierY);

            using (var render = _mapper.CreateRender())
            {
                foreach (var child in children)
                {
                    var childSize = child.Size;

                    if (childSize.IsHeightStretched)
                    {
                        Debug.LogError("Cannot render vertically stretched widgets inside Column.\n" +
                                       $"Try to wrap '{child.GetType().Name}' into another widget with fixed height");
                        continue;
                    }

                    var childView = render.RenderItem(child);

                    LayoutData layout;
                    layout.Size           = childSize;
                    layout.Alignment      = childAlignment;
                    layout.Corner         = corner;
                    layout.CornerPosition = cornerPosition;
                    ViewLayoutUtility.SetLayout(childView.rectTransform, layout);

                    cornerPosition += new Vector2(0, childSize.Height);
                }
            }
        }
Ejemplo n.º 3
0
        protected override void Render()
        {
            var children   = State.Children;
            var crossAxis  = State.CrossAxisAlignment;
            var mainAxis   = State.MainAxisAlignment;
            var columnSize = State.InnerSize;

            var alignX = mainAxis == MainAxisAlignment.Start ? Alignment.TopLeft.X
                : mainAxis == MainAxisAlignment.End ? Alignment.TopRight.X
                : Alignment.Center.X;

            var alignY = crossAxis == CrossAxisAlignment.Start ? Alignment.TopCenter.Y
                : crossAxis == CrossAxisAlignment.End ? Alignment.BottomCenter.Y
                : Alignment.Center.Y;

            var offsetMultiplierX = mainAxis == MainAxisAlignment.Start ? 0
                : mainAxis == MainAxisAlignment.End ? 1f
                : 0.5f;

            var childAlignment = new Alignment(alignX, alignY);
            var corner         = childAlignment.WithLeft();
            var cornerPosition = new Vector2(-columnSize.Width * offsetMultiplierX, 0);

            using (var render = _mapper.CreateRender())
            {
                foreach (var child in children)
                {
                    var childSize = child.Size;

                    if (childSize.IsWidthStretched)
                    {
                        Debug.LogError("Cannot render horizontally stretched widgets inside Row.");
                        continue;
                    }

                    var childView = render.RenderItem(child);

                    LayoutData layout;
                    layout.Size           = childSize;
                    layout.Alignment      = childAlignment;
                    layout.Corner         = corner;
                    layout.CornerPosition = cornerPosition;
                    ViewLayoutUtility.SetLayout(childView.rectTransform, layout);

                    cornerPosition += new Vector2(childSize.Width, 0);
                }
            }
        }
Ejemplo n.º 4
0
        protected override void Render()
        {
            using (var render = _mapper.CreateRender())
            {
                var child = State;

                var childView = render.RenderItem(child);
                var childSize = child.Size;

                LayoutData layout;
                layout.Size           = childSize;
                layout.Alignment      = Alignment.Center;
                layout.Corner         = Alignment.Center;
                layout.CornerPosition = Vector2.zero;
                ViewLayoutUtility.SetLayout(childView.rectTransform, layout);
            }
        }
Ejemplo n.º 5
0
        protected override void Render()
        {
            var alignment = State.Alignment;

            using (var render = _mapper.CreateRender())
            {
                var child = State.Child;
                ChildView = render.RenderItem(child);
                var childSize = child.Size.GetSizeUnbounded();

                LayoutData layout;
                layout.Size           = childSize;
                layout.Alignment      = alignment;
                layout.Corner         = alignment;
                layout.CornerPosition = Vector2.zero;
                ViewLayoutUtility.SetLayout(ChildView.rectTransform, layout);
            }
        }
Ejemplo n.º 6
0
        protected override void Render()
        {
            var children  = State.Children;
            var mainAxis  = State.MainAxisAlignment;
            var crossAxis = State.CrossAxisAlignment;
            var listSize  = State.InnerSize;

            var alignX = crossAxis == CrossAxisAlignment.Start ? Alignment.TopLeft.X
                : crossAxis == CrossAxisAlignment.End ? Alignment.TopRight.X
                : Alignment.Center.X;

            var childAlignment = new Alignment(alignX, Alignment.TopCenter.Y);
            var corner         = childAlignment.WithTop();
            var cornerPosition = new Vector2(0, 0);

            // content root
            {
                var contentPivotX = crossAxis == CrossAxisAlignment.Start ? 0.0f
                    : crossAxis == CrossAxisAlignment.End ? 1.0f
                    : 0.5f;

                var contentPivotY = mainAxis == MainAxisAlignment.Start ? 1.0f
                    : mainAxis == MainAxisAlignment.End ? 0.0f
                    : 0.5f;

                _contentRoot.pivot = new Vector2(contentPivotX, contentPivotY);

                LayoutData contentLayout;
                contentLayout.Size           = WidgetSize.FixedHeight(listSize.Height);
                contentLayout.Alignment      = childAlignment;
                contentLayout.Corner         = childAlignment;
                contentLayout.CornerPosition = Vector2.zero;
                ViewLayoutUtility.SetLayout(_contentRoot, contentLayout);
            }

            using (var render = _mapper.CreateRender())
            {
                foreach (var child in children)
                {
                    var childSize = child.Size;

                    if (childSize.IsHeightStretched)
                    {
                        Debug.LogError("Cannot render vertically stretched widgets inside ScrollList.\n" +
                                       $"Try to wrap '{child.GetType().Name}' into another widget with fixed height");
                        continue;
                    }

                    var childView = render.RenderItem(child);

                    LayoutData layout;
                    layout.Size           = childSize;
                    layout.Alignment      = childAlignment;
                    layout.Corner         = corner;
                    layout.CornerPosition = cornerPosition;
                    ViewLayoutUtility.SetLayout(childView.rectTransform, layout);

                    cornerPosition += new Vector2(0, childSize.Height);
                }
            }
        }
Ejemplo n.º 7
0
        protected override void Render()
        {
            var children  = State.Children;
            var crossAxis = State.CrossAxisAlignment;
            var mainAxis  = State.MainAxisAlignment;

            var alignX = crossAxis == CrossAxisAlignment.Start ? Alignment.TopLeft.X
                : crossAxis == CrossAxisAlignment.End ? Alignment.TopRight.X
                : Alignment.Center.X;

            var alignY = mainAxis == MainAxisAlignment.Start ? Alignment.TopCenter.Y
                : mainAxis == MainAxisAlignment.End ? Alignment.BottomCenter.Y
                : Alignment.Center.Y;

            var offsetMultiplierY = mainAxis == MainAxisAlignment.Start ? 0
                : mainAxis == MainAxisAlignment.End ? 1f
                : 0.5f;

            var childrenHeight      = 0f;
            var unboundedChildCount = 0;

            foreach (var child in children)
            {
                var childHeight = child.Size.GetSizeUnbounded().y;

                if (float.IsInfinity(childHeight))
                {
                    unboundedChildCount += 1;
                }
                else
                {
                    childrenHeight += childHeight;
                }
            }

            var columnHeight = Mathf.Max(Bounds.y, childrenHeight);
            var flexHeight   = Mathf.Max(0, (columnHeight - childrenHeight) / Mathf.Max(1, unboundedChildCount));
            var childBound   = new Vector2(float.PositiveInfinity, flexHeight);

            var childAlignment = new Alignment(alignX, alignY);
            var corner         = childAlignment.WithTop();
            var cornerPosition = new Vector2(0, -childrenHeight * offsetMultiplierY);

            using (var render = _mapper.CreateRender())
            {
                foreach (var child in children)
                {
                    var childSize = child.Size.GetSize(childBound);

                    var childView = render.RenderItem(child);

                    LayoutData layout;
                    layout.Size           = childSize;
                    layout.Alignment      = childAlignment;
                    layout.Corner         = corner;
                    layout.CornerPosition = cornerPosition;
                    ViewLayoutUtility.SetLayout(childView.rectTransform, layout);

                    cornerPosition += new Vector2(0, childSize.y);
                }
            }
        }
Ejemplo n.º 8
0
        protected override void Render()
        {
            var children  = State.Children;
            var crossAxis = State.CrossAxisAlignment;
            var mainAxis  = State.MainAxisAlignment;
            var gridSize  = State.InnerSize.GetSize(Bounds);

            var alignX = crossAxis == CrossAxisAlignment.Start ? Alignment.TopLeft.X
                : crossAxis == CrossAxisAlignment.End ? Alignment.TopRight.X
                : Alignment.Center.X;

            var alignY = mainAxis == MainAxisAlignment.Start ? Alignment.TopCenter.Y
                : mainAxis == MainAxisAlignment.End ? Alignment.BottomCenter.Y
                : Alignment.Center.Y;

            var offsetMultiplierX = crossAxis == CrossAxisAlignment.Start ? 0.0f
                : crossAxis == CrossAxisAlignment.End ? 1.0f
                : 0.5f;

            var offsetMultiplierY = mainAxis == MainAxisAlignment.Start ? 0.0f
                : mainAxis == MainAxisAlignment.End ? 1.0f
                : 0.5f;

            var childAlignment = new Alignment(alignX, alignY);
            var cornerPosition = new Vector2(
                -gridSize.x * offsetMultiplierX,
                -gridSize.y * offsetMultiplierY);

            using (var render = _mapper.CreateRender())
            {
                var newLine            = true;
                var lineLastChildIndex = 0;
                var lineHeight         = 0f;
                var lineMaxWidth       = State.MaxCrossAxisExtent;
                var lineMaxChildCount  = State.MaxCrossAxisCount;

                for (var childIndex = 0; childIndex < children.Length; childIndex++)
                {
                    var child     = children[childIndex];
                    var childSize = child.Size.GetSize(Bounds);

                    if (newLine)
                    {
                        newLine    = false;
                        lineHeight = childSize.y;
                        var lineWidth      = childSize.x;
                        var lineChildCount = 1;

                        for (int i = childIndex + 1; i < children.Length; i++)
                        {
                            var nextChildSize = children[i].Size.GetSize(Bounds);
                            if (lineChildCount + 1 <= lineMaxChildCount &&
                                lineWidth + nextChildSize.x <= lineMaxWidth)
                            {
                                lineChildCount++;
                                lineWidth += nextChildSize.x;
                                lineHeight = Math.Max(lineHeight, nextChildSize.y);
                            }
                            else
                            {
                                break;
                            }
                        }

                        lineLastChildIndex = childIndex + lineChildCount - 1;
                        cornerPosition.x   = -lineWidth * offsetMultiplierX;
                    }

                    var childView = render.RenderItem(child);

                    LayoutData layout;
                    layout.Size           = childSize;
                    layout.Alignment      = childAlignment;
                    layout.Corner         = childAlignment.WithLeft();
                    layout.CornerPosition = cornerPosition + new Vector2(0, lineHeight * offsetMultiplierY);
                    ViewLayoutUtility.SetLayout(childView.rectTransform, layout);

                    if (childIndex == lineLastChildIndex)
                    {
                        newLine           = true;
                        cornerPosition.y += lineHeight;
                    }
                    else
                    {
                        cornerPosition.x += childSize.x;
                    }
                }
            }
        }
Ejemplo n.º 9
0
        protected override void Render()
        {
            var sticky  = State.Sticky;
            var useMask = State.UseMask;

            if (_rectMask.enabled != useMask)
            {
                _rectMask.enabled = useMask;
            }

            var visibilityIndices = _visibilityIndices.Value;
            var startIndex        = visibilityIndices.x;
            var endIndex          = visibilityIndices.y;

            _childPositions.Clear();
            _nextChildren.Clear();

            using (var render = _mapper.CreateRender())
            {
                DoLayout(State, RenderContent, RenderChild);

                foreach (var data in _nextChildren)
                {
                    if (data.childIndex >= startIndex && data.childIndex <= endIndex)
                    {
                        continue;
                    }

                    render.Reuse(data.child);
                }

                foreach (var data in _nextChildren)
                {
                    var isSticky = data.child.Key != null && data.child.Key == sticky;

                    if ((data.childIndex < startIndex || data.childIndex > endIndex) && !isSticky)
                    {
                        continue;
                    }

                    var childView = render.RenderItem(data.child);

                    LayoutData layout;
                    layout.Size           = data.childSize;
                    layout.Alignment      = data.childAlignment;
                    layout.Corner         = data.childAlignment.WithLeft();
                    layout.CornerPosition = data.cornerPosition;

                    Transform childParent = _contentRoot;

                    if (isSticky && _sticked.Value)
                    {
                        childParent = transform;

                        layout.Corner         = Alignment.TopCenter;
                        layout.CornerPosition = Vector2.zero;
                    }

                    if (childView.rectTransform.parent != childParent)
                    {
                        childView.rectTransform.SetParent(childParent, false);
                    }

                    ViewLayoutUtility.SetLayout(childView.rectTransform, layout);
                }
            }
        }