Description
Hello!
I want to define a style for the label, when it is in the default state and when it is in the focused state.
LV_STATE_DEFAULT - LV_LABEL_LONG_DOT
LV_STATE_FOCUSED - LV_LABEL_LONG_SCROLL_CIRCULAR
How using the function: lv_obj_set_style… define such a label appearance ?
What MCU/Processor/Board and compiler are you using?
ESP32-C3, ESP-IDF v5.0
What LVGL version are you using?
v8.3.9
Hey,
You can do it like this:
static void label_focus_event_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
if(code == LV_EVENT_FOCUSED) {
lv_obj_t * label = lv_event_get_target_obj(e);
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
}
else if(code == LV_EVENT_DEFOCUSED) {
lv_obj_t * label = lv_event_get_target_obj(e);
lv_label_set_long_mode(label, LV_LABEL_LONG_DOT);
}
}
lv_obj_t * label = lv_label_create(lv_screen_active());
lv_label_set_text(label, "I'm a very long text");
lv_label_set_long_mode(label, LV_LABEL_LONG_DOT);
lv_obj_add_flag(label, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_flag(label, LV_OBJ_FLAG_CLICK_FOCUSABLE);
lv_obj_set_size(label, 50, 18);
lv_obj_set_pos(label, 10, 10);
lv_obj_add_event_cb(label, label_focus_event_cb, LV_EVENT_ALL, 0);
lv_obj_set_style_bg_opa(label, LV_OPA_COVER, 0);
lv_obj_set_style_bg_color(label, lv_color_hex(0xff8888), 0);
lv_obj_set_style_bg_color(label, lv_color_hex(0x88ff88), LV_STATE_FOCUSED);
lv_obj_t * dropdown = lv_dropdown_create(lv_screen_active());
lv_obj_set_pos(dropdown, 100, 10);
If it works for you, would you be interested in converting it to an LVGL example?