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_demo_widgets.py (20622B)

      1 #!/opt/bin/lv_micropython
      2 import lvgl as lv
      3 import time
      4 import SDL
      5 lv.init()
      6 
      7 LV_DEMO_WIDGETS_SLIDESHOW = 0
      8 LV_THEME_DEFAULT_COLOR_PRIMARY=lv.color_hex(0x01a2b1)
      9 LV_THEME_DEFAULT_COLOR_SECONDARY=lv.color_hex(0x44d1b6)
     10 
     11 LV_LED_BRIGHT_MIN = 120
     12 LV_LED_BRIGHT_MAX = 255
     13 
     14 SDL.init(w=480,h=320)
     15 
     16 LV_DPI =130
     17 LV_ANIM_REPEAT_INFINITE = -1
     18 
     19 # Register SDL display driver.
     20 
     21 disp_buf1 = lv.disp_buf_t()
     22 buf1_1 = bytes(480 * 10)
     23 disp_buf1.init(buf1_1, None, len(buf1_1)//4)
     24 disp_drv = lv.disp_drv_t()
     25 disp_drv.init()
     26 disp_drv.buffer = disp_buf1
     27 disp_drv.flush_cb = SDL.monitor_flush
     28 disp_drv.hor_res = 480
     29 disp_drv.ver_res = 320
     30 disp_drv.register()
     31 
     32 # Register SDL mouse driver
     33 
     34 indev_drv = lv.indev_drv_t()
     35 indev_drv.init()
     36 indev_drv.type = lv.INDEV_TYPE.POINTER
     37 indev_drv.read_cb = SDL.mouse_read
     38 indev_drv.register()
     39 # print("Running the Unix version")
     40 
     41 # Create a screen and load it
     42 scr=lv.obj()
     43 lv.scr_load(scr)
     44 
     45 def LV_DPX(n):
     46     if n == 0:
     47         return n
     48     scr=lv.scr_act()
     49     display = scr.get_disp()
     50     dpi = display.get_dpi()
     51     # print("dpi: ",dpi)
     52     tmp = (dpi*n+80)//160
     53     # print("tmp: ",tmp)
     54     if tmp > 1:
     55         return tmp
     56     else:
     57         return 1
     58 
     59 def color_chg_event_cb(sw, e):
     60     if e == lv.EVENT.VALUE_CHANGED:
     61         flag = lv.THEME_MATERIAL_FLAG.LIGHT
     62         if sw.get_state():
     63             flag=lv.THEME_MATERIAL_FLAG.DARK
     64         theme = lv.theme_material_init(LV_THEME_DEFAULT_COLOR_PRIMARY,LV_THEME_DEFAULT_COLOR_SECONDARY,flag,
     65                                        lv.theme_get_font_small(), lv.theme_get_font_normal(), lv.theme_get_font_subtitle(),
     66                                        lv.theme_get_font_title())
     67 def slider_event_cb(slider, e):
     68     if e == lv.EVENT.VALUE_CHANGED:
     69         if slider.get_type() == lv.slider.TYPE.NORMAL:
     70             slider_value = slider.get_value()
     71             slider.set_style_local_value_str(lv.slider.PART.KNOB, lv.STATE.DEFAULT, str(slider_value))
     72         else:
     73             slider_left=slider.get_left_value()
     74             slider_right=slider.get_value()
     75             slider_string = str(slider_left) + '-' + str(slider_right)
     76             # print("slider left value: %d, slider right value: %d"%(slider_left,slider_right))
     77             slider.set_style_local_value_str(lv.slider.PART.INDIC, lv.STATE.DEFAULT, slider_string)
     78 
     79 def linemeter_anim(a,lmeter, value):
     80     lmeter.set_value(value)
     81     label = lmeter.get_child(None)
     82     label.set_text(str(value))
     83     label.align(lmeter, lv.ALIGN.CENTER, 0, 0)
     84 
     85 def gauge_anim(a,gauge,val):
     86     gauge.set_value(0,val)
     87     label=gauge.get_child(None)
     88     label.set_text(str(val))
     89     label.align(gauge, lv.ALIGN.CENTER, 0, 0)
     90 
     91 def bar_anim(task,bar):
     92     val = bar.get_value()
     93     # print("bar value: ",val)
     94     max_value = bar.get_max_value()
     95     val += 1
     96     if val > max_value:
     97         val=0
     98     bar.set_value(val,lv.ANIM.OFF)
     99     cpy_string = "Copying %d/%d"% (val, max_value)
    100     # print(cpy_string)
    101     bar.set_style_local_value_str(lv.bar.PART.BG, lv.STATE.DEFAULT, cpy_string)
    102 
    103 def arc_phase1_ready_cb(a,arc):
    104     a_arc=lv.anim_t()
    105     a_arc.init()
    106     a_arc.set_custom_exec_cb(lambda a_arc, val: anim_phase2(a_arc,arc,val))
    107     a_arc.set_values(360, 0)
    108     a_arc.set_time(1000)
    109     a_arc.set_ready_cb(lambda a: arc_phase2_ready_cb(a,arc))
    110     lv.anim_t.start(a_arc)
    111 
    112 def arc_phase2_ready_cb(a,arc):
    113     a_arc=lv.anim_t()
    114     a_arc.init()
    115     a_arc.set_custom_exec_cb(lambda a_arc, val: anim_phase1(a_arc,arc,val))
    116     a_arc.set_time(1000)
    117     a_arc.set_values(0, 360)
    118     a_arc.set_ready_cb(lambda a: arc_phase1_ready_cb(a,arc))
    119     lv.anim_t.start(a_arc)
    120 
    121 def anim_phase1(a,arc,val):
    122     arc.set_end_angle(val)
    123     label = arc.get_child(None)
    124     label.set_text(str(val))
    125     label.align(arc, lv.ALIGN.CENTER, 0, 0)
    126 
    127 def anim_phase2(a,arc,val):
    128     arc.set_end_angle(val)
    129     label = arc.get_child(None)
    130     label.set_text(str(val))
    131     label.align(arc, lv.ALIGN.CENTER, 0, 0)
    132 
    133 def controls_create(parent):
    134     lv.page.set_scrl_layout(lv.page.__cast__(parent), lv.LAYOUT.PRETTY_TOP)
    135     if LV_DEMO_WIDGETS_SLIDESHOW == 0:
    136         btns = ["Cancel", "Ok", ""]
    137         m = lv.msgbox(lv.scr_act(), None)
    138         m.add_btns(btns)
    139         btnm = lv.btnmatrix.__cast__(m.get_btnmatrix())
    140         # print("type(btnm): ",type(btnm))
    141         btnm.set_btn_ctrl(1, lv.btnmatrix.CTRL.CHECK_STATE)
    142 
    143     h = lv.cont(parent, None)
    144     h.set_layout(lv.LAYOUT.PRETTY_MID)
    145     h.add_style(lv.cont.PART.MAIN, style_box)
    146     h.set_drag_parent(True)
    147 
    148     h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Basics")
    149 
    150     disp_size = display.get_size_category()
    151     if disp_size <= lv.DISP_SIZE.SMALL:
    152         grid_w= lv.page.get_width_grid(lv.page.__cast__(parent),1,1)
    153         # print("grid_w: ",grid_w)
    154     else:
    155         grid_w= lv.page.get_width_grid(lv.page.__cast__(parent),2,1)
    156         # print("grid_w: ",grid_w)
    157 
    158     h.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT)
    159     h.set_width(grid_w)
    160     btn = lv.btn(h,None)
    161     btn.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT)
    162     if disp_size <= lv.DISP_SIZE.SMALL:
    163         button_width=h.get_width_grid(1,1)
    164     else:
    165         button_width=h.get_width_grid(2,1)
    166     # print("button_width: %d"%button_width)
    167 
    168     btn.set_width(button_width)
    169     label = lv.label(btn, None)
    170     label.set_text("Button")
    171 
    172     btn = lv.btn(h, btn)
    173     btn.toggle()
    174     label = lv.label(btn, None)
    175     label.set_text("Button")
    176 
    177     lv.switch(h, None)
    178 
    179     lv.checkbox(h, None)
    180 
    181     fit_w = h.get_width_fit()
    182 
    183     slider = lv.slider(h, None)
    184     slider.set_value(40, lv.ANIM.OFF)
    185     slider.set_event_cb(slider_event_cb)
    186     slider.set_width_margin(fit_w);
    187 
    188     # Use the knobs style value the display the current value in focused state
    189     slider.set_style_local_margin_top(lv.slider.PART.BG, lv.STATE.DEFAULT, LV_DPX(25))
    190     slider.set_style_local_value_font(lv.slider.PART.KNOB, lv.STATE.DEFAULT, lv.theme_get_font_small())
    191     slider.set_style_local_value_ofs_y(lv.slider.PART.KNOB, lv.STATE.FOCUSED, - LV_DPX(25))
    192     slider.set_style_local_value_opa(lv.slider.PART.KNOB, lv.STATE.DEFAULT, lv.OPA.TRANSP)
    193     slider.set_style_local_value_opa(lv.slider.PART.KNOB, lv.STATE.FOCUSED, lv.OPA.COVER)
    194     slider.set_style_local_transition_time(lv.slider.PART.KNOB, lv.STATE.DEFAULT, 300)
    195     slider.set_style_local_transition_prop_5(lv.slider.PART.KNOB, lv.STATE.DEFAULT, lv.STYLE.VALUE_OFS_Y)
    196     slider.set_style_local_transition_prop_6(lv.slider.PART.KNOB, lv.STATE.DEFAULT, lv.STYLE.VALUE_OPA)
    197 
    198     slider = lv.slider(h, None)
    199     slider.set_type(lv.slider.TYPE.RANGE)
    200     slider.set_value(70, lv.ANIM.OFF)
    201     slider.set_left_value(30, lv.ANIM.OFF)
    202     slider.set_style_local_value_ofs_y(lv.slider.PART.INDIC, lv.STATE.DEFAULT, - LV_DPX(25))
    203     slider.set_style_local_value_font(lv.slider.PART.INDIC, lv.STATE.DEFAULT, lv.theme_get_font_small())
    204     slider.set_style_local_value_opa(lv.slider.PART.INDIC, lv.STATE.DEFAULT, lv.OPA.COVER)
    205     slider.set_event_cb(slider_event_cb)
    206     lv.event_send(slider,lv.EVENT.VALUE_CHANGED, None)      # To refresh the text
    207     if slider.get_width() > fit_w:
    208         slider.set_width(fit_w)
    209 
    210     h = lv.cont(parent, h)
    211     h.set_fit(lv.FIT.NONE)
    212     h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Text input")
    213 
    214     ta = lv.textarea(h, None)
    215     lv.cont.set_fit2(h,lv.FIT.PARENT, lv.FIT.NONE)
    216     ta.set_text("")
    217     ta.set_placeholder_text("E-mail address")
    218     ta.set_one_line(True)
    219     ta.set_cursor_hidden(True)
    220     #lv_obj_set_event_cb(ta, ta_event_cb);
    221 
    222     ta = lv.textarea(h, ta)
    223     ta.set_pwd_mode(True)
    224     ta.set_placeholder_text("Password")
    225 
    226     ta = lv.textarea(h, None)
    227     lv.cont.set_fit2(h,lv.FIT.PARENT, lv.FIT.NONE)
    228     ta.set_text("")
    229     ta.set_placeholder_text("Message")
    230     ta.set_cursor_hidden(True)
    231     #lv_obj_set_event_cb(ta, ta_event_cb);
    232     lv.cont.set_fit4(h, lv.FIT.PARENT, lv.FIT.PARENT, lv.FIT.NONE, lv.FIT.PARENT)
    233 
    234 #    if LV_DEMO_WIDGETS_SLIDESHOW:
    235 #        tab_content_anim_create(parent)
    236 
    237 def visuals_create(parent):
    238     page = lv.page.__cast__(parent)
    239     lv.page.set_scrl_layout(page, lv.LAYOUT.PRETTY_TOP)
    240 
    241     disp_size = display.get_size_category()
    242 
    243     grid_h_chart = lv.page.get_height_grid(page,1,1)
    244     if disp_size <= lv.DISP_SIZE.LARGE:
    245         grid_w_chart=lv.page.get_width_grid(page,1,1)
    246     else:
    247         grid_w_chart=lv.page.get_width_grid(page,1,2)
    248 
    249     chart = lv.chart(parent, None)
    250     chart.add_style(lv.chart.PART.BG, style_box)
    251     if disp_size <= lv.DISP_SIZE.SMALL:
    252         chart.set_style_local_text_font(lv.chart.PART.SERIES_BG, lv.STATE.DEFAULT, lv.theme_get_font_small())
    253 
    254     chart.set_drag_parent(True)
    255     chart.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Line chart")
    256     chart.set_width_margin(grid_w_chart)
    257     chart.set_height_margin(grid_h_chart)
    258     chart.set_div_line_count(3, 0)
    259     chart.set_point_count(8)
    260     chart.set_type(lv.chart.TYPE.LINE)
    261 
    262     if disp_size > lv.DISP_SIZE.SMALL:
    263         chart.set_style_local_pad_left(lv.chart.PART.BG, lv.STATE.DEFAULT, 4 * (LV_DPI // 10))
    264         chart.set_style_local_pad_bottom(lv.chart.PART.BG, lv.STATE.DEFAULT, 3 * (LV_DPI // 10))
    265         chart.set_style_local_pad_right(lv.chart.PART.BG, lv.STATE.DEFAULT, 2 * (LV_DPI // 10))
    266         chart.set_style_local_pad_top(lv.chart.PART.BG, lv.STATE.DEFAULT, 2 * (LV_DPI // 10))
    267         chart.set_y_tick_length(0, 0)
    268         chart.set_x_tick_length(0, 0)
    269         chart.set_y_tick_texts("600\n500\n400\n300\n200", 0, lv.chart.AXIS.DRAW_LAST_TICK)
    270         chart.set_x_tick_texts("Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug", 0, lv.chart.AXIS.DRAW_LAST_TICK)
    271 
    272     s1 = chart.add_series(LV_THEME_DEFAULT_COLOR_PRIMARY)
    273     s2 = chart.add_series(LV_THEME_DEFAULT_COLOR_SECONDARY)
    274 
    275     chart.set_next(s1, 10)
    276     chart.set_next(s1, 90)
    277     chart.set_next(s1, 30)
    278     chart.set_next(s1, 60)
    279     chart.set_next(s1, 10)
    280     chart.set_next(s1, 90)
    281     chart.set_next(s1, 30)
    282     chart.set_next(s1, 60)
    283     chart.set_next(s1, 10)
    284     chart.set_next(s1, 90)
    285 
    286     chart.set_next(s2, 32)
    287     chart.set_next(s2, 66)
    288     chart.set_next(s2, 5)
    289     chart.set_next(s2, 47)
    290     chart.set_next(s2, 32)
    291     chart.set_next(s2, 32)
    292     chart.set_next(s2, 66)
    293     chart.set_next(s2, 5)
    294     chart.set_next(s2, 47)
    295     chart.set_next(s2, 66)
    296     chart.set_next(s2, 5)
    297     chart.set_next(s2, 47)
    298 
    299     chart2 = lv.chart(parent, chart)
    300     chart2.set_type(lv.chart.TYPE.COLUMN)
    301     chart2.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Column chart")
    302 
    303     s1 = chart2.add_series(LV_THEME_DEFAULT_COLOR_PRIMARY)
    304     s2 = chart2.add_series(LV_THEME_DEFAULT_COLOR_SECONDARY)
    305 
    306     chart2.set_next(s1, 10)
    307     chart2.set_next(s1, 90)
    308     chart2.set_next(s1, 30)
    309     chart2.set_next(s1, 60)
    310     chart2.set_next(s1, 10)
    311     chart2.set_next(s1, 90)
    312     chart2.set_next(s1, 30)
    313     chart2.set_next(s1, 60)
    314     chart2.set_next(s1, 10)
    315     chart2.set_next(s1, 90)
    316 
    317     chart2.set_next(s2, 32)
    318     chart2.set_next(s2, 66)
    319     chart2.set_next(s2, 5)
    320     chart2.set_next(s2, 47)
    321     chart2.set_next(s2, 32)
    322     chart2.set_next(s2, 32)
    323     chart2.set_next(s2, 66)
    324     chart2.set_next(s2, 5)
    325     chart2.set_next(s2, 47)
    326     chart2.set_next(s2, 66)
    327     chart2.set_next(s2, 5)
    328     chart2.set_next(s2, 47)
    329 
    330     if disp_size <= lv.DISP_SIZE.SMALL:
    331         grid_w_meter = lv.page.get_width_grid(page, 1, 1)
    332     elif disp_size <= lv.DISP_SIZE.MEDIUM :
    333         grid_w_meter = lv.page.get_width_grid(page, 2, 1)
    334     else:
    335         grid_w_meter = lv.page.get_width_grid(page, 3, 1)
    336 
    337     meter_h = lv.page.get_height_fit(page)
    338     if grid_w_meter < meter_h:
    339         meter_size = grid_w_meter
    340     else:
    341         meter_size = meter_h
    342 
    343     lmeter = lv.linemeter(parent, None)
    344     lmeter.set_drag_parent(True)
    345     lmeter.set_value(50)
    346     lmeter.set_size(meter_size, meter_size)
    347     lmeter.add_style(lv.linemeter.PART.MAIN, style_box)
    348     lmeter.set_style_local_value_str(lv.linemeter.PART.MAIN, lv.STATE.DEFAULT, "Line meter")
    349 
    350     label = lv.label(lmeter, None)
    351     label.align(lmeter, lv.ALIGN.CENTER, 0, 0)
    352     label.set_style_local_text_font(lv.label.PART.MAIN, lv.STATE.DEFAULT, lv.theme_get_font_title());
    353 
    354     a_lm=lv.anim_t()
    355     a_lm.init()
    356     a_lm.set_custom_exec_cb(lambda a, val: linemeter_anim(a,lmeter,val))
    357     a_lm.set_values(0, 100)
    358     a_lm.set_time(4000)
    359     a_lm.set_playback_time(1000)
    360     a_lm.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
    361     lv.anim_t.start(a_lm)
    362 
    363     gauge = lv.gauge(parent, None)
    364     gauge.set_drag_parent(True)
    365     gauge.set_size(meter_size, meter_size)
    366     gauge.add_style(lv.gauge.PART.MAIN, style_box)
    367     gauge.set_style_local_value_str(lv.gauge.PART.MAIN, lv.STATE.DEFAULT, "Gauge")
    368 
    369     label = lv.label(gauge, label)
    370     label.align(gauge, lv.ALIGN.CENTER, 0, grid_w_meter // 3)
    371 
    372     a_ga=lv.anim_t()
    373     a_ga.init()
    374     a_ga.set_custom_exec_cb(lambda a, val: linemeter_anim(a,lmeter,val))
    375     a_ga.set_values(0, 100)
    376     a_ga.set_time(4000)
    377     a_ga.set_playback_time(1000)
    378     a_ga.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
    379     a_ga.set_custom_exec_cb(lambda a, val: gauge_anim(a,gauge,val))
    380     lv.anim_t.start(a_ga)
    381 
    382     arc = lv.arc(parent,None)
    383     arc.set_drag_parent(True)
    384     arc.set_bg_angles(0, 360)
    385     arc.set_rotation(270)
    386     arc.set_angles(0, 0)
    387     arc.set_size(meter_size, meter_size)
    388     arc.add_style(lv.arc.PART.BG, style_box)
    389     arc.set_style_local_value_str(lv.arc.PART.BG, lv.STATE.DEFAULT, "Arc");
    390 
    391     label = lv.label(arc)
    392     label.align(arc, lv.ALIGN.CENTER, 0, 0)
    393 
    394     a_arc=lv.anim_t()
    395     a_arc.init()
    396     a_arc.set_custom_exec_cb(lambda a_arc, val: anim_phase1(a_arc,arc,val))
    397     a_arc.set_values(0, 360)
    398     a_arc.set_ready_cb(lambda a: arc_phase1_ready_cb(a,arc))
    399     # a_arc.set_repeat_count(LV_ANIM_REPEAT_INFINITE)
    400     a_arc.set_time(1000)
    401     lv.anim_t.start(a_arc)
    402 
    403     # Create a bar and use the backgrounds value style property to display the current value
    404     bar_h = lv.cont(parent, None)
    405     bar_h.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT)
    406     bar_h.add_style(lv.cont.PART.MAIN, style_box);
    407     bar_h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Bar")
    408 
    409     if disp_size <= lv.DISP_SIZE.SMALL:
    410         bar_h.set_width(lv.page_get_width_grid(page, 1, 1))
    411     elif disp_size <= lv.DISP_SIZE.MEDIUM:
    412         bar_h.set_width(lv.page.get_width_grid(page, 2, 1))
    413     else:
    414         bar_h.set_width(lv.page.get_width_grid(parent, 3, 2))
    415 
    416     bar = lv.bar(bar_h,None)
    417     bar.set_width(lv.cont.get_width_fit(bar_h))
    418     bar.set_style_local_value_font(lv.bar.PART.BG, lv.STATE.DEFAULT, lv.theme_get_font_small())
    419     bar.set_style_local_value_align(lv.bar.PART.BG, lv.STATE.DEFAULT, lv.ALIGN.OUT_BOTTOM_MID)
    420     bar.set_style_local_value_ofs_y(lv.bar.PART.BG, lv.STATE.DEFAULT, LV_DPI // 20)
    421     bar.set_style_local_margin_bottom(lv.bar.PART.BG, lv.STATE.DEFAULT, LV_DPI // 7)
    422     bar.align(None, lv.ALIGN.CENTER, 0, 0)
    423     bar.set_value(30,lv.ANIM.OFF)
    424 
    425     led_h = lv.cont(parent, None)
    426     led_h.set_layout(lv.LAYOUT.PRETTY_MID)
    427     if disp_size <= lv.DISP_SIZE.SMALL:
    428         led_h.set_width(lv.page.get_width_grid(page, 1, 1))
    429     elif disp_size <= lv.DISP_SIZE.MEDIUM:
    430         led_h.set_width(lv.page.get_width_grid(page, 2, 1))
    431     else:
    432         led_h.set_width(lv.page.get_width_grid(page, 3, 1))
    433 
    434     led_h.set_height(lv.obj.get_height(lv.obj.__cast__(bar_h)))
    435     led_h.add_style(lv.cont.PART.MAIN, style_box)
    436     led_h.set_drag_parent(True)
    437     led_h.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "LEDs")
    438 
    439     led = lv.led(led_h, None)
    440     led_size = lv.obj.get_height_fit(lv.obj.__cast__(led_h))
    441     led.set_size(led_size, led_size)
    442     led.off()
    443 
    444     led = lv.led(led_h, led)
    445     led.set_bright((LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN) // 2 + LV_LED_BRIGHT_MIN)
    446 
    447     led = lv.led(led_h, led)
    448     led.on()
    449 
    450     if disp_size == lv.DISP_SIZE.MEDIUM:
    451         led_h.add_protect(lv.PROTECT.POS)
    452         led_h.align(bar_h, lv.ALIGN.OUT_BOTTOM_MID, 0, lv.obj.get_style_margin_top(lv.obj.__cast__(led_h), lv.obj.PART.MAIN) + lv.obj.get_style_pad_inner(parent, lv.page.PART.SCROLLABLE))
    453 
    454     task = lv.task_create_basic()
    455     task.set_cb(lambda task: bar_anim(task, bar))
    456     task.set_period(100)
    457     task.set_prio(lv.TASK_PRIO.LOWEST)
    458 
    459 def selectors_create(parent):
    460     page = lv.page.__cast__(parent)
    461     lv.page.set_scrl_layout(page, lv.LAYOUT.PRETTY_MID)
    462 
    463     grid_h = page.get_height_grid(1, 1)
    464 
    465     if disp_size <= lv.DISP_SIZE.SMALL:
    466         grid_w = page.get_width_grid(1, 1)
    467     else:
    468         grid_w = page.get_width_grid(2, 1)
    469 
    470     cal = lv.calendar(parent, None)
    471     cal.set_drag_parent(True)
    472     if disp_size > lv.DISP_SIZE.MEDIUM:
    473         cal.set_size(min(grid_h, grid_w), min(grid_h, grid_w));
    474     else :
    475         cal.set_size(grid_w, grid_w)
    476         if disp_size <= lv.DISP_SIZE.SMALL:
    477             cal.set_style_local_text_font(lv.calendat.PART.BG, lv.STATE.DEFAULT, lv.theme_get_font_small())
    478 
    479     hl = [{ "year":2020, "month":1, "day":5},
    480           {"year":2020, "month":1, "day":9}]
    481 
    482     h = lv.cont(parent, None)
    483     h.set_drag_parent(True)
    484     if disp_size <= lv.DISP_SIZE.SMALL:
    485         h.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT)
    486         h.set_width(lv.page.get_width_fit(page))
    487         h.set_layout(lv.LAYOUT.COLUMN_MID)
    488     elif disp_size <= lv.DISP_SIZE.MEDIUM:
    489         h.set_size(lv.obj.get_width(lv.obj.__cast__(cal)), lv.obj.get_height(lv.obj.__cast__(cal)))
    490         h.set_layout(lv.LAYOUT.PRETTY_TOP);
    491     else :
    492         h.set_click(False)
    493         h.set_style_local_bg_opa(lv.PART.MAIN, lv.STATE.DEFAULT, lv.OPA.TRANSP)
    494         h.set_style_local_border_opa(lv.PART.MAIN, lv.STATE.DEFAULT, lv.OPA.TRANSP)
    495         h.set_style_local_pad_left(lv.cont.PART.MAIN, lv.STATE.DEFAULT, 0)
    496         h.set_style_local_pad_right(lv.cont.PART.MAIN, lv.STATE.DEFAULT, 0)
    497         h.set_style_local_pad_top(lv.cont.PART_MAIN, LV_STATE_DEFAULT, 0);
    498         h.set_size(min(grid_h, grid_w), min(grid_h, grid_w))
    499         h.set_layout(lv.LAYOUT.PRETTY_TOP)
    500 
    501     roller = lv.roller(h, None)
    502     roller.add_style(lv.cont.PART.MAIN, style_box)
    503     roller.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Roller")
    504     roller.set_auto_fit(False)
    505     roller.set_align(lv.label.ALIGN.CENTER)
    506     roller.set_visible_row_count(4)
    507     if disp_size <= lv.DISP_SIZE.SMALL:
    508         roller.set_width(lv.cont.get_width_grid(h, 1 , 1))
    509     else:
    510         roller.set_width(lv.cont.get_width_grid(h, 2 , 1))
    511 
    512 
    513     dd = lv.dropdown(h, None)
    514     dd.add_style(lv.cont.PART.MAIN, style_box)
    515     dd.set_style_local_value_str(lv.cont.PART.MAIN, lv.STATE.DEFAULT, "Dropdown")
    516     if disp_size <= lv.DISP_SIZE.SMALL:
    517         dd.set_width(lv.cont.get_width_grid(h, 1 , 1))
    518     else:
    519         dd.set_width(lv.cont.get_width_grid(h, 2 , 1))
    520 
    521     dd.set_options("Alpha\nBravo\nCharlie\nDelta\nEcho\nFoxtrot\nGolf\nHotel\nIndia\nJuliette\nKilo\nLima\nMike\nNovember\n"
    522                    "Oscar\nPapa\nQuebec\nRomeo\nSierra\nTango\nUniform\nVictor\nWhiskey\nXray\nYankee\nZulu")
    523 
    524     list = lv.list(parent, None)
    525     list.set_scroll_propagation(True)
    526     list.set_size(grid_w, grid_h)
    527 
    528     txts = [lv.SYMBOL.SAVE, "Save", lv.SYMBOL.CUT, "Cut", lv.SYMBOL.COPY, "Copy",
    529             lv.SYMBOL.OK, "This is a quite long text to scroll on the list", lv.SYMBOL.EDIT, "Edit", lv.SYMBOL.WIFI, "Wifi",
    530             lv.SYMBOL.BLUETOOTH, "Bluetooth",  lv.SYMBOL.GPS, "GPS", lv.SYMBOL.USB, "USB",
    531             lv.SYMBOL.SD_CARD, "SD card", lv.SYMBOL.CLOSE, "Close"]
    532 
    533 
    534     for i in range(0,len(txts)//2,2):
    535         btn = list.add_btn(txts[i], txts[i + 1]);
    536         lv.btn.set_checkable(lv.btn.__cast__(btn),True)
    537 
    538         # Make a button disabled
    539         if i == 4:
    540             btn.set_state(lv.btn.STATE.DISABLED)
    541 
    542     cal.set_highlighted_dates(hl, 2)
    543 
    544 tv = lv.tabview(lv.scr_act(), None)
    545 display = scr.get_disp()
    546 disp_size = display.get_size_category()
    547 tv.set_style_local_pad_left(lv.tabview.PART.TAB_BG, lv.STATE.DEFAULT, disp_drv.hor_res // 2)
    548 
    549 sw = lv.switch(lv.scr_act(), None)
    550 if lv.theme_get_flags() & lv.THEME_MATERIAL_FLAG.DARK:
    551    sw.on(LV_ANIM_OFF)
    552 sw.set_event_cb(color_chg_event_cb)
    553 sw.set_pos(LV_DPX(10), LV_DPX(10))
    554 sw.set_style_local_value_str(lv.switch.PART.BG, lv.STATE.DEFAULT, "Dark")
    555 sw.set_style_local_value_align(lv.switch.PART.BG, lv.STATE.DEFAULT, lv.ALIGN.OUT_RIGHT_MID)
    556 sw.set_style_local_value_ofs_x(lv.switch.PART.BG, lv.STATE.DEFAULT, LV_DPI//35)
    557 
    558 t1 = tv.add_tab("Controls")
    559 t2 = tv.add_tab("Visuals")
    560 t3 = tv.add_tab("Selectors")
    561 
    562 style_box = lv.style_t()
    563 style_box.init()
    564 # print("LV_DPX(10): %d, LV_DPX(10): %d"%(LV_DPX(10),LV_DPX(30)))
    565 style_box.set_value_align(lv.STATE.DEFAULT, lv.ALIGN.OUT_TOP_LEFT)
    566 style_box.set_value_ofs_y(lv.STATE.DEFAULT, - LV_DPX(10))
    567 style_box.set_margin_top(lv.STATE.DEFAULT, LV_DPX(30))
    568 
    569 controls_create(t1)
    570 visuals_create(t2)
    571 selectors_create(t3)
    572