Buttons
Buttons are used for actions, command rows, icon tools, and segmented choices.
Controls And Helpers
| Control/helper | Use it for | Emits events |
|---|---|---|
MuiButton |
Base clickable button control. | MUI_EVENT_CLICK |
MuiButtonAction |
Button class returned by most friendly button helpers. | MUI_EVENT_CLICK |
Mui::Button |
Standard text button. | MUI_EVENT_CLICK through returned button ID |
Mui::ButtonPrimary |
Primary action button. | MUI_EVENT_CLICK |
Mui::ButtonGhost |
Low-emphasis action button. | MUI_EVENT_CLICK |
Mui::ButtonDanger |
Destructive or risky action. | MUI_EVENT_CLICK |
Mui::IconButton |
Icon-only action. | MUI_EVENT_CLICK |
Mui::ButtonIcon |
Text button with icon. | MUI_EVENT_CLICK |
Mui::ButtonRow |
Row of independent action buttons. | Each button emits MUI_EVENT_CLICK when assigned an ID |
Mui::ButtonGroup |
Mutually exclusive segmented choices. | Button clicks through contained buttons |
Event Fields
For button clicks, read:
| Field | Meaning |
|---|---|
event.ControlId() |
The button action ID assigned with .Id(...). |
event.Text() |
Button text. |
event.Value() |
Optional UserValue(...) payload. |
event.Argb() |
First UserArgb(...) payload. |
event.Sender() |
Button element. Cast to read UserArgb2() when two ARGB payloads were stored with .UserArgb(argb1, argb2). |
MuiButtonAction
Purpose
MuiButtonAction is the button class returned by Mui::Button, Mui::ButtonPrimary, Mui::IconButton, and related factory helpers. It extends MuiButton with an optional owned MuiClickHandler for legacy callbacks.
For new EA panels, prefer the event bus: assign .Id(...), pass NULL for the handler argument on factory helpers, and handle MUI_EVENT_CLICK in OnMuiEvent(...).
Source: Include/ModernUI/Core/UI.mqh (subclass of MuiButton in Controls/Inputs/Button.mqh).
Create It
Recommended factory helpers (handler NULL when using the event bus):
MuiButtonAction *save=Mui::ButtonPrimary(parent,"Save",NULL);
save.Id(APP_ACTION_SAVE);
MuiButtonAction *reset=Mui::Button(parent,"Reset",NULL);
reset.Id(APP_ACTION_RESET);
MuiButtonAction *close=Mui::IconButton(parent,MUI_ICON_CLOSE,NULL);
close.Id(APP_ACTION_CLOSE);
Other Mui:: helpers that return MuiButtonAction*: ButtonGhost, ButtonDanger, ButtonIcon, ButtonIconAlign.
Bounds-based creation via MuiCreate::Button / MuiCreate::IconButton also constructs MuiButtonAction internally and returns MuiButton*.
Direct construction:
MuiButtonAction *b=new MuiButtonAction();
b.Text("Apply");
b.Kind(MUI_BUTTON_PRIMARY);
parent.Add(b);
b.Id(APP_ACTION_APPLY);
Events
App-level events reach OnMuiEvent(...) only when the control has .Id(...) set to a non-negative value. See Event Bus.
| Event | When it fires | Useful fields |
|---|---|---|
MUI_EVENT_CLICK |
Primary click, or Enter/Space while the button is focused | ControlId(), Text() (button label), Value() (UserValue()), Argb() (UserArgb1()), Sender() (for UserArgb2() or control-specific reads) |
Optional legacy path: SetHandler(MuiClickHandler*) / OnClick(handler) runs after the base click logic and does not replace the event bus when an ID is assigned.
Common Setters
Inherited from MuiButton unless noted.
| Setter | Purpose |
|---|---|
.Id(...) |
App-level routing ID for MUI_EVENT_CLICK. |
.Text(...) / .text |
Button label. |
.Kind(...) |
Visual variant: MUI_BUTTON_DEFAULT, MUI_BUTTON_PRIMARY, MUI_BUTTON_GHOST, MUI_BUTTON_DANGER. |
.Icon(...), .IconOnly(...), .IconLeft(...), .IconRight(...), .IconPosition(...), .IconSize(...), .IconColor(...) |
Built-in semantic icon layout and colour. |
.ClearIcon() |
Removes icon. |
.SetFixedSize(w, h) |
Fixed width/height; height 0 uses theme button height on Mui:: helpers. |
.FullWidth(...), .Flex(...), .Margin(...), .Pad(...), .Radius(...) |
Layout and chrome. |
.Align(h, v) |
Text/icon alignment inside the button. |
.SizePt(...) |
Font size override. |
.UserValue(...) |
Numeric payload copied to event.Value() on click. |
.UserArgb(argb1, argb2) |
Colour payloads; event.Argb() receives argb1. |
.Enabled(...), .Visible(...) |
Interaction and visibility. |
.SetHandler(...) / .OnClick(handler) |
Legacy owned click handler (MuiButtonAction only). |
Common Reads
| Getter | Purpose |
|---|---|
.Text() / .text |
Current label. |
.Kind() |
Current button kind. |
.IconKind(), .IconSize(), .IconColorArgb() |
Icon state. |
.UserValue(), .UserArgb1(), .UserArgb2() |
Payloads attached for the next click event. |
.Id() |
Assigned event ID. |
.Enabled(), .Visible() |
State. |
Notes
MuiButton(base class) performs the actual click painting and emitsMUI_EVENT_CLICK;MuiButtonActionadds handler ownership only.- Keyboard: Enter and Space activate a focused button the same way as a click.
Mui::ButtonRowandMui::ButtonGroupcontainMuiButtonActioninstances; assign.Id(...)on each button you want on the event bus (see Factory helpers (reference)).
Example
enum PANEL_ACTION
{
PANEL_ACTION_SAVE,
PANEL_ACTION_RESET
};
class CMyPanel : public MuiEventSink
{
private:
MuiRoot m_ui;
MuiButtonAction *m_bSave;
MuiButtonAction *m_bReset;
public:
void Build(MuiContainer *parent)
{
m_bSave=Mui::ButtonPrimary(parent,"Save",NULL);
m_bSave.Id(PANEL_ACTION_SAVE);
m_bSave.UserValue(1.0);
m_bReset=Mui::Button(parent,"Reset",NULL);
m_bReset.Id(PANEL_ACTION_RESET);
}
virtual void OnMuiEvent(MuiRoot &root,const MuiEventData &event)
{
if(event.EventId()!=MUI_EVENT_CLICK)
return;
if(event.ControlId()==PANEL_ACTION_SAVE)
Mui::ToastSuccess(root,"Saved");
else if(event.ControlId()==PANEL_ACTION_RESET)
m_bReset.Enabled(false);
}
};
Related
- Buttons guide
- Event Bus
- Factory helpers (reference) —
Mui::Button,Mui::ButtonRow,Mui::ButtonGroup