Page 1 of 1

Autoscaling Text

Posted: 02 Apr 2014, 21:13
by wckdspn
Historically, we've had issues with localized text in menus that takes up too much space (I'm looking at you German). Optimally, we restructure layout so things look correct for all of the locales we support, but sometimes things come in late and we are forced to make it work within our existing constraints. Our usual solution is to autoscale the text to fit into an area in which it is nested.

The question is, what is the best way to do this such that it is as painless as possible for artists. Ideally it would just be an additional property we can attach to Text objects that causes it to scale instead of truncate or wrap. The behavior can be implemented as long as we can determine the exact width of the text (in pixels) with the current font and scale. We'll need to execute it right after the text is set, without necessitating setting the text manually (as artists are relying on ViewModel classes).

Thoughts?

Re: Autoscaling Text

Posted: 02 Apr 2014, 22:01
by sfernandez
Why don't just use a Viewbox to wrap the text?

Re: Autoscaling Text

Posted: 02 Apr 2014, 23:47
by wckdspn
The issue with Viewbox is that it scales up as well as down, whereas we really only want to scale the text if it *doesn't* fit.

Re: Autoscaling Text

Posted: 03 Apr 2014, 00:47
by sfernandez
The Viewbox has the option to scale only in one direction:
<Viewbox StretchDirection="DownOnly" Width="200">
    <TextBlock Text="{Binding DisplayName}" FontSize="18"/>
</Viewbox>
The previous Viewbox will render the text on 18 pixels height while text fits inside the 200 pixel width. And will scale it down if text doesn't fit. I think this is exactly what you need ;)

Re: Autoscaling Text

Posted: 03 Apr 2014, 00:54
by wckdspn
That is indeed what we need, yes. Thank you.