Skip to content

input: add keyboard and mouse input flags#217

Open
RobLoach wants to merge 2 commits into
masterfrom
fix/input-mouse-gamepad-key
Open

input: add keyboard and mouse input flags#217
RobLoach wants to merge 2 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
/**
* 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
* 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
#define NK_CONSOLE_INPUT_H__

/**
* Flags that control which input sources are accepted by an input 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.

In the doxygen docs of nk_console_input_flags, add @see nk_console_input()

@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
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