ctrlTextWidth: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (fixed missing command group)
m (Text replacement - "Category:Eden Editor" to "Eden Editor")
 
(44 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| arma3 |Game name=
|game1= arma3
|version1= 1.78


|1.78|Game version=
|gr1= GUI Control


|gr1= GUI Control |GROUP1=
|descr= Returns the width of the control text including left and right margins (0.008 each). Supported control [[ctrlType|types]] are:
____________________________________________________________________________________________
{{Columns|2|
 
* [[CT_STATIC]] 0
| Returns the width of the control text including left and right margins (0.008 each). Supported control [[ctrlType|types]] are:
* [[CT_EDIT]] 2
* [[DialogControls-Text|CT_STATIC]] 0
* [[CT_STRUCTURED_TEXT]] 13
* [[DialogControls-EditBox|CT_EDIT]] 2
* {{GVI|arma3|2.06|size= 0.75}} [[CT_XKEYDESC]] 40
* [[DialogControls-Text|CT_STRUCTURED_TEXT]] 13  
* {{GVI|arma3|2.06|size= 0.75}} [[CT_XBUTTON]] 41
{{Informative | For control independent text width estimate see [[getTextWidth]]}} |DESCRIPTION=
* {{GVI|arma3|2.06|size= 0.75}} [[CT_SHORTCUTBUTTON]] 16
____________________________________________________________________________________________
* {{GVI|arma3|2.06|size= 0.75}} [[CT_BUTTON]] 1
 
* {{GVI|arma3|2.06|size= 0.75}} [[CT_ACTIVETEXT]] 11
| '''ctrlTextWidth''' control |SYNTAX=
}}
{{Feature|informative|For control-independent text width estimate see [[getTextWidth]].}}


|p1= control: [[Control]] |PARAMETER1=
|s1= [[ctrlTextWidth]] control


| [[Number]] |RETURNVALUE=
|p1= control: [[Control]]


|r1= [[Number]]


|x1= <code>_w = [[ctrlTextWidth]] _ctrl;</code>|EXAMPLE1=
|x1= <sqf>private _w = ctrlTextWidth _ctrl;</sqf>


____________________________________________________________________________________________
|seealso= [[getTextWidth]] [[ctrlTextHeight]] [[ctrlSetText]] [[ctrlType]] [[Arma: GUI Configuration]]
 
| [[getTextWidth]], [[ctrlTextHeight]], [[ctrlSetText]], [[ctrlType]], [[Arma: GUI Configuration]] |SEEALSO=
 
|  |MPBEHAVIOUR=
____________________________________________________________________________________________
}}
}}


<h3 style='display:none'>Notes</h3>
{{Note
<dl class='command_description'>
|user= R3vo
<!-- Note Section BEGIN -->
|timestamp= 20201028221000
|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.<br>


<!-- Note Section END -->
'''Solution (Execute in [[:Category:Eden Editor|Eden Editor]]):'''
</dl>


<h3 style='display:none'>Bottom Section</h3>
<sqf>
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
disableSerialization;
[[Category:Arma 3: New Scripting Commands List|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Command_Group:_GUI_Control|{{uc:{{PAGENAME}}}}]]


<!-- CONTINUE Notes -->
private _display = findDisplay 313 createDisplay "RscDisplayEmpty";


<!-- DISCONTINUE Notes -->
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;


<!-- CONTINUE Notes -->
private _longestLineWidth = 0;
<dl class="command_description">
private _exampleString = "abcdefghijklmnopqrstuvxyz0134567890";
<dd class="notedate">Posted on October 28, 2020 - 22:10 (UTC)</dd>
private _text = "";
<dt class="note">[[User:R3vo|R3vo]]</dt>
<dd class="note">
When working with multiline controls [[ctrlTextWidth]] or [[getTextWidth]] will not return a proper value since the text will be treated as one long line.</br>


'''Solution (Execute in [[Eden Editor]]):'''
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;
};


<code> [[disableSerialization]];
_edit ctrlSetPositionW (_longestLineWidth + 2 * 0.008); // width of longest line + left and right margin set in engine
 
_edit ctrlCommit 0;
[[private]] _display {{=}} [[findDisplay]] 313 [[createDisplay]] "RscDisplayEmpty";
_edit ctrlSetText _text;
 
</sqf>
[[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]] {{cc|Loop through all lines and find the longest one}}
{
    _lineText {{=}} _exampleString [[select]] <nowiki>[</nowiki>[[round]] [[random]] 35];
    _longestLineWidth {{=}} _longestLineWidth [[max]] (_lineText [[getTextWidth]] ["EtelkaMonospacePro", 0.03]);
    _text {{=}} _text [[+]] _lineText [[+]] [[endl]];
};
_edit [[ctrlSetPositionW]] (_longestLineWidth [[+]] 2 * 0.008); {{cc|Width of longest line + left and right margin set in engine}}
_edit [[ctrlCommit]] 0;
_edit [[ctrlSetText]] _text;</code>
</dd>
</dl>
<!-- DISCONTINUE Notes -->
 
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on October 28, 2020 - 22:51 (UTC)</dd>
<dt class="note">[[User:R3vo|R3vo]]</dt>
<dd class="note">
It's important to set the width of the multiline text control '''before''' adding any text to it.
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 14:26, 9 July 2023

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:
private _w = ctrlTextWidth _ctrl;

Additional Information

See also:
getTextWidth ctrlTextHeight ctrlSetText ctrlType Arma: 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
R3vo - c
Posted on Oct 28, 2020 - 22:10 (UTC)
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;