Steffen Posted January 15, 2018 Report Posted January 15, 2018 How do i attach a specific button/widget to a listener? Using gwinAttachListener will get me the events from the button but to my understanding also those from all other widgets which is a little impractical when there is a lot of them. I also found geventAttachSource but could not get this to work as i do not have a GSourceHandle for my button and using the GHandle did nothing. Some of the demo code used gwinGetButtonSource to do that but this function does not seem to exist anymore. What is the proper way to have only events from specific widgets on a listener?
inmarket Posted January 15, 2018 Report Posted January 15, 2018 No. You can however do a simple test for just the object you are after when you get an event. The source object is one of the fields in the gwin event structure.
Joel Bodenmann Posted January 15, 2018 Report Posted January 15, 2018 One thing that helps is using the widget tags. This way you can simply switch-case every widget based on an uint16_t that gets added to each widget. More information: https://wiki.ugfx.io/index.php/Widgets#Tag
Steffen Posted January 15, 2018 Author Report Posted January 15, 2018 Thanks, the tags in combination with the source object is what i ended up using and it worked out rather well thus far. One thing you could perhaps consider for future versions is to have a option to set user pointers for the tag rather than an u16. This would make it a lot more flexible and in some cases could even remove the need for additional switch cases (i.e directly calling a function pointer from there).
Joel Bodenmann Posted January 15, 2018 Report Posted January 15, 2018 Glad to hear that you managed to get it working! Thank you for your suggestion. This surely sounds interesting. I added as task to our ToDo list - we'll look into it.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now