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_btn_2.py (1588B)

      1 #
      2 # Style a button from scratch
      3 #
      4 
      5 # Init the style for the default state
      6 style = lv.style_t()
      7 style.init()
      8 
      9 style.set_radius(3)
     10 
     11 style.set_bg_opa(lv.OPA.COVER)
     12 style.set_bg_color(lv.palette_main(lv.PALETTE.BLUE))
     13 style.set_bg_grad_color(lv.palette_darken(lv.PALETTE.BLUE, 2))
     14 style.set_bg_grad_dir(lv.GRAD_DIR.VER)
     15 
     16 style.set_border_opa(lv.OPA._40)
     17 style.set_border_width(2)
     18 style.set_border_color(lv.palette_main(lv.PALETTE.GREY))
     19 
     20 style.set_shadow_width(8)
     21 style.set_shadow_color(lv.palette_main(lv.PALETTE.GREY))
     22 style.set_shadow_ofs_y(8)
     23 
     24 style.set_outline_opa(lv.OPA.COVER)
     25 style.set_outline_color(lv.palette_main(lv.PALETTE.BLUE))
     26 
     27 style.set_text_color(lv.color_white())
     28 style.set_pad_all(10)
     29 
     30 # Init the pressed style
     31 style_pr = lv.style_t()
     32 style_pr.init()
     33 
     34 # Add a large outline when pressed
     35 style_pr.set_outline_width(30)
     36 style_pr.set_outline_opa(lv.OPA.TRANSP)
     37 
     38 style_pr.set_translate_y(5)
     39 style_pr.set_shadow_ofs_y(3)
     40 style_pr.set_bg_color(lv.palette_darken(lv.PALETTE.BLUE, 2))
     41 style_pr.set_bg_grad_color(lv.palette_darken(lv.PALETTE.BLUE, 4))
     42 
     43 # Add a transition to the outline
     44 trans = lv.style_transition_dsc_t()
     45 props = [lv.STYLE.OUTLINE_WIDTH, lv.STYLE.OUTLINE_OPA, 0]
     46 trans.init(props, lv.anim_t.path_linear, 300, 0, None)
     47 
     48 style_pr.set_transition(trans)
     49 
     50 btn1 = lv.btn(lv.scr_act())
     51 btn1.remove_style_all()                          # Remove the style coming from the theme
     52 btn1.add_style(style, 0)
     53 btn1.add_style(style_pr, lv.STATE.PRESSED)
     54 btn1.set_size(lv.SIZE.CONTENT, lv.SIZE.CONTENT)
     55 btn1.center()
     56 
     57 label = lv.label(btn1)
     58 label.set_text("Button")
     59 label.center()
     60