Nuklear icon indicating copy to clipboard operation
Nuklear copied to clipboard

Each Enter or Backspace key press will repeat several times in GLFW.

Open AllenDang opened this issue 6 years ago • 4 comments

I'm using GLFW 3.3 with GL3 backend under MacOS v10.15.1.

In TextEditor, each Enter or Backspace key press will generate several key press events which makes the TextEditor nearly unusable.

I compiled nuklear with below defines:

    NK_INCLUDE_FIXED_TYPES: 1
    NK_INCLUDE_STANDARD_IO: 1
    NK_INCLUDE_DEFAULT_ALLOCATOR: 1
    NK_INCLUDE_VERTEX_BUFFER_OUTPUT: 1
    NK_INCLUDE_FONT_BAKING: 1
    NK_INCLUDE_DEFAULT_FONT: 1
    NK_KEYSTATE_BASED_INPUT: 1

How to fix it?

AllenDang avatar Dec 17 '19 10:12 AllenDang

This is probably related to https://github.com/Immediate-Mode-UI/Nuklear/pull/14, as before the PR when a mouse button was clicked, it wasn't consumed. I'm assuming the same is the case with keyboard input (I've not done anything related to editable text yet, so can't confirm this statement yet). The key is "down" in the nk_context even though it is already consumed by the text input, but will remain in that state until the key up event is called. This could potentially be solved the same way as mouse input; by adding a bool per key that is reset when the key is released and set when the key is consumed.

Nielsbishere avatar Dec 23 '19 16:12 Nielsbishere

Has this problem not been solved yet? I have the same problem windows + glfw3 + GL3

00BUG00 avatar Dec 02 '21 17:12 00BUG00

I think glfw might be the problem here. Nuklear uses glfw char callbacks for normal characters. Special characters like backspace and up key are not reported in the glfw char callback. So Nuklear uses glfwGetKey for all special characters, which is called every time nk_glfw3_new_frame() is called. And when special characters are held down, nk_edit_string() modifies the string in the textbox everytime that it is called.

Solutions: 1. #define NK_KEYSTATE_BASED_INPUT in your project this makes it so whenever you press down on a special key, the key is only reported once. But this means you cannot hold down backspace to delete a bunch of text. 2. make nuklear use key callback for all characters?
idk. I don't know much about nuklear and glfw. But I wanna try and help

telephone001 avatar May 15 '23 18:05 telephone001

@telephone001 thanks! We maintainers & devs are fully booked in our lifes so any help is highly appreciated.

dumblob avatar Jun 09 '23 17:06 dumblob