Пример #1
0
        private void MouseWheelHandler(Event e)
        {
            IViewport vp = Viewport;

            if (e.DefaultPrevented || null == vp || !vp.Visible)
            {
                return;
            }

            //Debug.Log("HScrollBar MouseWheelHandler");

            MouseEvent me     = (MouseEvent)e;
            var        delta  = me.CurrentEvent.delta.y;
            int        nSteps = (int)Math.Abs(delta);

            nSteps = 1; // TEMP

            // Scroll event.delta "steps".
            //Debug.Log("delta: " + delta);
            NavigationUnit navigationUnit = (delta > 0) ? NavigationUnit.Right : NavigationUnit.Left;

            for (int hStep = 0; hStep < nSteps; hStep++)
            {
                float hspDelta = vp.GetHorizontalScrollPositionDelta(navigationUnit);
                //if (null != hspDelta)
                vp.HorizontalScrollPosition += hspDelta;
            }

            e.PreventDefault();
        }
Пример #2
0
        /**
         *  Delegation method that determines which item
         *  to navigate to based on the current item in focus
         *  and user input in terms of NavigationUnit. This method
         *  is used by subclasses of OldListBase to handle
         *  keyboard navigation. OldListBase maps user input to
         *  NavigationUnit constants.
         *
         *  <p>Subclasses can override this method to compute other
         *  values that are based on the current index and key
         *  stroke encountered. </p>
         *
         *  Param: currentIndex The current index of the item with focus.
         *
         *  Param: navigationUnit The NavigationUnit constant that determines
         *  which item to navigate to next.
         *
         *  Param: ArrowKeysWrapFocus If <code>true</code>, using arrow keys to
         *  navigate within the component wraps when it hits either end.
         *
         *  Returns: The index of the next item to jump to. Returns -1
         *  when if the layout doesn't recognize the navigationUnit.
         */
        ///<summary>
        ///</summary>
        ///<param name="currentIndex"></param>
        ///<param name="navigationUnit"></param>
        ///<param name="arrowKeysWrapFocus"></param>
        ///<returns></returns>
        internal virtual int GetNavigationDestinationIndex(int currentIndex, NavigationUnit navigationUnit, bool arrowKeysWrapFocus) // TEMP internal
        {
            if (null == Target || Target.NumberOfChildren < 1)
            {
                return(-1);
            }

            //Sub-classes implement according to their own layout
            //logic. Common cases handled here.
            switch (navigationUnit)
            {
            case NavigationUnit.Home:
                return(0);

            case NavigationUnit.End:
                return(Target.NumberOfChildren - 1);

            default:
                return(-1);
            }
        }
Пример #3
0
        private void MouseWheelHandler(Event e)
        {
            //Debug.Log("VScrollBar->MouseWheelHandler: " + e.Target);
            IViewport vp = Viewport;

            if (e.DefaultPrevented || null == vp || !vp.Visible)
            {
                return;
            }

            /* If the scrollbar is a part of the scroller, but is not visible, do not process mouse wheel
             * this way we are giving a chance for the horizontal scroll to work */
            if (!Visible)
            {
                return;
            }

            MouseEvent me = (MouseEvent)e;
            //Debug.Log(me.CurrentEvent.delta.y);
            var delta  = me.CurrentEvent.delta.y;
            int nSteps = (int)Math.Abs(delta);

            //Debug.Log("MouseWheelHandler. delta: " + delta);

            // Scroll event.delta "steps".
            nSteps = 1; // TEMP

            NavigationUnit navigationUnit = (delta > 0) ? NavigationUnit.Down : NavigationUnit.Up;

            for (int vStep = 0; vStep < nSteps; vStep++)
            {
                //Debug.Log("vStep: " + vStep);
                float vspDelta = vp.GetVerticalScrollPositionDelta(navigationUnit);
                //Debug.Log("  vspDelta: " + vspDelta);
                //if (null != vspDelta)
                vp.VerticalScrollPosition += vspDelta;
            }

            e.PreventDefault();
        }
Пример #4
0
        /// <summary>
        /// Returns the amount to add to the viewport's current verticalScrollPositionto scroll by the requested scrolling unit.
        /// </summary>
        /// <param name="navigationUnit"></param>
        /// <returns></returns>
        internal float GetVerticalScrollPositionDelta(NavigationUnit navigationUnit) // TEMP internal
        {
            GroupBase g = Target;

            if (null == g)
            {
                return(0);
            }

            Rectangle scrollRect = GetScrollRect();

            if (null == scrollRect)
            {
                return(0);
            }

            // Special case: if the scrollRect's origin is 0,0 and it's bigger
            // than the target, then there's no where to scroll to
            if ((scrollRect.Y == 0) && (scrollRect.Height >= g.ContentHeight))
            {
                return(0);
            }

            // maxDelta is the horizontalScrollPosition delta required
            // to scroll to the END and minDelta scrolls to HOME.
            float     maxDelta = g.ContentHeight - scrollRect.Bottom; // Bottom
            float     minDelta = -scrollRect.Top;                     // Top
            Rectangle getElementBounds;

            switch (navigationUnit)
            {
            case NavigationUnit.Up:
            case NavigationUnit.PageUp:
                // Find the bounds of the first non-fully visible element
                // that spans right of the scrollRect.
                getElementBounds = GetElementBoundsAboveScrollRect(scrollRect);
                break;

            case NavigationUnit.Down:
            case NavigationUnit.PageDown:
                // Find the bounds of the first non-fully visible element
                // that spans below the scrollRect.
                getElementBounds = GetElementBoundsBelowScrollRect(scrollRect);
                break;

            case NavigationUnit.Home:
                return(minDelta);

            case NavigationUnit.End:
                return(maxDelta);

            default:
                return(0);
            }

            if (null == getElementBounds)
            {
                return(0);
            }

            float delta = 0;

            switch (navigationUnit)
            {
            case NavigationUnit.Up:
                // Snap the top edge of element to the top edge of the scrollRect.
                // The element is the the first non-fully visible element above the scrollRect.
                delta = Math.Max(getElementBounds.Top - scrollRect.Top, -scrollRect.Height);
                break;

            case NavigationUnit.Down:
                // Snap the bottom edge of the element to the bottom edge of the scrollRect.
                // The element is the the first non-fully visible element below the scrollRect.
                delta = Math.Min(getElementBounds.Bottom - scrollRect.Bottom, scrollRect.Height);
                break;

            case NavigationUnit.PageUp:
            {
                // Snap the bottom edge of the element to the bottom edge of the scrollRect.
                // The element is the the first non-fully visible element below the scrollRect.
                delta = getElementBounds.Bottom - scrollRect.Bottom;

                // Special case: when an element is taller than the scrollRect,
                // we want to snap its top edge to the top edge of the scrollRect.
                // The delta will be limited to the height of the scrollRect further below.
                if (delta >= 0)
                {
                    delta = Math.Max(getElementBounds.Top - scrollRect.Top, -scrollRect.Height);
                }
            }
            break;

            case NavigationUnit.PageDown:
            {
                // Align the top edge of the element to the top edge of the scrollRect.
                // The element is the the first non-fully visible element below the scrollRect.
                delta = getElementBounds.Top - scrollRect.Top;

                // Special case: when an element is taller than the scrollRect,
                // we want to snap its bottom edge to the bottom edge of the scrollRect.
                // The delta will be limited to the height of the scrollRect further below.
                if (delta <= 0)
                {
                    delta = Math.Min(getElementBounds.Bottom - scrollRect.Bottom, scrollRect.Height);
                }
            }
            break;
            }

            //Debug.Log("delta: " + delta + "; minDelta: " + minDelta + ", maxDelta: " + maxDelta);
            return(Math.Min(maxDelta, Math.Max(minDelta, delta * (
                                                   this is TileLayout || navigationUnit == NavigationUnit.PageUp || navigationUnit == NavigationUnit.PageDown ?
                                                   1 : StepSize)))); // temp dirty fix
        }
Пример #5
0
        /// <summary>
        /// Returns the amount to add to the viewport's current horizontalScrollPosition to scroll by the requested scrolling unit.
        /// </summary>
        /// <param name="navigationUnit"></param>
        /// <returns></returns>
        internal float GetHorizontalScrollPositionDelta(NavigationUnit navigationUnit) // TEMP internal
        {
            GroupBase g = Target;

            if (null == g)
            {
                return(0);
            }

            Rectangle scrollRect = GetScrollRect();

            if (null == scrollRect)
            {
                return(0);
            }

            // Special case: if the scrollRect's origin is 0,0 and it's bigger
            // than the target, then there's no where to scroll to
            if ((scrollRect.X == 0) && (scrollRect.Width >= g.ContentWidth))
            {
                return(0);
            }

            // maxDelta is the horizontalScrollPosition delta required
            // to scroll to the END and minDelta scrolls to HOME.
            float     maxDelta = g.ContentWidth - scrollRect.Right; //Right;
            float     minDelta = -scrollRect.Left;                  //Left;
            Rectangle getElementBounds;

            switch (navigationUnit)
            {
            case NavigationUnit.Left:
            case NavigationUnit.PageLeft:
                // Find the bounds of the first non-fully visible element
                // to the left of the scrollRect.
                getElementBounds = GetElementBoundsLeftOfScrollRect(scrollRect);
                break;

            case NavigationUnit.Right:
            case NavigationUnit.PageRight:
                // Find the bounds of the first non-fully visible element
                // to the right of the scrollRect.
                getElementBounds = GetElementBoundsRightOfScrollRect(scrollRect);
                break;

            case NavigationUnit.Home:
                return(minDelta);

            case NavigationUnit.End:
                return(maxDelta);

            default:
                return(0);
            }

            if (null == getElementBounds)
            {
                return(0);
            }

            float delta = 0f;

            switch (navigationUnit)
            {
            case NavigationUnit.Left:
                // Snap the left edge of element to the left edge of the scrollRect.
                // The element is the the first non-fully visible element left of the scrollRect.
                delta = Math.Max(getElementBounds.Left - scrollRect.Left, -scrollRect.Width);
                break;

            case NavigationUnit.Right:
                // Snap the right edge of the element to the right edge of the scrollRect.
                // The element is the the first non-fully visible element right of the scrollRect.
                delta = Math.Min(getElementBounds.Right - scrollRect.Right, scrollRect.Width);
                break;

            case NavigationUnit.PageLeft:
            {
                // Snap the right edge of the element to the right edge of the scrollRect.
                // The element is the the first non-fully visible element left of the scrollRect.
                delta = getElementBounds.Right - scrollRect.Right;

                // Special case: when an element is wider than the scrollRect,
                // we want to snap its left edge to the left edge of the scrollRect.
                // The delta will be limited to the width of the scrollRect further below.
                if (delta >= 0)
                {
                    delta = Math.Max(getElementBounds.Left - scrollRect.Left, -scrollRect.Width);
                }
            }
            break;

            case NavigationUnit.PageRight:
            {
                // Align the left edge of the element to the left edge of the scrollRect.
                // The element is the the first non-fully visible element right of the scrollRect.
                delta = getElementBounds.Left - scrollRect.Left;

                // Special case: when an element is wider than the scrollRect,
                // we want to snap its right edge to the right edge of the scrollRect.
                // The delta will be limited to the width of the scrollRect further below.
                if (delta <= 0)
                {
                    delta = Math.Min(getElementBounds.Right - scrollRect.Right, scrollRect.Width);
                }
            }
            break;
            }

            // Makse sure we don't get out of bounds. Also, don't scroll
            // by more than the scrollRect width at a time.
            return(Math.Min(maxDelta, Math.Max(minDelta, delta * (
                                                   this is TileLayout || navigationUnit == NavigationUnit.PageUp || navigationUnit == NavigationUnit.PageDown || navigationUnit == NavigationUnit.PageLeft || navigationUnit == NavigationUnit.PageRight ?
                                                   1 : StepSize)))); // temp dirty fix
        }
Пример #6
0
        /**
         *   
         */  
        override internal int GetNavigationDestinationIndex(int currentIndex, NavigationUnit navigationUnit, bool arrowKeysWrapFocus)
        {
            if (null == Target || Target.NumberOfContentChildren < 1)
                return -1;

            int maxIndex = Target.NumberOfContentChildren - 1;

            // Special case when nothing was previously selected
            if (currentIndex == -1)
            {
                if (navigationUnit == NavigationUnit.Up || navigationUnit == NavigationUnit.Left)
                    return arrowKeysWrapFocus ? maxIndex : -1;

                if (navigationUnit == NavigationUnit.Down || navigationUnit == NavigationUnit.Right)
                    return 0;    
            }    
                
            // Make sure currentIndex is within range
            bool inRows = _orientation == TileOrientation.Rows;
            currentIndex = Math.Max(0, Math.Min(maxIndex, currentIndex));

            // Find the current column and row
            int currentRow;
            int currentColumn;
            if (inRows)
            {
                // Is the TileLayout initialized with valid values?
                if (_columnCount == 0 || _rowHeight + _verticalGap == 0)
                    return currentIndex;
                        
                currentRow = currentIndex / _columnCount;
                currentColumn = currentIndex - currentRow * _columnCount;
            }
            else
            {
                // Is the TileLayout initialized with valid values?
                if (_rowCount == 0 || _columnWidth + _horizontalGap == 0)
                    return currentIndex;
        
                currentColumn = currentIndex / _rowCount;
                currentRow = currentIndex - currentColumn * _rowCount;
            }
            
            int newRow = currentRow;
            int newColumn = currentColumn;

            // Handle user input, almost all range checks are
            // performed after the calculations, at the end of the method.
            switch (navigationUnit)
            {
                case NavigationUnit.Left: 
                {
                    // If we are at the first column, can
                    // we go to the previous element (last column, previous row)?
                    if (newColumn == 0 && inRows && newRow > 0)
                    {
                        newRow--;
                        newColumn = _columnCount - 1;
                    }
                    else if (arrowKeysWrapFocus && newColumn == 0 && inRows && newRow == 0)
                    {
                        newRow = _rowCount - 1;
                        newColumn = _columnCount - 1;
                    }
                    else
                        newColumn--;
                    break;
                }

                case NavigationUnit.Right:
                {
                    // If we are at the last column, can
                    // we go to the next element (first column, next row)?
                    if (newColumn == _columnCount - 1 && inRows && newRow < _rowCount - 1)
                    {
                        newColumn = 0;
                        newRow++;
                    }
                    else if (arrowKeysWrapFocus && newColumn == _columnCount - 1 && inRows && newRow == _rowCount - 1)
                    {
                        newColumn = 0;
                        newRow = 0;
                    }
                    else
                        newColumn++;
                    break;
                } 

                case NavigationUnit.Up:
                {
                    // If we are at the first row, can we
                    // go to the previous element (previous column, last row)?
                    if (newRow == 0 && !inRows && newColumn > 0)
                    {
                        newColumn--;
                        newRow = _rowCount - 1;
                    }
                    else if (arrowKeysWrapFocus && newRow == 0 && !inRows && newColumn == 0)
                    {
                        newColumn = _columnCount - 1;
                        newRow = _rowCount - 1;
                    }
                    else
                        newRow--;
                    break; 
                }

                case NavigationUnit.Down:
                {
                    // If we are at the last row, can we
                    // go to the next element (next column, first row)?
                    if (newRow == _rowCount - 1 && !inRows && newColumn < _columnCount - 1)
                    {
                        newColumn++;
                        newRow = 0;
                    }
                    else if (arrowKeysWrapFocus && newRow == _rowCount - 1 && !inRows && newColumn == _columnCount - 1)
                    {
                        newColumn = 0;
                        newRow = 0;
                    }
                    else
                        newRow++;
                    break; 
                }

                case NavigationUnit.PageUp:
                case NavigationUnit.PageDown:
                {
                    // Ensure we have a valid scrollRect as we use it for calculations below
                    Rectangle scrollRect = GetScrollRect();
                    if (null == scrollRect)
                        scrollRect = new Rectangle(0, 0, Target.ContentWidth, Target.ContentHeight);
                     
                    if (inRows)
                    {
                        int firstVisibleRow = (int) Mathf.Ceil(scrollRect.Top / ((float)_rowHeight + _verticalGap));
                        int lastVisibleRow = (int) Mathf.Floor(scrollRect.Bottom / ((float)_rowHeight + _verticalGap));
                         
                        if (navigationUnit == NavigationUnit.PageUp)
                        {
                            // Is the current row visible, somewhere in the middle of the scrollRect?
                            if (firstVisibleRow < currentRow && currentRow <= lastVisibleRow)
                                newRow = firstVisibleRow;
                            else                             
                                newRow = 2 * firstVisibleRow - lastVisibleRow;
                        } 
                        else
                        {
                            // Is the current row visible, somewhere in the middle of the scrollRect?
                            if (firstVisibleRow <= currentRow && currentRow < lastVisibleRow)
                                newRow = lastVisibleRow;
                            else                             
                                newRow = 2 * lastVisibleRow - firstVisibleRow;
                        }
                    }
                    else
                    {
                        int firstVisibleColumn = (int) Mathf.Ceil(scrollRect.Left / ((float)_columnWidth + _horizontalGap));
                        int lastVisibleColumn = (int) Mathf.Floor(scrollRect.Right / ((float)_columnWidth + _horizontalGap));
                        
                        if (navigationUnit == NavigationUnit.PageUp)
                        {
                            // Is the current column visible, somewhere in the middle of the scrollRect?
                            if (firstVisibleColumn < currentColumn && currentColumn <= lastVisibleColumn)
                                newColumn = firstVisibleColumn;
                            else    
                                newColumn = 2 * firstVisibleColumn - lastVisibleColumn; 
                        }
                        else
                        {
                            // Is the current column visible, somewhere in the middle of the scrollRect?
                            if (firstVisibleColumn <= currentColumn && currentColumn < lastVisibleColumn)
                                newColumn = lastVisibleColumn;
                            else    
                                newColumn = 2 * lastVisibleColumn - firstVisibleColumn;
                        }
                    }
                    break; 
                }
                default: 
                    return base.GetNavigationDestinationIndex(currentIndex, navigationUnit, arrowKeysWrapFocus);
            }

            // Make sure rows and columns are within range
            newRow = Math.Max(0, Math.Min(_rowCount - 1, newRow));
            newColumn = Math.Max(0, Math.Min(_columnCount - 1, newColumn));

            // Calculate the new index based on orientation        
            if (inRows)  
            {
                // Make sure we don't return an index for an empty space in the last row.
                // newRow is guaranteed to be greater than zero:
                
                // Step 1: We can end up at the empty space in the last row if we moved right from
                // the last item.
                if (currentIndex == maxIndex && newColumn > currentColumn)
                    newColumn = currentColumn;
                    
                // Step 2: We can end up at the empty space in the last row if we moved down from
                // the previous row.    
                if (newRow == _rowCount - 1 && newColumn > maxIndex - _columnCount * (_rowCount - 1))
                    newRow--;

                return newRow * _columnCount + newColumn;
            }
            else
            {
                // Make sure we don't return an index for an empty space in the last column.
                // newColumn is guaranteed to be greater than zero:

                // Step 1: We can end up at the empty space in the last column if we moved down from
                // the last item.
                if (currentIndex == maxIndex && newRow > currentRow)
                    newRow = currentRow;

                // Step 2: We can end up at the empty space in the last column if we moved right from
                // the previous column.    
                if (newColumn == _columnCount - 1 && newRow > maxIndex - _rowCount * (_columnCount - 1))
                    newColumn--;

                return newColumn * _rowCount + newRow;
            }
        }
Пример #7
0
        /**
         *   
         */
        override internal int GetNavigationDestinationIndex(int currentIndex, NavigationUnit navigationUnit, bool arrowKeysWrapFocus)
        {
            if (null == Target || Target.NumberOfContentChildren < 1)
                return -1;

            int maxIndex = Target.NumberOfContentChildren - 1;

            // Special case when nothing was previously selected
            if (currentIndex == -1)
            {
                if (navigationUnit == NavigationUnit.Left)
                    return arrowKeysWrapFocus ? maxIndex : -1;

                if (navigationUnit == NavigationUnit.Right)
                    return 0;
            }

            currentIndex = Math.Max(0, Math.Min(maxIndex, currentIndex));

            int newIndex;
            Rectangle bounds;
            float x;

            switch (navigationUnit)
            {
                case NavigationUnit.Left:
                    {
                        if (arrowKeysWrapFocus && currentIndex == 0)
                            newIndex = maxIndex;
                        else
                            newIndex = currentIndex - 1;
                        break;
                    }

                case NavigationUnit.Right:
                    {
                        if (arrowKeysWrapFocus && currentIndex == maxIndex)
                            newIndex = 0;
                        else
                            newIndex = currentIndex + 1;
                        ;
                        break;
                    }

                case NavigationUnit.PageUp:
                case NavigationUnit.PageLeft:
                    // Find the first fully visible element
                    var firstVisible = FirstIndexInView;
                    var firstFullyVisible = firstVisible;
                    if (FractionOfElementInView(firstFullyVisible) < 1)
                        firstFullyVisible += 1;

                    // Is the current element in the middle of the viewport?
                    if (firstFullyVisible < currentIndex && currentIndex <= LastIndexInView)
                        newIndex = firstFullyVisible;
                    else
                    {
                        // Find an element that's one page up
                        if (currentIndex == firstFullyVisible || currentIndex == firstVisible)
                        {
                            // currentIndex is visible, we can calculate where the scrollRect top
                            // would end up if we scroll by a page                    
                            x = GetVerticalScrollPositionDelta(NavigationUnit.PageLeft) + GetScrollRect().Left;
                        }
                        else
                        {
                            // currentIndex is not visible, just find an element a page up from currentIndex
                            x = GetElementBounds(currentIndex).Right - GetScrollRect().Width;
                        }

                        // Find the element after the last element that spans above the y position
                        newIndex = currentIndex - 1;
                        while (0 <= newIndex)
                        {
                            bounds = GetElementBounds(newIndex);
                            if (null != bounds && bounds.Left < x)
                            {
                                // This element spans the y position, so return the next one
                                newIndex = Math.Min(currentIndex - 1, newIndex + 1);
                                break;
                            }
                            newIndex--;
                        }
                    }
                    break;

                case NavigationUnit.PageDown:
                case NavigationUnit.PageRight:
                    // Find the last fully visible element:
                    var lastVisible = LastIndexInView;
                    var lastFullyVisible = lastVisible;
                    if (FractionOfElementInView(lastFullyVisible) < 1)
                        lastFullyVisible -= 1;

                    // Is the current element in the middle of the viewport?
                    if (FirstIndexInView <= currentIndex && currentIndex < lastFullyVisible)
                        newIndex = lastFullyVisible;
                    else
                    {
                        // Find an element that's one page down
                        if (currentIndex == lastFullyVisible || currentIndex == lastVisible)
                        {
                            // currentIndex is visible, we can calculate where the scrollRect bottom
                            // would end up if we scroll by a page                    
                            x = GetVerticalScrollPositionDelta(NavigationUnit.PageRight) + GetScrollRect().Right;
                        }
                        else
                        {
                            // currentIndex is not visible, just find an element a page down from currentIndex
                            x = GetElementBounds(currentIndex).Left + GetScrollRect().Width;
                        }

                        // Find the element before the first element that spans below the y position
                        newIndex = currentIndex + 1;
                        while (newIndex <= maxIndex)
                        {
                            bounds = GetElementBounds(newIndex);
                            if (null != bounds && bounds.Right > x)
                            {
                                // This element spans the y position, so return the previous one
                                newIndex = Math.Max(currentIndex + 1, newIndex - 1);
                                break;
                            }
                            newIndex++;
                        }
                    }
                    break;
                default:
                    return base.GetNavigationDestinationIndex(currentIndex, navigationUnit, arrowKeysWrapFocus);
            }
            return Math.Max(0, Math.Min(maxIndex, newIndex));
        }
Пример #8
0
 ///<summary>
 ///</summary>
 ///<param name="navigationUnit"></param>
 ///<returns></returns>
 public float GetVerticalScrollPositionDelta(NavigationUnit navigationUnit)
 {
     return((null != _layout) ? _layout.GetVerticalScrollPositionDelta(navigationUnit) : 0);
 }
Пример #9
0
 ///<summary>
 ///</summary>
 ///<param name="navigationUnit"></param>
 ///<returns></returns>
 public float GetVerticalScrollPositionDelta(NavigationUnit navigationUnit)
 {
     return (null != _layout) ? _layout.GetVerticalScrollPositionDelta(navigationUnit) : 0;
 }
Пример #10
0
        /**
         *  Delegation method that determines which item  
         *  to navigate to based on the current item in focus 
         *  and user input in terms of NavigationUnit. This method
         *  is used by subclasses of OldListBase to handle 
         *  keyboard navigation. OldListBase maps user input to
         *  NavigationUnit constants.
         * 
         *  <p>Subclasses can override this method to compute other 
         *  values that are based on the current index and key 
         *  stroke encountered. </p>
         * 
         *  Param: currentIndex The current index of the item with focus.
         * 
         *  Param: navigationUnit The NavigationUnit constant that determines
         *  which item to navigate to next.  
         * 
         *  Param: ArrowKeysWrapFocus If <code>true</code>, using arrow keys to 
         *  navigate within the component wraps when it hits either end.
         * 
         *  Returns: The index of the next item to jump to. Returns -1
         *  when if the layout doesn't recognize the navigationUnit.
         */  
        ///<summary>
        ///</summary>
        ///<param name="currentIndex"></param>
        ///<param name="navigationUnit"></param>
        ///<param name="arrowKeysWrapFocus"></param>
        ///<returns></returns>
        internal virtual int GetNavigationDestinationIndex(int currentIndex, NavigationUnit navigationUnit, bool arrowKeysWrapFocus) // TEMP internal
        {
            if (null == Target || Target.NumberOfChildren < 1)
                return -1; 

            //Sub-classes implement according to their own layout 
            //logic. Common cases handled here. 
            switch (navigationUnit)
            {
                case NavigationUnit.Home:
                    return 0; 

                case NavigationUnit.End:
                    return Target.NumberOfChildren - 1; 

                default:
                    return -1;
            }
        }
Пример #11
0
        /// <summary>
        /// Returns the amount to add to the viewport's current verticalScrollPositionto scroll by the requested scrolling unit.
        /// </summary>
        /// <param name="navigationUnit"></param>
        /// <returns></returns>
        internal float GetVerticalScrollPositionDelta(NavigationUnit navigationUnit) // TEMP internal
        {
            GroupBase g = Target;
            if (null == g)
                return 0;     

            Rectangle scrollRect = GetScrollRect();
            if (null == scrollRect)
                return 0;

            // Special case: if the scrollRect's origin is 0,0 and it's bigger 
            // than the target, then there's no where to scroll to
            if ((scrollRect.Y == 0) && (scrollRect.Height >= g.ContentHeight))
                return 0;

            // maxDelta is the horizontalScrollPosition delta required 
            // to scroll to the END and minDelta scrolls to HOME. 
            float maxDelta = g.ContentHeight - scrollRect.Bottom; // Bottom
            float minDelta = -scrollRect.Top; // Top
            Rectangle getElementBounds;
            switch(navigationUnit)
            {
                case NavigationUnit.Up:
                case NavigationUnit.PageUp:
                    // Find the bounds of the first non-fully visible element
                    // that spans right of the scrollRect.
                    getElementBounds = GetElementBoundsAboveScrollRect(scrollRect);
                    break;

                case NavigationUnit.Down:
                case NavigationUnit.PageDown:
                    // Find the bounds of the first non-fully visible element
                    // that spans below the scrollRect.
                    getElementBounds = GetElementBoundsBelowScrollRect(scrollRect);
                    break;

                case NavigationUnit.Home: 
                    return minDelta;

                case NavigationUnit.End: 
                    return maxDelta;

                default:
                    return 0;
            }

            if (null == getElementBounds)
                return 0;

            float delta = 0;
            switch (navigationUnit)
            {
                case NavigationUnit.Up:
                    // Snap the top edge of element to the top edge of the scrollRect.
                    // The element is the the first non-fully visible element above the scrollRect.
                    delta = Math.Max(getElementBounds.Top - scrollRect.Top, -scrollRect.Height);
                    break;    
                case NavigationUnit.Down:
                    // Snap the bottom edge of the element to the bottom edge of the scrollRect.
                    // The element is the the first non-fully visible element below the scrollRect.
                    delta = Math.Min(getElementBounds.Bottom - scrollRect.Bottom, scrollRect.Height);
                    break;    
                case NavigationUnit.PageUp:
                    {
                        // Snap the bottom edge of the element to the bottom edge of the scrollRect.
                        // The element is the the first non-fully visible element below the scrollRect. 
                        delta = getElementBounds.Bottom - scrollRect.Bottom;
                    
                        // Special case: when an element is taller than the scrollRect,
                        // we want to snap its top edge to the top edge of the scrollRect.
                        // The delta will be limited to the height of the scrollRect further below.
                        if (delta >= 0)
                            delta = Math.Max(getElementBounds.Top - scrollRect.Top, -scrollRect.Height);  
                    }
                    break;
                case NavigationUnit.PageDown:
                    {
                        // Align the top edge of the element to the top edge of the scrollRect.
                        // The element is the the first non-fully visible element below the scrollRect.
                        delta = getElementBounds.Top - scrollRect.Top;
                    
                        // Special case: when an element is taller than the scrollRect,
                        // we want to snap its bottom edge to the bottom edge of the scrollRect.
                        // The delta will be limited to the height of the scrollRect further below.
                        if (delta <= 0)
                            delta = Math.Min(getElementBounds.Bottom - scrollRect.Bottom, scrollRect.Height);
                    }
                    break;
            }

            //Debug.Log("delta: " + delta + "; minDelta: " + minDelta + ", maxDelta: " + maxDelta);
            return Math.Min(maxDelta, Math.Max(minDelta, delta * (
                this is TileLayout || navigationUnit == NavigationUnit.PageUp || navigationUnit == NavigationUnit.PageDown ? 
                1 : StepSize))); // temp dirty fix
        }
Пример #12
0
        /// <summary>
        /// Returns the amount to add to the viewport's current horizontalScrollPosition to scroll by the requested scrolling unit.
        /// </summary>
        /// <param name="navigationUnit"></param>
        /// <returns></returns>
        internal float GetHorizontalScrollPositionDelta(NavigationUnit navigationUnit) // TEMP internal
        {
            GroupBase g = Target;
            if (null == g)
                return 0;     

            Rectangle scrollRect = GetScrollRect();
            if (null == scrollRect)
                return 0;
                
            // Special case: if the scrollRect's origin is 0,0 and it's bigger 
            // than the target, then there's no where to scroll to
            if ((scrollRect.X == 0) && (scrollRect.Width >= g.ContentWidth))
                return 0;  

            // maxDelta is the horizontalScrollPosition delta required 
            // to scroll to the END and minDelta scrolls to HOME. 
            float maxDelta = g.ContentWidth - scrollRect.Right; //Right;
            float minDelta = -scrollRect.Left; //Left;
            Rectangle getElementBounds;
            switch(navigationUnit)
            {
                case NavigationUnit.Left:
                case NavigationUnit.PageLeft:
                    // Find the bounds of the first non-fully visible element
                    // to the left of the scrollRect.
                    getElementBounds = GetElementBoundsLeftOfScrollRect(scrollRect);
                    break;

                case NavigationUnit.Right:
                case NavigationUnit.PageRight:
                    // Find the bounds of the first non-fully visible element
                    // to the right of the scrollRect.
                    getElementBounds = GetElementBoundsRightOfScrollRect(scrollRect);
                    break;

                case NavigationUnit.Home: 
                    return minDelta;
                    
                case NavigationUnit.End: 
                    return maxDelta;
                    
                default:
                    return 0;
            }
            
            if (null == getElementBounds)
                return 0;

            float delta = 0f;
            switch (navigationUnit)
            {
                case NavigationUnit.Left:
                    // Snap the left edge of element to the left edge of the scrollRect.
                    // The element is the the first non-fully visible element left of the scrollRect.
                    delta = Math.Max(getElementBounds.Left - scrollRect.Left, -scrollRect.Width);
                    break;    
                case NavigationUnit.Right:
                    // Snap the right edge of the element to the right edge of the scrollRect.
                    // The element is the the first non-fully visible element right of the scrollRect.
                    delta = Math.Min(getElementBounds.Right - scrollRect.Right, scrollRect.Width);
                    break;    
                case NavigationUnit.PageLeft:
                    {
                        // Snap the right edge of the element to the right edge of the scrollRect.
                        // The element is the the first non-fully visible element left of the scrollRect. 
                        delta = getElementBounds.Right - scrollRect.Right;
                    
                        // Special case: when an element is wider than the scrollRect,
                        // we want to snap its left edge to the left edge of the scrollRect.
                        // The delta will be limited to the width of the scrollRect further below.
                        if (delta >= 0)
                            delta = Math.Max(getElementBounds.Left - scrollRect.Left, -scrollRect.Width);  
                    }
                    break;
                case NavigationUnit.PageRight:
                    {
                        // Align the left edge of the element to the left edge of the scrollRect.
                        // The element is the the first non-fully visible element right of the scrollRect.
                        delta = getElementBounds.Left - scrollRect.Left;
                    
                        // Special case: when an element is wider than the scrollRect,
                        // we want to snap its right edge to the right edge of the scrollRect.
                        // The delta will be limited to the width of the scrollRect further below.
                        if (delta <= 0)
                            delta = Math.Min(getElementBounds.Right - scrollRect.Right, scrollRect.Width);
                    }
                    break;
            }

            // Makse sure we don't get out of bounds. Also, don't scroll 
            // by more than the scrollRect width at a time.
            return Math.Min(maxDelta, Math.Max(minDelta, delta * (
                this is TileLayout || navigationUnit == NavigationUnit.PageUp || navigationUnit == NavigationUnit.PageDown || navigationUnit == NavigationUnit.PageLeft || navigationUnit == NavigationUnit.PageRight ?
                1 : StepSize))); // temp dirty fix
        }