Difference between revisions of "TextField:setLayout"

From GiderosMobile
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
'''<translate>Available since</translate>:''' Gideros 2017.10<br/>
+
'''Available since:''' Gideros 2017.10<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/TextField|TextField]]<br/>
+
'''Class:''' [[TextField]]<br/>
=== <translate>Description</translate> ===
+
 
<translate>Change the layout parameters for this TextField
+
=== Description ===
    Layout parameters can contain the following fields:
+
Changes the layout parameters for this TextField Layout.
    - w,h: Width/height of the area to layout the text in
+
<syntaxhighlight lang="lua">
    - flags: A or combination of `FontBase`.TLF_xxx constants instructing how to layout the text
+
TextField:setLayout(layout)
    - letterSpacing: The space to add between each letter of the text
+
</syntaxhighlight>
    - lineSpacing: The space to add between each line of the text
+
 
    - tabSpace: The size of a tab in space characters increment, default to 4 if unspecified
+
''layout'' can contain the following fields:
    - breakChar: A string the will be inserted to indicated broken words</translate>
+
* w, h: width/height of the area to layout the text in
<source lang="lua">
+
* flags: a combination of [[FontBase Constants|FontBase.TLF_xxx]] constants instructing how to layout the text
TextField:setLayout(layout)
+
* letterSpacing: the space to add between each letter of the text
</source>
+
* lineSpacing: the space to add between each line of the text
=== <translate>Parameters</translate> ===
+
* tabSpace: the size of a tab in space characters increment, default to 4 if unspecified
'''layout''': (table) <translate>Layout parameters</translate> <br/>
+
* breakChar: a string that will be inserted to indicated broken words
 +
* alignX, alignY: relative alignment of the text inside its cell. Defaults to 0.5,0.5. '''Since 2020.7'''
 +
 
 +
=== Parameters ===
 +
'''layout''': (table) layout parameters<br/>
 +
 
 +
=== Example ===
 +
<syntaxhighlight lang="lua">
 +
-- a string variable
 +
local mystring = "Some very long text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor."
 +
 
 +
-- the text field with default system font
 +
local textfield = TextField.new(nil, mystring)
 +
 
 +
-- we set the string that will be used as sample for determining text line height
 +
textfield:setSample(mystring)
 +
 
 +
-- then we set the layout: width, height, line spacing and justify center
 +
textfield:setLayout( {w=200, h=100, lineSpacing=7, flags=FontBase.TLF_CENTER} )
 +
 
 +
-- finally, we set the text position and add it to stage
 +
textfield:setPosition(50, 50)
 +
stage:addChild(textfield)
 +
</syntaxhighlight>
 +
 
 +
{{TextField}}

Latest revision as of 02:25, 18 November 2023

Available since: Gideros 2017.10
Class: TextField

Description

Changes the layout parameters for this TextField Layout.

TextField:setLayout(layout)

layout can contain the following fields:

  • w, h: width/height of the area to layout the text in
  • flags: a combination of FontBase.TLF_xxx constants instructing how to layout the text
  • letterSpacing: the space to add between each letter of the text
  • lineSpacing: the space to add between each line of the text
  • tabSpace: the size of a tab in space characters increment, default to 4 if unspecified
  • breakChar: a string that will be inserted to indicated broken words
  • alignX, alignY: relative alignment of the text inside its cell. Defaults to 0.5,0.5. Since 2020.7

Parameters

layout: (table) layout parameters

Example

-- a string variable
local mystring = "Some very long text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor."

-- the text field with default system font
local textfield = TextField.new(nil, mystring)

-- we set the string that will be used as sample for determining text line height
textfield:setSample(mystring)

-- then we set the layout: width, height, line spacing and justify center
textfield:setLayout( {w=200, h=100, lineSpacing=7, flags=FontBase.TLF_CENTER} )

-- finally, we set the text position and add it to stage
textfield:setPosition(50, 50)
stage:addChild(textfield)