3
$\begingroup$

I am really struggling with horizontal alignments.

Look at lower right image example.

Layer + Parent are in one column and a split function defines the width of the next column that contains the layer and parent UI elements.

The problem is that this way the row like horizontal alignment is off. Parent text is higher than the parent UI element.

I tried different row ideas but nothing worked. To my frustration in the upper right corner the parent UI is drawn on the left side while the layer element is on the right side. What causes this?

enter image description here

So this is what I try to do. Lets say 30/70 column spacing and the content aligned along their top edge

The % value should be global so I have to adjust it once and the layer + parent UI will be stretched along the length.

enter image description here

$\endgroup$
0

1 Answer 1

8
$\begingroup$

Two approaches.

not pixel accurate, but less code.

c = layout.column()
row = c.row()
split = row.split(percentage=0.3) # use factor instead of percentage for Blender 2.8+
c = split.column()
c.label("Layers")
split = split.split()
c = split.column()
c.prop(obj, "layers", text="")

c = layout.column(align=True)        
c.prop(obj, "parent", text="Parent")

enter image description here

Pixel perfect but a little convoluted!

c = layout.column()
row = c.row()
split = row.split(percentage=0.3)
c = split.column()
c.label("Layers")
split = split.split()
c = split.column()
c.prop(obj, "layers", text="")

c = layout.column()
row = c.row()
split = row.split(percentage=0.3)
c = split.column()
c.label("Parent")
split = split.split()
c = split.column()
c.prop(obj, "parent", text="")

enter image description here

The second version can be restated using a function, there's a lot of repetition, and you might want to do the same for more properties..

    def draw_props(labelname, propname):
        c = layout.column()
        row = c.row()
        split = row.split(percentage=0.3)
        c = split.column()
        c.label(labelname)
        split = split.split()
        c = split.column()
        c.prop(obj, propname, text="")
    
    draw_props("Layers", "layers")
    draw_props("Parent", "parent")
$\endgroup$
2
  • $\begingroup$ Ah you confirmed my opinion that you cannot do that with one percentage call. Would that not be possible to define the number as a global one so each percentage could fetch the number? $\endgroup$ Jan 5, 2016 at 23:10
  • $\begingroup$ you can make a function inside the draw function (nested function). I 've done that on many occasion to simplify my UI code. Else you are bound by the Blender layout $\endgroup$
    – zeffii
    Jan 5, 2016 at 23:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .