Button

Introduction

Button is a standard clickable object with states for enabled (default), hover, pressed, and disabled.

Layout Requirements

The Button control has no requirements - an empty container is sufficient.

TextInstance

The Button control can optionally include a Text instance named TextInstance. Setting the Button control's Text property changes the TextInstance's displayed string.

Code Example

Buttons provide events for Click and Push events. The following code shows how to handle these events on a button obtained from a gum runtime object named ButtonInstance:

void CustomInitialize()
{

    var button = TutorialScreenGum
        .GetGraphicalUiElementByName("ButtonInstance")
        .FormsControlAsObject as Button;

    button.Click += HandleButtonClick;
    button.Push += HandleButtonPush;
}

private void HandleButtonClick(object sender, EventArgs e)
{
    // handle click logic here
}

private void HandleButtonPush(object sender, EventArgs e)
{
    // handle push logic here
}

Code Example - Code-Only Creation

void CustomInitialize()
{
    // This will construct a button using the default
    // visual which should be set-up by Glue, or which can be
    // manually set up in code.
    var button = new Button();
    button.Visual.AddToManagers();
    button.Text = "Hello";
    button.Click += HandleButtonClick;
    button.Push += HandleButtonPush;
}

private void HandleButtonClick(object sender, EventArgs e)
{
    // handle click logic here
}

private void HandleButtonPush(object sender, EventArgs e)
{
    // handle push logic here
}

Last updated