Re: How to find the exact size a button is going to get?

On Tue, 2008-06-03 at 13:03 +0200, Toralf Lund wrote:
> Paul Davis wrote:
> > On Tue, 2008-06-03 at 09:36 +0200, Toralf Lund wrote:
> >   
> >> varun shrivastava wrote:
> >>     
> >>> you can access GtkAllocation structure which stores the x, y, width 
> >>> and height allocated to a widget
> >>>       
> >> That will (only) give me the size of an existing widget, won't it?
> >>
> >> Not what I'm looking for; as I was saying, I want to know what size a 
> >> widget will have without actually creating it. Or differently put, I'd 
> >> like to know the "rules" for margins/borders that are drawn around a 
> >> widget I add to a button.
> >>     
> >
> > gtk_widget_size_request() is your friend.
> >   
> Hmmm. I still don't understand how this is supposed to help we when the 
> widget doesn't exist. Perhaps I'm a bit slow today...

it depends how accurate you want to be. the widget's dimensions can be
affected by an RC file. there is no fixed sized that is known in
advance. a user may have reduced button border widths, or increased
them. they may have changed several other properties about the widget,
or a theme may be doing this for them.

create a GtkWindow (do not show it). create the widget, add it to the
window. show the widget (not the window). this forces all style
information to be processed and "injected" into the widget. then call
size_request. then delete the window and widget, and continue on. the
whole process takes a couple of msecs at best.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]