1
$\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$
4
$\begingroup$

Two approaches.

not pixel accurate, but less code.

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(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$
  • $\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$ – Claas Kuhnen Jan 5 '16 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 '16 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.