예제 #1
0
        public virtual MyGuiControlBase GetNextFocusControl(MyGuiControlBase currentFocusControl, bool forwardMovement)
        {
            int currentIdx = Elements.IndexOf(currentFocusControl);

            if (currentIdx == -1 && !forwardMovement)
            {
                currentIdx = Elements.Count;
            }

            int i = (forwardMovement) ? (currentIdx + 1)
                                      : (currentIdx - 1);
            int step = (forwardMovement) ? +1 : -1;

            while ((forwardMovement && i < Elements.Count) ||
                   (!forwardMovement && i >= 0))
            {
                if (MyGuiScreenBase.CanHaveFocusRightNow(Elements[i]))
                {
                    return(Elements[i]);
                }

                i += step;
            }

            return(Owner.GetNextFocusControl(this, forwardMovement));
        }
예제 #2
0
        public MyGuiControlBase GetNextFocusControl(MyGuiControlBase currentFocusControl, bool forwardMovement)
        {
            Debug.Assert(currentFocusControl.Owner == this);

            var visibleControls = Controls.GetVisibleControls();

            // Pretend that both Controls and Elements are in single array.
            int totalCount = visibleControls.Count + Elements.Count;

            int idxCurrent = visibleControls.IndexOf(currentFocusControl);

            if (idxCurrent == -1)
            {
                idxCurrent = Elements.IndexOf(currentFocusControl);
                Debug.Assert(idxCurrent != -1);
                idxCurrent += visibleControls.Count;
            }

            int sign = (forwardMovement) ? +1 : -1;

            for (int i = 1; i < totalCount; ++i)
            {
                int idx = idxCurrent + (sign * i);
                if (forwardMovement)
                {
                    idx %= totalCount;
                }
                else if (idx < 0)
                {
                    idx += totalCount;
                }

                if (idx < visibleControls.Count)
                {
                    if (CanHaveFocusRightNow(visibleControls[idx]))
                    {
                        if (visibleControls[idx] is MyGuiControlParent)
                        {
                            return(visibleControls[idx].GetFocusControl(forwardMovement));
                        }
                        else
                        {
                            return(visibleControls[idx]);
                        }
                    }
                }
                else
                {
                    idx -= visibleControls.Count;
                    if (CanHaveFocusRightNow(Elements[idx]))
                    {
                        return(Elements[idx]);
                    }
                }
            }

            return(null);
        }