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:text

Text control

(Information and examples taken from the DroidScript documentation)

Description

Create Text objects using the CreateText method of the app object:

txt = app.CreateText( text, width, height, options );

You can use the “Multiline” option to allow multi-line text and the “Left” or “Right” options to align the text. The default is single line centered text.

Use the SetText and GetText functions of the Text object to set and get it's text.

Example - Single line

function OnStart()
{
  lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
 
  txt = app.CreateText( "Hello" );
  txt.SetTextSize( 22 );
  lay.AddChild( txt );
 
  app.AddLayout( lay );
} 

You can change the look of a Text using the SetBackColor and SetTextColor functions on the Text object.

Example - Multi line

function OnStart()
{
  lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
 
  txt = app.CreateText( "Hello\nWorld", 0.8, 0.2, "Multiline" );
  txt.SetTextSize( 12 );
  txt.SetTextColor( "#ff6666ff" );
  txt.SetBackColor( "#ffffffff" );
  lay.AddChild( txt );
 
  app.AddLayout( lay );
}

You can also set a background image/pattern or background gradient for the Text using the SetBackground and SetBackGradient functions. See Layouts for examples of how to use these functions.

Methods

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

Method Description
Text.Destroy()
Text.GetAbsHeight()
Text.GetAbsWidth()
Text.GetHeight()
Text.GetLineCount()
Text.GetLineStart( line )
Text.GetLineTop( line )
Text.GetMaxLines()
Text.GetPosition()
Text.GetText()
Text.GetTextSize( mode )
Text.GetType() Returns “Text”
Text.GetVisibility()
Text.GetWidth()
Text.Release()
Text.SetBackColor( color )
Text.SetBackGradient( color1,color2,color3,p4,p5,p6,p7 )
Text.SetBackGradientRadial( x,y,r,color1,color2,color3,p7 )
Text.SetBackground( imagefile,options )
Text.SetEllipsize( mode ) Shorten long text with “…” mode=“Start”,“Middle”, “End” or “marq
Text.SetFontFile( file )
Text.SetHtml( html )
Text.SetMargins( left,top,right,bottom )
Text.SetOnLongTouch( callback )
Text.SetOnTouch( callback )
Text.SetOnTouchDown( callback )
Text.SetOnTouchMove( callback )
Text.SetOnTouchUp( callback )
Text.SetPadding( left,top,right,bottom )
Text.SetPosition( left,top,width,height )
Text.SetScale( x,y )
Text.SetSize( width,height )
Text.SetText( text )
Text.SetTextColor( color )
Text.SetTextShadow( radius,dx,dy,color )
Text.SetTextSize( size,mode )
Text.SetTouchable( touchable )
Text.SetVisibility( HideShow )

Options

Option Description
AutoScale reduces text size to fit if needed
Bold Write bold Text
FontAwesome Use this to display Icons
from this inbuilt font
Html
Left
Monospace use monospace font
Multiline
Right
NoWrap
Log Log=='multiline,left,nowrap'
built_in/text.txt · Last modified: 2019/06/22 01:01 (external edit)