yellowstonegames / SquidLib

Useful tools for roguelike, role-playing, strategy, and other grid-based games in Java. Feedback is welcome!
Other
448 stars 46 forks source link

SquidMessageBox oddly trimming spaces during wrapping #194

Closed Rakaneth closed 6 years ago

Rakaneth commented 6 years ago

SquidMessageBox seems to be exhibiting some odd behavior when wrapping IColoredStrings - it is eating spaces.

image

This does not seem to occur in SquidPanel (here I used a manual IColoredString.wrap()): image

The relevant code can be found here, in the describeCombat function.

tommyettinger commented 6 years ago

Weird stuff, hm... I'll take a look as soon as I can; family is visiting Jan 7 (today in most timezones) but I should be able to take a look after they head home. I wonder what's different between the two wrapping implementations...

tommyettinger commented 6 years ago

This is very odd, but I've narrowed down a possible cause. Still working on a fix. It looks like (when using GDXMarkup to generate IColoredString instances) closing a color tag with [] before a space (but not after a space) causes wrap() to ignore the space, possibly due to the behavior of String.split() with delimiters at the end of input. You can see on the bottom line here, the first space gets eaten:

This doesn't happen on the line above it because wrap() doesn't need to be called. The markup I'm using looks like this, where the text length is exactly within the line length for the first and one larger than the line length for the second (requiring wrapping):

        smb.appendWrappingMessage(GDXMarkup.instance.colorString("[CW Red]alpha[] [CW Apricot]beta [][CW Yellow]gamma [CW Jade]delta [CW Blue]epsilon [CW Purple]zeta[]..."));
        smb.appendWrappingMessage(GDXMarkup.instance.colorString("[CW Red]alpha[] [CW Apricot]beta [][CW Yellow]gamma [CW Jade]delta [CW Blue]epsilon [CW Purple]zeta[] eta"));

EDIT: Corrected a typo where "zeta" wasn't correctly colored because "CW" wasn't capitalized correctly. The image should have "zeta" in purple.

tommyettinger commented 6 years ago

This should be fixed now. The current TinyTest code that produced the above screenshot before now looks like: The issue did turn out to be String.split(); we now use StringKit.split(), which has various subtle differences including preserving trailing spaces (at the very least, it does this when they're the only contents of the String being split up).