Re: finding the position of a (just created) widget



Julian Bradfield <jcb+gtk dcs ed ac uk> writes:
Is there a clean way to get a synchronous resize calculation done?


No, because you can't know (for sure) what size the window manager
will assign a window until the window appears onscreen. Also, you
typically can't use a synchronous calculation since the user can
resize the window, for example. Moreover the resize calculation isn't
that expensive but isn't free either, so GTK likes to save it for an
idle handler.

So, no clean way. Any synchronous calculation is going to be a hack
that depends on assumptions that won't be true in all cases, which
makes your app less robust under modification and when porting between
GTK versions.

For most layout setups (where you expect the widget to get exactly its
requisition), you can just gtk_widget_size_request().

If you have a more complex layout you'd have to size_request() the
toplevel window, size_allocate it the whole size it requested, then
look at widget->allocation on your widget. But this won't properly
take into account some stuff such as geometry hints. 

Basically, GTK does not have a concept of synchronous size, so what
you're doing is trying to guess what size the widget will have, GTK
does not have this information to give you.

The clean solution is to just do anything that depends on the size in
a size_allocate signal handler, then your app will automatically
adjust to users resizing the window as a bonus.

Havoc





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