1import fs_driver 2 3 4def event_handler(e): 5 code = e.get_code() 6 obj = e.get_target() 7 if code == lv.EVENT.VALUE_CHANGED: 8 option = " "*10 9 obj.get_selected_str(option, len(option)) 10 print("Selected value: %s\n" + option.strip()) 11 12# 13# Roller with various alignments and larger text in the selected area 14# 15 16# A style to make the selected option larger 17style_sel = lv.style_t() 18style_sel.init() 19 20try: 21 style_sel.set_text_font(lv.font_montserrat_22) 22except: 23 fs_drv = lv.fs_drv_t() 24 fs_driver.fs_register(fs_drv, 'S') 25 print("montserrat-22 not enabled in lv_conf.h, dynamically loading the font") 26 font_montserrat_22 = lv.font_load("S:" + "../../assets/font/montserrat-22.fnt") 27 style_sel.set_text_font(font_montserrat_22) 28 29opts = "\n".join(["1","2","3","4","5","6","7","8","9","10"]) 30 31# A roller on the left with left aligned text, and custom width 32roller = lv.roller(lv.scr_act()) 33roller.set_options(opts, lv.roller.MODE.NORMAL) 34roller.set_visible_row_count(2) 35roller.set_width(100) 36roller.add_style(style_sel, lv.PART.SELECTED) 37roller.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0) 38roller.align(lv.ALIGN.LEFT_MID, 10, 0) 39roller.add_event_cb(event_handler, lv.EVENT.ALL, None) 40roller.set_selected(2, lv.ANIM.OFF) 41 42# A roller in the middle with center aligned text, and auto (default) width 43roller = lv.roller(lv.scr_act()) 44roller.set_options(opts, lv.roller.MODE.NORMAL) 45roller.set_visible_row_count(3) 46roller.add_style(style_sel, lv.PART.SELECTED) 47roller.align(lv.ALIGN.CENTER, 0, 0) 48roller.add_event_cb(event_handler, lv.EVENT.ALL, None) 49roller.set_selected(5, lv.ANIM.OFF) 50 51# A roller on the right with right aligned text, and custom width 52roller = lv.roller(lv.scr_act()) 53roller.set_options(opts, lv.roller.MODE.NORMAL) 54roller.set_visible_row_count(4) 55roller.set_width(80) 56roller.add_style(style_sel, lv.PART.SELECTED) 57roller.set_style_text_align(lv.TEXT_ALIGN.RIGHT, 0) 58roller.align(lv.ALIGN.RIGHT_MID, -10, 0) 59roller.add_event_cb(event_handler, lv.EVENT.ALL, None) 60roller.set_selected(8, lv.ANIM.OFF) 61