Hi,
How to clear screen using lv_textarea and positioning cursor at upper left corner of text area, like cls command in windows command prompt ?
I would appreciate a suggestion on how to use the backspace ( 0x08 ) in the lv_textarea as well.
Backspace ( 0x08 ) is the code returned by my pc keyboard.
Thank’s.
Hi @Baldhead ,
You can simply call:
lv_textarea_set_text(your_ta, "");
to clear the the text area. The default implementation of the text area implements backspace etc. so you shouldn’t have to do any extra work for this. See the library code here to see the default implementation.
I hope that helps.
Kind Regards,
Pete
Thank’s @pete-pjb , “lv_textarea_set_text(your_ta, “”);” worked to clear screen.
I am echoing the typed characters directly to display ( but i can parse it if needed, and send another character to lv_textarea to lvgl backspace in screen ).
When i echo backspace ( 0x08 ) to screen, the cursor dont moves.
void terminal_lvgl( char character )
{
term.ch = getchar();
lv_textarea_add_char( ta, term.ch );
if( iscntrl( term.ch ) ) // A character is considered to be a control character if its ASCII value is in the range 0x00 to 0x1F inclusive, or 0x7F.
{
parse_control_signals( );
}
}
static void parse_control_signals( )
{
if( term.ch == 0x08 && term.index != 0 ) // Backspace code.
{
term.index--;
term.str[ term.index ] = '\0';
uint32_t position = lv_textarea_get_cursor_pos( ta );
lv_textarea_set_cursor_pos( ta, position - 1 );
lv_textarea_add_char( ta, ' ' );
lv_textarea_set_cursor_pos( ta, position - 1 );
return;
}
}
Do i need to define the backspace code in the lvgl ?
In see this in file lv_symbol_def.h:
#if !defined LV_SYMBOL_BACKSPACE
#define LV_SYMBOL_BACKSPACE "\xEF\x95\x9A" /*62810, 0xF55A*/
#endif
In my case only needed to call lv_textarea_del_char( ) two times and worked.
if( term.ch == 0x08 && term.index != 0 ) // Backspace code ( 0X08 ).
{
term.index--;
term.str[ term.index ] = '\0';
lv_textarea_del_char( ta );
lv_textarea_del_char( ta );
return;
}
1 Like