For all the plugins I’ve written and read, the module is the common space between widgets. So if you want widget a to change widget b you modify the param bound to b in response to the param change on a in your module ::process
If you want ui to ui changes it’s not hard - you can subclass widgets easily and get the events - but most folks have not done that afaics and I have not had to in my code.
That’s exactly what I’d like to avoid, but thanks.
I’m looking for a simple propagation-flow pattern.
Not sure what you mean with “subclass and get events”.
Let say I have my CustomButton: once I click on it (i.e. onMouseDown) I set a flag “clicked” on true, and from that time every CustomKnobs need to draw some stuff, until I re click on it (re setting the flag on false).
I don’t want to create an array and get the pointers of each knobs, iterating it later every time I mouse down.
Event Emitter is useful for these purposes, but I still need that object on Module class; otherwise, every time I create a Knob/Button, I should pass the EventEmitter reference to it…
Of course… but I need to pass “MyModule” instance on every widget. So every time I addParam, I need to get the instance of the widget being created and pass to it the module pointer. Thats the “Array” part.
Dynamic_cast if you want - you will get your class
Make an alternate constructor for your widget which is bound to your class if you prefer and use that instead of createParam
Or inject your own base classes into the hierarchy. So make a ‘MyModuleBase : engine::Module` and then have all your modules inherit that etc… and then static cast safely to that base (with null checks)
Or make a constructor which takes a lambda and bind to the module at construction time
All options which would work. AddParam just takes a ParamWidget* (addChild takes a Widget* if you don’t need param); the createParam constructor is a convenience but you can read the code and use other creation paths if you want.
You can also make a common widget base class if you want in your project (which may be what you want I think). So make a ‘MyModuleWidget : ModuleWidget’ and have it have a method like ‘Bus *getBus()’ where ‘Bus *’ is an instance of the communication bus thing you sketched out.
Then for each of your widgets have them implement something like ‘Busable’ interface. So you then write
Struct myWidget : app::WhateverWidget, Busable
Then in your module code you can do
Auto wid = createParam<MyWidget>(...)
You get the idea (sorry for the bad autocorrect - I’m on an ipad). Then you are entirely in widget space, you don’t have to reference module, and you use the parent ModuleWidget as the holder for your inter communication bus. I think that’s the pattern you are looking for.
Like I said, I haven’t seen someone need or use that pattern exactly like that. Most things seem module intermediated. But if you want non-module-intermediated widget converasation I think you will end up with a solution like that (just not in gross pseudocode)