- Home /
Sizing skin text
I was wondering if there is a way to automatically adjust the size of the font to fit within the GUI.box. Currently the script uses a skin to render the text to the screen, the skin also contains information on the font type and size, is there a way to change the size of the skins font so that it will always fit within the box? Here is the line of code that is used to draw the skin to the screen.
[Coded in C#]
GUI.Box(new Rect(0, 0, ((slotsX slotSize) + (slotGapPadding slotsX)) - 2, slotSize), "" + "Inventory" + "", skin.GetStyle("Inventory"));
Any help is much appreciated.
With a style, you can use CalcSize() to get a size for a specific string. You'd then have to calc the new font size and create a new style for the font and size for use in the GUI.Box...or modify and restore the style you are using:
Vector2 size = skin.GetStyle("Inventory").CalcSize(new GUIContent(text));
How would I change the Vector2 into a int so that it can be used to change the font size ?
I don't have a firm answer...that is why I put the info in as a comment. You may be able to just scale it. Looking only at the width, something like this might work:
int fontSize = rect.width / size.x * orignalFontSize;
Where 'rect.width' is width used in the rect used to display the box.
If the sizing is not frequent, then an alternate approach would be to try increasing/decreasing sizes until the CalcSize() set you had a good fit.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
What is way to flash the screen WITHOUT using a Texture? 2 Answers
I can do this in JS or not ??? 2 Answers