This project is read-only.

Get SpriteFont used by the UI framework

Aug 29, 2012 at 9:45 PM

How would I go about getting the SpriteFont for any of the controls?

Aug 30, 2012 at 9:19 AM

It's controlled by the theme you're using (via the resources and associations made in the XML file defining the theme).

The controls themselves do not provide any property for retrieving the SpriteFont (they couldn't - they don't have any concept of graphics, that's all up to the visualizer). Also, each GUI control could use any number of fonts at the same time and again use different ones depending on its state.

The default theme only uses two SpriteFonts. If you want to use them for your own text, my recommendation would be to just load them via the content pipeline. The only other option would be to modify the default visualizer so that it returns the first sprite font used in a given control and state, but that would be pretty messy.

Aug 30, 2012 at 9:19 PM

Thank you for your quick response.

My goal is not necessarily to draw my own text using the font, but instead to determine the size of the text.  I need this so I can dynamically size a list of buttons depending on the text they need to display.

Aug 31, 2012 at 7:59 PM

As I was looking over your source code, I came across the MeasureString method in the FlatGuiGraphics.  In order to get the size of the string, I added a property for FlatGuiGraphics in the FlatGuiVisualizer.

Thank you again,