acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
lv_example_roller_2.c (2386B)
1 #include "../../lv_examples.h" 2 #if LV_USE_ROLLER && LV_FONT_MONTSERRAT_22 && LV_BUILD_EXAMPLES 3 4 static void event_handler(lv_event_t * e) 5 { 6 lv_event_code_t code = lv_event_get_code(e); 7 lv_obj_t * obj = lv_event_get_target(e); 8 if(code == LV_EVENT_VALUE_CHANGED) { 9 char buf[32]; 10 lv_roller_get_selected_str(obj, buf, sizeof(buf)); 11 LV_LOG_USER("Selected value: %s", buf); 12 } 13 } 14 15 /** 16 * Roller with various alignments and larger text in the selected area 17 */ 18 void lv_example_roller_2(void) 19 { 20 /*A style to make the selected option larger*/ 21 static lv_style_t style_sel; 22 lv_style_init(&style_sel); 23 lv_style_set_text_font(&style_sel, &lv_font_montserrat_22); 24 25 const char * opts = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10"; 26 lv_obj_t * roller; 27 28 /*A roller on the left with left aligned text, and custom width*/ 29 roller = lv_roller_create(lv_scr_act()); 30 lv_roller_set_options(roller, opts, LV_ROLLER_MODE_NORMAL); 31 lv_roller_set_visible_row_count(roller, 2); 32 lv_obj_set_width(roller, 100); 33 lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED); 34 lv_obj_set_style_text_align(roller, LV_TEXT_ALIGN_LEFT, 0); 35 lv_obj_align(roller, LV_ALIGN_LEFT_MID, 10, 0); 36 lv_obj_add_event_cb(roller, event_handler, LV_EVENT_ALL, NULL); 37 lv_roller_set_selected(roller, 2, LV_ANIM_OFF); 38 39 /*A roller on the middle with center aligned text, and auto (default) width*/ 40 roller = lv_roller_create(lv_scr_act()); 41 lv_roller_set_options(roller, opts, LV_ROLLER_MODE_NORMAL); 42 lv_roller_set_visible_row_count(roller, 3); 43 lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED); 44 lv_obj_align(roller, LV_ALIGN_CENTER, 0, 0); 45 lv_obj_add_event_cb(roller, event_handler, LV_EVENT_ALL, NULL); 46 lv_roller_set_selected(roller, 5, LV_ANIM_OFF); 47 48 /*A roller on the right with right aligned text, and custom width*/ 49 roller = lv_roller_create(lv_scr_act()); 50 lv_roller_set_options(roller, opts, LV_ROLLER_MODE_NORMAL); 51 lv_roller_set_visible_row_count(roller, 4); 52 lv_obj_set_width(roller, 80); 53 lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED); 54 lv_obj_set_style_text_align(roller, LV_TEXT_ALIGN_RIGHT, 0); 55 lv_obj_align(roller, LV_ALIGN_RIGHT_MID, -10, 0); 56 lv_obj_add_event_cb(roller, event_handler, LV_EVENT_ALL, NULL); 57 lv_roller_set_selected(roller, 8, LV_ANIM_OFF); 58 } 59 60 #endif