Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attaching tags to widgets to distinguish widgets in event handlers #668

Open
SourceOfDeath opened this issue Oct 6, 2022 · 1 comment
Open

Comments

@SourceOfDeath
Copy link

let's say widgets are stored in a container like that:
vector<vector< unique_ptr<textbox> >> _someContainer;
registering an event handler:
_someContainer[var1][var2]->events().text_changed([](const nana::arg_textbox& texev)->void { //I can get a widget self texev.widget......; //but how can I get the indexes var1 and var2? })

In Delphi VCL (and Lazarus LCL) all widgets has .tag field of type integer. Does NANA have a mechanism of a similar purpose? Maybe use the tooltip string to store special information? Inherit from the desired class and add your own fields? I don't want to look through the entire container and compare pointers to find the desired widget. It looks silly. It is not advisable to perform cumbersome calculations in a frequently called handler. Does NANA have ready tools?

@ashbob999
Copy link

ashbob999 commented Oct 8, 2022

You could just add _someContainer, var1and var2 to the capture group of the lambda.

vector<vector< unique_ptr<textbox> >> _someContainer;
_someContainer[var1][var2]->events().text_changed([&_someContainer, var1, var2](const nana::arg_textbox& texev)->void {
    // now you have access to _someContainer, var1 and var2
    const auto& wdg = _someContainer[var1][var2];
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants