Delivered-To: lablgtk at yquem.inria.fr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:date:to:subject:message-id:mail-followup-to:references:mime-version:content-type:content-disposition:in-reply-to:user-agent:from; bh=MG15mbZX2P172zQH6G/zWuI4yV3L4UPXZBt8klRlywE=; b=qLyNONqcNXPF3Qlk3pQuzSIJNinSY6NiTAuWjOwvRanCBxPSZjwagseOx5g7qKJEitCfUV5/l8QNzz01k41/GVmI6wxAEDf56C6AiIZLZbQNOCjX4zxY7L+yvbojEvd70ZZgGtZAVnJEXFs0EgP7yd9w5mPzwwbIpTkFqy//92s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:to:subject:message-id:mail-followup-to:references:mime-version:content-type:content-disposition:in-reply-to:user-agent:from; b=D7QrFOp+tD/fdv02X77EzHCa4Yo+RMudoKZFM4PpVExAbi6WAVjB2Z5aAhiVkr0A7EqvV9aWxgvKB7BMhhd+DqKUEtZdS2NU8dBaAnk0TPnGaDJSBj09qJ3xryOBi89FePEFADXWckf8CZ9nQ9ujJsGHWdZHwzF+YCRr2liAheY= Date: Thu, 7 Feb 2008 16:52:10 +0100 To: lablgtk at yquem.inria.fr Subject: Re: [Lablgtk] getting the natural size of a widget Message-ID: <20080207155209.GA5619 at localhost> Mail-Followup-To: Julien Moutinho , lablgtk@yquem.inria.fr References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: From: Julien Moutinho Content-Type: multipart/mixed; boundary="AqsLC8rIMeq19msA" Content-Length: 7644 --AqsLC8rIMeq19msA Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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. --AqsLC8rIMeq19msA Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="lablgtk_example__size_request.ml" (* ocamlc -g -I +lablgtk2 lablgtk.cma lablgnomecanvas.cma gtkInit.cmo \ lablgtk_example__size_request.ml && ./a.out *) let window = GWindow.window () ~show: true in let _ = window#connect#destroy ~callback: GMain.Main.quit in let canvas = GnoCanvas.canvas () ~packing: window#add in let root_group = canvas#root in let () = print_string "root_group#get_bounds:"; Array.iter (fun x -> print_string (" "^(string_of_float x))) root_group#get_bounds; print_endline "" in let widget = GMisc.label () ~text: "Hello" ~show: true in let width, height = GtkBase.Widget.size_request widget#as_widget in let width = float_of_int width and height = float_of_int height in let widget = GnoCanvas.widget root_group ~widget ~width ~height in let () = print_string "widget#get_bounds:"; Array.iter (fun x -> print_string (" "^(string_of_float x))) widget#get_bounds; print_endline "" in let widget = GMisc.label () ~text: "World" ~show: true in let x, y = width +. 2., height +. 2. in let width, height = GtkBase.Widget.size_request widget#as_widget in let width = float_of_int width and height = float_of_int height in let widget = GnoCanvas.widget root_group ~widget ~x ~y ~width ~height in let () = print_string "widget#get_bounds:"; Array.iter (fun x -> print_string (" "^(string_of_float x))) widget#get_bounds; print_endline "" in print_endline ("List.length root_group#get_items = "^string_of_int (List.length root_group#get_items)); let () = print_string "root_group#get_bounds:"; Array.iter (fun x -> print_string (" "^(string_of_float x))) root_group#get_bounds; print_endline "" in List.iter begin fun item -> let property = try Some (Gobject.Property.get_dyn item#as_item "widget") with Not_found -> None in match property with | Some (`OBJECT (Some obj)) -> print_endline "found a widget item:"; let obj = GtkBase.Widget.cast obj in let requested_width, requested_height = GtkBase.Widget.size_request obj in print_endline (" requested_width = "^string_of_int requested_width); print_endline (" requested_height = "^string_of_int requested_height); | _ -> () end root_group#get_items; GMain.Main.main () --AqsLC8rIMeq19msA Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="lablgtk__gtk_widget_size_request.patch" Content-Transfer-Encoding: quoted-printable Index: src/ml_gtk.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- src/ml_gtk.c (r=C3=A9vision 1386) +++ src/ml_gtk.c (copie de travail) @@ -299,6 +299,18 @@ ML_2 (gtk_widget_get_ancestor, GtkWidget_val, Int_val, Val_GtkWidget) ML_1 (gtk_widget_get_colormap, GtkWidget_val, Val_GdkColormap) ML_1 (gtk_widget_get_visual, GtkWidget_val, (value)) +CAMLprim value +ml_gtk_widget_size_request (value w) +{ + CAMLparam1(w); + CAMLlocal1(ret); + GtkRequisition r; + gtk_widget_size_request (GtkWidget_val(w), &r); + ret =3D alloc_small (2,0); + Field(ret,0) =3D Val_int(r.width); + Field(ret,1) =3D Val_int(r.height); + CAMLreturn(ret); +} CAMLprim value ml_gtk_widget_get_pointer (value w) { int x,y; Index: src/gtkBase.ml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- src/gtkBase.ml (r=C3=A9vision 1386) +++ src/gtkBase.ml (copie de travail) @@ -64,6 +64,7 @@ external unrealize : [>`widget] obj -> unit =3D "ml_gtk_widget_unrealize" external queue_draw : [>`widget] obj -> unit =3D "ml_gtk_widget_queue_dr= aw" external queue_resize : [>`widget] obj -> unit =3D "ml_gtk_widget_queue_= resize" + external size_request : [>`widget] obj -> Gtk.requisition =3D "ml_gtk_wi= dget_size_request" external draw : [>`widget] obj -> Gdk.Rectangle.t option -> unit =3D "ml_gtk_widget_draw" (* Index: src/gtk.ml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- src/gtk.ml (r=C3=A9vision 1386) +++ src/gtk.ml (copie de travail) @@ -135,6 +135,7 @@ type statusbar_context type selection_data =20 +type requisition =3D int * int type rectangle =3D { x: int; y: int; width: int; height: int } type target_entry =3D { target: string; flags: target_flags list; info: in= t } type box_packing =3D --AqsLC8rIMeq19msA 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 --AqsLC8rIMeq19msA--