How to customize field column sizes on a form

I’m currently customizing a form view and I’ve attached a screenshot for reference. I’m trying to better control the layout and spacing of fields and labels in a row.

For example at the very first row, I have two columns (“Hooks” and “Picks”) that are placed too far apart from each other, creating a lot of empty space in between.
And DPN File field and the field next to it (the upload button) is really far from it.
I’d like to:

  • Show three or more label+field pairs in a single row (not just two i.e., a way to fit as many label+field pairs in a single row or only label, or only field depending if I want to show only label or field for a column).
  • Control the width or spacing of the columns to bring fields closer together. (Goal would be to bring first two fields together - Hooks and Picks)
  • Possibly align fields to the left or right within a row, depending on the context. (Sometimes I would want to have all the fields align to the left or right, it’s fine if I have to add an attribute to each xml tag for that).
  • Understand what layout options Tryton provides to help fine-tune this, such as col, colspan, xalign, yalign, I want to understand these work. I assumed this worked like css flex but I think I got this wrong.

Basically, I’m looking to mix and match fields in a more compact and readable layout, rather than them being too spaced out.

Can someone guide me on how to approach this? Any examples or tips would be greatly appreciated.

Thanks in advance!

Here you can use a group with a colspan of 3 of 4 and col="-1". This way you get more flexibility with arranging fields closer together. In Tryton this is often used to add checkboxes (boolean fields).
To have a cleaner look, you should use a col >0, e.g.

<group id="hooks-picks" colspan="2" col="4">
    <label name="hooks">
    <field name="hooks">
    <label name="picks">
    <field name="picks">
</group>

This way the fields and labels of “Hooks” and “Picks” are arranged in the space which is actually occupied by the label and field of “Hooks”. “Total Picks” would move to where actually “Picks” is.

A little cleaner look gives this:

<label name="hooks">
<group id="hooks-picks" colspan="1" col="4">
    <field name="hooks">
    <label name="picks">
    <field name="picks">
</group>

This way the “Hooks” label is in line with the other labels on the left side of the form.

Here you could play a long time with xexpand, xfilland xalign. But in your example the problem seems to be the default col of 4 in the form definition. So each label and field is arranged in a table with only 4 columns. A field or a label will never step over the column border of the previous column.
But you can change this default by using a col="6" for the general layout and using group for the detail. E.g.

<form col="6">
    <label name=…
</form>

Yes, CSS is the representation in SAO, but the XML is also rendered in GTK for the Tryton Client. All the attribute names come from GTK. You can look up their behaviour in tools like gtk-demo.

To be true I havn’t exactly understand the difference between xexpand and xfill. Usually I play around with them.

Also you can run the Tryton server and client with --dev option to let it reload view changes. In the client you just need to re-open the view to see the changes quasi-immediately. Not sure if this is the default with Sao.
HIH

3 Likes

thanks, @udono , this is a very good and helpful explanation!

1 Like

Hey there @udono,

Thanks a lot for your detailed and insightful response. I appreciate the time you took to explain everything.

Would you mind elaborating a bit more on how to practically use these variables too → xalign, yalign, xfill, and yfill in the somewhat similar context (form view) ? I can find them in the documentation, but for practicality, it would be really helpful if the usage is clear to me and how to apply them effectively.

Thanks again!

In general the prefix x is related to horizontal changes and y to vertical changes.

xalign and yalign are numbers between 0.0 and 1.0. xalign 0.0 is at the left (e.g. label1), 0.5 is in the middle (e.g. label2) and 1.0 is at the right (e.g. label3) of a space.
E.g. of a form col="4":

+--------------------------+---------------+----------+---------+
| label1                   | [field1]      |  label   | [field] |
+--------------------------+---------------+----------+---------+
|        label2            | [field2]      |  label   | [field] |
+--------------------------+---------------+----------+---------+
|                   label3 | [field3]      |  label   | [field] |
+--------------------------+---------------+----------+---------+

yalign 0.0 is on top (e.g. labelX), 0.5 is in the center (e.g. labelY) and 1.0 is at the bottom (e.g. labelZ) of a space.

+---------------------------------------------------------------+
| labelX                   | [                                  | 
|                          | huge                               |  
|                          | one2many                           | 
|                          | field                              | 
|                          |  ]                                 | 
+---------------------------------------------------------------+

+---------------------------------------------------------------+
|                          | [                                  | 
|                          | huge                               |  
| labelY                   | one2many                           | 
|                          | field                              | 
|                          |  ]                                 | 
+---------------------------------------------------------------+

+---------------------------------------------------------------+
|                          | [                                  | 
|                          | huge                               |  
|                          | one2many                           | 
|                          | field                              | 
| labelZ                   |  ]                                 | 
+---------------------------------------------------------------+

xfill and yfill are 0 or 1 and if 1, the widget tries to fill the given space. With this you can make widgets larger (wider or higher). HIH

2 Likes