Gtk4: How to specify rows and columns of a GtkGrid object within a GtkBuilder ui file

Viewed 300

I would like to use a GtkBuilder ui file to declare a GtkGrid with 3 rows and 2 columns. The ui file should be usable with gtk4-rs (https://github.com/gtk-rs/gtk4-rs). Initially I used glade to get a first sketch of the ui file, but unfortunately gtk4-rs did fail to load it. Therefore I striped it down until I could start my app. How can I assign the elements into columns, so that gtk4-rs will still be able to load it?

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <requires lib="gtk+" version="3.4"/>
  <object class="GtkApplicationWindow" id="window">
    <child>
      <object class="GtkGrid">
        <child>
          <object class="GtkLabel">
            <property name="label" translatable="yes">Label1</property>
          </object>
        </child>
        <child>
          <object class="GtkButton" id="src_button">
            <property name="label" translatable="yes">Source</property>
          </object>
        </child>
        <child>
          <object class="GtkLabel">
            <property name="label" translatable="yes">Label2</property>
          </object>
        </child>
        <child>
          <object class="GtkButton" id="trg_button">
            <property name="label" translatable="yes">Target</property>
          </object>
        </child>
        <child>
          <object class="GtkButton">
            <property name="label" translatable="yes">Start</property>
            <property name="receives-default">True</property>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>

Where do I find the DTD for GtkGrind or other Gtk4 objects??

1 Answers

I don't know, did you found it out or not, but someone probably will come across to this post looking for the answer. Solution is to use <layout> inside child <object>. In your example it will be:

<?xml version="1.0" encoding="UTF-8"?>
<interface>
    <requires lib="gtk+" version="3.4"/>
    <object class="GtkApplicationWindow" id="window">
        <child>
            <object class="GtkGrid">
                <child>
                    <object class="GtkLabel">
                        <property name="label" translatable="yes">Label1</property>
                        <layout>
                            <property name="row">0</property>
                            <property name="column">0</property>
                        </layout>
                    </object>
                </child>
                <child>
                    <object class="GtkButton" id="src_button">
                        <property name="label" translatable="yes">Source</property>
                        <layout>
                            <property name="row">0</property>
                            <property name="column">1</property>
                        </layout>
                    </object>
                </child>
                <child>
                    <object class="GtkLabel">
                        <property name="label" translatable="yes">Label2</property>
                        <layout>
                            <property name="row">1</property>
                            <property name="column">0</property>
                        </layout>
                    </object>
                </child>
                <child>
                    <object class="GtkButton" id="trg_button">
                        <property name="label" translatable="yes">Target</property>
                        <layout>
                            <property name="row">1</property>
                            <property name="column">1</property>
                        </layout>
                    </object>
                </child>
                <child>
                    <object class="GtkButton">
                        <property name="label" translatable="yes">Start</property>
                        <property name="receives-default">True</property>
                        <layout>
                            <property name="row">3</property>
                            <property name="column">0</property>
                        </layout>
                    </object>
                </child>
            </object>
        </child>
    </object>
</interface>
Related