Exemple #1
0
        private void performLayout()
        {
            OnLayout?.Invoke();

            if (!Children.Any())
            {
                return;
            }

            var positions = ComputeLayoutPositions().ToArray();

            int i = 0;

            foreach (var d in FlowingChildren)
            {
                if (i > positions.Length)
                {
                    throw new InvalidOperationException(
                              $"{GetType().FullName}.{nameof(ComputeLayoutPositions)} returned a total of {positions.Length} positions for {i} children. {nameof(ComputeLayoutPositions)} must return 1 position per child.");
                }

                // In some cases (see the right hand side of the conditional) we want to permit relatively sized children
                // in our flow direction; specifically, when children use FillMode.Fit to preserve the aspect ratio.
                // Consider the following use case: A flow container has a fixed width but an automatic height, and flows
                // in the vertical direction. Now, we can add relatively sized children with FillMode.Fit to make sure their
                // aspect ratio is preserved while still allowing them to flow vertically. This special case can not result
                // in an autosize-related feedback loop, and we can thus simply allow it.
                if ((d.RelativeSizeAxes & AutoSizeAxes) != 0 && (d.FillMode != FillMode.Fit || d.RelativeSizeAxes != Axes.Both || d.Size.X > RelativeChildSize.X || d.Size.Y > RelativeChildSize.Y || AutoSizeAxes == Axes.Both))
                {
                    throw new InvalidOperationException(
                              "Drawables inside a flow container may not have a relative size axis that the flow container is auto sizing for." +
                              $"The flow container is set to autosize in {AutoSizeAxes} axes and the child is set to relative size in {d.RelativeSizeAxes} axes.");
                }

                if (d.RelativePositionAxes != Axes.None)
                {
                    throw new InvalidOperationException($"A flow container cannot contain a child with relative positioning (it is {d.RelativePositionAxes}).");
                }

                var finalPos = positions[i];
                if (d.Position != finalPos)
                {
                    d.TransformTo(d.PopulateTransform(new FlowTransform {
                        Rewindable = false
                    }, finalPos, LayoutDuration, LayoutEasing));
                }

                ++i;
            }

            if (i != positions.Length)
            {
                throw new InvalidOperationException(
                          $"{GetType().FullName}.{nameof(ComputeLayoutPositions)} returned a total of {positions.Length} positions for {i} children. {nameof(ComputeLayoutPositions)} must return 1 position per child.");
            }
        }
Exemple #2
0
        public void OnPointerExit(PointerEventData eventData)
        {
            CardModel cardModel = CardModel.GetPointerDrag(eventData);

            if (cardModel != null && cardModel.PlaceHolderCardZone == this)
            {
                cardModel.PlaceHolderCardZone = null;
            }
            OnLayout?.Invoke();
        }
Exemple #3
0
        protected override void UpdateAfterChildren()
        {
            base.UpdateAfterChildren();

            if (!layout.EnsureValid())
            {
                layout.Refresh(delegate
                {
                    OnLayout?.Invoke();

                    if (!Children.Any())
                    {
                        return;
                    }

                    var positions = ComputeLayoutPositions().ToArray();

                    int i = 0;
                    foreach (var d in FlowingChildren)
                    {
                        if (i > positions.Length)
                        {
                            throw new InvalidOperationException(
                                $"{GetType().FullName}.{nameof(ComputeLayoutPositions)} returned a total of {positions.Length} positions for {i} children. {nameof(ComputeLayoutPositions)} must return 1 position per child.");
                        }

                        if ((d.RelativeSizeAxes & AutoSizeAxes) != 0)
                        {
                            throw new InvalidOperationException(
                                "Drawables inside a flow container may not have a relative size axis that the flow container is auto sizing for." +
                                $"The flow container is set to autosize in {AutoSizeAxes} axes and the child is set to relative size in {d.RelativeSizeAxes} axes.");
                        }

                        if (d.RelativePositionAxes != Axes.None)
                        {
                            throw new InvalidOperationException($"A flow container cannot contain a child with relative positioning (it is {d.RelativePositionAxes}).");
                        }

                        var finalPos = positions[i];
                        if (d.Position != finalPos)
                        {
                            d.MoveTo(finalPos, LayoutDuration, LayoutEasing);
                        }

                        ++i;
                    }

                    if (i != positions.Length)
                    {
                        throw new InvalidOperationException(
                            $"{GetType().FullName}.{nameof(ComputeLayoutPositions)} returned a total of {positions.Length} positions for {i} children. {nameof(ComputeLayoutPositions)} must return 1 position per child.");
                    }
                });
            }
        }
Exemple #4
0
        public virtual void Layout(List <IDataRogueControlRenderer> controlRenderers, ISystemContainer systemContainer, List <MapCoordinate> playerFov, object handle)
        {
            if (!Initialised)
            {
                InitialiseControls();
                Initialised = true;
            }

            OnLayout?.Invoke(null, null);

            foreach (var control in Controls.ToList())
            {
                if (control.Visible)
                {
                    control.Layout(controlRenderers, systemContainer, handle, playerFov, Position);
                }
            }
        }
Exemple #5
0
        public void UpdateLayout(RectTransform child, Vector2 targetPosition)
        {
            if (child == null)
            {
                return;
            }

            switch (type)
            {
            case CardZoneType.Vertical:
            case CardZoneType.Horizontal:
                int newSiblingIndex = transform.childCount;
                for (var i = 0; i < transform.childCount; i++)
                {
                    if (type == CardZoneType.Vertical
                            ? targetPosition.y <transform.GetChild(i).position.y
                                                : targetPosition.x> transform.GetChild(i).position.x)
                    {
                        continue;
                    }
                    newSiblingIndex = i;
                    if (child.GetSiblingIndex() < newSiblingIndex)
                    {
                        newSiblingIndex--;
                    }
                    break;
                }

                child.SetSiblingIndex(newSiblingIndex);
                break;

            case CardZoneType.Area:
            default:
                child.position = targetPosition;
                break;
            }

            OnLayout?.Invoke();
        }
Exemple #6
0
 internal virtual void DoLayout()
 {
     OnLayout?.Invoke();
 }
Exemple #7
0
        protected override void UpdateLayout()
        {
            base.UpdateLayout();

            if (layout.IsValid)
            {
                return;
            }

            layout.Refresh(delegate
            {
                OnLayout?.Invoke();

                if (Children.FirstOrDefault() == null)
                {
                    return(Vector2.Zero);
                }

                Vector2 current = new Vector2(Math.Max(0, Padding.X), Math.Max(0, Padding.Y));

                Vector2 max = maximumSize;
                if (direction == FlowDirection.Full && maximumSize == Vector2.Zero)
                {
                    var actual = ActualSize;

                    //If we are autosize and haven't specified a maximum size, we should allow infinite expansion.
                    //If we are inheriting then we need to use the parent size (our ActualSize).
                    max.X = (SizeMode & InheritMode.X) == 0 ? float.MaxValue : actual.X;
                    max.Y = (SizeMode & InheritMode.Y) == 0 ? float.MaxValue : actual.Y;
                }

                float rowMaxHeight = 0;
                foreach (Drawable d in Children)
                {
                    if (((int)direction & (int)d.SizeMode) > 0)
                    {
                        //if the inheriting mode of the drawable shares the same directional value as our flow direction, we have to ignore it.
                        continue;
                    }

                    Vector2 size = Vector2.Zero;

                    if (d.IsVisible)
                    {
                        size = d.ActualSize * d.Scale * ChildrenScale;

                        if (Direction != FlowDirection.HorizontalOnly && current.X + size.X > max.X)
                        {
                            current.X  = Math.Max(0, Padding.X);
                            current.Y += rowMaxHeight;

                            rowMaxHeight = 0;
                        }

                        //todo: check this is correct
                        if (size.X > 0)
                        {
                            size.X = Math.Max(0, size.X + Padding.X);
                        }
                        if (size.Y > 0)
                        {
                            size.Y = Math.Max(0, size.Y + Padding.Y);
                        }

                        if (size.Y > rowMaxHeight)
                        {
                            rowMaxHeight = size.Y;
                        }
                    }

                    if (current != d.Position)
                    {
                        d.MoveTo(current, LayoutDuration, LayoutEasing);
                        d.UpdateSubTree();
                    }

                    current.X += size.X;
                }

                return(current);
            });
        }