Gamua / Starling-Framework

The Cross Platform Game Engine
http://www.starling-framework.org
Other
2.84k stars 819 forks source link

Textfield autoSize bug with isHtmlText enabled #924

Open jimmymjing opened 7 years ago

jimmymjing commented 7 years ago

Hello, Textfield's autoSize doesn't work once I upgraded to Starling 2.0.

textFieldIns.isHtmlText = true;
textFieldIns.autoSize = TextFieldAutoSize.BOTH_DIRECTIONS;

This bug has been mentioned here also: https://github.com/Gamua/Starling-Framework/issues/820

I find that if I disable isHtmlText property the autoSize would work properly though.

PrimaryFeather commented 7 years ago

Unfortunately, that's a limitation of the autoSize property: Horizontal autoSize does not work for HTML text, since such text might contain custom alignment.

For example, think of HTML content that contains one line that's aligned to the left, and another that's aligned to the right. What would be the optimal size for such a TextField?

I definitely need to add this information to the API reference. I'll do that!

jimmymjing commented 7 years ago

But autoSize works with HTML text in Starling 1.7... The way I found this problem is because I updated the Starling to 2.0.

PrimaryFeather commented 7 years ago

Hm, well, Starling 1.7 allowed to use autoSize on html text, but if you inserted text with a problematic alignment (e.g. both left- and right-aligned paragraphs), this caused an exception. Thus the change in Starling 2.0 to not allow autoSize for HTML text at all, to play safe. Unfortunately, there is no way I can find out myself which kinds of alignments are used inside the text.

Sorry! 😦

jimmymjing commented 7 years ago

Thanks so much for your reply, Daniel! I will try to find other solutions then. Actually I was trying to achieve a typewriter effect for subtitles. And I need </br> for line break. I set the textfield as autsized so I could vertically center the textfield depending on how many lines it may contain.

PrimaryFeather commented 7 years ago

Your welcome!

I set the textfield as autsized so I could vertically center the textfield depending on how many lines it may contain.

Hm — I just checked this, and vertical autosizing should actually work! It's just the horizontal autosize variants that don't. So you could set the TextField to a fixed width, but let the height be automatically calculated.

Could you try that out?

jimmymjing commented 7 years ago

Hello Daniel, Yes, vertical autosizing works perfectly! Thanks. As you've answered on the forum, I will try monospace letter solution for center-aligned typewriter effect.(as it is a very common RPG games subtitle effect. just wonder how they achieved this...)