User Tools

Site Tools


built_in:buttons

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

built_in:buttons [2018/05/21 00:13]
geez437 [The Button control]
built_in:buttons [2018/07/21 05:36]
Line 1: Line 1:
-=====The Button control===== 
- 
-//(Information and examples taken from the DroidScript documentation)// 
- 
-=====Description===== 
- 
-Create buttons using the **CreateButton** method of the **[[built_in:app|app]]** object:  
- 
-<code>btn = app.CreateButton( text, width, height, options );</code> 
- 
-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: <code>Button.SetText("This is a string.");   </code>                                                   | 
-| 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 ===== 
- 
-^ Options      ^ Description                                          ^ 
-| 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       | [[sample_code:button_styles|Custom Buttons sample]]  | 
-| NoPad        | Removes default padding of custom buttons            | 
-| FontAwesome  | Use Font-Awesome icons                               | 
-| Html         | Enable HTML in button-text                           | 
- 
----- 
- 
-====Example - Default Size==== 
- 
-<code javascript> 
- 
-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!"); 
-} 
- 
-</code> 
- 
-====Example - Fixed Size==== 
- 
-<code javascript> 
- 
-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!"); 
-} 
- 
-</code> 
- 
-====Example - Fill layout width==== 
- 
-<code javascript> 
- 
-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!"); 
-} 
- 
-</code> 
- 
-====Example - Change Style==== 
- 
-<code javascript> 
- 
-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 ); 
-} 
- 
-</code> 
  
built_in/buttons.txt ยท Last modified: 2018/07/21 05:36 (external edit)