Delivered-To: lablgtk at yquem.inria.fr Message-ID: Date: Fri, 8 Feb 2008 19:59:42 +0000 From: "David Powers" To: "Julien Moutinho" , lablgtk at yquem.inria.fr Subject: Re: [Lablgtk] getting the natural size of a widget In-Reply-To: <20080207155209.GA5619 at localhost> MIME-Version: 1.0 References: <20080207155209.GA5619@localhost> Mime-version: 1.0 Content-Type: multipart/mixed; boundary="===============0625855640==" Content-Length: 7775 --===============0625855640== Content-Type: multipart/alternative; boundary="----=_Part_29271_16079674.1202500782165" ------=_Part_29271_16079674.1202500782165 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 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://julien_moutinho@svn.gna.org/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 > Lablgtk@yquem.inria.fr > http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk > > > ------=_Part_29271_16079674.1202500782165 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 <julien.moutinho@gmail.com> 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://julien_moutinho@svn.gna.org/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
Lablgtk@yquem.inria.fr
http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk



------=_Part_29271_16079674.1202500782165-- --===============0625855640== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Lablgtk mailing list Lablgtk@yquem.inria.fr http://yquem.inria.fr/cgi-bin/mailman/listinfo/lablgtk --===============0625855640==--