예제 #1
0
 void SetScrollPositionFor(TupleViewsHolder vh, double scrollPosition, bool force)
 {
     vh.Adapter.StopMovement();
     if (force || vh.Adapter.GetNormalizedPosition() != scrollPosition)
     {
         vh.Adapter.SetNormalizedPosition(scrollPosition);
     }
 }
예제 #2
0
        void OnTupleAdapterScrollPositionChanged(TupleViewsHolder vh, double scrollPosition)
        {
            // Don't override a currently dragged scrollbar
            if (IsColumnsScrolbarDragging())
            {
                // And also make sure it doesn't have any inertia left from a previous drag
                vh.Adapter.StopMovement();

                // Also do the same with the currently active vh, if it's different
                if (_TupleVHActivelyMoving != null)
                {
                    if (_TupleVHActivelyMoving != vh)
                    {
                        _TupleVHActivelyMoving.Adapter.StopMovement();
                    }

                    _TupleVHActivelyMoving = null;
                }

                return;
            }

            if (!vh.Adapter.IsDragging)
            {
                if (!AssureActivelyMovingVHIsStillActive())
                {
                    return;
                }

                // Always allow the last dragged to continue influencing other vhs even after the drag has finished
                if (_TupleVHActivelyMoving != vh)
                {
                    return;
                }
            }

            // Make sure no other adapter is in the Dragging state (can happen sometimes)
            for (int i = 0; i < _VisibleItemsCount; i++)
            {
                var otherVH = GetItemViewsHolder(i);
                if (otherVH == vh)
                {
                    continue;
                }
                if (otherVH.Adapter.IsDragging)
                {
                    return;
                }
            }
            _TupleVHActivelyMoving = vh;

            // Only set for the header, and its event will further set the position on the value tuples
            SetScrollPositionFor(_Header, scrollPosition, false);
        }
예제 #3
0
        void SyncPositionsIfNeeded(bool force)
        {
            if (_VisibleItemsCount == 0)
            {
                return;
            }

            if (_TupleVHActivelyMoving == null)
            {
                if (!force)
                {
                    return;
                }

                // First
                //_ValueTupleVHActivelyMoving = GetItemViewsHolder(0);
                _TupleVHActivelyMoving = _Header;
            }
            else
            {
                if (!force)
                {
                    AssureActivelyMovingVHIsStillActive();

                    if (_TupleVHActivelyMoving == null)
                    {
                        return;
                    }
                }
            }

            if (!force)
            {
                // Don't override a currently dragged scrollbar
                if (IsColumnsScrolbarDragging())
                {
                    return;
                }

                // Already syncing in OnDrag
                if (_TupleVHActivelyMoving.Adapter.IsDragging)
                {
                    return;
                }
            }

            --_ManualSyncPositionsActionsPending;
            double pos = _TupleVHActivelyMoving.Adapter.GetNormalizedPosition();

            SetScrollPositionForAllChildrenExceptDraggedAndHeader(pos);
        }
예제 #4
0
        bool AssureActivelyMovingVHIsStillActive()
        {
            var vh = _TupleVHActivelyMoving;

            if (vh != null)
            {
                if (!vh.Adapter.IsDragging && vh.Adapter.Velocity.magnitude == 0f)
                {
                    _TupleVHActivelyMoving = null;
                }
            }

            return(_TupleVHActivelyMoving != null);
        }
예제 #5
0
        void SetScrollPositionForAllChildrenExceptDraggedAndHeader(double scrollPosition)
        {
            TupleViewsHolder exceptVH2 = _TupleVHActivelyMoving;
            TupleViewsHolder exceptVH1 = _Header;

            for (int i = 0; i < _VisibleItemsCount; i++)
            {
                var vh = GetItemViewsHolder(i);
                if (exceptVH1 != null && vh == exceptVH1)
                {
                    continue;
                }
                if (exceptVH2 != null && vh == exceptVH2)
                {
                    continue;
                }

                SetScrollPositionFor(vh, scrollPosition, true);
            }
        }
예제 #6
0
        void OnHeaderTupleAdapterScrollPositionChanged(double scrollPosition)
        {
            // If the header is dragged directly, override everything
            if (_Header.Adapter.IsDragging)
            {
                if (_TupleVHActivelyMoving != null)
                {
                    _TupleVHActivelyMoving = null;
                }
            }

            if (_TupleVHActivelyMoving == null)
            {
                // Header dragged directly or via scrollbar
            }
            else
            {
                // Header dragged as a result of a value tuple being dragged in OnTupleAdapterScrollPositionChanged
                AssureActivelyMovingVHIsStillActive();
            }

            SetScrollPositionForAllChildrenExceptDraggedAndHeader(scrollPosition);
        }
예제 #7
0
        /// <summary>
        /// Initializes a viewsholder on creation. This is called for both the header and the value tuples, when they're first created
        /// </summary>
        protected virtual void InitTupleViewsHolder(TupleViewsHolder vh, RectTransform prefab, RectTransform parent, int itemIndex)
        {
            vh.Init(prefab, parent, itemIndex);

            // Keeping the same time scale in children as in the parent
            vh.Adapter.TupleParameters.UseUnscaledTime = _Params.UseUnscaledTime;

            // Making sure the tuple's value prefab has the same size in the tuple's scrolling direction, so they'll be perfectly aligned
            if (_Header != null)             // header will be created first through this method, in which case it'll be null
            {
                var tupleValuePrefab = vh.Adapter.TupleParameters.ItemPrefab;
                if (!_TupleValuePrefabsResizedToFitHeader.Contains(tupleValuePrefab))
                {
                    UnityEngine.Assertions.Assert.IsTrue(_Header != null);
                    var headerSize = _Header.Adapter.TupleParameters.ItemPrefab.rect.size;
                    int hor1_vert0 = 1 - _InternalState.hor0_vert1;
                    tupleValuePrefab.SetSizeWithCurrentAnchors((RectTransform.Axis)hor1_vert0, headerSize[hor1_vert0]);
                    _TupleValuePrefabsResizedToFitHeader.Add(tupleValuePrefab);
                }
            }

            vh.Adapter.Init();
        }
예제 #8
0
 void TransferVelocityOfActivelyMovingTupleToHeader()
 {
     _Header.Adapter.Velocity = _TupleVHActivelyMoving.Adapter.Velocity;
     _TupleVHActivelyMoving.Adapter.StopMovement();
     _TupleVHActivelyMoving = _Header;
 }