void __focusIn(EventContext context)
        {
            if (!editable || !Application.isPlaying)
            {
                return;
            }

            _editing = true;

            if (_caret == null)
            {
                CreateCaret();
            }

            if (!string.IsNullOrEmpty(_promptText))
            {
                UpdateText();
            }

            float caretSize;

            //如果界面缩小过,光标很容易看不见,这里放大一下
            if (UIConfig.inputCaretSize == 1 && GRoot.contentScaleFactor < 1)
            {
                caretSize = (float)UIConfig.inputCaretSize / GRoot.contentScaleFactor;
            }
            else
            {
                caretSize = UIConfig.inputCaretSize;
            }
            _caret.SetSize(caretSize, textField.textFormat.size);
            _caret.DrawRect(0, Color.clear, textField.textFormat.color);
            AddChild(_caret);

            _selectionShape.Clear();
            AddChild(_selectionShape);

            if (!textField.Redraw())
            {
                TextField.CharPosition cp = GetCharPosition(_caretPosition);
                AdjustCaret(cp);
            }

            if (Stage.keyboardInput)
            {
                if (keyboardInput)
                {
                    Stage.inst.OpenKeyboard(_text, false, _displayAsPassword ? false : !textField.singleLine,
                                            _displayAsPassword, false, null, keyboardType, hideInput);

                    SetSelection(0, -1);
                }
            }
            else
            {
                Input.imeCompositionMode = IMECompositionMode.On;
                _composing = 0;
            }
        }
Beispiel #2
0
        void __focusIn(EventContext context)
        {
            if (!editable)
            {
                return;
            }

            _editing = true;

            if (_caret == null)
            {
                CreateCaret();
            }

            if (!string.IsNullOrEmpty(_promptText))
            {
                UpdateText();
            }

            float caretSize = UIConfig.inputCaretSize;

            _caret.SetSize(caretSize, textField.textFormat.size);
            _caret.DrawRect(0, Color.Transparent, textField.textFormat.color);
            AddChild(_caret);

            _selectionShape.Clear();
            AddChild(_selectionShape);

            if (!textField.Rebuild())
            {
                TextField.CharPosition cp = GetCharPosition(_caretPosition);
                AdjustCaret(cp);
            }

            IMEAdapter.compositionMode = IMEAdapter.CompositionMode.On;
            _composing = 0;
        }
        void __focusIn(EventContext context)
        {
            if (!Application.isPlaying)
            {
                return;
            }

            _editing        = true;
            _textBeforeEdit = _text;

            if (_caret == null)
            {
                CreateCaret();
            }

            if (!string.IsNullOrEmpty(_promptText))
            {
                UpdateText();
            }

            float caretSize;

            //如果界面缩小过,光标很容易看不见,这里放大一下
            if (UIConfig.inputCaretSize == 1 && UIContentScaler.scaleFactor < 1)
            {
                caretSize = UIConfig.inputCaretSize / UIContentScaler.scaleFactor;
            }
            else
            {
                caretSize = UIConfig.inputCaretSize;
            }
            _caret.SetSize(caretSize, textField.textFormat.size);
            _caret.DrawRect(0, Color.clear, textField.textFormat.color);
            _caret.visible = _editable;
            AddChild(_caret);

            _selectionShape.Clear();
            AddChildAt(_selectionShape, 0);

            if (!textField.Redraw())
            {
                TextField.CharPosition cp = GetCharPosition(_caretPosition);
                AdjustCaret(cp);
            }

            if (Stage.keyboardInput)
            {
                if (keyboardInput)
                {
                    Stage.inst.OpenKeyboard(_text, false, _displayAsPassword ? false : !textField.singleLine,
                                            _displayAsPassword, false, null, keyboardType, hideInput);

                    SetSelection(0, -1);
                }
            }
            else
            {
                if (!disableIME)
                {
                    Input.imeCompositionMode = IMECompositionMode.On;
                }
                else
                {
                    Input.imeCompositionMode = IMECompositionMode.Off;
                }
                _composing = 0;

                if ((string)context.data == "key") //select all if got focus by tab key
                {
                    SetSelection(0, -1);
                }

                TextInputHistory.inst.StartRecord(this);
            }
        }