{"name":"ctrlTextWidth","operator":null,"title":"ctrlTextWidth","type":"command","url":"https://community.bistudio.com/wiki/ctrlTextWidth","revid":373703,"updated":"2025-06-20T08:16:47Z","groups":["GUI Control"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"1.78"}],"since":{"game":"arma3","name":"Arma 3","version":"1.78"},"arma3_since":"1.78","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Returns the width of the control text including left and right margins (0.008 each). Supported control types are:\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","since":null,"effect":null,"exec":null,"params":[{"name":"control","type":"Control","optional":false,"default":null,"description":null,"types":["Control"],"since":null,"text":"control: Control"}],"returns":{"type":"Number","types":["Number"],"description":null,"text":"Number"},"form":"unary","operator":null,"left":null,"right":{"text":"control","types":["Control"]}}],"examples":[{"text":"```sqf\nprivate _w = ctrlTextWidth _ctrl;\n```","code":["private _w = ctrlTextWidth _ctrl;"]}],"multiplayer":null,"problems":null,"aliases":[],"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."}],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: GUI Control","Introduced with Arma 3 version 1.78","Scripting Commands"]}