Add delete char callback
This commit is contained in:
parent
eb45f02afa
commit
1941060d4c
@ -51,7 +51,11 @@ static void onCursorPosCallback(GLFWwindow *window, double x, double y) {
|
||||
|
||||
static void onKeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods) {
|
||||
if(Input::isKeyboardCaptured()) {
|
||||
if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) Input::uncaptureKeyboardInput(kekData.activeKeyboardCapture.id);
|
||||
if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
|
||||
Input::uncaptureKeyboardInput(kekData.activeKeyboardCapture.id);
|
||||
}else if(key == GLFW_KEY_BACKSPACE && (action == GLFW_PRESS || action == GLFW_REPEAT)) {
|
||||
kekData.activeKeyboardCapture.callback(window, KEK_INPUT_DELETE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -101,17 +101,21 @@ GLFWCursorMode getCursorMode() {
|
||||
|
||||
KeyboardCapture captureKeyboardInput(KeyCharCallback callback, Callable uncaptureCallback) {
|
||||
KeyboardCapture id = nextID++;
|
||||
kekData.activeKeyboardCapture.id = id;
|
||||
kekData.activeKeyboardCapture.callback = callback;
|
||||
kekData.activeKeyboardCapture.uncaptureCallback = uncaptureCallback;
|
||||
kekData.activeKeyboardCapture = {
|
||||
id,
|
||||
callback,
|
||||
uncaptureCallback
|
||||
};
|
||||
return id;
|
||||
}
|
||||
|
||||
bool uncaptureKeyboardInput(KeyboardCapture capture) {
|
||||
if(capture == KEK_INVALID_ID || capture != kekData.activeKeyboardCapture.id) return false;
|
||||
kekData.activeKeyboardCapture.id = KEK_INVALID_ID;
|
||||
kekData.activeKeyboardCapture.callback = KeyCharCallback();
|
||||
kekData.activeKeyboardCapture.uncaptureCallback = Callable();
|
||||
kekData.activeKeyboardCapture = {
|
||||
KEK_INVALID_ID,
|
||||
KeyCharCallback(),
|
||||
Callable()
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -40,3 +40,5 @@
|
||||
|
||||
#define KEK_DEFAULT_FONT "font/MaredivRegular-yeg3.ttf"
|
||||
#define KEK_DEFAULT_FONT_SIZE_PIXELS 24
|
||||
|
||||
#define KEK_INPUT_DELETE -1u
|
||||
|
@ -23,7 +23,11 @@ void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods, v
|
||||
void onButtonClick(void *data) {
|
||||
Input::captureKeyboardInput(KeyCharCallback([](GLFWwindow *window, unsigned int codepoint, void *data) {
|
||||
std::u32string str = Unicode::convertStdToU32(button->text->getText());
|
||||
if(codepoint == KEK_INPUT_DELETE) {
|
||||
str = str.substr(0, str.length() - 1);
|
||||
}else {
|
||||
str.push_back(codepoint);
|
||||
}
|
||||
button->text->setText(Unicode::convertU32ToStd(str));
|
||||
}, nullptr), Callable());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user