Create account / Log in

Leading and trailing spaces in text l abels

Issues with the Vassal engine.

Moderators: uckelman, Tim M

Leading and trailing spaces in text l abels

Postby crispy1critter » April 12th, 2021, 10:40 pm

If I create a text label, using the mono-space font, and include leading and/or trailing spaces, such spaces are included in the label as displayed. This can be useful where you want a uniform appearance in the background of the label across multiple pieces with different text.

But when I clone the piece, the leading and trailing spaces are removed on the cloned copy. Is this deliberate? Or just an artifact of how things work?

I can even imagine a case where at a scenario setup I would want all spaces for the label, and the player(s) would edit during the game. Note that all space labels are not accepted during creation

Thanks
crispy1critter
 
Posts: 14
Joined: February 24th, 2018, 4:06 am

Re: Leading and trailing spaces in text l abels

Postby Cattlesquat » April 13th, 2021, 3:00 am

Well I'm sure it's this code inside the Text Label that's doing it:

Code: Select all
public void mySetState(String s) {
  setLabel(s.trim());
}


Since "trim" removes leading and trailing spaces. I'm actually surprised your original piece's label "survives" that (or maybe it too loses its spaces as soon as it's saved and reloaded?)

If you want to work around it however you could put a $thing$ inside it that referenced a property that had leading/trailing spaces, and then the spaces would display?

I'm not precisely sure *why* the "trim" is there, and whether it is necessary -- a more accomplished expert on our encoding/decoding would have to weigh in.

Brian
User avatar
Cattlesquat
 
Posts: 1141
Joined: December 2nd, 2019, 4:57 pm
Location: Baltimore, Maryland, USA

Re: Leading and trailing spaces in text l abels

Postby crispy1critter » April 13th, 2021, 10:36 pm

Yeah - the spaces don't survive save/load, and trim probably has some generic usefulness, possibly w.r.t. buffer over-runs. I'll find another way to achieve the effect I want.
crispy1critter
 
Posts: 14
Joined: February 24th, 2018, 4:06 am

Re: Leading and trailing spaces in text l abels

Postby jrwatts » April 14th, 2021, 12:16 am

If you don't mind using HTML in your text labels, you could add   (the HTML entity for a non-breaking space) where you want spaces. Alternatively, if you set the text label to $someCalculatedProperty$, and then create a CP called someCalculatedProperty, you should be able to set that to " (put leading and trailing spaces inside double-quotes) ". Not positive that will work, but I can't think why it wouldn't.
jrwatts
 
Posts: 334
Joined: April 29th, 2020, 10:30 pm

Re: Leading and trailing spaces in text l abels

Postby crispy1critter » April 14th, 2021, 4:32 am

It needs to be something a user can easily do when designing a scenario; html is too much. (Though I love it's use in menu and chart labels.) The idea is that the pieces in a "wing" (or whatever) can be identified by the same color and size label, and the text of the label can further distinguish among the pieces

I have an alternate work-around
crispy1critter
 
Posts: 14
Joined: February 24th, 2018, 4:06 am

Re: Leading and trailing spaces in text l abels

Postby barbanera » April 14th, 2021, 4:08 pm

crispy1critter wrote:It needs to be something a user can easily do when designing a scenario; html is too much. (Though I love it's use in menu and chart labels.) The idea is that the pieces in a "wing" (or whatever) can be identified by the same color and size label, and the text of the label can further distinguish among the pieces

I have an alternate work-around


For similar applications I tend to use a image showing just a orange, say, rectangle of the required side. Then you place your text label at its center, with a transparent background. You can even use Game Piece Image Definitions inside Vassal to create such simple images, but beware of the limited colour palette. If the users are supposed to edit those text labels, I would make sure to truncate them to a maximum number of characters, to avoid them spewing out of the colored space.
barbanera
 
Posts: 516
Joined: January 12th, 2012, 2:27 pm


Return to Technical Support & Bugs

Who is online

Users browsing this forum: No registered users and 4 guests