User Tools

Site Tools


Sidebar

Privacy Policy

News

Version 2.50 is out since Jan 1st 2022


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

built_in:buttons

This is an old revision of the document!


The Button control

(Information and examples taken from the DroidScript documentation)

Description

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


Methods

Some controls use the same methods.
For examples of the same methods look here.

Method Description
Button.GetAbsHeight()
Button.GetAbsWidth()
Button.GetHeight()
Button.GetPosition()
Button.GetText() Fetches the recent caption (text) of a button. Returns a string.
Button.GetTextSize( mode )
Button.GetType()
Button.GetVisibility()
Button.GetWidth()
Button.SetFontFile( file )
Button.SetHtml( html )
Button.SetMargins( left,top,right,bottom )
Button.SetOnTouch( callback )
Button.SetPadding( left,top,right,bottom )
Button.SetPosition( left, top, width, height )
Button.SetScale( x,y )
Button.SetSize( width, height )
Button.SetStyle(color1,color2,radius,strokeClr,strokeWidth,shadow) Used with Custom option
Button.SetText( text ) Changes the caption (text) displayed in a button to the given string value. Example:
Button.SetText("This is a string.");   
Button.SetTextColor( colorcode ) Sets the text color of a button. Use css-style color code, i.e. “#ffffff” for white.
Button.SetTextShadow( radius,dx,dy,color )
Button.SetTextSize( size,mode )
Button.SetVisibility( HideShow ) “Hide” hides the button without affecting the rest of the layout. “Show” displays the button. “Gone” hides the button totally, so that the layout will be rearranged. (See example below.)

Options

NoPad Removes default padding of custom buttons
Alum Display the Button in aluminum style
FillX Fill the layout width
Gray Display the Button in Gray Color
NoSound Play no sound, if the button will be touched
Custom Custom Buttons sample
NoPad Removes default padding of custom buttons
FontAwesome Use Font-Awesome icons
Html Enable HTML in button-text

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!");
}

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!");
}

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!");
}

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 );
}
built_in/buttons.1524151310.txt.gz · Last modified: 2018/04/19 23:21 (external edit)