Saturday, June 9, 2012

GtkGrid example

I've just upgraded my Fedora 16 installation to Fedora 17 which includes gtk3-3.4. I was working on some hobby project—written in genie—of mine before the upgrade. After upgrading, I tried to compile the source code, but got deprecation errors for GtkHBox and GtkVBox. So I checked devhelp, and was suggested to use GtkBox instead. So I read GtkBox documentation, then I found out that it's also will face the same fate as it's brothers. GtkGrid became the new way. I kinda don't like this change. But anyhow, life must goes on.

Continuing on, GtkGrid is similar to GtkTable, but unlike GtkTable, it stores the child's expand and margin property instead of having its container to give allocation to it. Seems to me to be GtkBuilder or GtkUIManager (I never used this before) friendly.
 
In genie, If you want to create a box with 3 buttons with the following layout
[<button1:!expand><<<<button2:expand>>>>><button3:!expand>]

the old way to do this is
...
var
     box = new HBox(false, 0)
     b1 = new Button.with_label("button1")
     b2 = new Button.with_label("button2")
     b3 = new Button.with_label("button3")

box.pack_start(b1, false, true, 0)
box.pack_start(b2, true, false, 0)
box.pack_start(b3, false, true, 0)
...

now, with GtkGrid, you had to do like this

...
var
     grid = new Grid
     b1 = new Button.with_label("button1")
     b2 = new Button.with_label("button2")
     b3 = new Button.with_label("button3")

b2.expand = true
grid.attach(b1, 0, 0, 1, 1)
grid.attach(b2, 0, 1, 1, 1)
grid.attach(b3, 0, 2, 1, 1)
...

No comments:

Post a Comment