Factory Helpers
ModernUI factory helpers live under the Mui::... namespace.
They create common controls and add them to a parent where appropriate.
Use factory helpers for normal UI construction. Use raw new plus Add when you need more control over construction, ownership, or layout.
Include path
#include <ModernUI\ModernUI.mqh>
The umbrella header includes the factory layer.
Factory style
Most helpers follow this shape:
parent first
then title/text/value/options
then optional advanced handler where applicable
then width and height
Examples:
MuiLabel *label=Mui::Label(parent,"Ready");
MuiButtonAction *button=Mui::Button(parent,"Save",NULL,160.0,0.0);
button.Id(PANEL_ACTION_SAVE);
MuiSpinEditHost *spin=Mui::SpinEdit(parent,0.1,10.0,1.0,0.1,1,NULL,220.0,0.0);
Parent-first creation
When you pass a parent, the helper normally adds the created control to that parent.
MuiButtonAction *button=Mui::Button(section.body,"Save",NULL,160.0,0.0);
When a helper needs a control that will be wrapped later, create it with parent == NULL.
MuiButtonAction *button=Mui::Button(NULL,"Run",NULL,120.0,0.0);
Mui::LabeledField(section.body,"Action",button,"");
Default sizes
A width or height of 0.0 usually means “use the defaultâ€.
Examples:
Mui::Button(parent,"Save",handler,160.0,0.0); // theme button height
Mui::TextBox(parent,"Default",0.0,0.0); // default width and theme input height
Mui::ComboBox(parent,items,0,0.0,0.0); // default combo size
Creation helpers vs setter helpers
Creation helpers build controls.
MuiLabeledSpinEdit risk=Mui::LabeledSpinEdit(section.body,"Risk %",0.1,10.0,0.1,1.0);
Setters customise the returned controls.
if(risk.control!=NULL)
{
risk.control.Value(2.0);
risk.control.AccentColor(0xFF2563EB);
}
Common helper groups
| Group | Examples |
|---|---|
| Text/display | Label, CaptionLabel, Badge, Alert, Progress |
| Actions | Button, ButtonPrimary, ButtonGhost, ButtonDanger, IconButton |
| Inputs | TextBox, TextArea, SpinEdit, ComboBox, DatePicker, ColorPicker |
| Data | ListView, TableView, TreeView, ListBox, SimpleTable |
| Layout/composition | AppWindow, Section, LabeledField, DrawerSection |
| Feedback | Toast, ToastSuccess, ToastWarning, ToastError, StatusRow |
| Navigation | Tabs, TabsFromNames, Accordion |
When to use raw controls
Use raw controls when:
- you need custom construction order
- you need a custom table/list/tree source
- you need to delay adding a control
- you need custom ownership rules
- a factory hides a detail you must configure before adding
- you are building a reusable composite control
Common mistakes
Passing a parent when you meant to wrap later
For LabeledField, create the child control with NULL parent.
Assuming all setters are chainable
ModernUI uses simple void setters. Call setters one line at a time.
Using factory helpers for everything
Factories are convenient, but raw controls remain the full-power path.
Related pages
- Factory helpers (reference) — per-helper signatures, return types, and examples
- Controls reference
- Fast wrapper types
- Setter naming
- Ownership and lifetime