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