i've this code
Main.adb
With Gtk.Main; Use Gtk.Main;
With Gtk.Window; Use Gtk.Window;
With Gtk.Button; Use Gtk.Button;
With Gtk.Widget; Use Gtk.Widget;
With Gtk.Grid; Use Gtk.Grid;
Procedure Main is
Win : Gtk_Window;
Button : Gtk_Button;
Button2 : Gtk_Button;
Button3 : Gtk_Button;
Grid : Gtk_Grid;
begin
Init;
Gtk_New (Win);
Win.Set_Default_Size (Width => 380,
Height => 502);
Gtk_New (Button,"Button");
Gtk_New (Button2,"Button2");
Gtk_New (Button3,"Button3");
Gtk_New (Grid);
Grid.Attach (Button,0,0);
Grid.Attach (Button2,0,100);
Grid.Attach (Button3,75,20);
Win.Add (Grid);
Win.Show_All;
Gtk.Main.Main;
end Main;
here I would like my first button to be at the top on the far left, my third button to the right but at the bottom and my Second button must be at the bottom. I tried almost all the methods but still in vain I can't align my widgets correctly so does anyone have an idea on how I can align all my widgets with a Gtk_Grid.
You can just add widgets to cells. As is already stated in the comment, the
Top
andLeft
parameters ofAttach
represent the cell indices (row/column), not pixels. See the annotated example below.If you want to position a widget using coordinates, then you can use a GTK Fixed container. Be aware, however, that this container is almost never a good solution for positioning widgets; widgets should, in principle, always be positioned using layout containers HBox, VBox, Table, Grid and Layout. This is to ensure proper widget composition regardless of the screen resolution and screen size of the user. This is emphasized in the description of the Fixed widget:
I've added an example that shows the usage of both container widgets, Grid and Fixed. In these example, I've moved the GTK code into a separate package in order to add a
Destroy_Event_Callback
which in turn will callGtk.Main.Main_Quit
to stop the GTK event loop and properly exit the program when you close the window.app.adb (using GTK Fixed, see manual and GtkAda source)
app.adb (using GTK Grid, see manual and GtkAda source)
app.ads
main.adb