Arma 3 Scripting

ctrlTextWidth

  • Arma 3 v1.78

Command · Markdown · JSON · original wiki page

Description

Returns the width of the control text including left and right margins (0.008 each). Supported control types are:

Note

For control-independent text width estimate see getTextWidth.

Syntax

ctrlTextWidth control

Parameters:

Returns: Number

Examples

Example 1

private _w = ctrlTextWidth _ctrl;

See also

getTextWidth · ctrlTextHeight · ctrlSetText · ctrlType · Arma: GUI Configuration

Community notes

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;

Sa-Matra

If you have ui2textures in the text, there is a slight change this command can return NaN if texture is bugged, can be checked with finite for these rare cases.