I am not entirely sure how to do what you are suggesting, since in the past I have opted to lay all my widgets out by hand using lv_obj_align calls. I am having trouble finding a way to get the container to center things on the horizontal axis while simultaneously keeping them in a row.
If your labels are a constant size you could increase the left and right padding on your container to get something closer to what you want.
Another idea is to use two containers. Create a parent container using LV_LAYOUT_COLUMN_MID, then, put your current layout on the child container and set it to shrink to fit its children. I think that might do what you want, though you would need to fiddle with the styling to hide the second container’s border.
For cases where an existing container layout happens to do what I want, I just use that. In other cases, I set the object’s position by hand. If I want it to always sit at a relative position to another object, I make use of lv_obj_align.
It’s not the cleanest solution, but it works for me. If you have many display sizes this is significantly more complicated to manage, though.
LVGL 8.0 is coming soon and will introduce support for the flexbox and grid layouts used in browsers. I believe these two combined can support just about any layout you would want. That should render this problem largely obsolete.
I see, thanks. The “align to a relative position to another object” I think it is not the case here (as I don’t have the other object to get the center of)
It is not just the display size problem but also the easy way to create the layout. It may happen if I change some size or position of an object I will have to adjust the positions of the others.
I came from a QT background so I was expecting a similar behavior or functionalities (maybe I was expecting too much )
QT also has that “springs” thing to adjust / force the layout.
I came with a solution, not perfect, that is, I created a container for each label and I manually set the size of the container (that I calculate based on screen size or parent size). That way I manage to manually “adjust” the placement of the labels centered, each one on its own centered container.
In your original post, it is hard to tell what is the desired outcome. The two images examples appear to be of what you do NOT want? Can you post a view of what the desired outcome is? Also, is your use case specifically for 4 labels, or are you just using 4 as an example and you want it to be for x labels?
Ok, thanks. The alignment looks to be how the tab bar appears on a tab view, via a button matrix, divided into n even sections with the text centered per section. If your “container within a container” approach works for you, I’d use that, I do a lot of manual layout with lv_obj_align, but I can’t think of anything right now that would be simpler