Difference between revisions of "FontBase:layoutText"

From GiderosMobile
m (put gideros function at the beginning)
m (Text replacement - "<source" to "<syntaxhighlight")
Line 4: Line 4:
 
=== Description ===
 
=== Description ===
 
Computes the layout of the given text according to a given rectangular region size, layout flags and other parameters.
 
Computes the layout of the given text according to a given rectangular region size, layout flags and other parameters.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
(table) = FontBase:layoutText(text,width,height,flags,letterSpacing,lineSpacing,tabSpace,breakChar)
 
(table) = FontBase:layoutText(text,width,height,flags,letterSpacing,lineSpacing,tabSpace,breakChar)
 
</source>
 
</source>

Revision as of 14:28, 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. <syntaxhighlight lang="lua"> (table) = FontBase:layoutText(text,width,height,flags,letterSpacing,lineSpacing,tabSpace,breakChar) </source>

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