In the previous example, we used the box layout. Now let's learn another layout, grid. In fact, these la s are similar. If you understand the previous example, it is not difficult to use grid.
Program running effect:
Package mainimport ("github.com/gotk3/gotk3/glib" "github.com/gotk3/gotk3/gtk" "OS") func main () {const appid = "com. nayoso. example "app, _: = GTK. applicationnew (appid, glib. application_flags_none) app. connect ("Activate", func () {onactivate (APP)}) app. run (OS. ARGs)} func onactivate (application * GTK. application) {appwindow, _: = GTK. applicationwindownew (Application) appwindow. settitle ("Grid example") // -- above, the general code is input, and the following is the focus of this example:-D grid, _: = GTK. gridnew () // create the container appwindow. add (GRID) // Add the container to the window // now let's create some buttons to demonstrate the grid effect button1, _: = GTK. buttonnewwithlabel ("button 1") button2, _: = GTK. buttonnewwithlabel ("button 2") button3, _: = GTK. buttonnewwithlabel ("button 3") // Add buttons to the grid. attach (button1, 0, 0, 1, 1) // parameter: left, top, width, high grid. attach (button2, 1, 0, 1, 1) grid. attach (button3, 0, 1, 2, 1) // -- note that the button is in a coordinate axis, with the origin on the top left and the X axis on the right, Y axis down // -- it doesn't matter if you don't like it very much or understand it very well. I will introduce the visual UI design tool appwindow later. showall ()}
You may find that I sometimes use containers and la s to name the same thing. In fact, this is because it has both of these two properties.
Golang GTK + 3 Tutorial: grid layout