Guest User

I cannot center a widget using GBin.alignment

a guest
Feb 18th, 2026
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 2.07 KB | Source Code | 0 0
  1.  
  2. (* ocamlopt.opt -o squava -w s -I +lablgtk2 lablgtk.cmxa squava.ml *)
  3. (* ./squava *)
  4.  
  5. let window =
  6.     GMain.init ();
  7.     let wnd = GWindow.window ~resizable:true ~title:"Squava board game" ()
  8.     in  wnd#connect#destroy GMain.quit; wnd
  9.  
  10. let vbox1 =
  11.     GPack.vbox ~packing:window#add ()
  12.  
  13. let button id tooltip =
  14.     let but = GButton.tool_button ~stock:id () in
  15.     but#misc#set_tooltip_text tooltip;
  16.     but
  17.    
  18. let start =
  19.     button `NEW "Start a new game"
  20.  
  21. let about =
  22.     button `ABOUT "About Squava"
  23.    
  24. let toolbar =
  25.     let bar = GButton.toolbar
  26.         ~orientation:`HORIZONTAL ~style:`ICONS ~packing:vbox1#pack ()
  27.     in
  28.     bar#set_icon_size `LARGE_TOOLBAR;
  29.     bar#insert start;  
  30.     bar#insert (GButton.separator_tool_item ());
  31.     bar#insert about;  
  32.     bar
  33.  
  34. let center =
  35.     GBin.alignment ~xalign:0.5 ~yalign:0.5 ~packing:vbox1#add ()
  36.  
  37. let asize =
  38.     245
  39. let area =
  40.     GMisc.drawing_area ~width:asize ~height:asize ~packing:center#add ()
  41. let drawing =
  42.     new GDraw.drawable (area#misc#realize (); area#misc#window)
  43.  
  44. let statusbar =
  45.     GMisc.statusbar ~has_resize_grip:true ~packing:vbox1#pack ()
  46.  
  47. let dialog = GWindow.about_dialog
  48.     ~authors:
  49.     ["Game design by Cameron Browne & N\xC3\xA9stor Romeral Andr\xC3\xA9s";
  50.     "Program by SpiceGuid (<[email protected]>)"]
  51.     ~copyright:"Copyright \xC2\xA9 2026 SpiceGuid"
  52.     ~license:"GNU General Public License v3"
  53.     ~version:"0.1"
  54.     ~website:"https://boardgamegeek.com/boardgame/112745/squava"
  55.     ~website_label:"Board Game Geek : Squava"
  56.     ~parent:window
  57.     ~destroy_with_parent:true ()
  58.  
  59. let sqr_size = 
  60.     49
  61. let exposed _ =
  62.     drawing#set_foreground `WHITE;
  63.     drawing#rectangle ~x:0 ~y:0 ~width:asize ~height:asize ~filled:true ();
  64.     drawing#set_foreground `BLACK;
  65.     let y = ref 0 in
  66.     while !y <= asize do
  67.         drawing#line ~x:0 ~y:!y ~x:asize ~y:!y;
  68.         y := !y + sqr_size;
  69.     done;
  70.     let x = ref 0 in
  71.     while !x <= asize do
  72.         drawing#line ~x:!x ~y:0 ~x:!x ~y:asize;
  73.         x := !x + sqr_size;
  74.     done;
  75.     false
  76.  
  77. let () =
  78.     about#connect#clicked (fun () -> dialog#run (); dialog#misc#hide ());
  79.     area#event#connect#expose ~callback:exposed;
  80.     window#show ();
  81.     GMain.main ()
  82.  
Add Comment
Please, Sign In to add comment