2021-04-08 13:07:48 +02:00
|
|
|
#include "../../lv_examples.h"
|
2021-02-19 18:19:32 +01:00
|
|
|
#if LV_USE_ROLLER && LV_FONT_MONTSERRAT_22 && LV_BUILD_EXAMPLES
|
2021-02-04 14:46:11 +01:00
|
|
|
|
|
|
|
static void event_handler(lv_obj_t * obj, lv_event_t event)
|
|
|
|
{
|
|
|
|
if(event == LV_EVENT_VALUE_CHANGED) {
|
|
|
|
char buf[32];
|
|
|
|
lv_roller_get_selected_str(obj, buf, sizeof(buf));
|
2021-02-14 14:56:34 +01:00
|
|
|
LV_LOG_USER("Selected value: %s\n", buf);
|
2021-02-04 14:46:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Roller with various alignments and larger text in the selected area
|
|
|
|
*/
|
2021-02-07 22:39:54 +01:00
|
|
|
void lv_example_roller_2(void)
|
2021-02-04 14:46:11 +01:00
|
|
|
{
|
|
|
|
/*A style to make the selected option larger*/
|
|
|
|
static lv_style_t style_sel;
|
|
|
|
lv_style_init(&style_sel);
|
|
|
|
lv_style_set_text_font(&style_sel, &lv_font_montserrat_22);
|
|
|
|
|
|
|
|
const char * opts = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10";
|
|
|
|
lv_obj_t *roller;
|
|
|
|
|
|
|
|
/*A roller on the left with left aligned text, and custom width*/
|
2021-03-25 13:36:50 +01:00
|
|
|
roller = lv_roller_create(lv_scr_act());
|
2021-02-04 14:46:11 +01:00
|
|
|
lv_roller_set_options(roller, opts, LV_ROLLER_MODE_NORMAL);
|
|
|
|
lv_roller_set_visible_row_count(roller, 2);
|
|
|
|
lv_obj_set_width(roller, 100);
|
2021-03-31 19:57:14 +02:00
|
|
|
lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED);
|
|
|
|
lv_obj_set_style_text_align(roller, LV_TEXT_ALIGN_LEFT, 0);
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align(roller, LV_ALIGN_LEFT_MID, 10, 0);
|
2021-02-04 14:46:11 +01:00
|
|
|
lv_obj_add_event_cb(roller, event_handler, NULL);
|
|
|
|
lv_roller_set_selected(roller, 2, LV_ANIM_OFF);
|
|
|
|
|
|
|
|
/*A roller on the middle with center aligned text, and auto (default) width*/
|
2021-03-25 13:36:50 +01:00
|
|
|
roller = lv_roller_create(lv_scr_act());
|
2021-02-04 14:46:11 +01:00
|
|
|
lv_roller_set_options(roller, opts, LV_ROLLER_MODE_NORMAL);
|
|
|
|
lv_roller_set_visible_row_count(roller, 3);
|
2021-03-31 19:57:14 +02:00
|
|
|
lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED);
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align(roller, LV_ALIGN_CENTER, 0, 0);
|
2021-02-04 14:46:11 +01:00
|
|
|
lv_obj_add_event_cb(roller, event_handler, NULL);
|
|
|
|
lv_roller_set_selected(roller, 5, LV_ANIM_OFF);
|
|
|
|
|
|
|
|
/*A roller on the right with right aligned text, and custom width*/
|
2021-03-25 13:36:50 +01:00
|
|
|
roller = lv_roller_create(lv_scr_act());
|
2021-02-04 14:46:11 +01:00
|
|
|
lv_roller_set_options(roller, opts, LV_ROLLER_MODE_NORMAL);
|
|
|
|
lv_roller_set_visible_row_count(roller, 4);
|
|
|
|
lv_obj_set_width(roller, 80);
|
2021-03-31 19:57:14 +02:00
|
|
|
lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED);
|
|
|
|
lv_obj_set_style_text_align(roller, LV_TEXT_ALIGN_RIGHT, 0);
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align(roller, LV_ALIGN_RIGHT_MID, -10, 0);
|
2021-02-04 14:46:11 +01:00
|
|
|
lv_obj_add_event_cb(roller, event_handler, NULL);
|
|
|
|
lv_roller_set_selected(roller, 8, LV_ANIM_OFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|