Elements

Button

A clickable button element that can contain child elements. Extends Group functionality.

Constructor

new Button(new Label("Click me"));
new Button(new Image(texture), new Label("Icon Button"));

Examples

Click Event Handling

Buttons handle click events:

new Button(new Label("Save"))
    .OnClick(_ => SaveDocument());

new Button(new Label("Delete"))
    .OnClick(_ => DeleteItem())
    .BindDisabled(IsDeleting);

Reactive Content

Button content can be bound to reactive properties:

// Button text bound to property
new Button(new Label().BindText(ButtonText));

// Icon + Text with reactive visibility
new Button(
    new Image("Icons/download").BindVisible(ShowIcon),
    new Label().BindText(ButtonLabel)
);

// Loading state example
new Button(
    new HorizontalGroup(
        new Loader().BindVisible(IsLoading),
        new Label().BindText(IsLoading.Select(loading =>
            loading ? "Saving..." : "Save"))
    )
).BindDisabled(IsLoading);

State Management

Buttons can reactively respond to state:

new Button(new Label("Submit"))
    .ClassName("primary-button")
    .BindDisabled(IsSubmitting)
    .BindVisible(CanSubmit)
    .BindClassName("loading", IsSubmitting)
    .OnClick(_ => SubmitForm());

Properties

PropTypeDefault
children?
IElement[]
[]
disabled?
bool
false
visible?
bool
true
name?
string
""
pickingMode?
PickingMode
PickingMode.Position

Methods

PropTypeDefault
OnClick?
(EventCallback<ClickEvent>) => Button
-
Disabled?
(bool = true) => Button
-
GetDisabled?
() => bool
-
BindDisabled?
(Observable<bool>) => Button
-
Visible?
(bool) => Button
-
GetVisible?
() => bool
-
BindVisible?
(Observable<bool>) => Button
-
ClassName?
(string, bool = true) => Button
-
BindClassName?
(string, Observable<bool>) => Button
-
StyleSheet?
(StyleSheet) => Button or (string) => Button
-
Flex?
(int flexGrow, int flexShrink = 0) => Button
-
JustifyContent?
(Justify) => Button
-
AlignItems?
(Align) => Button
-
BindChildren?
<TChild>(Observable<TChild[]>, Func<TChild, IElement>) => Button
-

Button extends Group which extends BaseElement.