Jump to content
HazJ

Automatically adjust string length

Recommended Posts

Hi. I have become a little stuck and need someone to point me in the right direction. How do I get the control height to automatically adjust string length. I am thinking ctrlTextHeight command but not sure what to do with it. It sounds simple, get the ctrlTextWidth but I still need to apply the default h value? Surely it will just return that instead of string length? I can use count to get the string length but example output from one is like 1051. I am using ControlsGroup container. Any ideas?

{
	_message = _display ctrlCreate ["RscText", (100 + _forEachIndex), _logsContainer];
	_message ctrlSetText _x;
	_message ctrlSetPosition
	[
		0,
		(0.04 * _forEachIndex),
		???,
		???
	];
	_message ctrlCommit 0;
} forEach messagesArr;

UPDATE: Attempt 2.

Getting warmer or colder? Hmm. 😀

{
	_message = _display ctrlCreate ["RscText", (100 + _forEachIndex), _logsContainer];
	_message ctrlSetText _x;
	_message ctrlSetPosition
	[
		0,
		(0.04 * _forEachIndex),
		1,
		10
	];
	_height = ctrlTextHeight _message;
	_message ctrlSetPosition
	[
		0,
		(0.04 * _forEachIndex),
		1,
		_height
	];
	_message ctrlCommit 0;
} forEach messagesArr;

Share this post


Link to post
Share on other sites

Bump. Still stuck. Any ideas?

Maybe @Larrow

😃

Share this post


Link to post
Share on other sites

I'm using the following, works like a charm:
 

/*
Function name: MRH_fnc_MilsimTools_Core_SetCtrlSize
Author: Mr H.
Description: Resizes given control's height according to the size of the text it contains
Return value: none
Public: no
Parameters:
0 - <NUMBER> displayIDC
1- <NUMBER> controlIDC 
Example(s):
[260518,1105] call MRH_fnc_MilsimTools_Core_SetCtrlSize;
*/
params ["_displayIDC","_ctrlIDC"];
_control =((findDisplay _displayIDC) displayCtrl _ctrlIDC);
_myControlPos = ctrlPosition _control;
_ctrlh = ctrlTextHeight _control;
_xpos = _myControlPos select 0;
_ypos = _myControlPos select 1;
_width = _myControlPos select 2;
_control ctrlSetPosition [_xpos,_ypos  ,_width ,_ctrlh];
_control ctrlCommit 0;

 

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×