I suggest using this UIElement class for handling groups of UI elements:
https://github.com/UltraEngine/Extras/tree/main/Code/Utilities
This is how I handle all the major "areas" in the editor interface. You create a derived class and store variables for all the widgets you create in the class, then call Listen() to intercept the events you want to process in your ProcessEvent override.
Note that UIElement is not a widget, it is just a container for storing widgets and responding to events.
class MainPanel : public UIElement
{
public:
shared_ptr<Widget> panel, button;
bool Initialize(int x, int y, int width, int height, shared_ptr<Widget> parent)
{
panel = CreatePanel(x, y, width, height, parent);
button = CreateButton("TEST", 20, 20, 80, 30, panel);
Listen(EVENT_WIDGETACTION, button);
return true;
}
bool ProcessEvent(const Event& e)
{
if (e.id == EVENT_WIDGETACTION and e.source == button)
{
Print("PRESS");
return false;// stop processing this event
}
return true;// allow other hooks to process the event
}
};