This example demonstrates how widgets can be made into plugins.
Plugins are widgets that can be instantiated by a string. They can be loaded dynamically during runtime instead of having to be statically linked in.
In this example, we create a simple custom widget that modulates its background color as a function of time:
To create a plugin from the widget, we just need to use a simple macro:
This macro creates the data structures necessary to load the plugin. Basically, it creates a factory function that creates an instance of the SampleWidget when called. This factory function is automatically registered to the MultiWidgets::Plugins class. It can be instantiated with MultiWidgets::createPlugin function.
Full source code for the example is listed below: