How to programmatically select roller position?


How to programmatically select roller position?

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

ESP32 littlevgl Ver2.0.1 for arduino IDE

What do you want to achieve?

when ESP32 boot up i use below roller code to load default value from EEprom display on roller .
lv_obj_t * roller1 = lv_roller_create(h, NULL);
lv_roller_set_options(roller1, " 0 \n 1 \n 2 \n 3 \n 4 \n 5 \n 6 \n 7 \n 8 \n 9 ", true);
lv_roller_set_selected(roller1,BTRolload1, false);
lv_roller_set_visible_row_count(roller1, 3);
lv_obj_set_event_cb(roller1, B1roller_event);

i have one cancel button when user press on the cancel button. I need the roller roll back to the original position use variable BTRolload1.

What have you tried so far?

static void Btn_Cancel(lv_obj_t * obj, lv_event_t event)
if(event == LV_EVENT_CLICKED) {
lv_roller_set_selected(roller1,BTRolload1, false);// THIS CODE DON’T WORK
else if(event == LV_EVENT_VALUE_CHANGED) {


Thank You

1 Like

Try the following a roller+button example
It works for me.

lv_obj_t* roller;

void roller_create(){
  roller = lv_roller_create( lv_scr_act(), NULL);
    lv_roller_set_options(roller, "0\n1\n2\n3\n4\n5\n6\n7\n8\n9", true);
    lv_roller_set_fix_width(roller, 100);
    lv_roller_set_selected(roller, 0, false);
    lv_roller_set_visible_row_count(roller, 3);
    lv_obj_align(roller, NULL , LV_ALIGN_CENTER,0,-30);
  lv_obj_t* reset_btn = lv_btn_create( lv_scr_act(), NULL);
    lv_obj_t* reset_lb = lv_label_create(reset_btn, NULL);
      lv_label_set_text(reset_lb, "RESET");
    lv_obj_align(reset_btn, roller , LV_ALIGN_OUT_BOTTOM_MID,0,10);
    lv_obj_set_event_cb(reset_btn, [](lv_obj_t *btn, lv_event_t event){
      if(event != LV_EVENT_CLICKED) return;
      lv_roller_set_selected(roller, 0, true);

Is this a C++ construct? I have never seen it before but it looks really useful!

It’s called Lambda Expressions, it seems C++. ^^

it work ,

Thank you