Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key repeat for nk_keys #639

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Conversation

PROP65
Copy link
Contributor

@PROP65 PROP65 commented May 9, 2024

Adds key repeat for nk_keys (Arrows, Home, End, Backspace, Delete, etc).

The default delay and interval can be changed, as well as updated at runtime.

/* send 20 inputs per second after a key has been held for 1/3 of a second */
#define NK_INPUT_REPEATER_DELAY 0.33f
#define NK_INPUT_REPEATER_INTERVAL 0.05f
#define NK_KEY_REPEAT
#include "nuklear.h"

...

struct nk_context ctx;
nk_init_default(&ctx, 0);
/* update at runtime, 10 inputs per second after 0.4 seconds */
ctx.input.keyboard.repeater_delay    = 0.40f;
ctx.input.keyboard.repeater_interval = 0.10f;

Tested and working with the following render backends.

  • glfw_opengl2
  • glfw_opengl3
  • glfw_vulkan

@RobLoach
Copy link
Contributor

Nice work! Looking good... Adding delta time to the renders will help too #628

src/nuklear.h Outdated Show resolved Hide resolved
@PROP65
Copy link
Contributor Author

PROP65 commented Aug 30, 2024

I've reworked this patch to make the key repeat functionality more generic/reusable.
Most of the changes have been moved to nuklear_input.c and a new function is provided (nk_input_is_key_fired) to check the new boolean.

After submitting this pull request I realized some backends have key repeat via their abstraction layer (SDL, X11, etc) so this functionality is also now opt-in and can be enabled by defining NK_KEY_REPEAT before including Nuklear

...
#define NK_KEY_REPEAT
#include "nuklear.h"
...

@PROP65 PROP65 requested a review from RobLoach September 4, 2024 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants