Tasmota/tasmota/berry/lvgl_examples/lvgl_demo.be

81 lines
3.7 KiB
Plaintext
Raw Normal View History

2021-09-06 22:12:39 +01:00
#- start LVGL and init environment -#
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-09-06 22:12:39 +01:00
scr = lv.scr_act() # default screean object
f20 = lv.montserrat_font(20) # load embedded Montserrat 20
2021-09-06 22:12:39 +01:00
#- Background with a gradient from black #000000 (bottom) to dark blue #0000A0 (top) -#
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)
scr.set_style_bg_grad_dir(lv.GRAD_DIR_VER, lv.PART_MAIN | lv.STATE_DEFAULT)
2021-09-06 22:12:39 +01:00
#- Upper state line -#
stat_line = lv.label(scr)
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
stat_line.set_style_bg_color(lv.color(0xD00000), lv.PART_MAIN | lv.STATE_DEFAULT) # background #000088
stat_line.set_style_bg_opa(lv.OPA_COVER, lv.PART_MAIN | lv.STATE_DEFAULT) # 100% background opacity
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")
stat_line.refr_size() # new in LVGL8
stat_line.refr_pos() # new in LVGL8
2021-09-06 22:12:39 +01:00
#- display wifi strength indicator icon (for professionals ;) -#
2021-12-27 17:12:38 +00:00
wifi_icon = lv.wifi_arcs_icon(stat_line) # the widget takes care of positioning and driver stuff
clock_icon = lv.clock_icon(stat_line)
2021-09-06 22:12:39 +01:00
#- create a style for the buttons -#
btn_style = lv.style()
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
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-09-06 22:12:39 +01:00
#- create buttons -#
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
prev_btn.add_style(btn_style, lv.PART_MAIN | lv.STATE_DEFAULT) # style of button
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
prev_label.center()
2021-09-06 22:12:39 +01:00
next_btn = lv.btn(scr) # right button
next_btn.set_pos(220,vres-40)
next_btn.set_size(80, 30)
next_btn.add_style(btn_style, lv.PART_MAIN | lv.STATE_DEFAULT)
next_label = lv.label(next_btn)
next_label.set_text(">")
next_label.center()
home_btn = lv.btn(scr) # center button
home_btn.set_pos(120,vres-40)
home_btn.set_size(80, 30)
home_btn.add_style(btn_style, lv.PART_MAIN | lv.STATE_DEFAULT)
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
home_label.center()
2021-09-06 22:12:39 +01:00
#- callback function when a button is pressed, react to EVENT_CLICKED event -#
def btn_clicked_cb(obj, event)
2021-09-06 22:12:39 +01:00
var btn = "Unknown"
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
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)