RobLoach / nuklear_console

Console-like user interface for Nuklear with gamepad, keyboard or mouse support
https://robloach.github.io/nuklear_console/
MIT License
13 stars 3 forks source link

Abstraction for nuklear_gamepad #19

Closed RobLoach closed 4 months ago

RobLoach commented 5 months ago

https://github.com/RobLoach/nuklear_gamepad

RobLoach commented 5 months ago

Hmmm, I'm unsure about this... But perhaps making it easier to include?

brianwatling commented 5 months ago

I've just started using nuklear_console and found that I want to disable a good chunk of nuklear_gamepad by defining NK_GAMEPAD_NONE before the implementation. That let's me build an abstraction layer between grabbing physical input and telling nuklear_console what action to perform (basically the ability to do remapping like what Steam Input does). For example, I might have an "up" mapped to the "w" key which fakes NK_GAMEPAD_BUTTON_UP like in the following abbreviated code:

nk_gamepad_button(..., NK_GAMEPAD_BUTTON_UP, action_up.is_active)
nk_gamepad_button(..., NK_GAMEPAD_BUTTON_DOWN, action_down.is_active)
...

Perhaps nuklear_console should have an abstraction layer of it's own and let users send actions in rather than directly reading a gamepad. Some of the actions I've seen in nuklear_console are up, down, page down, page up, back, select - not sure yet if there's more. There could be a helper utility to easily connect nuklear_gamepad for simple cases where controller input should be mapped directly

RobLoach commented 5 months ago

That's a nice idea. You'll see most of the logic for the buttons over in nk_console_button_pushed()... https://github.com/RobLoach/nuklear_console/blob/master/nuklear_console.h#L541-L544

I'd really like a Gamepad API in Nuklear itself, but I'm unsure the best way to do that.

RobLoach commented 4 months ago

Fixed in https://github.com/RobLoach/nuklear_console/commit/145b9e8f141652d0fdd8ee89076a7ef645bd7493 .

#define NK_CONSOLE_GAMEPAD_IS_BUTTON_PRESSED MyOwnButtonPressed(gamepads, index, button)