Dropdown list change font

Description

What MCU/Processor/Board and compiler are you using?

PC Simulation(VS 2019) / custom board stm32f469

What LVGL version are you using?

8.0 / 8.1

What do you want to achieve?

Need change font in dropdown list

What have you tried so far?

First i tried like Drop-down list (lv_dropdown) β€” LVGL documentation

static void rv_drop_cb(lv_event_t *event)
{
	lv_event_code_t code = lv_event_get_code(event);
	xenon_t *pmod = (xenon_t*)event->user_data;
        lv_obj_t *ddlist = pmod->gui.rv_btn.button;
	lv_obj_t *list = lv_dropdown_get_list(ddlist);
	if(list != NULL) {
		lv_obj_add_style(list, &pmod->gui.rus_font_40, LV_PART_MAIN);
		lv_obj_add_style(list, &pmod->gui.rus_font_40, LV_PART_SCROLLBAR);
		lv_obj_add_style(list, &pmod->gui.rus_font_40, LV_PART_SELECTED);
	}
	switch(code){
		case LV_EVENT_VALUE_CHANGED: {
			
			break;
		}
		default: {
			break;
		}
	}
}

But lv_dropdown_get_list(ddlist) always return NULL and i can’t add style

And what happen in simulation

lv_obj_t *rv_btn = lv_dropdown_create(gui.main_scr);
lv_dropdown_t *ddlist = (lv_dropdown_t*)rv_btn;

list NULL

Please help me in this problem

I realized that the value of list is assigned only when you click on the list in lv_dropdown_event.
But when is called my callback, in callstack I dont see it, only lv_dropdown_list_event and
lv_dropdown_get_list return NULL

When should I call the lv_dropdown_get_list so that the pointer is not NULL?

You have to listen for the LV_EVENT_READY event.

lv_obj_add_event_cb(dropdown, dropdown_event_cb, LV_EVENT_ALL, NULL);

void dropdown_event_cb(lv_event_t *e) {
    switch (lv_event_get_code(e)) {
        case LV_EVENT_READY: {
            lv_obj_add_style(lv_dropdown_get_list(lv_event_get_target(e)), &..., 0);
            break;
        }
        default:
            break;
    }
}
1 Like