Text alignment for Button Matrices

I’m working on a layout that has a lot of buttons with left- and right- aligned text on an esp32. I think this kind of layout is reasonably common – for example, on this forum each topic has the title text left-aligned and replies/views/activity right-aligned. I’d love to use button matrices to implement this, as using individual lists and labels uses a whopping 80kB of memory just for the layout. I know that I could use several button matrices on top of each other to draw multiple pieces of text on each button, but it looks like there is no way to align the text in each of the button matrix’s buttons to anything other than the buttons’ respective centers.

If I’m missing a feature that could be used to easily implement this or if there are other text alignment plans for v7.0 I’d love to hear about them. Otherwise, I’d be happy to implement this and file a PR for it. After doing some testing, it looks like only the following bit of code in lv_btnm.c needs modified, although functions to allow this to be changed, documentation, etc. would also be necessary.

area_tmp.x1 += (btn_w - txt_size.x) / 2;
area_tmp.y1 += (btn_h - txt_size.y) / 2;

Just to be sure, do you mean this view?

If so, it really would be a reasonable update. We could use buttons_style.body.padding.left/right to set the spacing on the left and right.
It seems the alignment options can go to lv_btnm_ctrl_t.
Do you agree?

Blockquote
Just to be sure, do you mean this view?

Absolutely, that’s exactly what I mean!

Blockquote
We could use buttons_style.body.padding.left/right to set the spacing on the left and right.

Using the padding to set those values also makes perfect sense. Here I was thinking that there would have to be another field in lv_btnm_ctrl_t to set them, but that would work much better. As far as I can tell those padding values are currently unused by the button matrix.

Yes, the alignment options would have to go into lv_btnm_ctrl_t. I’ve seen that some other features can be disabled to reduce RAM usage, do you think it would be worth doing that for this field?

Yes, there are unused now.

Which features do you mean?

Blockquote
Yes, there are unused now.

Perfect, thanks!

Blockquote
Which features do you mean?

I was thinking of LV_USE_OBJ_REALIGN – AFAIK the button matrix is mostly meant to save RAM, so I was a bit worried that adding more fields to it might be a problem. Sorry about that though, looking through more LVGL code it seems like a non-issue. Would I be okay to put together a PR for this?

Yes, please! Thanks in advance. :slightly_smiling_face: