2010-03-11, 09:37 AM
Ok. So.
Sometimes the text that I need to display in a plugin can be... quite long. Far longer than is going to fit in even the most generous of displays, to say nothing of more typical examples of screen real-estate.
That means I have to truncate the text at some useful position if I don't want it running off the end, or, alternately, if I want to append some suffix before sending it out to be rendered. (Say, for example, the resolution or the codec of the video.)
Just the same, if the user is using a widescreen, they have more width available than those that are not. Further, smaller font sizes will provide space for more text. In these cases, I would like to tailor the length of the displayed string based on what space is available, instead of taking a "well, this works for me, hope it works for you too!" approach.
.net provides the .measureString() method, but I need to know the font and a UI element's available width. The first I can likely get through some creative reading of the skin xml files. As for the latter, I'm not as sure.
Read the percentages from the xml and apply them to the current screen's resolution? Seems a bit flakey -- is there a better way? (Or an alternate approach entirely?)
Sometimes the text that I need to display in a plugin can be... quite long. Far longer than is going to fit in even the most generous of displays, to say nothing of more typical examples of screen real-estate.
That means I have to truncate the text at some useful position if I don't want it running off the end, or, alternately, if I want to append some suffix before sending it out to be rendered. (Say, for example, the resolution or the codec of the video.)
Just the same, if the user is using a widescreen, they have more width available than those that are not. Further, smaller font sizes will provide space for more text. In these cases, I would like to tailor the length of the displayed string based on what space is available, instead of taking a "well, this works for me, hope it works for you too!" approach.
.net provides the .measureString() method, but I need to know the font and a UI element's available width. The first I can likely get through some creative reading of the skin xml files. As for the latter, I'm not as sure.
Read the percentages from the xml and apply them to the current screen's resolution? Seems a bit flakey -- is there a better way? (Or an alternate approach entirely?)