Date: Wed, 22 Mar 2006 21:18:22 +1100 From: Erik de Castro Lopo To: lablgtk at math.nagoya-u.ac.jp Subject: Re: Box packing Message-Id: <20060322211822.7cc2e774.ocaml-erikd at mega-nerd.com> In-Reply-To: <20060322192654.172c7ea3.ocaml-erikd at mega-nerd.com> References: <20060322192654.172c7ea3.ocaml-erikd at mega-nerd.com> Organization: Erik Conspiracy Secret Labs Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Content-Length: 2632 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: ------------------------------------------------------------------ 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 main_box = 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:main_box#add () 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 main_box = let hbox = GPack.hbox ~homogeneous:false ~packing:main_box#add () in let text = GText.view ~width:100 ~height:100 ~border_width:3 ~packing:(hbox#pack ~expand:true ~fill:true) () in let vvalue = GData.adjustment ~lower:0.0 ~upper:100.0 ~step_incr:1.0 ~page_incr:1.0 ~page_size:0.0 () in let vscroll = GRange.scrollbar `VERTICAL ~adjustment:vvalue ~packing:hbox#pack () in hbox 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 in let textpanes = create_text_panes main_vbox in let hvalue = GData.adjustment ~lower:0.0 ~upper:100.0 ~step_incr:1.0 ~page_incr:1.0 ~page_size:0.0 () in let hscroll = GRange.scrollbar `HORIZONTAL ~adjustment:hvalue ~packing:main_vbox#pack () in window#show () ; GMain.Main.main () let _ = Printexc.print main () ------------------------------------------------------------------ Cheers, Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo +-----------------------------------------------------------+ "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of CommonLisp." -- Greenspuns Tenth Rule Of Programming