Difference between revisions of "FontBase:layoutText"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
 
 
'''Available since:''' Gideros 2017.10<br/>
 
'''Available since:''' Gideros 2017.10<br/>
 +
'''Class:''' [[FontBase]]<br/>
 +
 
=== Description ===
 
=== Description ===
<br />
+
Computes the layout of the given text according to a given rectangular region size, layout flags and other parameters.
Compute the layout of the given text according to a given rectangular region size, layout flags and other parameters.<br />
+
<syntaxhighlight lang="lua">
<br />
+
(table) = FontBase:layoutText(text,width,height,flags,letterSpacing,lineSpacing,tabSpace,breakChar)
Refer to `TextField:setLayout` for a description of the arguments.<br/>
+
</syntaxhighlight>
 +
 
 +
Refer to [[TextField:setLayout]] for a description of the arguments.
 +
 
 
The returned table contains the following fields:
 
The returned table contains the following fields:
- x,y,w,h: Computed bounding box of the full text
+
* x,y,w,h: computed bounding box of the full text
- lines: The number of lines used to display the text
+
* lines: the number of lines used to display the text
- parts: Information about individual chunks of texts.
+
* parts: information about individual chunks of texts
<br /><br />
+
 
Each table in the part field of the returned table describe the placement of chunks of text. Their fields are:
+
Each table in the part field of the returned table describes the placement of chunks of text. Their fields are:
- text: The text to display in this chunk
+
* text: the text to display in this chunk
- x,y,w,h: Computed bounding box of this chunk   
+
* x,y,w,h: computed bounding box of this chunk   
- dx,dy: Coordinates to draw this chunk at
+
* dx,dy: coordinates to draw this chunk at
- sep: separator character that came just after this chunk in text block
+
* sep: separator character that came just after this chunk in text block
- line: line number this chunk belongs to
+
* line: line number this chunk belongs to
<source lang="lua">
+
 
(table) = FontBase:layoutText(text,width,height,flags,letterSpacing,lineSpacing,tabSpace,breakChar)
+
=== Parameters ===
</source>
+
'''text''': (string) <br/>
'''text''': (string) ''''''<br/>
+
'''width''': (number) <br/>
'''width''': (number) ''''''<br/>
+
'''height''': (number) <br/>
'''height''': (number) ''''''<br/>
+
'''flags''': (number, default=FontBase.TLF_NOWRAP) <br/>
'''flags''': (number, default=FontBase.TLF_NOWRAP) ''''''<br/>
+
'''letterSpacing''': (number, default = 0) <br/>
'''letterSpacing''': (number, default = 0) ''''''<br/>
+
'''lineSpacing''': (number, default = 0) <br/>
'''lineSpacing''': (number, default = 0) ''''''<br/>
+
'''tabSpace''': (number, default = 4) <br/>
'''tabSpace''': (number, default = 4) ''''''<br/>
 
 
'''breakChar''': (string)  '''optional'''<br/>
 
'''breakChar''': (string)  '''optional'''<br/>
'''Returns''' (table) A table describing how to draw the given text.<br/>
+
 
 +
=== Return values ===
 +
'''Returns''' (table) a table describing how to draw the given text<br/>
 +
 
 +
{{FontBase}}

Latest revision as of 15:29, 13 July 2023

Available since: Gideros 2017.10
Class: FontBase

Description

Computes the layout of the given text according to a given rectangular region size, layout flags and other parameters.

(table) = FontBase:layoutText(text,width,height,flags,letterSpacing,lineSpacing,tabSpace,breakChar)

Refer to TextField:setLayout for a description of the arguments.

The returned table contains the following fields:

  • x,y,w,h: computed bounding box of the full text
  • lines: the number of lines used to display the text
  • parts: information about individual chunks of texts

Each table in the part field of the returned table describes the placement of chunks of text. Their fields are:

  • text: the text to display in this chunk
  • x,y,w,h: computed bounding box of this chunk
  • dx,dy: coordinates to draw this chunk at
  • sep: separator character that came just after this chunk in text block
  • line: line number this chunk belongs to

Parameters

text: (string)
width: (number)
height: (number)
flags: (number, default=FontBase.TLF_NOWRAP)
letterSpacing: (number, default = 0)
lineSpacing: (number, default = 0)
tabSpace: (number, default = 4)
breakChar: (string) optional

Return values

Returns (table) a table describing how to draw the given text