adding micropython examples (#2286)
* adding micropython examples * adding micropython examples
This commit is contained in:
24
examples/styles/lv_example_style_1.py
Normal file
24
examples/styles/lv_example_style_1.py
Normal file
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# Using the Size, Position and Padding style properties
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
style.set_radius(5)
|
||||
|
||||
# Make a gradient
|
||||
style.set_width(150)
|
||||
style.set_height(lv.SIZE.CONTENT)
|
||||
|
||||
style.set_pad_ver(20)
|
||||
style.set_pad_left(5)
|
||||
|
||||
style.set_x(lv.pct(50))
|
||||
style.set_y(80)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
|
||||
label = lv.label(obj)
|
||||
label.set_text("Hello");
|
||||
|
||||
36
examples/styles/lv_example_style_10.py
Normal file
36
examples/styles/lv_example_style_10.py
Normal file
@@ -0,0 +1,36 @@
|
||||
#
|
||||
# Creating a transition
|
||||
#
|
||||
|
||||
props = [lv.STYLE.BG_COLOR, lv.STYLE.BORDER_COLOR, lv.STYLE.BORDER_WIDTH, 0]
|
||||
|
||||
# A default transition
|
||||
# Make it fast (100ms) and start with some delay (200 ms)
|
||||
|
||||
trans_def = lv.style_transition_dsc_t()
|
||||
trans_def.init(props, lv.anim_t.path_linear, 100, 200, None)
|
||||
|
||||
# A special transition when going to pressed state
|
||||
# Make it slow (500 ms) but start without delay
|
||||
|
||||
trans_pr = lv.style_transition_dsc_t()
|
||||
trans_pr.init(props, lv.anim_t.path_linear, 500, 0, None)
|
||||
|
||||
style_def = lv.style_t()
|
||||
style_def.init()
|
||||
style_def.set_transition(trans_def)
|
||||
|
||||
style_pr = lv.style_t()
|
||||
style_pr.init()
|
||||
style_pr.set_bg_color(lv.palette_main(lv.PALETTE.RED))
|
||||
style_pr.set_border_width(6)
|
||||
style_pr.set_border_color(lv.palette_darken(lv.PALETTE.RED, 3))
|
||||
style_pr.set_transition(trans_pr)
|
||||
|
||||
# Create an object with the new style_pr
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style_def, 0)
|
||||
obj.add_style(style_pr, lv.STATE.PRESSED)
|
||||
|
||||
obj.center()
|
||||
|
||||
44
examples/styles/lv_example_style_11.py
Normal file
44
examples/styles/lv_example_style_11.py
Normal file
@@ -0,0 +1,44 @@
|
||||
#
|
||||
# Using multiple styles
|
||||
#
|
||||
# A base style
|
||||
|
||||
style_base = lv.style_t()
|
||||
style_base.init()
|
||||
style_base.set_bg_color(lv.palette_main(lv.PALETTE.LIGHT_BLUE))
|
||||
style_base.set_border_color(lv.palette_darken(lv.PALETTE.LIGHT_BLUE, 3))
|
||||
style_base.set_border_width(2)
|
||||
style_base.set_radius(10)
|
||||
style_base.set_shadow_width(10)
|
||||
style_base.set_shadow_ofs_y(5)
|
||||
style_base.set_shadow_opa(lv.OPA._50)
|
||||
style_base.set_text_color(lv.color_white())
|
||||
style_base.set_width(100)
|
||||
style_base.set_height(lv.SIZE.CONTENT)
|
||||
|
||||
# Set only the properties that should be different
|
||||
style_warning = lv.style_t()
|
||||
style_warning.init()
|
||||
style_warning.set_bg_color(lv.palette_main(lv.PALETTE.YELLOW))
|
||||
style_warning.set_border_color(lv.palette_darken(lv.PALETTE.YELLOW, 3))
|
||||
style_warning.set_text_color(lv.palette_darken(lv.PALETTE.YELLOW, 4))
|
||||
|
||||
# Create an object with the base style only
|
||||
obj_base = lv.obj(lv.scr_act())
|
||||
obj_base.add_style(style_base, 0)
|
||||
obj_base.align(lv.ALIGN.LEFT_MID, 20, 0)
|
||||
|
||||
label = lv.label(obj_base)
|
||||
label.set_text("Base")
|
||||
label.center()
|
||||
|
||||
# Create an other object with the base style and earnings style too
|
||||
obj_warning = lv.obj(lv.scr_act())
|
||||
obj_warning.add_style(style_base, 0)
|
||||
obj_warning.add_style(style_warning, 0)
|
||||
obj_warning.align(lv.ALIGN.RIGHT_MID, -20, 0)
|
||||
|
||||
label = lv.label(obj_warning)
|
||||
label.set_text("Warning")
|
||||
label.center()
|
||||
|
||||
18
examples/styles/lv_example_style_12.py
Normal file
18
examples/styles/lv_example_style_12.py
Normal file
@@ -0,0 +1,18 @@
|
||||
#
|
||||
# Local styles
|
||||
#
|
||||
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
style.set_bg_color(lv.palette_main(lv.PALETTE.GREEN))
|
||||
style.set_border_color(lv.palette_lighten(lv.PALETTE.GREEN, 3))
|
||||
style.set_border_width(3)
|
||||
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
|
||||
# Overwrite the background color locally
|
||||
obj.set_style_bg_color(lv.palette_main(lv.PALETTE.ORANGE), lv.PART.MAIN)
|
||||
|
||||
obj.center()
|
||||
|
||||
23
examples/styles/lv_example_style_13.py
Normal file
23
examples/styles/lv_example_style_13.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# Add styles to parts and states
|
||||
#
|
||||
|
||||
style_indic = lv.style_t()
|
||||
style_indic.init()
|
||||
style_indic.set_bg_color(lv.palette_lighten(lv.PALETTE.RED, 3))
|
||||
style_indic.set_bg_grad_color(lv.palette_main(lv.PALETTE.RED))
|
||||
style_indic.set_bg_grad_dir(lv.GRAD_DIR.HOR)
|
||||
|
||||
style_indic_pr = lv.style_t()
|
||||
style_indic_pr.init()
|
||||
style_indic_pr.set_shadow_color(lv.palette_main(lv.PALETTE.RED))
|
||||
style_indic_pr.set_shadow_width(10)
|
||||
style_indic_pr.set_shadow_spread(3)
|
||||
|
||||
# Create an object with the new style_pr
|
||||
obj = lv.slider(lv.scr_act())
|
||||
obj.add_style(style_indic, lv.PART.INDICATOR)
|
||||
obj.add_style(style_indic_pr, lv.PART.INDICATOR | lv.STATE.PRESSED)
|
||||
obj.set_value(70, lv.ANIM.OFF)
|
||||
obj.center()
|
||||
|
||||
53
examples/styles/lv_example_style_14.py
Normal file
53
examples/styles/lv_example_style_14.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# Will be called when the styles of the base theme are already added
|
||||
# to add new styles
|
||||
|
||||
|
||||
class NewTheme(lv.theme_t):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
# Initialize the styles
|
||||
self.style_btn = lv.style_t()
|
||||
self.style_btn.init()
|
||||
self.style_btn.set_bg_color(lv.palette_main(lv.PALETTE.GREEN))
|
||||
self.style_btn.set_border_color(lv.palette_darken(lv.PALETTE.GREEN, 3))
|
||||
self.style_btn.set_border_width(3)
|
||||
|
||||
# This theme is based on active theme
|
||||
th_act = lv.theme_get_from_obj(lv.scr_act())
|
||||
# This theme will be applied only after base theme is applied
|
||||
self.set_parent(th_act)
|
||||
|
||||
class ExampleStyle_14():
|
||||
|
||||
def __init__(self):
|
||||
#
|
||||
# Extending the current theme
|
||||
#
|
||||
|
||||
btn = lv.btn(lv.scr_act())
|
||||
btn.align(lv.ALIGN.TOP_MID, 0, 20)
|
||||
|
||||
label = lv.label(btn)
|
||||
label.set_text("Original theme")
|
||||
|
||||
self.new_theme_init_and_set()
|
||||
|
||||
btn = lv.btn(lv.scr_act())
|
||||
btn.align(lv.ALIGN.BOTTOM_MID, 0, -20)
|
||||
|
||||
label = lv.label(btn)
|
||||
label.set_text("New theme")
|
||||
|
||||
def new_theme_apply_cb(self,th, obj):
|
||||
print(th,obj)
|
||||
if obj.get_class() == lv.btn_class:
|
||||
obj.add_style(self.th_new.style_btn, 0)
|
||||
|
||||
def new_theme_init_and_set(self):
|
||||
print("new_theme_init_and_set")
|
||||
# Initialize the new theme from the current theme
|
||||
self.th_new = NewTheme()
|
||||
self.th_new.set_apply_cb(self.new_theme_apply_cb)
|
||||
lv.disp_get_default().set_theme(self.th_new)
|
||||
|
||||
exampleStyle_14 = ExampleStyle_14()
|
||||
22
examples/styles/lv_example_style_2.py
Normal file
22
examples/styles/lv_example_style_2.py
Normal file
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# Using the background style properties
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
style.set_radius(5)
|
||||
|
||||
# Make a gradient
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 1))
|
||||
style.set_bg_grad_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_bg_grad_dir(lv.GRAD_DIR.VER)
|
||||
|
||||
# Shift the gradient to the bottom
|
||||
style.set_bg_main_stop(128)
|
||||
style.set_bg_grad_stop(192)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
obj.center()
|
||||
|
||||
22
examples/styles/lv_example_style_3.py
Normal file
22
examples/styles/lv_example_style_3.py
Normal file
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# Using the border style properties
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
# Set a background color and a radius
|
||||
style.set_radius(10)
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 1))
|
||||
|
||||
# Add border to the bottom+right
|
||||
style.set_border_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_border_width(5)
|
||||
style.set_border_opa(lv.OPA._50)
|
||||
style.set_border_side(lv.BORDER_SIDE.BOTTOM | lv.BORDER_SIDE.RIGHT)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
obj.center()
|
||||
|
||||
23
examples/styles/lv_example_style_4.py
Normal file
23
examples/styles/lv_example_style_4.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# Using the outline style properties
|
||||
#
|
||||
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
# Set a background color and a radius
|
||||
style.set_radius(5)
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 1))
|
||||
|
||||
# Add outline
|
||||
style.set_outline_width(2)
|
||||
style.set_outline_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_outline_pad(8)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
obj.center()
|
||||
|
||||
|
||||
23
examples/styles/lv_example_style_5.py
Normal file
23
examples/styles/lv_example_style_5.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#
|
||||
# Using the Shadow style properties
|
||||
#
|
||||
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
# Set a background color and a radius
|
||||
style.set_radius(5)
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 1))
|
||||
|
||||
# Add a shadow
|
||||
style.set_shadow_width(8)
|
||||
style.set_shadow_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_shadow_ofs_x(10)
|
||||
style.set_shadow_ofs_y(20)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.obj(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
obj.center()
|
||||
|
||||
44
examples/styles/lv_example_style_6.py
Normal file
44
examples/styles/lv_example_style_6.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from imagetools import get_png_info, open_png
|
||||
# Register PNG image decoder
|
||||
decoder = lv.img.decoder_create()
|
||||
decoder.info_cb = get_png_info
|
||||
decoder.open_cb = open_png
|
||||
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../assets/img_cogwheel_argb.png','rb') as f:
|
||||
png_data = f.read()
|
||||
except:
|
||||
print("Could not find img_cogwheel_argb.png")
|
||||
sys.exit()
|
||||
|
||||
img_cogwheel_argb = lv.img_dsc_t({
|
||||
'data_size': len(png_data),
|
||||
'data': png_data
|
||||
})
|
||||
|
||||
#
|
||||
# Using the Image style properties
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
# Set a background color and a radius
|
||||
style.set_radius(5)
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 3))
|
||||
style.set_border_width(2)
|
||||
style.set_border_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
|
||||
style.set_img_recolor(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_img_recolor_opa(lv.OPA._50)
|
||||
# style.set_transform_angle(300)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.img(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
|
||||
obj.set_src(img_cogwheel_argb)
|
||||
|
||||
obj.center()
|
||||
|
||||
15
examples/styles/lv_example_style_7.py
Normal file
15
examples/styles/lv_example_style_7.py
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
# Using the Arc style properties
|
||||
#
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
style.set_arc_color(lv.palette_main(lv.PALETTE.RED))
|
||||
style.set_arc_width(4)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.arc(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
obj.center()
|
||||
|
||||
|
||||
27
examples/styles/lv_example_style_8.py
Normal file
27
examples/styles/lv_example_style_8.py
Normal file
@@ -0,0 +1,27 @@
|
||||
#
|
||||
# Using the text style properties
|
||||
#
|
||||
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
style.set_radius(5)
|
||||
style.set_bg_opa(lv.OPA.COVER)
|
||||
style.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 3))
|
||||
style.set_border_width(2)
|
||||
style.set_border_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_pad_all(10)
|
||||
|
||||
style.set_text_color(lv.palette_main(lv.PALETTE.BLUE))
|
||||
style.set_text_letter_space(5)
|
||||
style.set_text_line_space(20)
|
||||
style.set_text_decor(lv.TEXT_DECOR.UNDERLINE)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.label(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
obj.set_text("Text of\n"
|
||||
"a label");
|
||||
|
||||
obj.center()
|
||||
|
||||
22
examples/styles/lv_example_style_9.py
Normal file
22
examples/styles/lv_example_style_9.py
Normal file
@@ -0,0 +1,22 @@
|
||||
#
|
||||
# Using the line style properties
|
||||
#
|
||||
|
||||
style = lv.style_t()
|
||||
style.init()
|
||||
|
||||
style.set_line_color(lv.palette_main(lv.PALETTE.GREY))
|
||||
style.set_line_width(6)
|
||||
style.set_line_rounded(True)
|
||||
|
||||
# Create an object with the new style
|
||||
obj = lv.line(lv.scr_act())
|
||||
obj.add_style(style, 0)
|
||||
p = [ {"x":10, "y":30},
|
||||
{"x":30, "y":50},
|
||||
{"x":100, "y":0}]
|
||||
|
||||
obj.set_points(p, 3)
|
||||
|
||||
obj.center()
|
||||
|
||||
Reference in New Issue
Block a user