ctrlTextWidth: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\{\{GameCategory\|(arma[0123])\|New[ _]Scripting[ _]Commands[ _]List\}\}" to "{{GameCategory|$1|New Scripting Commands}}")
m (Text replacement - "_{10,} " to "")
Line 1: Line 1:
{{Command|Comments=
{{Command|Comments=
____________________________________________________________________________________________


| arma3 |Game name=
| arma3 |Game name=
Line 7: Line 6:


|gr1= GUI Control |GROUP1=
|gr1= GUI Control |GROUP1=
____________________________________________________________________________________________


| Returns the width of the control text including left and right margins (0.008 each). Supported control [[ctrlType|types]] are:
| Returns the width of the control text including left and right margins (0.008 each). Supported control [[ctrlType|types]] are:
Line 14: Line 12:
* [[DialogControls-Text|CT_STRUCTURED_TEXT]] 13  
* [[DialogControls-Text|CT_STRUCTURED_TEXT]] 13  
{{Informative | For control-independent text width estimate see [[getTextWidth]]}} |DESCRIPTION=
{{Informative | For control-independent text width estimate see [[getTextWidth]]}} |DESCRIPTION=
____________________________________________________________________________________________


| '''ctrlTextWidth''' control |SYNTAX=
| '''ctrlTextWidth''' control |SYNTAX=
Line 25: Line 22:
|x1= <code>_w = [[ctrlTextWidth]] _ctrl;</code>|EXAMPLE1=  
|x1= <code>_w = [[ctrlTextWidth]] _ctrl;</code>|EXAMPLE1=  


____________________________________________________________________________________________


| [[getTextWidth]], [[ctrlTextHeight]], [[ctrlSetText]], [[ctrlType]], [[Arma: GUI Configuration]] |SEEALSO=  
| [[getTextWidth]], [[ctrlTextHeight]], [[ctrlSetText]], [[ctrlType]], [[Arma: GUI Configuration]] |SEEALSO=  


|  |MPBEHAVIOUR=  
|  |MPBEHAVIOUR=  
____________________________________________________________________________________________
}}
}}



Revision as of 01:38, 17 January 2021

Hover & click on the images for description

Description

Description:
Returns the width of the control text including left and right margins (0.008 each). Supported control types are:
For control-independent text width estimate see getTextWidth
Groups:
GUI Control

Syntax

Syntax:
ctrlTextWidth control
Parameters:
control: Control
Return Value:
Number

Examples

Example 1:
_w = ctrlTextWidth _ctrl;

Additional Information

See also:
getTextWidthctrlTextHeightctrlSetTextctrlTypeArma: GUI Configuration

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

Notes

Bottom Section


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;
Posted on October 28, 2020 - 22:51 (UTC)
R3vo
It's important to set the width of the multiline text control before adding any text to it.