示例#1
0
        public void EnterText(KeyboardInputEvent evt)
        {
            evt.StopPropagation();
            if (HasDisabledAttr())
            {
                return;
            }

            switch (evt.keyCode)
            {
            case KeyCode.Home:
                HandleHome(evt);
                break;

            case KeyCode.End:
                HandleEnd(evt);
                break;

            case KeyCode.Backspace:
                HandleBackspace(evt);
                break;

            case KeyCode.Delete:
                HandleDelete(evt);
                break;

            case KeyCode.LeftArrow:
                HandleLeftArrow(evt);
                break;

            case KeyCode.RightArrow:
                HandleRightArrow(evt);
                break;

            case KeyCode.C when evt.onlyControl && selectionRange.HasSelection:
                HandleCopy(evt);
                break;

            case KeyCode.V when evt.onlyControl && selectionRange.HasSelection:
                HandlePaste(evt);
                break;

            case KeyCode.X when evt.onlyControl && selectionRange.HasSelection:
                HandleCut(evt);
                break;

            case KeyCode.A when evt.onlyControl && selectionRange.HasSelection:
                HandleSelectAll(evt);
                //
                break;

            default:
                OnTextEntered(evt);
                break;
            }
        }
示例#2
0
        public void OnKeyDownNavigate(KeyboardInputEvent evt)
        {
            if (disabled)
            {
                return;
            }

            if (selecting && evt.keyCode == KeyCode.Escape)
            {
                selecting = false;
                return;
            }

            if (selecting && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.Space))
            {
                // space and return should only choose the currently keyboard-selected item
                if (keyboardNavigationIndex > -1)
                {
                    SetSelectedValue(keyboardNavigationIndex);
                    childrenElement.children[selectedIndex].style.ExitState(StyleState.Hover);
                }

                return;
            }

            // just submit the form if we have focus and are not in selection mode
            if (!selecting && evt.keyCode == KeyCode.Return)
            {
                Input.DelayEvent(this, new SubmitEvent());
                return;
            }

            // enable tab navigation
            if (evt.keyCode == KeyCode.Tab)
            {
                Input.DelayEvent(this, new TabNavigationEvent(evt));
                return;
            }

            if (!selecting)
            {
                // enter selection mode if we have focus and press space
                if (evt.keyCode == KeyCode.Space)
                {
                    selecting = true;

                    keyboardNavigationIndex = selectedIndex;
                    if (keyboardNavigationIndex == -1)
                    {
                        keyboardNavigationIndex = 0;
                    }

                    childrenElement.children[keyboardNavigationIndex].style.EnterState(StyleState.Hover);
                }
            }
        }
示例#3
0
        private void HandleBackspace(KeyboardInputEvent evt)
        {
            if (!InitKeyPress(evt))
            {
                return;
            }

            HandleCharactersDeletedBackwards();
            ScrollToCursor();
        }
示例#4
0
        public void OnKeyHeldDownWithFocus(KeyboardInputEvent evt)
        {
            if (inputElement.HasDisabledAttr())
            {
                return;
            }

            evt.StopPropagation();

            switch (evt.keyCode)
            {
            case KeyCode.UpArrow: IncrementContinuously();
                break;

            case KeyCode.DownArrow: DecrementContinuously();
                break;

            default: return;
            }
        }
示例#5
0
        public void OnKeyPressed(KeyboardInputEvent evt)
        {
            if (inputElement.HasDisabledAttr())
            {
                return;
            }

            evt.StopPropagation();

            switch (evt.keyCode)
            {
            case KeyCode.UpArrow: Increment();
                break;

            case KeyCode.DownArrow: Decrement();
                break;

            default: return;
            }

            keyLockTimestamp = Time.unscaledTime;
        }
示例#6
0
        private void OnTextEntered(KeyboardInputEvent evt)
        {
            if (evt.ctrl)
            {
                return;
            }

            char c = evt.character;

            if (evt.keyCode == KeyCode.Return)
            {
                if (!InitKeyPress(evt))
                {
                    return;
                }
                HandleSubmit();
                return;
            }

            if (evt.keyCode == KeyCode.Tab)
            {
                return;
            }

            if (c == '\n' || c == '\t')
            {
                return;
            }

            // assume we only ever use 1 text span for now, this should change in the future
            if (!textElement.textInfo.rootSpan.textStyle.fontAsset.HasCharacter(c))
            {
                return;
            }

            HandleCharactersEntered(c.ToString());
            ScrollToCursor();
        }
 public void OnEvent(object sender, KeyboardInputEvent args)
 {
     // Store event.
     inputEvent = args;
     processed  = false;
 }
示例#8
0
文件: UIEvent.cs 项目: veboys/UIForia
 protected UIEvent(string eventType, KeyboardInputEvent keyboardInputEvent)
 {
     this.eventType          = eventType;
     this.keyboardInputEvent = keyboardInputEvent;
     propagating             = true;
 }
示例#9
0
 public TabNavigationEvent(KeyboardInputEvent keyboardInputEvent)
     : base("tabnavigation", keyboardInputEvent)
 {
 }
示例#10
0
 private void HandleEnd(KeyboardInputEvent evt)
 {
     selectionRange = textElement.textInfo.MoveToEndOfLine(selectionRange, evt.shift);
     blinkStartTime = Time.unscaledTime;
     ScrollToCursor();
 }
示例#11
0
        public void OnKeyboardNavigate(KeyboardInputEvent evt)
        {
            if (disabled)
            {
                return;
            }

            if (debounce - Time.realtimeSinceStartup > -0.1)
            {
                return;
            }

            debounce = Time.realtimeSinceStartup;

            if (!selecting)
            {
                // if we are NOT in selection mode using the arrow keys should just cycle through the options and set them immediately
                if (evt.keyCode == KeyCode.UpArrow)
                {
                    selectedIndex--;
                    if (selectedIndex < 0)
                    {
                        selectedIndex = options.Count - 1;
                    }

                    SetSelectedValue(selectedIndex);
                    evt.StopPropagation();
                }
                else if (evt.keyCode == KeyCode.DownArrow)
                {
                    selectedIndex++;
                    if (selectedIndex == options.Count)
                    {
                        selectedIndex = 0;
                    }

                    SetSelectedValue(selectedIndex);
                    evt.StopPropagation();
                }
            }
            else
            {
                // use the up/down arrows to navigate through the options but only visually. pressing space or return will set the new value for real.

                if (evt.keyCode == KeyCode.UpArrow)
                {
                    if (keyboardNavigationIndex > -1)
                    {
                        childrenElement.children[keyboardNavigationIndex].style.ExitState(StyleState.Hover);
                    }

                    keyboardNavigationIndex--;
                    if (keyboardNavigationIndex < 0)
                    {
                        keyboardNavigationIndex = options.Count - 1;
                    }

                    ScrollElementIntoView();
                    evt.StopPropagation();
                }
                else if (evt.keyCode == KeyCode.DownArrow)
                {
                    if (keyboardNavigationIndex > -1)
                    {
                        childrenElement.children[keyboardNavigationIndex].style.ExitState(StyleState.Hover);
                    }

                    keyboardNavigationIndex++;
                    if (keyboardNavigationIndex == options.Count)
                    {
                        keyboardNavigationIndex = 0;
                    }

                    ScrollElementIntoView();
                    evt.StopPropagation();
                }
            }
        }