int FocusRingSort(FocusRingRecord a, FocusRingRecord b)
        {
            if (a.m_Focusable.tabIndex == 0 && b.m_Focusable.tabIndex == 0)
            {
                return(FocusRingAutoIndexSort(a, b));
            }
            else if (a.m_Focusable.tabIndex == 0)
            {
                // Only b has a focus index. It has priority.
                return(1);
            }
            else if (b.m_Focusable.tabIndex == 0)
            {
                // Only a has a focus index. It has priority.
                return(-1);
            }
            else
            {
                // a and b should be ordered using their focus index.
                int result = Comparer <int> .Default.Compare(a.m_Focusable.tabIndex, b.m_Focusable.tabIndex);

                // but if the focus index result is being equal, we need to fallback with their automatic index
                if (result == 0)
                {
                    result = FocusRingAutoIndexSort(a, b);
                }
                return(result);
            }
        }
        void BuildRingForScopeRecursive(VisualElement ve, ref int scopeIndex, List <FocusRingRecord> scopeList)
        {
            var veChildCount = ve.hierarchy.childCount;

            for (int i = 0; i < veChildCount; i++)
            {
                var child = ve.hierarchy[i];

                bool isSlot = child.parent != null && child == child.parent.contentContainer;

                if (child.isCompositeRoot || isSlot)
                {
                    var childRecord = new FocusRingRecord
                    {
                        m_AutoIndex            = scopeIndex++,
                        m_Focusable            = child,
                        m_IsSlot               = isSlot,
                        m_ScopeNavigationOrder = new List <FocusRingRecord>()
                    };
                    scopeList.Add(childRecord);

                    int autoIndex = 0;
                    BuildRingForScopeRecursive(child, ref autoIndex, childRecord.m_ScopeNavigationOrder);
                }
                else
                {
                    // isHierarchyDisplayed is not checked in canGrabFocus to let a hidden VisualElement grab the focus when calling the Focus method.
                    if (child.canGrabFocus && child.isHierarchyDisplayed && child.tabIndex >= 0)
                    {
                        scopeList.Add(new FocusRingRecord
                        {
                            m_AutoIndex            = scopeIndex++,
                            m_Focusable            = child,
                            m_IsSlot               = false,
                            m_ScopeNavigationOrder = null
                        });
                    }

                    BuildRingForScopeRecursive(child, ref scopeIndex, scopeList);
                }
            }
        }
Пример #3
0
        void BuildRingForScopeRecursive(VisualElement ve, ref int scopeIndex, List <FocusRingRecord> scopeList)
        {
            for (int i = 0; i < ve.hierarchy.childCount; i++)
            {
                var child = ve.hierarchy[i];

                bool isSlot = child.parent != null && child == child.parent.contentContainer;

                if (child.isCompositeRoot || isSlot)
                {
                    var childRecord = new FocusRingRecord
                    {
                        m_AutoIndex            = scopeIndex++,
                        m_Focusable            = child,
                        m_IsSlot               = isSlot,
                        m_ScopeNavigationOrder = new List <FocusRingRecord>()
                    };
                    scopeList.Add(childRecord);

                    int autoIndex = 0;
                    BuildRingForScopeRecursive(child, ref autoIndex, childRecord.m_ScopeNavigationOrder);
                }
                else
                {
                    if (child.canGrabFocus && child.tabIndex >= 0)
                    {
                        scopeList.Add(new FocusRingRecord
                        {
                            m_AutoIndex            = scopeIndex++,
                            m_Focusable            = child,
                            m_IsSlot               = false,
                            m_ScopeNavigationOrder = null
                        });
                    }

                    BuildRingForScopeRecursive(child, ref scopeIndex, scopeList);
                }
            }
        }
Пример #4
0
        int FocusRingAutoIndexSort(FocusRingRecord a, FocusRingRecord b)
        {
            // FIXME: Write specialized methods for each defaultFocusOrder.
            switch (defaultFocusOrder)
            {
            case DefaultFocusOrder.ChildOrder:
            default:
                return(Comparer <int> .Default.Compare(a.m_AutoIndex, b.m_AutoIndex));

            case DefaultFocusOrder.PositionXY:
            {
                VisualElement ave = a.m_Focusable as VisualElement;
                VisualElement bve = b.m_Focusable as VisualElement;

                if (ave != null && bve != null)
                {
                    if (ave.layout.position.x < bve.layout.position.x)
                    {
                        return(-1);
                    }
                    else if (ave.layout.position.x > bve.layout.position.x)
                    {
                        return(1);
                    }
                    else
                    {
                        if (ave.layout.position.y < bve.layout.position.y)
                        {
                            return(-1);
                        }
                        else if (ave.layout.position.y > bve.layout.position.y)
                        {
                            return(1);
                        }
                    }
                }

                // a and b should be ordered using their order of appearance.
                return(Comparer <int> .Default.Compare(a.m_AutoIndex, b.m_AutoIndex));
            }

            case DefaultFocusOrder.PositionYX:
            {
                VisualElement ave = a.m_Focusable as VisualElement;
                VisualElement bve = b.m_Focusable as VisualElement;

                if (ave != null && bve != null)
                {
                    if (ave.layout.position.y < bve.layout.position.y)
                    {
                        return(-1);
                    }
                    else if (ave.layout.position.y > bve.layout.position.y)
                    {
                        return(1);
                    }
                    else
                    {
                        if (ave.layout.position.x < bve.layout.position.x)
                        {
                            return(-1);
                        }
                        else if (ave.layout.position.x > bve.layout.position.x)
                        {
                            return(1);
                        }
                    }
                }

                // a and b should be ordered using their order of appearance.
                return(Comparer <int> .Default.Compare(a.m_AutoIndex, b.m_AutoIndex));
            }
            }
        }