studio icon indicating copy to clipboard operation
studio copied to clipboard

LVGL textarea: Add option to retain cursor position on text change

Open fietser28 opened this issue 6 months ago • 0 comments

Is your feature request related to a problem? Please describe. When the text area receives a new text using lv_textarea_set_text (used by code generated for flow) the cursor moves to the last position. Sometimes this is not desired.

When programming LVGL in C/C++ you can easily circumvent this by wrapping the lv_textarea_set_text with lv_textarea_get_cursor_pos and lv_textarea_set_cursor_pos. Because the screen is not updated between these calls, the cursors stays in the same location (with monospaced fonts).

Describe the solution you'd like Add a checkbox in the textarea widget properties "Retain cursor position on text update". If this checkbox is checked additional lv commands are generated in screens.c

Describe alternatives you've considered Adding native code via native actions or native variables. I tested this and it works BUT it is way to slow (or actually the lv calls are out of order for the desired result): You can see the cursor hop around on the screen. Manually changing the screen.c code wrapping the update in the tick section solved it.

Additional context Example of modified generated code (added _get_cursor_pos and _set_cursor_pos calls): image I've tested this first example and this works well. No cursor flickering.

Or probably more efficient: image

It seems LVGL handles out of bounds nicely (e.g. new text is shorter than old text).

fietser28 avatar Jul 31 '24 20:07 fietser28