Remove space between list elements on LVGL 7.7.2

Description

Remove space between list elements on LVGL 7.7.2

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

codeblocks simulator, atmel studio with GCC

What LVGL version are you using?

LVGL 7.7.2

What do you want to achieve?

Remove the space between list elements

What have you tried so far?

I tried using code snippets from
https://forum.lvgl.io/t/how-to-remove-space-between-buttons-in-list/865
but it does not compile with LVGL 7.7.2. I can’t use lv_list_set_style().

I tried lv_obj_set_style_local_pad_all() and lv_obj_set_style_local_margin_all() on LV_LIST_PART_SCROLLABLE and LV_LIST_PART_BG. They don’t affect the spacing between the button list elements.
As long as I can somehow get which element of the list is selected, I don’t mind if I don’t use buttons.

Also, is it possible to continuously show the scrollbar on the right?

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:


void lv_ex_list_1_mine(void)
{
    /*Create a list*/
    lv_obj_t * list1 = lv_list_create(lv_scr_act(), NULL);
    lv_obj_set_size(list1, 160, 200);
    lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0);

    lv_obj_set_style_local_text_font(list1, LV_LIST_PART_BG, LV_STATE_DEFAULT, &lv_font_montserrat_12);

    /*does not change spacing between elements. It changes the spacing between the whole list and the border*/
    lv_obj_set_style_local_pad_all(list1, LV_LIST_PART_SCROLLABLE, LV_STATE_DEFAULT, 0);

    /*don't see the effect*/
    lv_obj_set_style_local_margin_all( list1, LV_LIST_PART_SCROLLABLE, LV_STATE_DEFAULT, 0);

    /*does not change spacing between elements. It changes the spacing between the whole list and the border*/
     lv_obj_set_style_local_pad_all( list1, LV_LIST_PART_BG, LV_STATE_DEFAULT,0);


    static lv_style_t styleSCRL;
    lv_style_init(&styleSCRL);

  /*in LVGL 7.7.2, lv_style_t has no member body*/
    /*styleSCRL.body.padding.top = 0;*/
    /*styleSCRL.body.padding.bottom = 0;*/
   /* styleSCRL.body.padding.left = 0;*/
   /* styleSCRL.body.padding.right = 0;*/

   /* lv_list_set_style(list1, LV_LIST_STYLE_SCRL, &styleSCRL);*/
    /*lv_list_set_style() not in LVLG 7.7.2 */
    /*LV_LIST_STYLE_SCRL not in LVLG 7.7.2*/

    /*Add buttons to the list*/
    lv_obj_t * list_btn;

    list_btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, "A");
    lv_obj_set_event_cb(list_btn, event_handler_mine);

    list_btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, "B");
    lv_obj_set_event_cb(list_btn, event_handler_mine);

    list_btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, "C");
    lv_obj_set_event_cb(list_btn, event_handler_mine);

    list_btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, "D");
    lv_obj_set_event_cb(list_btn, event_handler_mine);


}

Screenshot and/or video

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

I came up with a solution: use lv_obj_set_style_local_pad_all for each button.

 const uint16_t button_pad = 4;
 list_btn = lv_list_add_btn(list1, LV_SYMBOL_FILE, "A");
 lv_obj_set_event_cb(list_btn, event_handler_mine);
 lv_obj_set_style_local_pad_all( list_btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, button_pad);

Also, is it possible to continuously show the scrollbar on the right?

I don’t know how to make the scrollbar appear continuously when the surface area of items in the list exceed the space of the list visible area.