Difference between revisions of "Font:getWrap"

m (Improve description of return)
(Add coloredtext variant)
 
Line 16: Line 16:
 
{{param|number|width|The maximum width of the wrapped text.}}
 
{{param|number|width|The maximum width of the wrapped text.}}
 
{{param|table|wrappedtext|A [[sequence]] containing each line of text that was wrapped.}}
 
{{param|table|wrappedtext|A [[sequence]] containing each line of text that was wrapped.}}
 +
 +
== Function ==
 +
{{newin|[[0.10.0]]|100|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
width, wrappedtext = Font:getWrap( coloredtext, wraplimit )
 +
</source>
 +
=== Arguments ===
 +
{{param|table|coloredtext|A table containing colors and strings, in the form of <code>{color1, string1, color2, string2, ...}</code>.}}
 +
{{subparam|table|color1|A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of <code>{red, green, blue, alpha}</code>.}}
 +
{{subparam|string|string1|A string of text which has a color specified by the previous color.}}
 +
{{subparam|table|color2|A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of <code>{red, green, blue, alpha}</code>.}}
 +
{{subparam|string|string2|A string of text which has a color specified by the previous color.}}
 +
{{subparam|tables and strings|...|Additional colors and strings.}}
 +
{{param|number|wraplimit|The maximum width in pixels of each line that ''text'' is allowed before wrapping.}}
 +
=== Returns ===
 +
{{param|number|width|The maximum width of the wrapped text.}}
 +
{{param|table|wrappedtext|A [[sequence]] of strings containing each line of text that was wrapped, with the color information stripped out.}}
  
 
== Function ==
 
== Function ==

Latest revision as of 17:48, 1 May 2022

Available since LÖVE 0.7.0
This function is not supported in earlier versions.

Gets formatting information for text, given a wrap limit.

This function accounts for newlines correctly (i.e. '\n').

Function

Available since LÖVE 0.10.0
This variant is not supported in earlier versions.

Synopsis

width, wrappedtext = Font:getWrap( text, wraplimit )

Arguments

string text
The text that will be wrapped.
number wraplimit
The maximum width in pixels of each line that text is allowed before wrapping.

Returns

number width
The maximum width of the wrapped text.
table wrappedtext
A sequence containing each line of text that was wrapped.

Function

Available since LÖVE 0.10.0
This variant is not supported in earlier versions.

Synopsis

width, wrappedtext = Font:getWrap( coloredtext, wraplimit )

Arguments

table coloredtext
A table containing colors and strings, in the form of {color1, string1, color2, string2, ...}.
table color1
A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of {red, green, blue, alpha}.
string string1
A string of text which has a color specified by the previous color.
table color2
A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of {red, green, blue, alpha}.
string string2
A string of text which has a color specified by the previous color.
tables and strings ...
Additional colors and strings.
number wraplimit
The maximum width in pixels of each line that text is allowed before wrapping.

Returns

number width
The maximum width of the wrapped text.
table wrappedtext
A sequence of strings containing each line of text that was wrapped, with the color information stripped out.

Function

Removed in LÖVE 0.10.0
This variant is not supported in that and later versions.

Synopsis

width, lines = Font:getWrap( text, wraplimit )

Arguments

string text
The text that would be wrapped.
number wraplimit
The maximum width in pixels of each line that text is allowed before wrapping.

Returns

number width
The maximum width of the wrapped text.
number lines
The number of lines that the wrapped text will have.

See Also

Other Languages