Esempio n. 1
0
            private InputFieldCaretState ProcessInput(Entity inputFieldEntity, DynamicBuffer <KeyboardInputBuffer> inputBuffer,
                                                      DynamicBuffer <TextData> textData, InputFieldCaretState caretState, int chunkIndex)
            {
                for (int i = 0; i < inputBuffer.Length; i++)
                {
                    var key = inputBuffer[i];
                    if (key.EventType == KeyboardEventType.Key)
                    {
                        switch ((KeyCode)key.KeyCode)
                        {
                        case KeyCode.Backspace:
                            if (caretState.CaretPosition > 0)
                            {
                                textData.RemoveAt(caretState.CaretPosition - 1);
                                caretState.CaretPosition--;
                            }
                            break;

                        case KeyCode.LeftArrow:
                            caretState.CaretPosition = math.max(0, caretState.CaretPosition - 1);
                            break;

                        case KeyCode.RightArrow:
                            caretState.CaretPosition = math.min(textData.Length, caretState.CaretPosition + 1);
                            break;

                        case KeyCode.Home:
                            caretState.CaretPosition = 0;
                            break;

                        case KeyCode.End:
                            caretState.CaretPosition = textData.Length;
                            break;

                        case KeyCode.Return:
                        case KeyCode.KeypadEnter:
                            CommandBuff.AddComponent(chunkIndex, inputFieldEntity, new InputFieldReturnEvent());
                            return(caretState);
                        }
                    }
                    else
                    {
                        textData.Insert(caretState.CaretPosition, new TextData()
                        {
                            Value = key.Character
                        });
                        caretState.CaretPosition++;
                    }
                }
                return(caretState);
            }
Esempio n. 2
0
            private InputFieldCaretState ProcessPointerInput(Entity inputFieldEntity, DynamicBuffer <PointerInputBuffer> pointerInputBuffer, DynamicBuffer <TextData> textData, InputFieldCaretState caretState, int chunkIdx)
            {
                for (int i = 0; i < pointerInputBuffer.Length; i++)
                {
                    var pointerEvent = pointerInputBuffer[i];
                    if (pointerEvent.EventType == PointerEventType.Selected)
                    {
                        caretState.CaretPosition = textData.Length;
                        CommandBuff.AddComponent(chunkIdx, inputFieldEntity, new InputFieldCaretEntityLink()
                        {
                            CaretEntity = CreateCaret(inputFieldEntity, chunkIdx)
                        });
                        //CommandBuff.RemoveComponent(chunkIdx, caretState.CaretEntity, typeof(Disabled));
                    }

                    if (pointerEvent.EventType == PointerEventType.Click)
                    {
                    }

                    if (pointerEvent.EventType == PointerEventType.Deselected)
                    {
                        CommandBuff.AddComponent(chunkIdx, inputFieldEntity, new InputFieldEndEditEvent());
                        if (InputFieldCaretLinkFromEntity.Exists(inputFieldEntity))
                        {
                            CommandBuff.DestroyEntity(chunkIdx, InputFieldCaretLinkFromEntity[inputFieldEntity].CaretEntity);
                            CommandBuff.RemoveComponent(chunkIdx, inputFieldEntity, typeof(InputFieldCaretEntityLink));
                        }
                        CommandBuff.AddComponent(chunkIdx, inputFieldEntity, new DirtyElementFlag());
                    }
                }

                return(caretState);
            }