This shows you the differences between two versions of the page.
built_in:buttons [2018/04/19 15:28] 78.209.123.22 Suppressed duplicate NoPad line |
built_in:buttons [2018/07/21 05:36] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | =====The Button control===== | ||
- | |||
- | // | ||
- | |||
- | =====Description===== | ||
- | |||
- | Create buttons using the **CreateButton** method of the **[[built_in: | ||
- | |||
- | < | ||
- | |||
- | 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 **' | ||
- | |||
- | 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 | ||
- | | Button.GetAbsHeight() | ||
- | | Button.GetAbsWidth() | ||
- | | Button.GetHeight() | ||
- | | Button.GetPosition() | ||
- | | Button.GetText() | ||
- | | Button.GetTextSize( mode ) | | | ||
- | | Button.GetType() | ||
- | | Button.GetVisibility() | ||
- | | Button.GetWidth() | ||
- | | Button.SetFontFile( file ) | | | ||
- | | Button.SetHtml( html ) | | | ||
- | | Button.SetMargins( left, | ||
- | | Button.SetOnTouch( callback ) | ||
- | | Button.SetPadding( left, | ||
- | | Button.SetPosition( left, top, width, height ) | | | ||
- | | Button.SetScale( x,y ) | | | ||
- | | Button.SetSize( width, height ) | ||
- | | Button.SetStyle(color1, | ||
- | | Button.SetText( text ) | Changes the caption (text) displayed in a button to the given string value. Example: < | ||
- | | Button.SetTextColor( colorcode ) | Sets the text color of a button. Use css-style color code, i.e. "# | ||
- | | Button.SetTextShadow( radius, | ||
- | | Button.SetTextSize( size,mode ) | ||
- | | Button.SetVisibility( HideShow ) | " | ||
- | |||
- | ===== Options ===== | ||
- | |||
- | ^ Options | ||
- | | Alum | Display the Button in aluminum style | | ||
- | | FillX | Fill the layout width | | ||
- | | Gray | Display the Button in Gray Color | | ||
- | | NoSound | ||
- | | Custom | ||
- | | NoPad | Removes default padding of custom buttons | ||
- | | FontAwesome | ||
- | | Html | Enable HTML in button-text | ||
- | |||
- | ---- | ||
- | |||
- | ====Example - Default Size==== | ||
- | |||
- | <code javascript> | ||
- | |||
- | function OnStart() | ||
- | { | ||
- | lay = app.CreateLayout( " | ||
- | |||
- | btn = app.CreateButton( "Press Me" ); | ||
- | btn.SetOnTouch( SayHello ); | ||
- | lay.AddChild( btn ); | ||
- | |||
- | app.AddLayout( lay ); | ||
- | } | ||
- | |||
- | function SayHello() | ||
- | { | ||
- | app.ShowPopup(" | ||
- | } | ||
- | |||
- | </ | ||
- | |||
- | ====Example - Fixed Size==== | ||
- | |||
- | <code javascript> | ||
- | |||
- | function OnStart() | ||
- | { | ||
- | lay = app.CreateLayout( " | ||
- | |||
- | btn = app.CreateButton( "Press Me", 0.5, 0.2 ); | ||
- | btn.SetOnTouch( SayHello ); | ||
- | lay.AddChild( btn ); | ||
- | |||
- | app.AddLayout( lay ); | ||
- | } | ||
- | |||
- | function SayHello() | ||
- | { | ||
- | app.ShowPopup(" | ||
- | } | ||
- | |||
- | </ | ||
- | |||
- | ====Example - Fill layout width==== | ||
- | |||
- | <code javascript> | ||
- | |||
- | function OnStart() | ||
- | { | ||
- | lay = app.CreateLayout( " | ||
- | lay.SetPadding( 0.02, 0.02, 0.02, 0.02 ); | ||
- | |||
- | btn = app.CreateButton( "Press Me", -1, -1, " | ||
- | btn.SetOnTouch( SayHello ); | ||
- | lay.AddChild( btn ); | ||
- | |||
- | app.AddLayout( lay ); | ||
- | } | ||
- | |||
- | function SayHello() | ||
- | { | ||
- | app.ShowPopup(" | ||
- | } | ||
- | |||
- | </ | ||
- | |||
- | ====Example - Change Style==== | ||
- | |||
- | <code javascript> | ||
- | |||
- | function OnStart() | ||
- | { | ||
- | lay = app.CreateLayout( " | ||
- | lay.SetPadding( 0.1, 0.1, 0.1, 0 ); | ||
- | |||
- | b1 = app.CreateButton( " | ||
- | lay.AddChild( b1 ); | ||
- | |||
- | b2 = app.CreateButton( " | ||
- | lay.AddChild( b2 ); | ||
- | |||
- | b3 = app.CreateButton( " | ||
- | lay.AddChild( b3 ); | ||
- | |||
- | app.AddLayout( lay ); | ||
- | } | ||
- | |||
- | </ | ||