2021-09-06 22:12:39 +01:00
|
|
|
#- start LVGL and init environment -#
|
2021-07-22 19:21:18 +01:00
|
|
|
lv.start()
|
|
|
|
|
2021-09-06 22:12:39 +01:00
|
|
|
hres = lv.get_hor_res() # should be 320
|
|
|
|
vres = lv.get_ver_res() # should be 240
|
2021-07-22 19:21:18 +01:00
|
|
|
|
2021-09-06 22:12:39 +01:00
|
|
|
scr = lv.scr_act() # default screean object
|
|
|
|
f20 = lv.montserrat_font(20) # load embedded Montserrat 20
|
2021-07-22 19:21:18 +01:00
|
|
|
|
2021-09-06 22:12:39 +01:00
|
|
|
#- Background with a gradient from black #000000 (bottom) to dark blue #0000A0 (top) -#
|
2021-10-15 18:34:37 +01:00
|
|
|
scr.set_style_bg_color(lv.color(0x0000A0), lv.PART_MAIN | lv.STATE_DEFAULT)
|
|
|
|
scr.set_style_bg_grad_color(lv.color(0x000000), lv.PART_MAIN | lv.STATE_DEFAULT)
|
2021-10-02 08:33:59 +01:00
|
|
|
scr.set_style_bg_grad_dir(lv.GRAD_DIR_VER, lv.PART_MAIN | lv.STATE_DEFAULT)
|
2021-07-22 19:21:18 +01:00
|
|
|
|
2021-09-06 22:12:39 +01:00
|
|
|
#- Upper state line -#
|
2021-10-15 18:34:37 +01:00
|
|
|
stat_line = lv.label(scr)
|
2021-10-02 08:33:59 +01:00
|
|
|
if f20 != nil stat_line.set_style_text_font(f20, lv.PART_MAIN | lv.STATE_DEFAULT) end
|
2021-10-02 09:31:38 +01:00
|
|
|
stat_line.set_long_mode(lv.LABEL_LONG_SCROLL) # auto scrolling if text does not fit
|
2021-09-06 22:12:39 +01:00
|
|
|
stat_line.set_width(hres)
|
2021-10-02 09:31:38 +01:00
|
|
|
stat_line.set_align(lv.TEXT_ALIGN_LEFT) # align text left
|
2021-10-15 18:34:37 +01:00
|
|
|
stat_line.set_style_bg_color(lv.color(0xD00000), lv.PART_MAIN | lv.STATE_DEFAULT) # background #000088
|
2021-10-02 08:33:59 +01:00
|
|
|
stat_line.set_style_bg_opa(lv.OPA_COVER, lv.PART_MAIN | lv.STATE_DEFAULT) # 100% background opacity
|
2021-10-15 18:34:37 +01:00
|
|
|
stat_line.set_style_text_color(lv.color(0xFFFFFF), lv.PART_MAIN | lv.STATE_DEFAULT) # text color #FFFFFF
|
2021-09-08 18:40:18 +01:00
|
|
|
stat_line.set_text("Tasmota")
|
2021-10-02 08:33:59 +01:00
|
|
|
stat_line.refr_size() # new in LVGL8
|
|
|
|
stat_line.refr_pos() # new in LVGL8
|
2021-07-22 19:21:18 +01:00
|
|
|
|
2021-09-06 22:12:39 +01:00
|
|
|
#- display wifi strength indicator icon (for professionals ;) -#
|
2021-09-08 18:40:18 +01:00
|
|
|
wifi_icon = lv_wifi_arcs_icon(stat_line) # the widget takes care of positioning and driver stuff
|
2021-09-09 19:32:19 +01:00
|
|
|
clock_icon = lv_clock_icon(stat_line)
|
2021-07-22 19:21:18 +01:00
|
|
|
|
2021-09-06 22:12:39 +01:00
|
|
|
#- create a style for the buttons -#
|
2021-10-15 18:34:37 +01:00
|
|
|
btn_style = lv.style()
|
2021-10-02 08:33:59 +01:00
|
|
|
btn_style.set_radius(10) # radius of rounded corners
|
|
|
|
btn_style.set_bg_opa(lv.OPA_COVER) # 100% backgrond opacity
|
|
|
|
if f20 != nil btn_style.set_text_font(f20) end # set font to Montserrat 20
|
2021-10-15 18:34:37 +01:00
|
|
|
btn_style.set_bg_color(lv.color(0x1fa3ec)) # background color #1FA3EC (Tasmota Blue)
|
|
|
|
btn_style.set_border_color(lv.color(0x0000FF)) # border color #0000FF
|
|
|
|
btn_style.set_text_color(lv.color(0xFFFFFF)) # text color white #FFFFFF
|
2021-07-22 19:21:18 +01:00
|
|
|
|
2021-09-06 22:12:39 +01:00
|
|
|
#- create buttons -#
|
2021-10-15 18:34:37 +01:00
|
|
|
prev_btn = lv.btn(scr) # create button with main screen as parent
|
2021-09-06 22:12:39 +01:00
|
|
|
prev_btn.set_pos(20,vres-40) # position of button
|
|
|
|
prev_btn.set_size(80, 30) # size of button
|
2021-10-02 08:33:59 +01:00
|
|
|
prev_btn.add_style(btn_style, lv.PART_MAIN | lv.STATE_DEFAULT) # style of button
|
2021-10-15 18:34:37 +01:00
|
|
|
prev_label = lv.label(prev_btn) # create a label as sub-object
|
2021-09-06 22:12:39 +01:00
|
|
|
prev_label.set_text("<") # set label text
|
2021-10-02 08:33:59 +01:00
|
|
|
prev_label.center()
|
2021-09-06 22:12:39 +01:00
|
|
|
|
2021-10-15 18:34:37 +01:00
|
|
|
next_btn = lv.btn(scr) # right button
|
2021-07-22 19:21:18 +01:00
|
|
|
next_btn.set_pos(220,vres-40)
|
|
|
|
next_btn.set_size(80, 30)
|
2021-10-02 08:33:59 +01:00
|
|
|
next_btn.add_style(btn_style, lv.PART_MAIN | lv.STATE_DEFAULT)
|
2021-10-15 18:34:37 +01:00
|
|
|
next_label = lv.label(next_btn)
|
2021-07-22 19:21:18 +01:00
|
|
|
next_label.set_text(">")
|
2021-10-02 08:33:59 +01:00
|
|
|
next_label.center()
|
2021-07-22 19:21:18 +01:00
|
|
|
|
2021-10-15 18:34:37 +01:00
|
|
|
home_btn = lv.btn(scr) # center button
|
2021-07-22 19:21:18 +01:00
|
|
|
home_btn.set_pos(120,vres-40)
|
|
|
|
home_btn.set_size(80, 30)
|
2021-10-02 08:33:59 +01:00
|
|
|
home_btn.add_style(btn_style, lv.PART_MAIN | lv.STATE_DEFAULT)
|
2021-10-15 18:34:37 +01:00
|
|
|
home_label = lv.label(home_btn)
|
2021-09-06 22:12:39 +01:00
|
|
|
home_label.set_text(lv.SYMBOL_OK) # set text as Home icon
|
2021-10-02 08:33:59 +01:00
|
|
|
home_label.center()
|
2021-07-22 19:21:18 +01:00
|
|
|
|
2021-09-06 22:12:39 +01:00
|
|
|
#- callback function when a button is pressed, react to EVENT_CLICKED event -#
|
2021-10-02 08:33:59 +01:00
|
|
|
|
|
|
|
def btn_clicked_cb(obj, event)
|
2021-09-06 22:12:39 +01:00
|
|
|
var btn = "Unknown"
|
2021-10-02 08:33:59 +01:00
|
|
|
if obj == prev_btn btn = "Prev"
|
|
|
|
elif obj == next_btn btn = "Next"
|
|
|
|
elif obj == home_btn btn = "Home"
|
2021-09-06 22:12:39 +01:00
|
|
|
end
|
|
|
|
print(btn, "button pressed")
|
|
|
|
end
|
2021-07-22 19:21:18 +01:00
|
|
|
|
2021-10-02 08:33:59 +01:00
|
|
|
|
|
|
|
prev_btn.add_event_cb(btn_clicked_cb, lv.EVENT_CLICKED, 0)
|
|
|
|
next_btn.add_event_cb(btn_clicked_cb, lv.EVENT_CLICKED, 0)
|
|
|
|
home_btn.add_event_cb(btn_clicked_cb, lv.EVENT_CLICKED, 0)
|