Description
I want to disable the cursor on textarea when it is in LV_STATE_DISABLED state. but I found no way to do directly. Is there any way to solve it ?
What LVGL version are you using?
V9.1.1
What do you want to achieve?
disable the cursor on textarea when the textarea is disable
What have you tried so far?
using lv_obj_set_style_anim_time api to set the time to 0, but when the textarea is focused, the cursor is still existed ( but not blinking)
Code to reproduce
static void cb_event_cb(lv_event_t* e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t* ta = static_cast<lv_obj_t*>(lv_event_get_user_data(e));
lv_obj_t* obj = static_cast<lv_obj_t*>(lv_event_get_target(e));
if (code == LV_EVENT_VALUE_CHANGED)
{
if (!(lv_obj_get_state(obj) & LV_STATE_CHECKED))
{
lv_obj_add_state(ta, LV_STATE_DISABLED);
}
else
{
lv_obj_remove_state(ta, LV_STATE_DISABLED);
}
}
}
static void ta_event_cb(lv_event_t* e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t* ta = static_cast<lv_obj_t*>(lv_event_get_target(e));
lv_obj_t* kb = static_cast<lv_obj_t*>(lv_event_get_user_data(e));
if (code == LV_EVENT_FOCUSED) {
if (lv_indev_get_type(lv_indev_active()) != LV_INDEV_TYPE_KEYPAD && !(lv_obj_get_state(ta) & LV_STATE_DISABLED)) {
lv_keyboard_set_textarea(kb, ta);
lv_obj_set_style_max_height(kb, LV_HOR_RES * 1 / 3, 0);
lv_obj_set_style_max_width(kb, LV_VER_RES * 2 / 3, 0);
//lv_obj_update_layout(tv); /*Be sure the sizes are recalculated*/
//lv_obj_set_height(tv, LV_VER_RES - lv_obj_get_height(kb));
lv_obj_remove_flag(kb, LV_OBJ_FLAG_HIDDEN);
lv_obj_scroll_to_view_recursive(ta, LV_ANIM_OFF);
lv_indev_wait_release(static_cast<lv_indev_t*>(lv_event_get_param(e)));
}
else if (lv_obj_get_state(ta) & LV_STATE_DISABLED)
{
lv_obj_set_style_anim_time(ta, 0, LV_PART_CURSOR | LV_STATE_FOCUSED);
}
}
else if (code == LV_EVENT_DEFOCUSED) {
lv_keyboard_set_textarea(kb, NULL);
//lv_obj_set_height(tv, LV_VER_RES);
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
lv_indev_reset(NULL, ta);
}
else if (code == LV_EVENT_READY || code == LV_EVENT_CANCEL) {
//lv_obj_set_height(tv, LV_VER_RES);
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
lv_indev_reset(NULL, ta); /*To forget the last clicked object to make it focusable again*/
}
else if (code == LV_EVENT_REFR_EXT_DRAW_SIZE)
{
lv_event_set_ext_draw_size(e, 100);
}
}
void create_single_network_config(lv_obj_t* parent,const char* title)
{
lv_obj_t* title_lab = lv_label_create(parent);
lv_obj_t* ip_txt = lv_textarea_create(parent);
lv_obj_t* submask_txt = lv_textarea_create(parent);
lv_obj_t* gateway_txt = lv_textarea_create(parent);
lv_obj_t* ip_lab = lv_label_create(ip_txt);
lv_obj_t* submask_lab = lv_label_create(submask_txt);
lv_obj_t* gateway_lab = lv_label_create(gateway_txt);
lv_obj_t* enable = lv_checkbox_create(parent);
lv_obj_t* kb = lv_keyboard_create(lv_screen_active());
lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUMBER);
lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
lv_label_set_text(title_lab, title);
lv_label_set_text(ip_lab, "Ip Address");
lv_label_set_text(submask_lab, "SubMask");
lv_label_set_text(gateway_lab, "GateWay");
lv_checkbox_set_text(enable, "Enable");
lv_obj_add_flag(ip_txt, LV_OBJ_FLAG_OVERFLOW_VISIBLE);
lv_obj_add_flag(submask_txt, LV_OBJ_FLAG_OVERFLOW_VISIBLE);
lv_obj_add_flag(gateway_txt, LV_OBJ_FLAG_OVERFLOW_VISIBLE);
lv_obj_align_to(ip_lab, ip_txt, LV_ALIGN_OUT_TOP_LEFT,0,-5);
lv_obj_align_to(submask_lab, submask_txt, LV_ALIGN_OUT_TOP_LEFT,0,-5);
lv_obj_align_to(gateway_lab, gateway_txt, LV_ALIGN_OUT_TOP_LEFT,0,-5);
lv_obj_add_state(ip_txt, LV_STATE_DISABLED);
/* lv_obj_add_state(submask_txt, LV_STATE_DISABLED);
lv_obj_add_state(gateway_txt, LV_STATE_DISABLED);*/
lv_obj_set_width(ip_txt, lv_pct(100));
lv_obj_set_width(submask_txt, lv_pct(100));
lv_obj_set_width(gateway_txt, lv_pct(100));
lv_obj_set_height(ip_txt, lv_pct(10));
lv_obj_set_height(submask_txt, lv_pct(10));
lv_obj_set_height(gateway_txt, lv_pct(10));
lv_obj_set_style_text_font(title_lab, &lv_font_montserrat_32, 0);
lv_obj_add_event_cb(ip_txt, ta_event_cb, LV_EVENT_ALL, kb);
lv_obj_add_event_cb(submask_txt, ta_event_cb, LV_EVENT_ALL, kb);
lv_obj_add_event_cb(gateway_txt, ta_event_cb, LV_EVENT_ALL, kb);
lv_obj_add_event_cb(enable, cb_event_cb, LV_EVENT_ALL, ip_txt);
lv_obj_set_grid_dsc_array(parent, network_col_dsc, network_row_dsc);
lv_obj_set_grid_cell(title_lab, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_STRETCH, 0, 1);
lv_obj_set_grid_cell(ip_txt, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 1, 1);
lv_obj_set_grid_cell(submask_txt, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 2, 1);
lv_obj_set_grid_cell(gateway_txt, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 3, 1);
lv_obj_set_grid_cell(enable, LV_GRID_ALIGN_START, 0, 1, LV_GRID_ALIGN_START, 4, 1);
}
void create_network_config(int num,lv_obj_t* parent)
{
lv_obj_t* tabview = lv_tabview_create(parent);
lv_tabview_set_tab_bar_position(tabview, LV_DIR_LEFT);
lv_tabview_set_tab_bar_size(tabview, 80);
for (int i = 0; i < num; i++)
{
char tab_cont[32] = { 0 };
sprintf(tab_cont, "Ethernet%d", i+1);
lv_obj_t* tab = lv_tabview_add_tab(tabview, tab_cont);
create_single_network_config(tab, tab_cont);
}
}
int main()
{
lv_init();
/*
* Optional workaround for users who wants UTF-8 console output.
* If you don't want that behavior can comment them out.
*
* Suggested by jinsc123654.
*/
#if LV_TXT_ENC == LV_TXT_ENC_UTF8
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
#endif
int32_t zoom_level = 100;
bool allow_dpi_override = false;
bool simulator_mode = true;
lv_display_t* display = lv_windows_create_display(
L"LVGL Windows Simulator Display 1",
800,
480,
zoom_level,
allow_dpi_override,
simulator_mode);
if (!display)
{
return -1;
}
HWND window_handle = lv_windows_get_display_window_handle(display);
if (!window_handle)
{
return -1;
}
HICON icon_handle = LoadIconW(
GetModuleHandleW(NULL),
MAKEINTRESOURCE(IDI_LVGL_WINDOWS));
if (icon_handle)
{
SendMessageW(
window_handle,
WM_SETICON,
TRUE,
(LPARAM)icon_handle);
SendMessageW(
window_handle,
WM_SETICON,
FALSE,
(LPARAM)icon_handle);
}
lv_indev_t* pointer_indev = lv_windows_acquire_pointer_indev(display);
if (!pointer_indev)
{
return -1;
}
lv_indev_t* keypad_indev = lv_windows_acquire_keypad_indev(display);
if (!keypad_indev)
{
return -1;
}
lv_indev_t* encoder_indev = lv_windows_acquire_encoder_indev(display);
if (!encoder_indev)
{
return -1;
}
lv_obj_t* window1 = lv_obj_create(lv_screen_active());
lv_obj_t* panel1 = lv_obj_create(window1);
lv_obj_t* panel2 = lv_obj_create(window1);
lv_obj_t* title = lv_label_create(panel1);
lv_obj_t* back_btn = lv_button_create(panel1);
lv_obj_t* back_btn_label = lv_label_create(back_btn);
lv_obj_t* next_btn = lv_button_create(panel1);
lv_obj_t* next_btn_label = lv_label_create(next_btn);
lv_label_set_text(title, "Configure Network");
lv_label_set_text(back_btn_label, "< Cancel");
lv_label_set_text(next_btn_label, "Apply >");
lv_obj_align(title, LV_ALIGN_CENTER, 0, 0);
lv_obj_align(back_btn, LV_ALIGN_BOTTOM_LEFT, 0, 0);
lv_obj_align(next_btn, LV_ALIGN_BOTTOM_RIGHT, 0, 0);
lv_obj_set_size(window1, lv_pct(100), lv_pct(100));
//lv_obj_set_flex_flow(panel2, LV_FLEX_FLOW_COLUMN);
create_network_config(4, panel2);
static lv_style_t style_label_title,style_label_back,style_label_right;
lv_style_init(&style_label_title);
lv_style_init(&style_label_back);
lv_style_init(&style_label_right);
lv_obj_set_style_bg_color(panel1, lv_palette_main(LV_PALETTE_GREY), 0);
lv_obj_set_style_bg_color(back_btn, lv_palette_main(LV_PALETTE_GREY), 0);
lv_obj_set_style_bg_color(next_btn, lv_palette_main(LV_PALETTE_GREY), 0);
//lv_obj_set_style_bg_color(panel2, lv_color_black(), 0);
//lv_obj_set_style_bg_color(window1, lv_color_black(), 0);
lv_obj_set_style_radius(window1, 0, 0);
lv_obj_set_style_radius(panel1, 0, 0);
lv_obj_set_style_radius(panel2, 0, 0);
lv_obj_set_style_pad_all(window1, 0, 0);
lv_obj_set_style_pad_all(panel1, 0, 0);
lv_obj_set_style_pad_all(panel2, 0, 0);
lv_obj_set_style_pad_row(window1, 0, 0);
lv_obj_set_style_pad_column(window1, 0, 0);
lv_obj_set_style_border_width(panel1, 0, 0);
lv_obj_set_style_border_width(panel2, 0, 0);
lv_style_set_text_color(&style_label_title, lv_color_hex(0xFFFFFF));
lv_style_set_text_color(&style_label_back, lv_palette_main(LV_PALETTE_BLUE));
lv_style_set_text_color(&style_label_right, lv_palette_main(LV_PALETTE_BLUE));
lv_obj_add_style(title, &style_label_title, 0);
lv_obj_add_style(back_btn_label, &style_label_back, 0);
lv_obj_add_style(next_btn_label, &style_label_right, 0);
lv_obj_set_flex_align(panel2, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_grid_dsc_array(window1, col_dsc, row_dsc);
lv_obj_set_grid_cell(panel1, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_STRETCH, 0, 1);
lv_obj_set_grid_cell(panel2, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_STRETCH, 1, 1);
while (1)
{
uint32_t time_till_next = lv_timer_handler();
lv_delay_ms(time_till_next);
}
return 0;
}