Root and Events
ModernUI is hosted inside an MT5 EA or indicator. MT5 owns the lifecycle. ModernUI works when you forward the correct entry points into MuiRoot.
The recommended EA pattern is one main panel class that owns MuiRoot and forwards native entry points through class methods.
OnInit
-> m_ui.Init
-> m_ui.SetEventSink
-> build UI tree
-> EventSetMillisecondTimer
OnTimer
-> m_ui.OnTimer
OnChartEvent
-> m_ui.OnChartEvent
OnDeinit
-> m_ui.Shutdown
Full skeleton
#property strict
#include <ModernUI\ModernUI.mqh>
class CPanel : public MuiEventSink
{
private:
MuiRoot m_ui;
public:
ENUM_INIT_RETCODE OnInitEvent(void)
{
if(!m_ui.Init(ChartID(),0,"MyUI_",512,16))
return INIT_FAILED;
m_ui.SetEventSink((MuiEventSink*)GetPointer(this));
CreateGUI();
EventSetMillisecondTimer(16);
return INIT_SUCCEEDED;
}
void OnDeinitEvent(const int reason) { EventKillTimer(); m_ui.Shutdown(); }
void OnTimerEvent(void) { m_ui.OnTimer(); }
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
{
m_ui.OnChartEvent(id,lparam,dparam,sparam);
}
void CreateGUI(void)
{
MuiAppWindow app=Mui::AppWindow(m_ui,"Panel",20,40,320,240,true);
Mui::Label(app.content,"Ready");
}
virtual void OnMuiEvent(MuiRoot &root,const MuiEventData &event)
{
}
};
Why SetEventSink matters
SetEventSink(...) connects app-level ModernUI events to your panel class.
Without it, controls can still render and route internal pointer state, but your OnMuiEvent(...) method will not receive button clicks, value changes, checkbox changes, confirms, or drawer state events.
Why OnTimer matters
OnTimer() lets ModernUI process scheduled frame work and commit canvas pixels.
Why OnChartEvent matters
Forward chart events so ModernUI can process mouse, keyboard, hover, drag, scroll, wheel, chart size, and chart change events.
Without event forwarding, controls may render but not behave correctly.
Why Shutdown matters
Shutdown() tears down the UI tree and lets native hosts remove chart objects.
Init order
Use this order:
- call
m_ui.Init - call
m_ui.SetEventSinkif using app-level events - set theme/scale if needed
- build UI
- start the timer