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

Ability to change window title? #108

Closed StrikerMan780 closed 1 week ago

StrikerMan780 commented 2 months ago

Apologies for asking so many questions, but is there a way to change the window title while you switch between pages in a menu? Wanting to have the title bar change as one switches through the Main Menu, Options, Save/Load, etc.

RobLoach commented 2 months ago

Use nk_console_render_window() instead and change the title paraameter?

const char* title = "Window Title"; 
nk_console_render_window(console, title, nk_rect(0, 0, (float)screen->width, (float)screen->height), NK_WINDOW_TITLE);

nk_console_render() is meant to be used within a nk_begin()/end(), where as render_window takes control over the nk_begin stuffs.

StrikerMan780 commented 2 months ago

I mean, that's what I'm using (I was never using nk_console_render on its own to begin with), but the menu setup is only done once at program init, so I'm wondering how I'm going to make it pass the title to it as it switches between menus. Perhaps an event for when you transition between menus is in order?

nk_console_render_window(console, title, nk_rect(menu_x, menu_y - (scale_y(300, 480) / 2.0f), menu_width, scale_y(300, 480)), NK_WINDOW_TITLE | NK_WINDOW_BORDER);

This is what my Init function looks like:

    // Init Console
    console = nk_console_init(&ctx);
    nk_console_button_onclick(console, "New Game", UIFunc_NewGame);

    nk_console_button(console, "Load Game");
    nk_console_button(console, "Save Game");

    nk_console_button(console, "Multiplayer");
    nk_console* options = nk_console_button(console, "Options");
    {
        nk_console_button(options, "Game Options");
        nk_console_button(options, "Video Options");
        nk_console_button(options, "Sound Options");
        nk_console_button(options, "Controls");
        nk_console_button_onclick(options, "Back", nk_console_button_back);
    }
    nk_console_button(console, "Instructions");
    nk_console_button(console, "Editor");

    nk_console* quitmenu = nk_console_button(console, "Quit");
    {
        nk_console_label(quitmenu, "Are you sure?");
        nk_console_button_onclick(quitmenu, "Yes", UIFunc_QuitGame);
        nk_console_button_onclick(quitmenu, "No", nk_console_button_back);
    }
StrikerMan780 commented 2 months ago

Hmm, I got around it by setting up an onclicked event, which sets the parent menu itself, and sets the title variable to the label of the button. Also wrote a wrapper to the back function that sets the title to the parent menu label.

EDIT: Though, I just realized, that doesn't account for the backspace key or B button on the controller. An event/callback is looking to be even more appealing. One that gives you a pointer to the menu you're switching to. (And some way to differentiate if you're going forwards or back would be nice, so I can use that to play different sounds for those transitions)

EDIT2: Did this, which I call from the menu loop. Hopefully it isn't too slow:

void UI_CheckMenuChange()
{
    nk_console* activeParent = nk_console_active_parent(console);
    if (activeParent == NULL)
        return;

    if (activeParent != currentMenu)
    {
        if (activeParent == currentMenu->parent)
        {
            playSFX("laser3.wav");
        }
        else
        {
            playSFX("beep.wav");
        }
        currentMenu = activeParent;
        tfury_menu_title = activeParent->label;
    }
}
RobLoach commented 2 months ago

pew pew pew pew pew pew pew pew pew BEEP!

RobLoach commented 1 week ago

Sounds like you got it fixed up. Thanks!