UILayout.alignment - is it broken?

According to the API docs, I should be able to set a UILayout’s alignment to LEFT, RIGHT, CENTER, or EXPAND- with the latter being the default. However, changing this property seems to have no effect at all, in any situation that I’ve ever tried to use it.

It could be that this property doesn’t even do what I expect, in which case I’m very curious what its intended purpose actually is.

Right now, for example- I’m working on a panel for my studio’s artists that has a series of operators with paths as the text label, and being paths it makes sense to left-align them. In that same panel, I have a general notification for the user that is just a label, and it makes sense to center-align that, which again doesn’t seem to be possible.

actual project I’m working on is under NDA, but the gist is as follows:

def draw(self, context):
    layout = self.layout

    col = layout.column()
    col.alignment = 'LEFT'
    col.operator('my.operator', text='C:\\Centered\\Text\\Is\\Not\\Always\\Best\\')
    col.operator('my.operator', text='C:\\This\\Looks\\Weird\\')
    col.operator('my.operator', text='C:\\Why\\Is\\Center\\Alignment\\Forced\\')

    col = layout.column()
    col.alignment = 'CENTER'
    col.label(text='This is a notification. It looks weird left-aligned. Alignment does nothing.')

Unfortunately, it’s not possible to choose how to align the labels, the layout engine isn’t too flexible… The alignment property isn’t too helpful for your scenario.

Here’s what can be done with the alignment property. The example shows how to get left aligned buttons:

    def draw(self, context):
        layout = self.layout

        row = layout.row()
        row.alignment = 'LEFT'
        col = row.column()
        col.scale_x = 1.0
        col.operator('render.render', text='C:\\Centered\\Text\\Is\\Not\\Always\\Best\\')
        col.operator('render.render', text='C:\\This\\Looks\\Weird\\')
        col.operator('render.render', text='C:\\Why\\Is\\Center\\Alignment\\Forced\\')

In order for the alignment option to take effect, you need to have a sub-layout and give it some scale value.

interesting… so that’s what it’s for. seems really odd that they would give us such control over a niche use case like that, but for commonly needed text-alignment we have nothing :confused:

oh well, it’ll just look weird i guess.