Autoscaling Text
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?
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?
-
-
sfernandez
Site Admin
- Posts: 3184
- Joined:
Re: Autoscaling Text
Why don't just use a Viewbox to wrap the text?
Re: Autoscaling Text
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.
-
-
sfernandez
Site Admin
- Posts: 3184
- Joined:
Re: Autoscaling Text
The Viewbox has the option to scale only in one direction:
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 ![Wink ;)](./images/smilies/icon_e_wink.gif)
Code: Select all
<Viewbox StretchDirection="DownOnly" Width="200">
<TextBlock Text="{Binding DisplayName}" FontSize="18"/>
</Viewbox>
![Wink ;)](./images/smilies/icon_e_wink.gif)
Who is online
Users browsing this forum: No registered users and 4 guests