Robert Arkiletian wrote:
> Is there any
> mechanism in FLTK to ensure the label of a button fits in the button?
Like the others have said, not built-in. What you could do is derive your
own button from Fl_Button. Overload the label() and/or copy_label() and use
fl_measure() to measure the new text. Then call size() if needed. After you
resize, try calling something like parent()->init_sizes(). This should tell
the parent (some derivative of Fl_Group I'm sure) that the button
grew/shrunk.
Something like (untested):
void MyButton::label(const char *lbl)
{
// setup the drawing context needed for fl_measure()
fl_draw(labelfont(), labelsize());
// Indicate we want the fully width. May need to do
// some conditionals based on align()??
int tw = 0;
int th = 0;
fl_measure(lbl, tw, th, 1);
// Set the new width if it is longer than the widget
if(tw > w())
size(tw, h());
// Set the new height if it is taller than the widget
if(th > h())
size(w(), h());
// Tell parent we changed dimensions
if(parent())
parent()->init_sizes();
// mark this widget for redrawing
redraw();
}
Maybe something like that would work for you? I wrote this just now so I
have no idea if this would really work or not.
The biggest problem I foresee is not resizing the button, but updating the
sibling/parent widgets. They will no doubt need to adjust their positions.
As that adjustment cascades upward to the topmost window, the window itself
may need to grow.
Some window managers do not like this. I did this once for a Fl_Box
containing an image. I wanted the box to grow/shrink with the image
dimensions. In the end I had to show() then hide() the window (containing
the Fl_Box) in order for the new window dimensions to take effect.
--
Alvin
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk