2
$\begingroup$

In the add-ons I am writing, I can only put one entity per line. I would like to be able to put multiple of them in one row. Is there something that allows me to do this?

The image from ArchiMesh is what I am aiming for:

$\endgroup$
1
  • 4
    $\begingroup$ You can use the layout.row() then populate that row with your operators. See : blender.stackexchange.com/a/58368/86891 and you should look into the ui_panel.py script template available directly in the text editor $\endgroup$
    – Gorgious
    May 7, 2020 at 7:01

2 Answers 2

7
$\begingroup$

UILayout.column_flow

Perhaps the easiest way to have a 2 column layout is using the column_flow layout, set to 2 columns.

Replacement draw method for Text Editor > Templates > Python > UI Panel Simple

enter image description here 11 add cube operator buttons by way of example

def draw(self, context):
    layout = self.layout
    cf = layout.column_flow(columns=2, align=False)
    for i in range(11):
        cf.operator("mesh.primitive_cube_add")

Changing to 3 columns.

enter image description here cf = layout.column_flow(columns=3)

enter image description here cf = layout.column_flow(columns=3, align=True)

$\endgroup$
1
5
$\begingroup$

To create multiple entities in a row, you need to use layout.row().

What layout.row() does is it essentialy tells Blender that you are focusing on a single row. Every prop, operator, etc you put after layout.row() will be in that row until you put another layout.row(), telling Blender to focus on the next row.

Here is an example:

layout = self.layout()
row = layout.row()   # Focus on this row
row.prop(prop, "property")   # Add a property
row.operator("operator")   # Adds an operator in the same row as the property.

row = layout.row()   # A new row

and properties here will be on a separate row.

You can also do row = layout.row(align = True) to make the borders of entities flush with each other.

$\endgroup$

You must log in to answer this question.