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_example_roller_3.py (3433B)

      1 import fs_driver
      2 import sys
      3 
      4 class Lv_Roller_3():
      5 
      6     def __init__(self):
      7         self.mask_top_id = -1
      8         self.mask_bottom_id = -1
      9 
     10         #
     11         # Add a fade mask to roller.
     12         #
     13         style = lv.style_t()
     14         style.init()
     15         style.set_bg_color(lv.color_black())
     16         style.set_text_color(lv.color_white())
     17 
     18         lv.scr_act().add_style(style, 0)
     19 
     20         roller1 = lv.roller(lv.scr_act())
     21         roller1.add_style(style, 0)
     22         roller1.set_style_border_width(0, 0)
     23         roller1.set_style_pad_all(0, 0)
     24         roller1.set_style_bg_opa(lv.OPA.TRANSP, lv.PART.SELECTED)
     25 
     26         #if LV_FONT_MONTSERRAT_22
     27         #    lv_obj_set_style_text_font(roller1, &lv_font_montserrat_22, LV_PART_SELECTED);
     28         #endif
     29         try:
     30             roller1.set_style_text_font(lv.font_montserrat_22,lv.PART.SELECTED)
     31         except:
     32             fs_drv = lv.fs_drv_t()
     33             fs_driver.fs_register(fs_drv, 'S')
     34             print("montserrat-22 not enabled in lv_conf.h, dynamically loading the font")
     35             font_montserrat_22 = lv.font_load("S:" + "../../assets/font/montserrat-22.fnt")
     36             roller1.set_style_text_font(font_montserrat_22,lv.PART.SELECTED)
     37 
     38         roller1.set_options("\n".join([
     39             "January",
     40             "February",
     41             "March",
     42             "April",
     43             "May",
     44             "June",
     45             "July",
     46             "August",
     47             "September",
     48             "October",
     49             "November",
     50             "December"]),lv.roller.MODE.NORMAL)
     51 
     52         roller1.center()
     53         roller1.set_visible_row_count(3)
     54         roller1.add_event_cb(self.mask_event_cb, lv.EVENT.ALL, None)
     55 
     56     def mask_event_cb(self,e):
     57 
     58         code = e.get_code()
     59         obj = e.get_target()
     60 
     61         if code == lv.EVENT.COVER_CHECK:
     62             e.set_cover_res(lv.COVER_RES.MASKED)
     63 
     64         elif code == lv.EVENT.DRAW_MAIN_BEGIN:
     65             # add mask
     66             font = obj.get_style_text_font(lv.PART.MAIN)
     67             line_space = obj.get_style_text_line_space(lv.PART.MAIN)
     68             font_h = font.get_line_height()
     69 
     70             roller_coords = lv.area_t()
     71             obj.get_coords(roller_coords)
     72 
     73             rect_area = lv.area_t()
     74             rect_area.x1 = roller_coords.x1
     75             rect_area.x2 = roller_coords.x2
     76             rect_area.y1 = roller_coords.y1
     77             rect_area.y2 = roller_coords.y1 + (obj.get_height() - font_h - line_space) // 2
     78 
     79             fade_mask_top = lv.draw_mask_fade_param_t()
     80             fade_mask_top.init(rect_area, lv.OPA.TRANSP, rect_area.y1, lv.OPA.COVER, rect_area.y2)
     81             self.mask_top_id = lv.draw_mask_add(fade_mask_top,None)
     82 
     83             rect_area.y1 = rect_area.y2 + font_h + line_space - 1
     84             rect_area.y2 = roller_coords.y2
     85 
     86             fade_mask_bottom = lv.draw_mask_fade_param_t()
     87             fade_mask_bottom.init(rect_area, lv.OPA.COVER, rect_area.y1, lv.OPA.TRANSP, rect_area.y2)
     88             self.mask_bottom_id = lv.draw_mask_add(fade_mask_bottom, None)
     89 
     90         elif code == lv.EVENT.DRAW_POST_END:
     91             fade_mask_top = lv.draw_mask_remove_id(self.mask_top_id)
     92             fade_mask_bottom = lv.draw_mask_remove_id(self.mask_bottom_id)
     93             # Remove the masks
     94             lv.draw_mask_remove_id(self.mask_top_id)
     95             lv.draw_mask_remove_id(self.mask_bottom_id)
     96             self.mask_top_id = -1
     97             self.mask_bottom_id = -1
     98 
     99 roller3 = Lv_Roller_3()