diff --git a/src/kekengine/cpp/input/input.cpp b/src/kekengine/cpp/input/input.cpp index e28d739..3c67ed6 100644 --- a/src/kekengine/cpp/input/input.cpp +++ b/src/kekengine/cpp/input/input.cpp @@ -1,8 +1,10 @@ #include "input.h" +#include #include #include +#include "constants.h" #include "internal.h" #include "internal/input.h" @@ -31,8 +33,15 @@ void onKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mo return; } - if(key == GLFW_KEY_BACKSPACE && (action == GLFW_PRESS || action == GLFW_REPEAT)) { - kekData.input->activeKeyboardCapture.charCallback(KeyCharEvent{window, KEK_INPUT_DELETE}); + if(action == GLFW_PRESS || action == GLFW_REPEAT) { + switch(key) { + case GLFW_KEY_BACKSPACE: + kekData.input->activeKeyboardCapture.charCallback(KeyCharEvent{window, KEK_INPUT_DELETE}); + break; + case GLFW_KEY_DELETE: + kekData.input->activeKeyboardCapture.charCallback(KeyCharEvent{window, KEK_INPUT_DELETE_FORWARD}); + break; + } } kekData.input->activeKeyboardCapture.keyCallback(KeyEvent{window, key, scancode, action, mods}); diff --git a/src/kekengine/cpp/ui/uielements.cpp b/src/kekengine/cpp/ui/uielements.cpp index ed07439..6a875f5 100644 --- a/src/kekengine/cpp/ui/uielements.cpp +++ b/src/kekengine/cpp/ui/uielements.cpp @@ -266,11 +266,19 @@ void TextFieldElement::focusEnter() { TextFieldElement *_this = (TextFieldElement *) data; std::u32string str = Unicode::convertStdToU32(_this->text); - if(event.codepoint == KEK_INPUT_DELETE) { - if(_this->cursorPos == str.length()) return; - str = str.erase(str.length() - _this->cursorPos - 1, 1); - } else { - str.insert(str.length() - _this->cursorPos, 1, event.codepoint); + switch(event.codepoint) { + case KEK_INPUT_DELETE: + if(_this->cursorPos == str.length()) return; + str = str.erase(str.length() - _this->cursorPos - 1, 1); + break; + case KEK_INPUT_DELETE_FORWARD: + if(_this->cursorPos == 0) return; + str = str.erase(str.length() - _this->cursorPos, 1); + _this->cursorPos--; + break; + default: + str.insert(str.length() - _this->cursorPos, 1, event.codepoint); + break; } _this->lastCharTyped = glfwGetTime(); @@ -337,5 +345,4 @@ void TextFieldElement::setText(std::string text) { this->cursorPos = 0; updateText(Unicode::convertStdToU32(text)); } - } diff --git a/src/kekengine/include/constants.h b/src/kekengine/include/constants.h index 8f8fcab..d57cbd6 100644 --- a/src/kekengine/include/constants.h +++ b/src/kekengine/include/constants.h @@ -42,6 +42,7 @@ #define KEK_DEFAULT_FONT_SIZE_PIXELS 24 #define KEK_INPUT_DELETE -1u +#define KEK_INPUT_DELETE_FORWARD -2u #define KEK_PLAYER_HEIGHT 2 #define KEK_PLAYER_RADIUS 0.5f