Lvgl 5.3 and highlight text in lv_ta

Just a quick question about lvgl 5.3 and text areas. I’m stuck on 5.3 for historical reasons.

I’d like to highlight some text in a text area. There does not appear to be a built in way of doing this. I’ve not been able to set styles on the various lv_ta components to do this. I’d like to set the background color of the text to a dark color that is different then the lv_ta background, and I’d like it to be inset with respect to the text area border. Essentially the usual GUI text highlight inside a text area. Something like what is shown below.


I’ve tried changing the styles set on the ext->label object. But that only partially works. I can change the text color, but not the background color.

Changing the background color on the lv_ta works of course. But I can’t get it to inset with respect to the border.

Any help is greatly appreciated.

Unfortunately, I only added built-in text selection support to LittlevGL in version 6.0. That would do exactly what you’re asking, but obviously it’s not available in 5.3.

If you had the skill and the time, you could try backporting the two relevant commits (82a095b and e63e1f2) to 5.3.

And, for the record, I know it’s time consuming, but would you mind filling out the template next time? You provided all the information we needed for this question, but many times others don’t give us enough information, so we’re trying to instill good habits. :wink:

You can play with lv_ta_get_label(); lv_label_set_body_draw(), and the paddings of the styles. It’s quite inconvenient and not flexible but IMO it’s the most simple way to make a text selected. Note that it can select only the whole text.

Thanks for the suggestions, I’ll have a look at the two options.

Apologies for not following the new template format, it took me awhile to figure out that it was markdown (or markdownish) and I had deleted it before I realized that.

I’ll update the templates to mention Markdown.