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; } }
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); } } }
private void HandleBackspace(KeyboardInputEvent evt) { if (!InitKeyPress(evt)) { return; } HandleCharactersDeletedBackwards(); ScrollToCursor(); }
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; } }
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; }
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; }
protected UIEvent(string eventType, KeyboardInputEvent keyboardInputEvent) { this.eventType = eventType; this.keyboardInputEvent = keyboardInputEvent; propagating = true; }
public TabNavigationEvent(KeyboardInputEvent keyboardInputEvent) : base("tabnavigation", keyboardInputEvent) { }
private void HandleEnd(KeyboardInputEvent evt) { selectionRange = textElement.textInfo.MoveToEndOfLine(selectionRange, evt.shift); blinkStartTime = Time.unscaledTime; ScrollToCursor(); }
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(); } } }