mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(calendar) improve MicroPython example (#2366)
Small improvements: - Remove cast from get_pressed_date - Check return value of get_pressed_date - Call set_today_date on clicked date - Compact highlighted_days - Added a switch to show different header type
This commit is contained in:
parent
1b6a39ca61
commit
5f6e07e57f
@ -4,9 +4,9 @@ def event_handler(evt):
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
source = evt.get_target()
|
||||
date = lv.calendar_date_t()
|
||||
lv.calendar.get_pressed_date(source,date)
|
||||
if date:
|
||||
print("Clicked date: %02d.%02d.%02d"%(date.day, date.month, date.year))
|
||||
if source.get_pressed_date(date) == lv.RES.OK:
|
||||
calendar.set_today_date(date.year, date.month, date.day)
|
||||
print("Clicked date: %02d.%02d.%02d"%(date.day, date.month, date.year))
|
||||
|
||||
|
||||
calendar = lv.calendar(lv.scr_act())
|
||||
@ -18,25 +18,32 @@ calendar.set_today_date(2021, 02, 23)
|
||||
calendar.set_showed_date(2021, 02)
|
||||
|
||||
# Highlight a few days
|
||||
highlighted_days=[]
|
||||
for i in range(3):
|
||||
highlighted_days.append(lv.calendar_date_t())
|
||||
highlighted_days=[
|
||||
lv.calendar_date_t({'year':2021, 'month':2, 'day':6}),
|
||||
lv.calendar_date_t({'year':2021, 'month':2, 'day':11}),
|
||||
lv.calendar_date_t({'year':2021, 'month':2, 'day':22})
|
||||
]
|
||||
|
||||
highlighted_days[0].year=2021
|
||||
highlighted_days[0].month=02
|
||||
highlighted_days[0].day=6
|
||||
calendar.set_highlighted_dates(highlighted_days, len(highlighted_days))
|
||||
|
||||
highlighted_days[1].year=2021
|
||||
highlighted_days[1].month=02
|
||||
highlighted_days[1].day=11
|
||||
# 2 options for header
|
||||
header1 = lv.calendar_header_dropdown(lv.scr_act(),calendar)
|
||||
header2 = lv.calendar_header_arrow(lv.scr_act(),calendar,25)
|
||||
|
||||
highlighted_days[2].year=2022
|
||||
highlighted_days[2].month=02
|
||||
highlighted_days[2].day=22
|
||||
# Switch to switch headeres
|
||||
header2.add_flag(lv.obj.FLAG.HIDDEN)
|
||||
header1.clear_flag(lv.obj.FLAG.HIDDEN)
|
||||
|
||||
calendar.set_highlighted_dates(highlighted_days, 3)
|
||||
|
||||
header = lv.calendar_header_dropdown(lv.scr_act(),calendar)
|
||||
# header = lv.calendar_header_arrow(lv.scr_act(),calendar,25)
|
||||
sw = lv.switch(lv.scr_act())
|
||||
sw.set_pos(20,20)
|
||||
|
||||
def sw_cb(e):
|
||||
obj = e.get_target()
|
||||
if obj.has_state(lv.STATE.CHECKED):
|
||||
header1.add_flag(lv.obj.FLAG.HIDDEN)
|
||||
header2.clear_flag(lv.obj.FLAG.HIDDEN)
|
||||
else:
|
||||
header2.add_flag(lv.obj.FLAG.HIDDEN)
|
||||
header1.clear_flag(lv.obj.FLAG.HIDDEN)
|
||||
|
||||
sw.add_event_cb(sw_cb, lv.EVENT.VALUE_CHANGED, None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user