How to set the list style of the dropdown list when open the dropdown list?

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

hi, I need to show dropdown list options with some chinese charactor, so I add my font to the button style by lv_obj_add_style(ddlist, &style, LV_PART_MAIN), but when I open the dropdown list, the options in the list is not fully display. So I read the docs again and try to add the list style in the LV_EVENT_VALUE_CHANGED, but it still doesn’t work. I debug the code shown below, I found while it open the dropdown list, it can’t run into the if condition, only when I clicked one option it can. Also, the list I get is always NULL.

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

What LVGL version are you using?

V 8.0.1

What do you want to achieve?

What have you tried so far?

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

    lv_style_t g_generalDropDownlist_Bg;
    lv_style_t g_generalDropDownlist_List;

static void dropdownlist_event_cb(lv_event_t* e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t* obj = lv_event_get_target(e);

    if (code == LV_EVENT_VALUE_CHANGED)
    {
        lv_obj_t* list = lv_dropdown_get_list(obj);

        if (list != NULL)
        {
            lv_obj_add_style(list, &g_generalDropDownlist_List, LV_PART_MAIN);
        }
    }
}

int main()
{
    lv_style_init(&g_generalDropDownlist_Bg);
    lv_style_set_radius(&g_generalDropDownlist_Bg, 0);
    lv_style_set_text_font(&g_generalDropDownlist_Bg, &msyh_12);

    lv_style_init(&g_generalDropDownlist_List);
    lv_style_set_text_font(&g_generalDropDownlist_List, &msyh_12);

    s_limitObj.ddlist = lv_dropdown_create(parent);
    lv_dropdown_set_symbol(s_limitObj.ddlist, NULL);
    lv_obj_add_style(s_limitObj.ddlist, &g_generalDropDownlist_Bg, LV_PART_MAIN);
    lv_dropdown_set_options(s_limitObj.ddlist, "参数1\n参数2\n参数3");
    lv_obj_set_width(s_limitObj.ddlist, 120);
    lv_obj_add_event_cb(s_limitObj.ddlist, dropdownlist_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
    lv_obj_align_to(s_limitObj.ddlist, LimitParamGroup,
                    LV_ALIGN_OUT_RIGHT_MID, 16, 0);
}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.


the effect is shown like this

@kisvegabor

Thanks for the report. It was really bug in LVGL. I’ve just fixed it in master.

I’ve noticed that LV_EVENT_VALUE_CHANGE for value change is not a good idea because it conflicts with option selection. I pushed a new fix to sends LV_EVENT_READY/CANCEL on open/close respectively.

Fine, it will be better to update the docs instructions, by the way, when will the new version be released?

I’ve updated the docs too. (Takes a few minutes to update)

There is no fixed release date for v8.1. We are working on the features listed here [v8.1] Planning · Issue #2276 · lvgl/lvgl · GitHub