Jump to content
iceman77

Scaling Text Control

Recommended Posts

I want to avoid using a static size for the text control. What's the best approach to auto scale a multi-line rscText control based on the amount of text? Thanks.

Share this post


Link to post
Share on other sites

To necro a thread, I have a similar question. Does anyone know of a way to scale the text size of a RscStructuredText box, depending on how much text is being inputted into the field? I'm just starting on stringtables and the problem of text in other launguages being too large for the box has got me looking for, but not finding, an answer.

 

@iceman77 Did you ever find a solution?

Share this post


Link to post
Share on other sites
h = [] spawn {
	disableSerialization;
	_ctrl = findDisplay 46 ctrlCreate [ "RscStructuredText", 1001 ];
	//Give ctrl 0 width
	_ctrl ctrlSetPosition[ 0, 0, 0, 0.02 * safeZoneH ];
	_ctrl ctrlCommit 0;
		
	_emptyWidth = ctrlTextWidth _ctrl;
	
	//Fill ctrl with text
	_string = "The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog";
	_ctrl ctrlSetStructuredText parseText format[ "<t align='left'>%1</t>", _string ];
	//Give ctrl a background color so we can see ctrl actual width
	_ctrl ctrlSetBackgroundColor[1,0,0,1];
	
	//Get text width
	_width = ctrlTextWidth _ctrl;
	_height = ctrlTextHeight _ctrl;
	
	//Notice in hint that the ctrlTextHeight is always 0 :/
	hint format[ "EW: %1\nW: %2\nH: %3", _emptyWidth, _width, _height ];
	
	//Resize ctrl to fit text
	//Needs a little padding so as not to cut off last few characters
	_twoCharPadding = ( _width / count _string ) * 2;
	_ctrl ctrlSetPosition[ 0, 0, _width + _twoCharPadding, 0.02 * safeZoneH ];
	_ctrl ctrlCommit 0;
};

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

@Larrow Thanks for the effort, but I'm looking for something that works the other way around. I want to scale the text size to the size of the ctrl, so that no matter what text is input into it, it'll resize to stay within the ctrl's boundaries.

 

Also, just looking at the comment on ctrlTextHeight on the wiki:

in ArmA 3 v.1.70.141764, this command always returns 0 if the control has no width.

Running the hint (and _width/_height obviously) after resizing the ctrl gives the height.

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

×