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_get_started_2.py (2369B)

      1 #
      2 # Create styles from scratch for buttons.
      3 #
      4 style_btn =  lv.style_t()
      5 style_btn_red = lv.style_t()
      6 style_btn_pressed = lv.style_t()
      7 
      8 # Create a simple button style
      9 style_btn.init()
     10 style_btn.set_radius(10)
     11 style_btn.set_bg_opa(lv.OPA.COVER)
     12 style_btn.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 3))
     13 style_btn.set_bg_grad_color(lv.palette_main(lv.PALETTE.GREY))
     14 style_btn.set_bg_grad_dir(lv.GRAD_DIR.VER)
     15 
     16 # Add a border
     17 style_btn.set_border_color(lv.color_white())
     18 style_btn.set_border_opa(lv.OPA._70)
     19 style_btn.set_border_width(2)
     20 
     21 # Set the text style
     22 style_btn.set_text_color(lv.color_white())
     23 
     24 # Create a red style. Change only some colors.
     25 style_btn_red.init()
     26 style_btn_red.set_bg_color(lv.palette_main(lv.PALETTE.RED))
     27 style_btn_red.set_bg_grad_color(lv.palette_lighten(lv.PALETTE.RED, 2))
     28 
     29 # Create a style for the pressed state.
     30 style_btn_pressed.init()
     31 style_btn_pressed.set_bg_color(lv.palette_main(lv.PALETTE.BLUE))
     32 style_btn_pressed.set_bg_grad_color(lv.palette_darken(lv.PALETTE.RED, 3))
     33 
     34 # Create a button and use the new styles
     35 btn = lv.btn(lv.scr_act())                  # Add a button the current screen
     36 # Remove the styles coming from the theme
     37 # Note that size and position are also stored as style properties
     38 # so lv_obj_remove_style_all will remove the set size and position too
     39 btn.remove_style_all()                      # Remove the styles coming from the theme
     40 btn.set_pos(10, 10)                         # Set its position
     41 btn.set_size(120, 50)                       # Set its size
     42 btn.add_style(style_btn, 0)
     43 btn.add_style(style_btn_pressed, lv.STATE.PRESSED)
     44 
     45 label = lv.label(btn)                       # Add a label to the button
     46 label.set_text("Button")                    # Set the labels text
     47 label.center()
     48 
     49 # Create another button and use the red style too
     50 btn2 = lv.btn(lv.scr_act())
     51 btn2.remove_style_all()                     # Remove the styles coming from the theme
     52 btn2.set_pos(10, 80)                        # Set its position
     53 btn2.set_size(120, 50)                      # Set its size
     54 btn2.add_style(style_btn, 0)
     55 btn2.add_style(style_btn_red, 0)
     56 btn2.add_style(style_btn_pressed, lv.STATE.PRESSED)
     57 btn2.set_style_radius(lv.RADIUS.CIRCLE, 0)  # Add a local style
     58 
     59 label = lv.label(btn2)                      # Add a label to the button
     60 label.set_text("Button 2")                  # Set the labels text
     61 label.center()
     62