{"name":"ctrlTextWidth","title":"ctrlTextWidth","type":"command","url":"https://community.bistudio.com/wiki/ctrlTextWidth","revid":373703,"updated":"2025-06-20T08:16:47Z","groups":["GUI Control"],"status":"ok","games":{"arma3":"1.78"},"since":"arma3 1.78","arma3_since":"1.78","description":"Returns the width of the control text including left and right margins (0.008 each). Supported control types are:\n\n- CT_STATIC 0\n- CT_EDIT 2\n- CT_STRUCTURED_TEXT 13\n- Arma 3 v2.06 CT_XKEYDESC 40\n- Arma 3 v2.06 CT_XBUTTON 41\n- Arma 3 v2.06 CT_SHORTCUTBUTTON 16\n- Arma 3 v2.06 CT_BUTTON 1\n- Arma 3 v2.06 CT_ACTIVETEXT 11\n\n> [!NOTE]\n> For control-independent text width estimate see getTextWidth.","syntaxes":[{"syntax":"ctrlTextWidth control","params":[{"name":"control","type":"Control","type_expr":"Control"}],"returns":{"type":"Number","type_expr":"Number"},"form":"unary","right":{"text":"control"}}],"examples":[{"code":["private _w = ctrlTextWidth _ctrl;"]}],"see_also":["getTextWidth","ctrlTextHeight","ctrlSetText","ctrlType","Arma: GUI Configuration"],"notes":[{"user":"R3vo","date":"2020-10-28T22:10:00Z","text":"When working with multiline controls ctrlTextWidth or getTextWidth will not return a proper value since the text will be treated as one long line.\n\n**Solution (Execute in Eden Editor):**\n\n```sqf\ndisableSerialization;\n\nprivate _display = findDisplay 313 createDisplay \"RscDisplayEmpty\";\n\nprivate _edit = _display ctrlCreate [\"RscEditMulti\", -1];\n_edit ctrlSetPosition [0,0,1,1];\n_edit ctrlSetBackgroundColor [0,0,0,1];\n_edit ctrlSetFont \"EtelkaMonospacePro\";\n_edit ctrlSetFontHeight 0.03;\n_edit ctrlCommit 0;\n\nprivate _longestLineWidth = 0;\nprivate _exampleString = \"abcdefghijklmnopqrstuvxyz0134567890\";\nprivate _text = \"\";\n\nfor \"_lines\" from 1 to 400 do // loop through all lines and find the longest one\n{\n    _lineText = _exampleString select [round random 35];\n    _longestLineWidth = _longestLineWidth max (_lineText getTextWidth [\"EtelkaMonospacePro\", 0.03]);\n    _text = _text + _lineText + endl;\n};\n\n_edit ctrlSetPositionW (_longestLineWidth + 2 * 0.008); // width of longest line + left and right margin set in engine\n_edit ctrlCommit 0;\n_edit ctrlSetText _text;\n```"},{"user":"Sa-Matra","date":"2025-06-20T04:57:35Z","text":"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."}]}