Auto-size lv_dropdown width

When sized too narrow, the dropdown widget currently draws the selected option text over the arrow symbol. At the same time, the widget doesn’t appear to be working with LV_SIZE_CONTENT set for the width (it just collapses down to almost zero width).

It’d be great if there was a way to automatically make the widget wide enough so that the longest available option fits without drawing over the arrow symbol. In fact, I think this should be the default mode because it looks rather bad when the text overflows into the symbol.

If I understand correctly, the culprit is that the handler for LV_EVENT_GET_SELF_SIZE only sets the height but not the width. To set the ideal width, I believe we’d have to measure the width of each option, pick the largest and add the width of the symbol.

I’d be curious if such a contribution would be acceptable or if maybe there’s another way to enable auto-width-sizing for the dropdown widget.

1 Like

Hi,

Your diagnosis is correct and I think it’d be a good feature. As all the options are stored in a single text, only this text’s width needs to be measured.

Contribution would be very welcome :slight_smile: