Is it possible (easily) to know the minimum width a component is going to take, before creating it ?
I know the component size is determined after creation, in the parent resized() method. However, my question is more :
How can I make sure the width I’m assigning to a component is high enough to make it render correctly (without ellipsing text and so on).
I need to know this, in order to compute the minimum width of a column in a table.
Use Font::getStringWidth? Or the GlyphArrangment class?
Let’s take the example of a text button.
Let’s say the button displays “Cancel”.
I can get “Cancel” text size with “getStringWidth”. However I need “( Cancel )” (poor ascii art) width.
In over words, is there a way to know what the look and feel for a component will add to the text (or better, call a LookAndFeel’s static function to get the minimum size of the component, given a font, considering no ellipsis on text).
Currently, I’m doing a poor getStringWidth(“Cancel”) + 50. But, sure as hell, it’s gonna break as soon as the look and feel changes.
I’m almost sure the code is almost here in the LAF class, so maybe it would be cool to add a common interface for this ?
There’s nothing in there that I can think of to do that kind of thing… If it’s a button, you could use changeWidthToFitText()…?
I guess you’ve already done this in the jucer, indirectly.
When I click “Add a text button” in the jucer, you automatically compute the button size, before creating it, right ?
I haven’t parsed the whole code to extract the resizing code for each component. Maybe this could be moved to the L&F code, for basic components like TxtButton, Radio and Combo, before actually creating the component ?
After all, L&F classes are like a graphic template class, and the size should be part of this template.
Anyway, I’ve measured the components and deduced a “worst” case width, but it’s dependent of the L&F drawing code. So if it changes, the measures will be wrong.
Do you think it’s possible to add a function like the current “void getTabButtonBestWidth (int, const String &, int)” but for minimum width “getTextButtonMinimumWidth(int, const String &, int&)” and so on for other basic components ?
Ok, I’ve looked into some buttons I need, here is a list of my searches:
 TextButton : getStringWidth(button.text) + button.height[/]
 ToggleButton : getStringWidth(button.text) + min(24, button.height) + 8[/]
 TextEditor : getStringWidth(text.largestWordcontent) + leftIndent (default 4px) + 1 + borderSize.left (default 1px) + borderSize.right (default 1px) => default sum is 7px [/]
 ComboBox : same as TextEditor[/][/list]
Those numbers are valid only while shiny or old lookAndFeel is selected.
BTW, TextButton assume it will be round in all look and feel (because of button.height in the sum) which, to my point of view, should be in the look and feel class.
Ok, my 2 cents, just in case someone performs a search on the forum.