From: Olivier Andrieu MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: <17441.11479.188490.759314 at karryall.dnsalias.org> Date: Wed, 22 Mar 2006 11:54:15 +0100 To: Erik de Castro Lopo Cc: lablgtk at math.nagoya-u.ac.jp Subject: Re: Box packing In-Reply-To: <20060322211822.7cc2e774.ocaml-erikd at mega-nerd.com> References: <20060322192654.172c7ea3.ocaml-erikd at mega-nerd.com> <20060322211822.7cc2e774.ocaml-erikd@mega-nerd.com> Content-Type: multipart/mixed; boundary="+m8HC5eNZt" Content-Length: 2340 --+m8HC5eNZt Content-Type: text/plain; charset=us-ascii Content-Description: message body and .signature Content-Transfer-Encoding: 7bit Erik de Castro Lopo [Wednesday 22 March 2006] : > > Erik de Castro Lopo wrote: > > > Hi all, > > > > Some time ago I did some coding with the GTK+ widgets in C. I am > > now trying to do something an Ocaml and I'm not finding it any > > easier than it was in C :-). > > > > I'm basically trying to construct something like a text editor > > with a menubar at the top, a text are in the middle and scroll > > bars to the right and bottom. > > Here's the code: Right: - don't use #add for packing in boxes, you can't control the options: #add happens to use expand:true and fill:true, you usually don't want that for a menubar. Use #pack instead. - use the GBin.scrolled_window for adding scrollbars, it takes care of all the packing, connecting, etc. of your widget Updated code in attachment. Cheers -- Olivier --+m8HC5eNZt Content-Type: text/plain Content-Disposition: inline; filename="b.ml" Content-Transfer-Encoding: 7bit let print msg () = print_endline msg ; flush stdout let file_entries = [ `I ("Open", print "Open") ; `I ("Save As", print "Save As") ; `S ; `I ("Quit", GMain.Main.quit) ] let create_menubar packing = let create_submenu label menubar = let item = GMenu.menu_item ~label ~packing:menubar#append () in GMenu.menu ~packing:item#set_submenu () in let box = GPack.vbox ~homogeneous:false ~packing () in let menubar = GMenu.menu_bar ~packing:(box#pack ~expand:false) () in let menu = create_submenu "File" menubar in GToolbox.build_menu menu ~entries:file_entries ; menubar let create_text_panes packing = GText.view ~width:100 ~height:100 ~border_width:3 ~packing () let main = (* Make a window *) let window = GWindow.window ~title:"Token Merge" () in ignore (window#connect#destroy ~callback:GMain.Main.quit) ; let main_vbox = GPack.vbox ~homogeneous:false ~packing:window#add () in let menubar = create_menubar main_vbox#pack in let scroll_w = GBin.scrolled_window ~packing:(main_vbox#pack ~expand:true) () in let textview = create_text_panes scroll_w#add in window#show () ; GMain.Main.main () --+m8HC5eNZt--