Ejemplo n.º 1
0
        public FocusChangeDirection GetFocusChangeDirection(Focusable currentFocusable, EventBase e)
        {
            if (e.eventTypeId == PointerDownEvent.TypeId())
            {
                if (focusController.GetFocusableParentForPointerEvent(e.target as Focusable, out var target))
                {
                    return(VisualElementFocusChangeTarget.GetPooled(target));
                }
            }

            if (e.eventTypeId == NavigationMoveEvent.TypeId())
            {
                switch (((NavigationMoveEvent)e).direction)
                {
                case NavigationMoveEvent.Direction.Left: return(Left);

                case NavigationMoveEvent.Direction.Up: return(Up);

                case NavigationMoveEvent.Direction.Right: return(Right);

                case NavigationMoveEvent.Direction.Down: return(Down);

                case NavigationMoveEvent.Direction.Next: return(Next);

                case NavigationMoveEvent.Direction.Previous: return(Previous);
                }
            }

            return(FocusChangeDirection.none);
        }
        public static VisualElementFocusChangeTarget GetPooled(Focusable target)
        {
            VisualElementFocusChangeTarget visualElementFocusChangeTarget = VisualElementFocusChangeTarget.Pool.Get();

            visualElementFocusChangeTarget.target = target;
            return(visualElementFocusChangeTarget);
        }
        /// <summary>
        /// Get the direction of the focus change for the given event. For example, when the Tab key is pressed, focus should be given to the element to the right in the focus ring.
        /// </summary>
        public FocusChangeDirection GetFocusChangeDirection(Focusable currentFocusable, EventBase e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            // FUTURE:
            // We could implement an extendable adapter system to convert event to a focus change direction.
            // This would enable new event sources to change the focus.

            if (e.eventTypeId == PointerDownEvent.TypeId())
            {
                if (focusController.GetFocusableParentForPointerEvent(e.target as Focusable, out var target))
                {
                    return(VisualElementFocusChangeTarget.GetPooled(target));
                }
            }

            if (currentFocusable is IMGUIContainer && e.imguiEvent != null)
            {
                // Let IMGUIContainer manage the focus change.
                return(FocusChangeDirection.none);
            }

            return(GetKeyDownFocusChangeDirection(e));
        }
        public FocusChangeDirection GetFocusChangeDirection(Focusable currentFocusable, EventBase e)
        {
            bool flag = e == null;

            if (flag)
            {
                throw new ArgumentNullException("e");
            }
            bool flag2 = e.eventTypeId == EventBase <MouseDownEvent> .TypeId();

            FocusChangeDirection result;

            if (flag2)
            {
                Focusable focusable = e.target as Focusable;
                bool      flag3     = focusable != null;
                if (flag3)
                {
                    result = VisualElementFocusChangeTarget.GetPooled(focusable);
                    return(result);
                }
            }
            bool flag4 = currentFocusable is IMGUIContainer && e.imguiEvent != null;

            if (flag4)
            {
                result = FocusChangeDirection.none;
            }
            else
            {
                result = VisualElementFocusRing.GetKeyDownFocusChangeDirection(e);
            }
            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get the direction of the focus change for the given event. For example, when the Tab key is pressed, focus should be given to the element to the right in the focus ring.
        /// </summary>
        public FocusChangeDirection GetFocusChangeDirection(Focusable currentFocusable, EventBase e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            // FUTURE:
            // We could implement an extendable adapter system to convert event to a focus change direction.
            // This would enable new event sources to change the focus.

            if (e.eventTypeId == PointerDownEvent.TypeId())
            {
                if (focusController.GetFocusableParentForPointerEvent(e.target as Focusable, out var target))
                {
                    return(VisualElementFocusChangeTarget.GetPooled(target));
                }
            }

            if (currentFocusable is IMGUIContainer)
            {
                // Let IMGUIContainer manage the focus change.
                return(FocusChangeDirection.none);
            }

            if (e.eventTypeId == NavigationMoveEvent.TypeId())
            {
                // If navigation event was sent to an element that doesn't have the focus, ignore it.
                // This is helpful in cases where a control reacts to KeyDown and moves the focus away, in which case
                // any further equivalent navigation events should not move the focus again.

                var direction = ((NavigationMoveEvent)e).direction;
                return(direction == NavigationMoveEvent.Direction.Next ? VisualElementFocusChangeDirection.right :
                       direction == NavigationMoveEvent.Direction.Previous ? VisualElementFocusChangeDirection.left :
                       FocusChangeDirection.none);
            }

            return(FocusChangeDirection.none);
        }
        public Focusable GetNextFocusable(Focusable currentFocusable, FocusChangeDirection direction)
        {
            bool      flag = direction == FocusChangeDirection.none || direction == FocusChangeDirection.unspecified;
            Focusable result;

            if (flag)
            {
                result = currentFocusable;
            }
            else
            {
                VisualElementFocusChangeTarget visualElementFocusChangeTarget = direction as VisualElementFocusChangeTarget;
                bool flag2 = visualElementFocusChangeTarget != null;
                if (flag2)
                {
                    result = visualElementFocusChangeTarget.target;
                }
                else
                {
                    this.DoUpdate();
                    bool flag3 = this.m_FocusRing.Count == 0;
                    if (flag3)
                    {
                        result = null;
                    }
                    else
                    {
                        int  num   = 0;
                        bool flag4 = direction == VisualElementFocusChangeDirection.right;
                        if (flag4)
                        {
                            num = this.GetFocusableInternalIndex(currentFocusable) + 1;
                            bool flag5 = currentFocusable != null && num == 0;
                            if (flag5)
                            {
                                result = VisualElementFocusRing.GetNextFocusableInTree(currentFocusable as VisualElement);
                                return(result);
                            }
                            bool flag6 = num == this.m_FocusRing.Count;
                            if (flag6)
                            {
                                num = 0;
                            }
                            while (this.m_FocusRing[num].m_Focusable.delegatesFocus)
                            {
                                num++;
                                bool flag7 = num == this.m_FocusRing.Count;
                                if (flag7)
                                {
                                    result = null;
                                    return(result);
                                }
                            }
                        }
                        else
                        {
                            bool flag8 = direction == VisualElementFocusChangeDirection.left;
                            if (flag8)
                            {
                                num = this.GetFocusableInternalIndex(currentFocusable) - 1;
                                bool flag9 = currentFocusable != null && num == -2;
                                if (flag9)
                                {
                                    result = VisualElementFocusRing.GetPreviousFocusableInTree(currentFocusable as VisualElement);
                                    return(result);
                                }
                                bool flag10 = num < 0;
                                if (flag10)
                                {
                                    num = this.m_FocusRing.Count - 1;
                                }
                                while (this.m_FocusRing[num].m_Focusable.delegatesFocus)
                                {
                                    num--;
                                    bool flag11 = num == -1;
                                    if (flag11)
                                    {
                                        result = null;
                                        return(result);
                                    }
                                }
                            }
                        }
                        result = this.m_FocusRing[num].m_Focusable;
                    }
                }
            }
            return(result);
        }