Page MenuHome

UI: Center align Menu Buttons without text
Needs ReviewPublic

Authored by Luis de Bethencourt Guimera (luisbg) on Aug 14 2019, 5:18 PM.



Menu Buttons with icons should only be aligned left if they have text since the breathing room for text and icons is different.

Only align a button to the left when it has text.

This can be visible in the Add a texture paint slot drop down menu button.

Notice that the cross icon is mis-aligned.

Diff Detail

rB Blender

Event Timeline

This also affects the snapping popover and object types visibility in a way that looks a little bit worse to me.

Hi Brecht, I did this approach because I thought it didn't affect adversely other menu buttons.

I have a different approach in mind in that case but I will investigate further before sending a new version.

Thanks for reviewing.

I'm no help here at the moment, despite pointing you at this. Looking around I can't find where that ICON_ADD button is actually added for that PAINT_OT_add_texture_paint_slot operator menu.

Luis de Bethencourt Guimera (luisbg) edited the summary of this revision. (Show Details)

My other approach is to make sure a uiBut has text before aligning it left. If it doesn't have text it should use the default center align.

That said, I can't reproduce your problem Brecht. This is how the snapping popover looks to me after applying either the original or new patches. So I'm not 100% confident it will solve it. Sorry.

Also, I didn't check if but is a valid pointer before destructuring because the code after it UI_but_drawflag_enable assumes the pointer isn't NULL. It should be safe.

This is how the snapping popover looks to me in git master. It is the same as with my patch. Not sure this is the place you are alluding to @Brecht Van Lommel (brecht)
My patch doesn't affect it but I want to make sure I'm looking at the right place.

Did not test the patch, but I meant the button that opens these popovers, not the contents.

When making these kinds of changing, copy a Blender build from before the changes and alt+tab between the two builds to see exactly what was affected.

I know this looks indirect but the button is only left-aligned when we also want to force it to become a UI_BTYPE_MENU, via the force_menu argument. Which from my research we only need to do for popovers in panels.

So to avoid centering the wrong buttons. I think we can keep Enum Menus as UI_BTYPE_PULLDOWN.

My alternative idea would be to use the content_hints item of the uiBlock. This feels more complicated than it needs to be.

This is how the buttons look before my patch:

And after:

I noticed more icons were affected by this wrong alignment besides 'ADD', for example 'PLUS'.
Maybe the problem is in the icons: their size/scaling doesn't match the left alignment. I would need some help to know how that area works if that is a preferred way of solving this.

But the fact that these icons align nicely when centered, is why I propose the patch as is.

Before the patch:

After the patch: