adding micropython examples (#2286)
* adding micropython examples * adding micropython examples
This commit is contained in:
@@ -1,24 +1,31 @@
|
||||
def event_handler(obj, event):
|
||||
if event == lv.EVENT.VALUE_CHANGED:
|
||||
def event_handler(e):
|
||||
code = e.get_code()
|
||||
obj = lv.roller.__cast__(e.get_target())
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
option = " "*10
|
||||
obj.get_selected_str(option, len(option))
|
||||
print("Selected month: %s" % option.strip())
|
||||
print("Selected month: " + option.strip())
|
||||
|
||||
#
|
||||
# An infinite roller with the name of the months
|
||||
#
|
||||
|
||||
roller1 = lv.roller(lv.scr_act())
|
||||
roller1.set_options("\n".join([
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"]), lv.roller.MODE.INIFINITE)
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"]),lv.roller.MODE.INFINITE)
|
||||
|
||||
roller1.set_visible_row_count(4)
|
||||
roller1.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
roller1.set_event_cb(event_handler)
|
||||
roller1.center()
|
||||
roller1.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
|
||||
|
||||
60
examples/widgets/roller/lv_example_roller_2.py
Normal file
60
examples/widgets/roller/lv_example_roller_2.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import fs_driver
|
||||
|
||||
def event_handler(e):
|
||||
code = e.get_code()
|
||||
obj = lv.roller.__cast__(e.get_target())
|
||||
if code == lv.EVENT.VALUE_CHANGED:
|
||||
option = " "*10
|
||||
obj.get_selected_str(option, len(option))
|
||||
print("Selected value: %s\n" + option.strip())
|
||||
|
||||
#
|
||||
# Roller with various alignments and larger text in the selected area
|
||||
#
|
||||
|
||||
# A style to make the selected option larger
|
||||
style_sel = lv.style_t()
|
||||
style_sel.init()
|
||||
|
||||
try:
|
||||
style_sel.set_text_font(lv.font_montserrat_22)
|
||||
except:
|
||||
fs_drv = lv.fs_drv_t()
|
||||
fs_driver.fs_register(fs_drv, 'S')
|
||||
print("montserrat-22 not enabled in lv_conf.h, dynamically loading the font")
|
||||
font_montserrat_22 = lv.font_load("S:" + "../../assets/font/montserrat-22.bin")
|
||||
style_sel.set_text_font(font_montserrat_22)
|
||||
|
||||
opts = "\n".join(["1","2","3","4","5","6","7","8","9","10"])
|
||||
|
||||
# A roller on the left with left aligned text, and custom width
|
||||
roller = lv.roller(lv.scr_act())
|
||||
roller.set_options(opts, lv.roller.MODE.NORMAL)
|
||||
roller.set_visible_row_count(2)
|
||||
roller.set_width(100)
|
||||
roller.add_style(style_sel, lv.PART.SELECTED)
|
||||
roller.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
|
||||
roller.align(lv.ALIGN.LEFT_MID, 10, 0)
|
||||
roller.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
roller.set_selected(2, lv.ANIM.OFF)
|
||||
|
||||
# A roller on the middle with center aligned text, and auto (default) width
|
||||
roller = lv.roller(lv.scr_act());
|
||||
roller.set_options(opts, lv.roller.MODE.NORMAL)
|
||||
roller.set_visible_row_count(3)
|
||||
roller.add_style(style_sel, lv.PART.SELECTED)
|
||||
roller.align(lv.ALIGN.CENTER, 0, 0)
|
||||
roller.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
roller.set_selected(5, lv.ANIM.OFF)
|
||||
|
||||
# A roller on the right with right aligned text, and custom width
|
||||
roller = lv.roller(lv.scr_act());
|
||||
roller.set_options(opts, lv.roller.MODE.NORMAL)
|
||||
roller.set_visible_row_count(4)
|
||||
roller.set_width(80)
|
||||
roller.add_style(style_sel, lv.PART.SELECTED)
|
||||
roller.set_style_text_align(lv.TEXT_ALIGN.RIGHT, 0)
|
||||
roller.align(lv.ALIGN.RIGHT_MID, -10, 0)
|
||||
roller.add_event_cb(event_handler, lv.EVENT.ALL, None)
|
||||
roller.set_selected(8, lv.ANIM.OFF)
|
||||
|
||||
93
examples/widgets/roller/lv_example_roller_3.py
Normal file
93
examples/widgets/roller/lv_example_roller_3.py
Normal file
@@ -0,0 +1,93 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
import time
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
import sys
|
||||
|
||||
class Lv_Roller_3():
|
||||
|
||||
def __init__(self):
|
||||
self.mask_top_id = -1
|
||||
self.mask_bottom_id = -1
|
||||
|
||||
#
|
||||
# Add an fade mask to roller.
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
style.set_bg_color(lv.color_black())
|
||||
style.set_text_color(lv.color_white())
|
||||
|
||||
lv.scr_act().add_style(style, 0)
|
||||
|
||||
roller1 = lv.roller(lv.scr_act())
|
||||
roller1.add_style(style, 0)
|
||||
roller1.set_style_border_width(0, 0)
|
||||
roller1.set_style_pad_all(0, 0)
|
||||
roller1.set_style_bg_opa(lv.OPA.TRANSP, lv.PART.SELECTED)
|
||||
|
||||
#if LV_FONT_MONTSERRAT_22
|
||||
# lv_obj_set_style_text_font(roller1, &lv_font_montserrat_22, LV_PART_SELECTED);
|
||||
#endif
|
||||
roller1.set_options("\n".join([
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"]),lv.roller.MODE.NORMAL)
|
||||
|
||||
roller1.center()
|
||||
roller1.set_visible_row_count(3)
|
||||
roller1.add_event_cb(self.mask_event_cb, lv.EVENT.ALL, None)
|
||||
|
||||
def mask_event_cb(self,e):
|
||||
|
||||
code = e.get_code()
|
||||
obj = e.get_target()
|
||||
|
||||
if code == lv.EVENT.COVER_CHECK:
|
||||
e.set_cover_res(lv.COVER_RES.MASKED)
|
||||
|
||||
elif code == lv.EVENT.DRAW_MAIN_BEGIN:
|
||||
# add mask
|
||||
font = obj.get_style_text_font(lv.PART.MAIN)
|
||||
line_space = obj.get_style_text_line_space(lv.PART.MAIN)
|
||||
font_h = font.get_line_height()
|
||||
|
||||
roller_coords = lv.area_t()
|
||||
obj.get_coords(roller_coords)
|
||||
|
||||
rect_area = lv.area_t()
|
||||
rect_area.x1 = roller_coords.x1
|
||||
rect_area.x2 = roller_coords.x2
|
||||
rect_area.y1 = roller_coords.y1
|
||||
rect_area.y2 = roller_coords.y1 + (obj.get_height() - font_h - line_space) // 2
|
||||
|
||||
fade_mask_top = lv.draw_mask_fade_param_t()
|
||||
fade_mask_top.init(rect_area, lv.OPA.TRANSP, rect_area.y1, lv.OPA.COVER, rect_area.y2)
|
||||
self.mask_top_id = lv.draw_mask_add(fade_mask_top,None)
|
||||
|
||||
rect_area.y1 = rect_area.y2 + font_h + line_space - 1
|
||||
rect_area.y2 = roller_coords.y2
|
||||
|
||||
fade_mask_bottom = lv.draw_mask_fade_param_t()
|
||||
fade_mask_bottom.init(rect_area, lv.OPA.COVER, rect_area.y1, lv.OPA.TRANSP, rect_area.y2)
|
||||
self.mask_bottom_id = lv.draw_mask_add(fade_mask_bottom, None)
|
||||
|
||||
elif code == lv.EVENT.DRAW_POST_END:
|
||||
fade_mask_top = lv.draw_mask_remove_id(self.mask_top_id)
|
||||
fade_mask_bottom = lv.draw_mask_remove_id(self.mask_bottom_id)
|
||||
# Remove the masks
|
||||
lv.draw_mask_remove_id(self.mask_top_id)
|
||||
lv.draw_mask_remove_id(self.mask_bottom_id)
|
||||
self.mask_top_id = -1;
|
||||
self.mask_bottom_id = -1;
|
||||
|
||||
roller3 = Lv_Roller_3()
|
||||
Reference in New Issue
Block a user