Skip to content

input: add keyboard and mouse input flags#217

Merged
RobLoach merged 25 commits into
masterfrom
fix/input-mouse-gamepad-key
May 31, 2026
Merged

input: add keyboard and mouse input flags#217
RobLoach merged 25 commits into
masterfrom
fix/input-mouse-gamepad-key

Conversation

@RobLoach
Copy link
Copy Markdown
Owner

Extends nk_console_input with nk_console_input_flags (NK_CONSOLE_INPUT_FLAG_GAMEPAD, _KEYBOARD, _MOUSE). New API: nk_console_input_set_flags(), nk_console_input_get_flags(), nk_console_input_set_keyboard_out(), nk_console_input_set_mouse_out(). The prompt text updates dynamically to reflect active sources; defaults to gamepad-only for backward compatibility. Fixes #16

@RobLoach RobLoach self-assigned this May 30, 2026
@RobLoach
Copy link
Copy Markdown
Owner Author

Add a demo case for this.

Comment thread nuklear_console_input.h Outdated
/**
* Set the keyboard output pointer. Called when a key is captured with NK_CONSOLE_INPUT_FLAG_KEYBOARD.
*/
NK_API void nk_console_input_set_keyboard_out(nk_console* widget, nk_rune* out_key);
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a nk_console_input_set_gamepad_out()... Should take all int gamepad_number, int* out_gamepad_number, enum nk_gamepad_button* out_gamepad_button.

Comment thread nuklear_console_input.h Outdated
* Use a bitwise OR of nk_console_input_flags values.
* Defaults to NK_CONSOLE_INPUT_FLAG_GAMEPAD.
*/
NK_API void nk_console_input_set_flags(nk_console* widget, nk_uint flags);
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking to add some helper constructors...

  • Add nk_console_input_gamepad() that just calls nk_console_input()
  • Add nk_console_input_key() that sets up the widget just for keyboard input
  • Add nk_console_input_mouse() that sets up the widget just for mouse input

Comment thread nuklear_console_input.h Outdated
Comment on lines +8 to +10
NK_CONSOLE_INPUT_FLAG_GAMEPAD = (1 << 0),
NK_CONSOLE_INPUT_FLAG_KEYBOARD = (1 << 1),
NK_CONSOLE_INPUT_FLAG_MOUSE = (1 << 2),
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use NK_FLAG() for NK_CONSOLE_INPUT_FLAG_GAMEPAD NK_CONSOLE_INPUT_FLAG_KEYBOARD and NK_CONSOLE_INPUT_FLAG_MOUSE

Comment thread nuklear_console_input.h
((nk_console_input_data*)widget->data)->out_key = out_key;
}

NK_API void nk_console_input_set_mouse_out(nk_console* widget, enum nk_buttons* out_mouse_button) {
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a helper methods that will check whether or not the selected output is a key, mouse button, or gamepad input devive.

nk_console_input_is_mouse()
nk_console_input_is_key()
nk_console_input_is_gamepad()

Comment thread nuklear_console_input.h
if (nk_input_is_mouse_released(&console->ctx->input, (enum nk_buttons)mi)) {
if (data->out_mouse_button != NULL) *data->out_mouse_button = (enum nk_buttons)mi;
nk_console_trigger_event(input, NK_CONSOLE_EVENT_CHANGED);
finished = nk_true;
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure the repesented key is presenteed nicely. Copy the nk_console_key_name() function over to nk_console_input_key_name(), and use it when rendering the widget.

Comment thread nuklear_console_input.h
@RobLoach RobLoach marked this pull request as draft May 30, 2026 15:33
@RobLoach RobLoach marked this pull request as ready for review May 30, 2026 18:40
Comment thread nuklear_console_input.h
data->out_gamepad_button = out_gamepad_button;
}

NK_API nk_bool nk_console_input_is_gamepad(nk_console* widget) {
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nk_console_input_is_gamepad and related functions return true wifbthe selected out variables were found to be the related input device.

Comment thread nuklear_console_input.h Outdated
}

NK_API nk_console* nk_console_input_gamepad(nk_console* parent, const char* label, int gamepad_number, int* out_gamepad_number, enum nk_gamepad_button* out_gamepad_button) {
return nk_console_input(parent, label, gamepad_number, out_gamepad_number, out_gamepad_button);
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a gamepad button, mouse button, or keyboard key are pressed, change the other out variables to NULL so that it's known which input device is chosen.

@RobLoach RobLoach marked this pull request as draft May 30, 2026 19:34
@RobLoach RobLoach marked this pull request as ready for review May 31, 2026 00:38
Comment thread nuklear_console_input.h Outdated
NK_API nk_console* nk_console_input_key(nk_console* parent, const char* label, nk_rune* out_key) {
nk_console* widget = nk_console_input(parent, label, -1, NULL, NULL);
if (widget == NULL) return NULL;
nk_console_input_set_keyboard_out(widget, out_key);
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename set_keyboard_out to set_key_out

Comment thread nuklear_console_input.h Outdated
for (ki = NK_KEY_NONE + 1; ki < NK_KEY_MAX; ki++) {
if (nk_input_is_key_released(&console->ctx->input, (enum nk_keys)ki)) {
if (data->out_key != NULL) *data->out_key = (nk_rune)ki;
data->out_gamepad_button = NULL;
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When clearing out the out_gamepad_button value, we should also clear out the gamepad_num

@RobLoach RobLoach marked this pull request as draft May 31, 2026 00:56
@RobLoach RobLoach marked this pull request as ready for review May 31, 2026 01:17
@RobLoach RobLoach merged commit 078fae8 into master May 31, 2026
1 check passed
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.

Widget: Input for Mouse, Gamepad, or Key

1 participant