Nuklear
This is a minimal-state, immediate-mode graphical user interface toolkit written in ANSI C and licensed under public domain. It was designed as a simple embeddable user interface for application and does not have any dependencies, a default render backend or OS window/input handling but instead provides a highly modular, library-based approach, with simple input state for input and draw commands describing primitive shapes as output. So instead of providing a layered library that tries to abstract over a number of platform and render backends, it focuses only on the actual UI.
 
Loading...
Searching...
No Matches
Input

The input API is responsible for holding the current input state composed of mouse, key and text input states.

It is worth noting that no direct OS or window handling is done in nuklear. Instead all input state has to be provided by platform specific code. This on one hand expects more work from the user and complicates usage but on the other hand provides simple abstraction over a big number of platforms, libraries and other already provided functionality.

while (GetEvent(&evt)) {
if (evt.type == MOUSE_MOVE)
nk_input_motion(&ctx, evt.motion.x, evt.motion.y);
else if (evt.type == [...]) {
// [...]
}
} nk_input_end(&ctx);
NK_API void nk_input_end(struct nk_context *)
End the input mirroring process by resetting mouse grabbing state to ensure the mouse cursor is not g...
NK_API void nk_input_begin(struct nk_context *)
Begins the input mirroring process by resetting text, scroll mouse, previous mouse position and movem...
NK_API void nk_input_motion(struct nk_context *, int x, int y)
Mirrors current mouse position to nuklear.

Usage

Input state needs to be provided to nuklear by first calling nk_input_begin which resets internal state like delta mouse position and button transitions. After nk_input_begin all current input state needs to be provided. This includes mouse motion, button and key pressed and released, text input and scrolling. Both event- or state-based input handling are supported by this API and should work without problems. Finally after all input state has been mirrored nk_input_end needs to be called to finish input process.

struct nk_context ctx;
nk_init_xxx(&ctx, ...);
while (1) {
Event evt;
while (GetEvent(&evt)) {
if (evt.type == MOUSE_MOVE)
nk_input_motion(&ctx, evt.motion.x, evt.motion.y);
else if (evt.type == [...]) {
// [...]
}
}
nk_input_end(&ctx);
// [...]
nk_clear(&ctx);
} nk_free(&ctx);
NK_API void nk_free(struct nk_context *)
Frees all memory allocated by nuklear; Not needed if context was initialized with nk_init_fixed.
NK_API void nk_clear(struct nk_context *)
Resets the context state at the end of the frame.

Reference

Function Description
nk_input_begin Begins the input mirroring process. Needs to be called before all other nk_input_xxx calls
nk_input_motion Mirrors mouse cursor position
nk_input_key Mirrors key state with either pressed or released
nk_input_button Mirrors mouse button state with either pressed or released
nk_input_scroll Mirrors mouse scroll values
nk_input_char Adds a single ASCII text character into an internal text buffer
nk_input_glyph Adds a single multi-byte UTF-8 character into an internal text buffer
nk_input_unicode Adds a single unicode rune into an internal text buffer
nk_input_end Ends the input mirroring process by calculating state changes. Don't call any nk_input_xxx function referenced above after this call