Wrapper for dynamically loaded plugins that can have their own Ui! #7101
Closed
zanciks
started this conversation in
Show and tell
Replies: 1 comment
-
|
I've only now realized what I fool I was :P |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey all! I've recently been working on an app, and I'm using egui/eframe. However, one requirement of my app was that it must have dynamically linked runtime plugins, and those plugins have to be able to modify the ui/have their own ui.
I believe I've found a solution for this, and figured I'd share it.
Before I paste a ton of code that you might skip over, I mention this here because I am considering moving the plugin/wrapper code into their own crates, so that people can import them and use it themselves. However, this will be a lot of work, as I have to write wrappers for a lot of egui structs/functions, so I am curious if others would be interested in this.
Inside of the host app, I have
main.rsandplugin_instance.rs. There are some other files, but nothing relevant to this topic. Inside ofplugin_instance.rsis, well, a PluginInstance struct.I'm using *mut c_void as pointers to Plugins, which for now, are just structs that:
First, I'll show off the crate with the Plugin trait, and how that works, since it's the most interesting part of this all.
Currently, this crate only has a
plugin.rs,lib.rs, and aui.rs. Plugin.rs looks like this:As you can see, it's a very simple trait at the moment. There may be more requirements in the future, but this is all that I have implemented. More interestingly, we have
ui.rs!This means that, while it would be a lot of work, one could implement wrapper functions for all egui Ui functions that are important to them (along with wrapper structs for things like Response, Grid, Layout, etc)!
Now, to put it to use, I have a little template plugin here:
Then we just load the plugin in our main app using libloading (or anything else, if you prefer).
Thanks for reading, and please let me know if you have any thoughts, or if you would find runtime plugins for egui useful!
Beta Was this translation helpful? Give feedback.
All reactions