Label.ComputeWidth fails with composed text

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Post Reply
User avatar
Dommy
Translator
Translator
Posts: 1866
Joined: 25 Aug 2011, 21:45
Location: Poland
Contact:

Label.ComputeWidth fails with composed text

Post by Dommy »

Label.ComputeWidth returns incorrect values when trying to compute width of translated or composed text.

Example:

Code: Select all

Label.Value = _("Continue");
log(Label.ComputeWidth(Label.Value));
or

Code: Select all

Label.Value = TL::Compose("Current attacker: %1", Players[0].User.Name);
log(Label.ComputeWidth(Label.Value));
Looks like this function is taking into account raw text, containing PU1 and PU2 characters instead actual visible output. Tried also to call time function one tick after setting new value, but it hasn't changed anything.
Ryzen 7 2700X, GTX 1070 Ti, 16 GB RAM, Windows 10 Insider Build
FORUM MODERATOR • CREATOR OF SHOOTMANIA GALAXY & TRACKMANIA² PURSUIT

Contact me via GALAXY & PURSUIT DISCORD
zocka
Posts: 205
Joined: 15 Jun 2010, 17:56

Re: Label.ComputeWidth fails with composed text

Post by zocka »

Regarding only translations, it seems you could use TextLib::GetTranslatedText() to get the displayed Text.
I can't remember this function being available, when I last needed it, so I don't have experiences using it.

To fix the length of composed text, you might be able to hack your way with something like:
1. Remove all wildcards in your text (replace %1...%n by "")
2. Append the values to your text
3. Compute width of that
You might get into a bit of trouble, if you have line breaks in your text. ("something something.nickname" would break different from "something nickname something.", but as "a %1 b" might be "%1 a b" in another language, you can't just replace spaces along with the wildcards.)

To avoid that you could of course create your own sprintf function without too much effort.

Another thing regarding line breaks and ComputeWidth:
noyranea wrote: Label.ComputeWidth(Text) returns only the length of the last line (more precisely the length it should have without autonewline=True[...]). This will be fixed soon.
Maybe it is fixed by now, but as I learned about the not yet released ComputeHeight function in the same post in february 2015, I'm sceptical :D
manialink minigame shatter
my manialink: zockaml
my maniaflash: maniaflash?zocka
Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: No registered users and 0 guests