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_scroll_6.py (2026B)

      1 def scroll_event_cb(e):
      2 
      3     cont = e.get_target()
      4 
      5     cont_a = lv.area_t()
      6     cont.get_coords(cont_a)
      7     cont_y_center = cont_a.y1 + cont_a.get_height() // 2
      8 
      9     r = cont.get_height() * 7 // 10
     10 
     11     child_cnt = cont.get_child_cnt()
     12     for i in range(child_cnt):
     13         child = cont.get_child(i)
     14         child_a = lv.area_t()
     15         child.get_coords(child_a)
     16 
     17         child_y_center = child_a.y1 + child_a.get_height() // 2
     18 
     19         diff_y = child_y_center - cont_y_center
     20         diff_y = abs(diff_y)
     21 
     22         # Get the x of diff_y on a circle.
     23 
     24         # If diff_y is out of the circle use the last point of the circle (the radius)
     25         if diff_y >= r:
     26             x = r
     27         else:
     28             # Use Pythagoras theorem to get x from radius and y
     29             x_sqr = r * r - diff_y * diff_y
     30             res = lv.sqrt_res_t()
     31             lv.sqrt(x_sqr, res, 0x8000)   # Use lvgl's built in sqrt root function
     32             x = r - res.i
     33 
     34         # Translate the item by the calculated X coordinate
     35         child.set_style_translate_x(x, 0)
     36 
     37         # Use some opacity with larger translations
     38         opa = lv.map(x, 0, r, lv.OPA.TRANSP, lv.OPA.COVER)
     39         child.set_style_opa(lv.OPA.COVER - opa, 0)
     40 
     41 #
     42 # Translate the object as they scroll
     43 #
     44 
     45 cont = lv.obj(lv.scr_act())
     46 cont.set_size(200, 200)
     47 cont.center()
     48 cont.set_flex_flow(lv.FLEX_FLOW.COLUMN)
     49 cont.add_event_cb(scroll_event_cb, lv.EVENT.SCROLL, None)
     50 cont.set_style_radius(lv.RADIUS.CIRCLE, 0)
     51 cont.set_style_clip_corner(True, 0)
     52 cont.set_scroll_dir(lv.DIR.VER)
     53 cont.set_scroll_snap_y(lv.SCROLL_SNAP.CENTER)
     54 cont.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
     55 
     56 for i in range(20):
     57     btn = lv.btn(cont)
     58     btn.set_width(lv.pct(100))
     59 
     60     label = lv.label(btn)
     61     label.set_text("Button " + str(i))
     62 
     63     # Update the buttons position manually for first*
     64     lv.event_send(cont, lv.EVENT.SCROLL, None)
     65 
     66     # Be sure the fist button is in the middle
     67     #lv.obj.scroll_to_view(cont.get_child(0), lv.ANIM.OFF)
     68     cont.get_child(0).scroll_to_view(lv.ANIM.OFF)