cnjinhao / nana

a modern C++ GUI library
https://nana.acemind.cn
Boost Software License 1.0
2.3k stars 331 forks source link

Modality not working for classes derived from nana::form #647

Closed ashbob999 closed 2 years ago

ashbob999 commented 2 years ago

Having a class that is derived from nana::form, that is used as a modal window, it does not show the modal window and instantly closes it.

#include <nana\gui.hpp>
#include <iostream>

using namespace std;
using namespace nana;

class fm1 : public form
{
public:
    fm1() : form()
    {
        this->caption("form 1");
    }
};

class fm2 : public form
{
public:
    fm2(form parent) : form(parent)
    {
        this->caption("form 2");
    }
};

int main()
{
    fm1 fm;
    fm.events().click([&fm]
    {
        fm2 fm_modal(fm);   // does not work
        //form fm_modal(fm);    // does work

        fm_modal.modality();
        std::cout << "modal form was closed" << std::endl;
    });
    fm.show();

    exec();
}
ashbob999 commented 2 years ago

Nevermind, i should have passed the parent as a form&, the above made a copy which broke it.