weimingtom / agui

Automatically exported from code.google.com/p/agui
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Is there simple way to automate button size according to text? #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
so I don't have to write button.setSize(<some formula to guess the size>);

Original issue reported on code.google.com by kovarex on 13 May 2012 at 11:51

GoogleCodeExporter commented 8 years ago
See Button.resizeToContents()... If you need more room, call 
Button.setMargins(t,l,b,r) ... If you need something more customized, override 
Button.resizeToContents().

A lot of Widgets have resizeToContents or resizeToWidth.

Original comment by joshua_l...@hotmail.com on 13 May 2012 at 2:16

GoogleCodeExporter commented 8 years ago
The code is:

   void Button::resizeToContents()
        {
                int w = getFont()->getTextWidth(getText()) +
                        getMargin(SIDE_LEFT) + getMargin(SIDE_RIGHT);
                int h = getFont()->getLineHeight() +
                        getMargin(SIDE_TOP) + getMargin(SIDE_BOTTOM);

                setSize(w,h);

        }

Original comment by josh.lar...@gmail.com on 13 May 2012 at 3:15

GoogleCodeExporter commented 8 years ago
Thanks for the nice answer and the fact it is implemented nicely :)

Original comment by kovarex on 19 May 2012 at 8:36