Velsen
Main St, Anywhere, USA 00000
1-111-222-3333

Hide Menu
gtkada example of fixed positioning of components
with Gtk.Main;
with Gtk.Window;
with Gtk.Fixed;
with Gtk.Button;
with Gtk.Widget;
with Gtk.Handlers;

procedure Fixed_Example is

   -- Callback package to handle window destruction
   package Window_Cb is new Gtk.Handlers.Callback (Gtk.Widget.Gtk_Widget_Record);

   procedure On_Destroy (Widget : access Gtk.Widget.Gtk_Widget_Record'Class) is
      pragma Unreferenced (Widget);
   begin
      Gtk.Main.Main_Quit;
   end On_Destroy;

   Window  : Gtk.Window.Gtk_Window;
   Fixed   : Gtk.Fixed.Gtk_Fixed;
   Button1 : Gtk.Button.Gtk_Button;
   Button2 : Gtk.Button.Gtk_Button;

begin
   -- 1. Initialize GTK
   Gtk.Main.Init;

   -- 2. Create and configure the top-level window
   Gtk.Window.Gtk_New (Window);
   Window.Set_Title ("GtkAda Gtk.Fixed Example");
   Window.Set_Default_Size (400, 300);

   -- Connect the close button (X) to exit the main loop
   Window_Cb.Connect (Window, "destroy", Window_Cb.To_Marshaller (On_Destroy'Access));

   -- 3. Create the Gtk_Fixed container and add it to the window
   Gtk.Fixed.Gtk_New (Fixed);
   Window.Add (Fixed);

   -- 4. Create buttons and place them at exact pixel coordinates (X, Y)
   Gtk.Button.Gtk_New (Button1, "Button at (30, 40)");
   Fixed.Put (Widget => Button1, X => 30, Y => 40);

   Gtk.Button.Gtk_New (Button2, "Button at (180, 150)");
   Fixed.Put (Widget => Button2, X => 180, Y => 150);

   -- 5. Show all widgets and start the GTK event loop
   Window.Show_All;
   Gtk.Main.Main;

end Fixed_Example;