samcrow / rust-xplm

Rust interfaces to the X-Plane plugin SDK
Apache License 2.0
39 stars 15 forks source link

Menu module bug (PluginMenuClickHandler) #11

Closed Ev1dentSnow closed 2 years ago

Ev1dentSnow commented 2 years ago

I identified a bug with the menu module. It is impossible to assign a clickhandler to an ActionItem because the PluginMenuClickHandler's itemclicked function requires an ActionItem as an argument, and you can't pass that because the ActionItem hasn't been created yet. It's a circular thing.

Here is an example in an image image

Thus it raises the question. Would using the menuitem from here (plugin patterns library for c++) conflict with xplm-rust (cause you know how it's possible to use c++ in Rust)? Is it interoperable or should one switch to using C++ fully if they want to use menus?

https://github.com/PhilippMuenzel/PPL/blob/master/src/menuitem.cpp

I was thinking of making a PR with a Rust wrapper for that menuitem (and maybe even the whole menu module) because there's no point in reinventing the wheel

samcrow commented 2 years ago

I think you may be slightly misunderstanding the API. Assuming click_handler is something that implements MenuClickHandler, you normally don't need to call its item_clicked function directly. You should be able to just pass click_handler to ActionItem::new.

Yes, if you are not using the menu parts of this library, you can use any code you want to create menu items.

Because of the Rust borrowing rules, we may need to reinvent the wheel to make user-friendly Rust interfaces to the X-Plane plugin system. PPL is great for C++, but it does not fit with Rust very well.

Ev1dentSnow commented 2 years ago

Ah yes it was me misunderstanding it, my code compiles now. Thanks for explaining, I wish you all the best for the future of this project of yours, hopefully more X-Plane devs will see it and consider using Rust in the future!