Back

Buttons

Create buttons using the CreateButton method of the app object:

 btn = app.CreateButton( text, width, height, options );

You can allow the button to auto-size by leaving out the dimensions or you can specify a width and height as decimal fractions. Setting the width and height to -1 whilst using the 'FillX' option will allow it to fill the layout width.

Use the SetOnTouch method of your button object to set the name of a function you want to be called when the button is touched.

Various button styles can be set by including a style name in the options parameter

Example - Default Size

function OnStart()
{
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

    btn = app.CreateButton( "Press Me" );
    btn.SetOnTouch( SayHello );
    lay.AddChild( btn );

    app.AddLayout( lay );
}

function SayHello()
{
    app.ShowPopup("Hello World!");
}
    Copy     Copy All      Run     

Example - Fixed size

function OnStart()
{
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

    btn = app.CreateButton( "Press Me", 0.5, 0.2 );
    btn.SetOnTouch( SayHello );
    lay.AddChild( btn );

    app.AddLayout( lay );
}

function SayHello()
{
    app.ShowPopup("Hello World!");
}
    Copy     Copy All      Run     

Example - Fill layout width

function OnStart()
{
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
    lay.SetPadding( 0.02, 0.02, 0.02, 0.02 );

    btn = app.CreateButton( "Press Me", -1, -1, "FillX" );
    btn.SetOnTouch( SayHello );
    lay.AddChild( btn );

    app.AddLayout( lay );
}

function SayHello()
{
    app.ShowPopup("Hello World!");
}
    Copy     Copy All      Run     

Example - Change style

function OnStart()
{
    lay = app.CreateLayout( "Linear", "Vertical,FillXY" );
    lay.SetPadding( 0.1, 0.1, 0.1, 0 );

    b1 = app.CreateButton( "Normal", -1, -1, "FillX" );
    lay.AddChild( b1 );

    b2 = app.CreateButton( "Gray", -1, -1, "FillX,Gray" );
    lay.AddChild( b2 );

    b3 = app.CreateButton( "Alum", -1, -1, "FillX,Alum" );
    lay.AddChild( b3 );

    app.AddLayout( lay );
}
    Copy     Copy All      Run     

See 'CreateButton for more informations and a complete function list