Jump to content
prykpryk

Apply alignment to structured text without losing linebreaks.

Recommended Posts

Hi.

I'm working on a script:

Pryk_fnc_hitTranspose = {
	_array = getAllHitPointsDamage _this;
	_text = "";
	_newarray = [];
	
	for "_i" from 0 to ((count (_array select 0))-1) do 
	{	
		_hitpoint = _array select 0 select _i;
		_dmg = round ((_array select 2 select _i)*100);
		_text = composetext [_text, linebreak, _hitpoint , ": ",str _dmg, "%"];
	};
	//_text = formatText ["<t align='left'>%1<t/>",_text]; //My best bet


	_text;
	
};

This function returns a structured text with linebreaks in it. I'm displaying this using another hint function somewhere outside. However I also want the text to be aligned to the left. My attempt of doing this is commented.

parseText only accepts strings and turning _text into a string loses linebreaks.

Any ideas?

Share this post


Link to post
Share on other sites

Why not use xml linebreaks then <br /> ?

Pryk_fnc_hitTranspose = {
	_array = getAllHitPointsDamage _this;
	_newarray = [];
	_text = "";
	for "_i" from 0 to ((count (_array select 0))-1) do 
	{	
		_hitpoint = _array select 0 select _i;
		_dmg = round ((_array select 2 select _i)*100);
		_text = _text + "<br />" + _hitpoint + ": " + (str _dmg) + "%";
	};
	_text = parseText ("<t align='left'>" + _text + "</t>");

	_text;
};

this should do

  • Like 2

Share this post


Link to post
Share on other sites

Nice idea.

Thanks.

 

PS. Removing _text = "" in outer scope did break it :)

Share this post


Link to post
Share on other sites
Pryk_fnc_hitTranspose = {
	private _arr = getAllHitPointsDamage _this;
	private _arrNew = (_arr select 0) apply {
		format ["%1: %2%3", _x, round ((_this getHitPointDamage _x) * 100), "%"]
	};

	private _text = _arrNew joinString "<br/>";
	_text = parseText ("<t align='left'>" + _text + "</t>");
	_text;
};

Just an alternative using different commands.  :)

  • Like 2

Share this post


Link to post
Share on other sites

PS. Removing _text = "" in outer scope did break it :)

 

That was by accident. ^^

Share this post


Link to post
Share on other sites
Pryk_fnc_hitTranspose = {
	private _arr = getAllHitPointsDamage _this;
	private _arrNew = (_arr select 0) apply {
		format ["%1: %2%3", _x, round ((_this getHitPointDamage _x) * 100), "%"]
	};

	private _text = _arrNew joinString "<br/>";
	_text = parseText ("<t align='left'>" + _text + "</t>");
	_text;
};

Just an alternative using different commands.  :)

 

Now that's a clever use of the new commands :thumbsup:

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

×