Skip to content
ModernUI A DaneTrades developer library

MuiRoot

MuiRoot is the root runtime object for a ModernUI panel.

It owns the active UI tree, routes chart events, runs timer-driven updates, manages layout/paint invalidation, owns the theme, handles scale/DPI settings, and tears the UI down during shutdown.

Every EA or indicator using ModernUI normally declares one root:

Reference excerpt
MuiRoot g_ui;

Include path

Reference excerpt
#include <ModernUI\ModernUI.mqh>

Minimal lifecycle

Full EA example
#property strict
#include <ModernUI\ModernUI.mqh>

MuiRoot g_ui;

int OnInit()
{
  if(!g_ui.Init(ChartID(),0,"MyUI_",512,16))
    return(INIT_FAILED);

  MuiPage *page=new MuiPage();
  page.Title("Demo");
  g_ui.SetRoot(page);

  EventSetMillisecondTimer(16);
  return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
  g_ui.Shutdown();
}

void OnTimer()
{
  g_ui.OnTimer();
}

void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
{
  g_ui.OnChartEvent(id,lparam,dparam,sparam);
}

Init

Reference excerpt
g_ui.Init(ChartID(),0,"MyUI_",512,16);

Common arguments:

Argument Meaning
ChartID() The chart to attach to
0 Chart subwindow index
"MyUI_" Object prefix for ModernUI chart objects
512 Logical width / canvas sizing baseline used by the root
16 Event queue reserve/capacity value used by examples

Use a unique object prefix per EA instance to avoid chart object name collisions.

SetRoot

SetRoot installs the UI tree.

UI build fragment
MuiPage *page=new MuiPage();
page.Title("Demo");
g_ui.SetRoot(page);

Fast wrappers such as Mui::AppWindow can call SetRoot for you.

Place inside OnInit after g_ui.Init succeeds
MuiAppWindow app=Mui::AppWindow(g_ui,"Panel",20,40,340,430,true);

OnTimer

Forward OnTimer() into the root.

Reference excerpt
void OnTimer()
{
  g_ui.OnTimer();
}

ModernUI uses timer-driven work to commit UI frames and keep canvas rendering predictable.

Most examples use:

Reference excerpt
EventSetMillisecondTimer(16);

OnChartEvent

Forward chart events into the root.

Reference excerpt
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
{
  g_ui.OnChartEvent(id,lparam,dparam,sparam);
}

Without chart event forwarding, pointer, keyboard, focus, hover, scroll, and overlay interactions will not work correctly.

Shutdown

Call Shutdown() in OnDeinit().

Reference excerpt
void OnDeinit(const int reason)
{
  g_ui.Shutdown();
}

This tears down the UI tree and lets native input hosts remove chart objects cleanly.

Refresh and layout updates

In day‑to‑day code prefer the friendly names.

Use RefreshAll() when something changed across the whole panel:

UI build fragment
g_ui.RefreshAll();

Use RefreshArea(...) when you know exactly which rectangle changed:

UI build fragment
MuiRect area;
area.x=20.0; area.y=20.0; area.w=120.0; area.h=24.0;
g_ui.RefreshArea(area);

Use Refresh() on a single control when only its visual state changed (text colour, hover, pressed, value):

UI build fragment
if(label!=NULL)
  label.Refresh();

When size, spacing, visibility or children changed, recalculate layout instead. Relayout() already schedules the redraw, so do not also call RefreshAll():

UI build fragment
if(panel!=NULL)
  panel.Relayout();

Friendly alias mapping

Friendly public method Existing/internal method Use it when
Refresh() (on control) InvalidateSelf() A control changed visually
Relayout() (on control) RequestLayoutSelf() Size, spacing, children or layout changed
g_ui.Refresh() / g_ui.RefreshAll() g_ui.Invalidate() The whole UI should redraw
g_ui.RefreshArea(r) g_ui.InvalidateRect(r) A known area changed
g_ui.Relayout() / g_ui.RelayoutAll() g_ui.RequestLayout() Structural changes across the panel
PaintBounds() internal/advanced Custom controls that draw outside their normal rectangle

The existing Invalidate* and RequestLayout* methods are kept for backwards compatibility. New code is encouraged to prefer the friendly names above.

Theme

Set a theme before building the UI where possible.

Place inside OnInit after g_ui.Init succeeds
MuiTheme theme=MuiTheme::Light();
theme.Dense(true);
g_ui.SetTheme(theme);

DPI and scale

ModernUI measures layout in logical units. By default, MuiRoot uses MUI_DPI_COMPENSATED, so Windows display scaling does not simply enlarge the whole panel.

Useful methods include:

Reference excerpt
g_ui.DpiMode(MUI_DPI_COMPENSATED);
g_ui.DpiMode(MUI_DPI_NATIVE);
g_ui.UiScale(1.10);
g_ui.SetScale(1.10);
g_ui.LogDpiDiagnostics();

Use SetScale when you want manual absolute scale.

Performance stats

Optional performance stats are exposed on MuiRoot.

Reference excerpt
g_ui.PerfStatsEnabled(true);
g_ui.PerfStatsReset();

string summary=g_ui.PerfStatsSummary();
int drops=g_ui.PerfStatsEventQueueDrops();

Use these for development and stress testing, not as precise micro-benchmarks.

Related pages