ctrlTextWidth: Difference between revisions
Jump to navigation
Jump to search
m (Reverted edits by R3vo (talk) to last revision by Lou Montana) Tag: Rollback |
No edit summary |
||
Line 46: | Line 46: | ||
<!-- CONTINUE Notes --> | <!-- CONTINUE Notes --> | ||
<!-- DISCONTINUE Notes --> | |||
<!-- CONTINUE Notes --> | |||
<dl class="command_description"> | |||
<dd class="notedate">Posted on October 28, 2020 - 22:10 (UTC)</dd> | |||
<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]]):''' | |||
<code> [[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]] {{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 [[ctrlSetText]] _text; | |||
_edit [[ctrlSetPositionW]] (_longestLineWidth [[+]] 2 * 0.008); {{cc|Width of longest line + left and right margin set in engine}} | |||
_edit [[ctrlCommit]] 1;</code> | |||
</dd> | |||
</dl> | |||
<!-- DISCONTINUE Notes --> | <!-- DISCONTINUE Notes --> |
Revision as of 23:10, 28 October 2020
Description
- Description:
- Returns the width of the control text including left and right margins (0.008 each). Supported control types are:
- CT_STATIC 0
- CT_EDIT 2
- CT_STRUCTURED_TEXT 13
- Groups:
- Uncategorised
Syntax
Examples
- Example 1:
_w = ctrlTextWidth _ctrl;
Additional Information
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 ctrlSetText _text; _edit ctrlSetPositionW (_longestLineWidth + 2 * 0.008); // Width of longest line + left and right margin set in engine _edit ctrlCommit 1;