getTextWidth

From Bohemia Interactive Community
Revision as of 00:48, 17 February 2021 by Lou Montana (talk | contribs) (Text replacement - "\| *((\[\[[a-zA-Z0-9_ |()]+\]\],? ?)+) * \}\}" to "|seealso= $1 }}")
Jump to navigation Jump to search
Hover & click on the images for description

Description

Description:
Description needed
Groups:
GUI ControlStrings

Syntax

Syntax:
Syntax needed
Parameters:
text: String - text string to measure
[font, size]: Array
font: String - font type
size: Number - font size
Return Value:
Return value needed

Examples

Example 1:
_textWidth = "Hello World" getTextWidth ["PuristaMedium", 0.03];
Example 2:
_textWidthInclMargins = ("Hello World" getTextWidth ["PuristaMedium", 0.03]) + 0.016;
Example 3:
private _ctrl = findDisplay 46 ctrlCreate ["RscText", -1]; _ctrl ctrlSetText "TestString"; _ctrl ctrlSetFont "PuristaMedium"; _ctrl ctrlSetFontHeight 0.04; ctrlTextWidth _ctrl == ("TestString" getTextWidth ["PuristaMedium", 0.04]) + 0.016; // true

Additional Information

See also:
ctrlTextWidth

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Posted on October 28, 2020 - 22:10 (UTC)
R3vo
When working with multiline controls ctrlTextWidth or getTextWidth will not return a proper value since the text will be treated as one long line.
Solution (Execute in Eden Editor): disableSerialization; private _display = findDisplay 313 createDisplay "RscDisplayEmpty"; private _edit = _display ctrlCreate ["RscEditMulti", -1]; _edit ctrlSetPosition [0,0,1,1]; _edit ctrlSetBackgroundColor [0,0,0,1]; _edit ctrlSetFont "EtelkaMonospacePro"; _edit ctrlSetFontHeight 0.03; _edit ctrlCommit 0; private _longestLineWidth = 0; private _exampleString = "abcdefghijklmnopqrstuvxyz0134567890"; private _text = ""; for "_lines" from 1 to 400 do // Loop through all lines and find the longest one { _lineText = _exampleString select [round random 35]; _longestLineWidth = _longestLineWidth max (_lineText getTextWidth ["EtelkaMonospacePro", 0.03]); _text = _text + _lineText + endl; }; _edit ctrlSetPositionW (_longestLineWidth + 2 * 0.008); // Width of longest line + left and right margin set in engine _edit ctrlCommit 0; _edit ctrlSetText _text;