Re: getting the natural size of a widget
"David Powers" <[email protected]>
| Newsgroups | gmane.comp.lang.ocaml.lib.gtk |
|---|---|
| Message-ID | <[email protected]> |
This is perfect - thank you so much. I'll see if I can get this rigged into our code base. -David On 2/7/08, Julien Moutinho <[email protected]> wrote: > > On Wed, Feb 06, 2008 at 08:34:04PM +0000, David Powers wrote: > > I am attempting to use the GnoCanvas to build what is essentially a > custom > > container. Placing widgets on the canvas works like a charm, but I > can't > > seem to find where the normal containers are reading their sizing hints > > from. I can read the height/width_request properties, but they seem to > be > > minimal sizes (e.g. for a text entry box I get a height and width of 1). > > Does anyone have any hints on where I could go hunting - or maybe I > should > > be taking a different approach? > > According to the following links, gtk_widget_size_request() is the way > containers read their sizing hints: > > > http://library.gnome.org/devel/gtk/stable/GtkContainer.html#size-requisition > > "The size requisition phase of the widget layout process operates > top-down. > It starts at a top-level widget, typically a GtkWindow. > The top-level widget asks its child for its size requisition by calling > gtk_widget_size_request(). To determine its requisition, the child asks > its own children for their requisitions and so on. > Finally, the top-level widget will get a requisition back from its > child." > > > http://library.gnome.org/devel/gtk/stable/GtkWidget.html#gtk-widget-size-request > > "This function is typically used when implementing a GtkContainer > subclass. > Obtains the preferred size of a widget. The container uses this > information > to arrange its child widgets and decide what size allocations to give > them > with gtk_widget_size_allocate()." > > Unfortunately, gtk_widget_size_request() has not been wrapped inside > LablGTK yet. > However, I'm joining a little patch which wraps it plus an example that > may help you. > I've also applied the patch to: > svn://[email protected]/svn/lablgtk/branches/moutinho > > NOTE: my lablgtk2 top-loop fails to run the example: > % lablgtk2 lablgtk_example__size_request.ml > Fatal error: exception Failure("float_of_string") > 2% > (This bug may be related to ~x ~y ~width ~height parameters, > because without them it does not fail) > > So you may have to run the example with this command: > > % ocamlc -g -I +lablgtk2 lablgtk.cma lablgnomecanvas.cma gtkInit.cmo \ > lablgtk_example__size_request.ml && ./a.out > root_group#get_bounds: 0. 0. 0. 0. > widget#get_bounds: 0. 0. 23. 12. > widget#get_bounds: 25. 14. 52. 26. > List.length root_group#get_items = 2 > root_group#get_bounds: 0. 0. 52. 26. > found a widget item: > requested_width = 23 > requested_height = 12 > found a widget item: > requested_width = 27 > requested_height = 12 > > HTH. > > > _______________________________________________ > Lablgtk mailing list > [email protected] > http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk > > > _______________________________________________ Lablgtk mailing list [email protected] http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk