Add forward delete to TextFieldElement
This commit is contained in:
parent
bbee789593
commit
638c716507
@ -1,8 +1,10 @@
|
||||
#include "input.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#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});
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user