示例#1
0
        public void Update()
        {
            if (this._client == 0 || this._keyboard == null)
            {
                return;
            }

            if (this._keyboard.canSetSelection && this._pendingSelection != null)
            {
                this._keyboard.selection = this._pendingSelection.Value;
                this._pendingSelection   = null;
            }

            if (this._keyboard.status == TouchScreenKeyboard.Status.Done)
            {
                if (!this._screenKeyboardDone)
                {
                    this._screenKeyboardDone = true;
                    Window.instance.run(() => {
                        TextInput._performAction(this._client,
                                                 TextInputAction.done);
                    });
                }
            }
            else if (this._keyboard.status == TouchScreenKeyboard.Status.Visible)
            {
                var keyboardSelection = this._keyboard.selection;
                var newValue          = new TextEditingValue(
                    this._keyboard.text,
                    this._keyboard.canGetSelection
                        ? new TextSelection(keyboardSelection.start, keyboardSelection.end)
                        : TextSelection.collapsed(0)
                    );
                var changed = this._value != newValue;

                this._value = newValue;
                if (changed)
                {
                    Window.instance.run(() => {
                        TextInput._updateEditingState(this._client,
                                                      this._value);
                    });
                }
            }
        }
示例#2
0
        public void Update()
        {
            if (_client == 0 || _keyboard == null)
            {
                return;
            }

            if (_keyboard.canSetSelection && _pendingSelection != null)
            {
                _keyboard.selection = _pendingSelection.Value;
                _pendingSelection   = null;
            }

            if (_keyboard.status == TouchScreenKeyboard.Status.Done)
            {
                if (!_screenKeyboardDone)
                {
                    _screenKeyboardDone = true;
                    Timer.create(TimeSpan.Zero, () => {
                        TextInput._performAction(_client,
                                                 TextInputAction.done);
                    });
                }
            }
            else if (_keyboard.status == TouchScreenKeyboard.Status.Visible)
            {
                var keyboardSelection = _keyboard.selection;
                var newValue          = new TextEditingValue(
                    _keyboard.text,
                    _keyboard.canGetSelection
                        ? new TextSelection(keyboardSelection.start, keyboardSelection.end)
                        : TextSelection.collapsed(0)
                    );
                var changed = _value != newValue;

                _value = newValue;
                if (changed)
                {
                    Timer.create(TimeSpan.Zero, () => {
                        TextInput._updateEditingState(_client,
                                                      _value);
                    });
                }
            }
        }
示例#3
0
        public void OnGUI()
        {
            if (TouchScreenKeyboard.isSupported)
            {
                return;
            }

            if (this._client == 0)
            {
                return;
            }


            var currentEvent = Event.current;
            var oldValue     = this._value;

            if (currentEvent != null && currentEvent.type == EventType.KeyDown)
            {
                if (currentEvent.keyCode == KeyCode.Backspace)
                {
                    if (this._value.selection.isValid)
                    {
                        this._value = this._value.deleteSelection(true);
                    }
                }
                else if (currentEvent.character != '\0')
                {
                    this._value = this._value.clearCompose();
                    char ch = currentEvent.character;
                    if (ch == '\r' || ch == 3)
                    {
                        ch = '\n';
                    }

                    if (ch == '\n')
                    {
                        Window.instance.run(() => { TextInput._performAction(this._client, TextInputAction.newline); });
                    }

                    if (_validateCharacter(ch))
                    {
                        this._value = this._value.insert(new string(ch, 1));
                    }
                }
                else if (!string.IsNullOrEmpty(Input.compositionString))
                {
                    this.isIMEInput = true;
                    this._value     = this._value.compose(Input.compositionString);
                }

                currentEvent.Use();
            }

            if (this._value != oldValue)
            {
                if (this.isIMEInput)
                {
                    var isIMEInput = this.isIMEInput;
                    Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value, isIMEInput); });
                    this.isIMEInput = false;
                }
                else
                {
                    Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); });
                }
            }
        }
示例#4
0
        public void OnGUI()
        {
            if (TouchScreenKeyboard.isSupported)
            {
                return;
            }

            if (_client == 0)
            {
                return;
            }


            while (!PointerEventConverter.KeyEvent.isEmpty())
            {
                var currentEvent = PointerEventConverter.KeyEvent.Dequeue();
                var oldValue     = _value;

                if (currentEvent != null && currentEvent.type == EventType.KeyDown)
                {
                    var response = TextInput._handleGlobalInputKey(_client,
                                                                   new RawKeyDownEvent(new RawKeyEventData(currentEvent)));

                    if (response.swallow)
                    {
                        if (response.inputAction != null)
                        {
                            Timer.create(TimeSpan.Zero,
                                         () => { TextInput._performAction(_client, response.inputAction.Value); });
                        }

                        if (_validateCharacter(response.input))
                        {
                            _value = _value.insert(new string(response.input, 1));
                        }
                    }
                    else if (currentEvent.keyCode == KeyCode.Backspace)
                    {
                        if (_value.selection.isValid)
                        {
                            _value = _value.deleteSelection(true);
                        }
                    }
                    else if (currentEvent.character != 0)
                    {
                        _value = _value.clearCompose();
                        char ch = currentEvent.character;
                        if (ch == '\r' || ch == 3)
                        {
                            ch = '\n';
                        }

                        if (ch == '\n')
                        {
                            Timer.create(TimeSpan.Zero, () => { TextInput._performAction(_client,
                                                                                         _textInputConfiguration?.inputAction ?? TextInputAction.newline); });
                        }

                        if (_validateCharacter(ch))
                        {
                            _value = _value.insert(new string(ch, 1));
                        }
                    }
                    else if (!string.IsNullOrEmpty(currentEvent.keyCode.ToString()))
                    {
                        isIMEInput = true;
                        _value     = _value.compose(currentEvent.keyCode.ToString());
                    }

                    currentEvent.Use();
                }

                if (_value != oldValue)
                {
                    if (this.isIMEInput)
                    {
                        var isIMEInput = this.isIMEInput;
                        Timer.create(TimeSpan.Zero,
                                     () => { TextInput._updateEditingState(_client, _value, isIMEInput); });
                        this.isIMEInput = false;
                    }
                    else
                    {
                        Timer.create(TimeSpan.Zero, () => { TextInput._updateEditingState(_client, _value, isIMEInput); });
                    }
                }
            }
        }
示例#5
0
 public KeyboadManager(TextInput textInput)
 {
     this._textInput = textInput;
 }