RobLoach / nuklear_console

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

Any way to disable nuklear_gamepad dependency? (I have my own controller implementation I'd like to pass forward to it) #106

Open StrikerMan780 opened 1 week ago

StrikerMan780 commented 1 week ago

Is there a way to disable the dependency on nuklear_gamepad? I have my own controller implementation, that I'd like to get the input for nuklear_console from.

RobLoach commented 1 week ago

Been curious about easing the dependency too. But in the mean time, you are able to implement your own custom gamepad input source. Something like this....

#define NK_GAMEPAD_NONE
#define NK_GAMEPAD_IMPLEMENTATION
#include "nuklear_gamepad.h"

void custom_gamepad_update(struct nk_gamepads* gamepads, void* user_data) {
    // Indicate that the left button is down for gamepad 0
    nk_gamepad_button(gamepads, 0, NK_GAMEPAD_BUTTON_LEFT, nk_true);
}

int main() {
  struct nk_gamepad_input_source input_source = {
    .update = &custom_gamepad_update
  };

  struct nk_gamepads gamepads;
  nk_gamepad_init_with_source(&gamepads, ctx, input_source);

  nk_console_set_gamepads(console, &gamepads);
}

Which platform are you using? I'd love to add more options for input sources to ease integrations.

StrikerMan780 commented 1 week ago

I'm using SDL2 as a base, but I have my own event loop for it, and a custom key->action remapping system so people can bind multiple keys and devices to the same action, among other things. I noticed that nuklear_console responds to the keyboard inputs in my loop, so I'm guessing if I just have my joystick handler send NK_KEY_UP/DOWN/LEFT/RIGHT inputs, I'll be set?

Also, thanks for replying, I appreciate it. I've been trying to get help with Nuklear itself in the main Nuklear repo, but nobody seems to reply there, making me feel like I'm up a creek without a paddle. This gives me some hope, though.

Case in point: https://github.com/Immediate-Mode-UI/Nuklear/issues/646 Might want to look at this, since it's relevant to, and affects nuklear_console quite severely.