nappgui_src icon indicating copy to clipboard operation
nappgui_src copied to clipboard

Windows require a panel and layout to make an OS menubar.

Open M0JXD opened this issue 6 months ago • 2 comments

Hi, I'm just starting to make an application and I thought I'd start making the menubar first. So my constructor function looked like this:

static App *i_create(void)
{
    App *app = heap_new(App);
    gui_respack(res_myapp_respack);
    gui_language("");
    app->window = window_create(ekWINDOW_STDRES);
    app->menu = myapp_menu_create();
    osapp_menubar(app->menu, app->window);
    window_OnClose(app->window, listener(app, i_OnClose, App));
    window_title(app->window, "myapp");
    window_origin(app->window, v2df(500, 200));
    window_show(app->window);
    return app;
}

The app kept segfaulting when it would enter osapp_menubar(). It turns out to apply a menubar to a window (at least on Linux where I'm developing, I imagine macOS might be different?) there must already be a panel (and subsequently a layout) attached to it. So this works:

static App *i_create(void)
{
    App *app = heap_new(App);
    Panel *panel = panel_create();
    Layout *layout = layout_create(0, 0);
    gui_respack(res_myapp_respack);
    gui_language("");
    app->window = window_create(ekWINDOW_STDRES);
    app->menu = myapp_menu_create();
    panel_layout(panel, layout);
    window_panel(app->window, panel);
    osapp_menubar(app->menu, app->window);
    window_OnClose(app->window, listener(app, i_OnClose, App));
    window_title(app->window, "myapp");
    window_origin(app->window, v2df(500, 200));
    window_show(app->window);
    return app;
}

While an app with only a menubar is pretty useless it had me baffled for a little while! I'm not sure whether this would be considered a bug/issue just in case someone really wants to make an app with only a menubar (which might be useful for something that does very simple processing?), as they'd run into the same issue.

M0JXD avatar Jun 08 '25 21:06 M0JXD

Hi @M0JXD

Although it's useless, NAppGUI supports creating a Window without an associated main panel. For consistency, it should also support an empty Window with a menu. Therefore, we consider this a bug.

On the other hand, NAppGUI always associates a menubar with the main Window. On platforms (such as macOS) where the menubar isn't docked to the window, NAppGUI will dock it to the application's global menu bar. However, we still require the window to keep the code portable.

frang75 avatar Jun 09 '25 13:06 frang75

Thanks for clarifying, I think this mostly a non-issue, I just wanted it logged so other people can find the solution if they've done the same as me, starting to develop the menubar first and wondering why things crash, but I'll leave the issue open if it should be fixed :)

M0JXD avatar Jun 09 '25 20:06 M0JXD