Immediate-Mode-UI / Nuklear

A single-header ANSI C immediate mode cross-platform GUI library
https://immediate-mode-ui.github.io/Nuklear/doc/index.html
Other
9.16k stars 551 forks source link

Key repeat for nk_keys #639

Open PROP65 opened 4 months ago

PROP65 commented 4 months ago

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.

RobLoach commented 4 months ago

Nice work! Looking good... Adding delta time to the renders will help too https://github.com/Immediate-Mode-UI/Nuklear/pull/628

PROP65 commented 1 month ago

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"
...