Hello everyone,
I want that when a scroll with 24 rows is displayed, it is positioned in a specific one. Is that possible? How would it be done? thanks.
Greetings.
Hi @Anhell,
I have read this a couple of times and I dont understand the question.
What is a scroll?
Do you have any screenshots?
What version of LVGL are you using?
Thanks
Hi Alex,
The LVGL version is 8.3.3.
These are the instructions I use to display 24 rows of information, corresponding to the 24 hours of the day. What I’m trying to achieve is that when viewing the screen the roller is positioned on the line corresponding to the current time.
current_time is the variable where I store the current time.
roller_rows is the variable where I store the 24 rows.
void Vista_screen_init(void)
{
Vista = lv_obj_create(NULL);
lv_obj_clear_flag(Vista, LV_OBJ_FLAG_SCROLLABLE);
Vista_Roller1 = lv_roller_create(Vista);
lv_obj_move_to_index(Vista_Roller1, current_time);
lv_roller_set_options(Vista_Roller1, roller_rows, LV_ROLLER_MODE_INFINITE);
lv_obj_set_width(Vista_Roller1, 308);
lv_obj_set_height(Vista_Roller1, 181);
lv_obj_set_x(Vista_Roller1, 0);
lv_obj_set_y(Vista_Roller1, 20);
lv_obj_set_align(Vista_Roller1, LV_ALIGN_CENTER);
lv_obj_set_style_text_font(Vista_Roller1, &font_Font20, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_add_flag(Vista_Roller1, LV_OBJ_FLAG_SCROLL_ONE);
}
I use the instruction: lv_obj_move_to_index(Vista_Roller1, current_time); but the roller is not positioned.
What am I doing wrong or not doing? Thanks for your help.
Ah! A roller
You probably want something like:
Where roller value is the index of the option (0 through 23).
lv_roller_set_selected(Vista_Roller1, rollerValue, LV_ANIM_OFF);
Also you will want to set that after you add the options.
Docs are here if you need them:
https://docs.lvgl.io/latest/en/html/widgets/roller.html
Hope that helps
Hello, it still doesn’t work.
I have added the following instruction:
lv_roller_set_selected(Vista_Roller1, (uint16_t)ec_hora, LV_ANIM_OFF);
At the end of the previous instructions and although the value of ec_hora is 17, the roller is positioned in the last row mounted.
ec_hora is a char *, I have tried as such, converting it to int and finally to uint16_t and it doesn’t work.
Hi,
What method did you try to use to convert it to an int (it needs to be an int).
According to:
https://www.tutorialspoint.com/how-do-i-convert-a-char-to-an-int-in-c-and-cplusplus
atoi(ec_hora)
Should work like so:
lv_roller_set_selected(Vista_Roller1, atoi(ec_hora), LV_ANIM_OFF);
Can you provide code used and a screenshot?
Thanks
This is my code:
void Vista_screen_init(void)
{
Vista = lv_obj_create(NULL);
lv_obj_clear_flag( Vista, LV_OBJ_FLAG_SCROLLABLE);
Vista_IBInicio = lv_btn_create( Vista);
lv_obj_set_width( Vista_IBInicio, 100);
lv_obj_set_height( Vista_IBInicio, 40);
lv_obj_set_x( Vista_IBInicio, -106);
lv_obj_set_y( Vista_IBInicio, -96);
lv_obj_set_align( Vista_IBInicio, LV_ALIGN_CENTER);
lv_obj_add_flag( Vista_IBInicio, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
lv_obj_clear_flag( Vista_IBInicio, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_style_border_color( Vista_IBInicio, lv_color_hex(0x06FA1F), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_opa( Vista_IBInicio, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width( Vista_IBInicio, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
Vista_LInicio = lv_label_create( Vista);
lv_obj_set_width( Vista_LInicio, LV_SIZE_CONTENT);
lv_obj_set_height( Vista_LInicio, LV_SIZE_CONTENT);
lv_obj_set_x( Vista_LInicio, -106);
lv_obj_set_y( Vista_LInicio, -95);
lv_obj_set_align( Vista_LInicio, LV_ALIGN_CENTER);
lv_label_set_text( Vista_LInicio, "Inicio");
Vista_IBMove = lv_btn_create( Vista);
lv_obj_set_width( Vista_IBMove, 100);
lv_obj_set_height( Vista_IBMove, 40);
lv_obj_set_x( Vista_IBMove, -1);
lv_obj_set_y( Vista_IBMove, -96);
lv_obj_set_align( Vista_IBMove, LV_ALIGN_CENTER);
lv_obj_add_flag( Vista_IBMove, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
lv_obj_clear_flag( Vista_IBMove, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_style_border_color( Vista_IBMove, lv_color_hex(0x757D76), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_opa( Vista_IBMove, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width( Vista_IBMove, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
Vista_LMove = lv_label_create( Vista);
lv_obj_set_width( Vista_LMove, LV_SIZE_CONTENT);
lv_obj_set_height( Vista_LMove, LV_SIZE_CONTENT);
lv_obj_set_x( Vista_LMove, -2);
lv_obj_set_y( Vista_LMove, -96);
lv_obj_set_align( Vista_LMove, LV_ALIGN_CENTER);
lv_label_set_text( Vista_LMove, "Desglose");
Vista_IBProxi = lv_btn_create( Vista);
lv_obj_set_width( Vista_IBProxi, 100);
lv_obj_set_height( Vista_IBProxi, 40);
lv_obj_set_x( Vista_IBProxi, 103);
lv_obj_set_y( Vista_IBProxi, -96);
lv_obj_set_align( Vista_IBProxi, LV_ALIGN_CENTER);
lv_obj_add_flag( Vista_IBProxi, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
lv_obj_clear_flag( Vista_IBProxi, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_style_border_color( Vista_IBProxi, lv_color_hex(0x06FA1F), LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_opa( Vista_IBProxi, 255, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_border_width( Vista_IBProxi, 2, LV_PART_MAIN | LV_STATE_DEFAULT);
Vista_LProxi = lv_label_create( Vista);
lv_obj_set_width( Vista_LProxi, LV_SIZE_CONTENT);
lv_obj_set_height( Vista_LProxi, LV_SIZE_CONTENT);
lv_obj_set_x( Vista_LProxi, 103);
lv_obj_set_y( Vista_LProxi, -96);
lv_obj_set_align( Vista_LProxi, LV_ALIGN_CENTER);
lv_label_set_text( Vista_LProxi, "Proximo dia");
Vista_Roller1 = lv_roller_create( Vista);
lv_obj_set_width( Vista_Roller1, 308);
lv_obj_set_height( Vista_Roller1, 181);
lv_obj_set_x( Vista_Roller1, 0);
lv_obj_set_y( Vista_Roller1, 20);
lv_obj_set_align( Vista_Roller1, LV_ALIGN_CENTER);
lv_obj_set_style_text_font( Vista_Roller1, & font_Font20, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_add_flag( Vista_Roller1, LV_OBJ_FLAG_SCROLL_ONE);
lv_obj_set_style_bg_color( Vista_Roller1, lv_color_hex(0x0BFF01), LV_PART_SELECTED | LV_STATE_CHECKED);
lv_obj_set_style_text_font( Vista_Roller1, & font_Font20, LV_PART_SELECTED | LV_STATE_DEFAULT);
lv_roller_set_options( Vista_Roller1, ec_scro, LV_ROLLER_MODE_INFINITE);
lv_roller_set_selected( Vista_Roller1, atoi(ec_hora), LV_ANIM_OFF);
lv_obj_add_event_cb( Vista_IBInicio, event_Vista_IBInicio, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb( Vista_IBProxi, event_Vista_IBProxi, LV_EVENT_ALL, NULL);
}
For a quick test can you try:
lv_roller_set_selected( Vista_Roller1, 15, LV_ANIM_OFF);
to see if it selects the 15th index (ie row 16)?
If that works then it must be the conversion or something else thats messing things up.
Thanks
Nothing, it still doesn’t work.
In case it helps you, this is the body from which the screens are mounted:
void init(void)
{
lv_disp_t * dispp = lv_disp_get_default();
lv_theme_t * theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), true, LV_FONT_DEFAULT);
lv_disp_set_theme(dispp, theme);
Inicio_screen_init();
**Vista_screen_init();**
Proxi_screen_init();
lv_disp_load_scr( Inicio);
}
And in the display Inicio_screen_init(); I use this:
lv_label_set_text(Inicio_Label5, ec_hora);
and it shows ec_hora without problems.
Thanks
[/quote]
Thats very strange!
I have it working as expected using the following code:
heating.hwStateRoller = lv_roller_create(parent);
lv_roller_set_options(heating.hwStateRoller,
"On\n"
"Scheduled\n"
"Off",
LV_ROLLER_MODE_INFINITE);
lv_obj_add_event_cb(heating.hwStateRoller, hwStateRoller_cb, LV_EVENT_VALUE_CHANGED, NULL); /*Assign an event function*/
lv_obj_align_to(heating.hwStateRoller, heating.hwsw, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
lv_roller_set_visible_row_count(heating.hwStateRoller, 3);
lv_obj_set_style_bg_color(heating.hwStateRoller, lv_color_hex(MAIN_BG_COLOUR), LV_PART_MAIN);
lv_obj_set_style_bg_color(heating.hwStateRoller, lv_color_hex(0x01a2b1), LV_PART_SELECTED);
lv_obj_set_style_border_color(heating.hwStateRoller, MAIN_BORDER_COLOUR, LV_PART_MAIN);
then as it’s set by MQTT the following:
void setHeatingHwRoller(lv_obj_t * roller, char* value)
{
int rollerValue = -1;
if(strcmp("ON", value) == 0)
{
rollerValue = 0;
}
else if(strcmp("HEAT", value) == 0)
{
rollerValue = 1;
}
else if(strcmp("OFF", value) == 0)
{
rollerValue = 2;
}
if(rollerValue != -1)
{
if(lv_roller_get_selected(roller) != rollerValue)
{
lv_roller_set_selected(roller, rollerValue, LV_ANIM_OFF);
}
}
}
I must admit I’m failing to understand why this isnt working for you.
Do you have anything else that could be setting it in another callback?
Maybe someone else has an idea?
Anyway, thank you very much for your help.
I will continue investigating and sorry for my English.