frang75 / nappgui_src

SDK for building cross-platform desktop apps in ANSI-C
https://www.nappgui.com
MIT License
442 stars 43 forks source link

Window default button function placement dependency #109

Closed SamSandq closed 2 months ago

SamSandq commented 2 months ago

In my code I had the following, where dialogue is an layout with an OK button:

    ...
    panel_layout(panel, dialogue);
    window_defbutton(w, ok);        //DOES NOT WORK!
    window_panel(w, panel);
    window_title(w, "Funtus");
    window_origin(w, pos);
    ...

The ok button does not show up as a default button. However, if I write

    ...
    panel_layout(panel, dialogue);
    window_panel(w, panel);
    window_defbutton(w, ok);        //WORKS!
    window_title(w, "Funtus");
    window_origin(w, pos);
    ...

it works fine.

So the placement does matter. If it isn't a bug, it should be documented.

frang75 commented 2 months ago

Before window_panel(w, panel); your window is an empty container and window_defbutton() does nothing, because any button exists in the window. For this reason exists window_defbutton() and not button_set_default(). Really in both cases the SDK is working fine.

SamSandq commented 2 months ago

I accept that it is working, but... having made all the definitions before instantiating the window, it makes sense that the default button declaration/definition also would be taken into account when creating the window.

I believe a note to the effect that the call to window_defbutton(...) must be made after the window has been created should be added to the documentation.

frang75 commented 2 months ago

Added a tip in function documentation: https://nappgui.com/en/gui/window.html#f28