Change position of elements inside lv_list

Hi, I’m using version 5.3 of library and trying to adjust elements in lv_list.

I want buttons have a position a bit left side:
lv_list_example

I have adjusted colomns left:

lv_page_set_scrl_layout(list, LV_LAYOUT_COL_L);

but still there is some space.

Maybe I can hardcode it somehow, I dont need scalable resolutiuon (it will run always on same screen size 160*128).

My code:

	char buf[50];
    lv_obj_t * list = NULL;
	lv_obj_t * list_btn = NULL;
	static lv_obj_t * scr = NULL;

    scr = lv_obj_create(NULL, NULL);
    scr->style_p->body.border.width = 2;
    lv_scr_load(scr);

	lv_theme_t *th = select_theme();

	//Create the list
	list = lv_list_create(lv_scr_act(), NULL);
	lv_obj_set_size(list, 160, (98));
	lv_obj_align(list, NULL, LV_ALIGN_IN_TOP_MID, 0, (30));
	lv_list_set_sb_mode(list, LV_SB_MODE_AUTO);
	lv_page_set_scrl_layout(list, LV_LAYOUT_COL_L);
	lv_group_add_obj(avo_group[group_idx], list);

	lv_list_set_style(list, LV_LIST_STYLE_BG, th->list.bg);
	lv_list_set_style(list, LV_LIST_STYLE_SCRL, th->list.scrl);
	lv_list_set_style(list, LV_LIST_STYLE_SB, th->list.sb);
	lv_list_set_style(list, LV_LIST_STYLE_BTN_REL, th->list.btn.rel);
	lv_list_set_style(list, LV_LIST_STYLE_BTN_PR, th->list.btn.pr);
	lv_list_set_style(list, LV_LIST_STYLE_BTN_TGL_REL, th->list.btn.tgl_rel);
	lv_list_set_style(list, LV_LIST_STYLE_BTN_TGL_PR, th->list.btn.tgl_pr);
	lv_list_set_style(list, LV_LIST_STYLE_BTN_INA, th->list.btn.ina);

	for (uint8_t i = 1; i < get_num(); i++) {
		sprintf(buf, "item_num #%d  ", i);

		list_btn = lv_list_add(list, NULL, buf, sel_action);
		lv_obj_set_free_num(list_btn, i);   /*Set a unique number*/
		lv_btn_set_fit(list_btn, false, false);
		lv_obj_set_size(list_btn, 140, 20);
	}

Please fill out the template instead of removing it.

Did you try removing padding on the list and its buttons’ styles?

1 Like

In v5.3 it’s not so flexible because there is only padding.hor. (In v6.0 there is padding.left/right too)

Setting padding.hor of LV_LIST_STYLE_BG or LV_LIST_STYLE_SCRLshould work.

But, as @embeddedt mentioned please fill the template when you create a new post.

1 Like