8000 Add theme example to AdvancedDemo · mhepp63/lv_binding_micropython@4b071bb · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b071bb

Browse files
committed
Add theme example to AdvancedDemo
Non circle buttons with shadow when not pressed
1 parent a06c487 commit 4b071bb

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

examples/advanced_demo.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
lv.init()
66

7-
# Create a style based on style_plain but with a symbol font
7+
##############################################################################
8+
# Styles
9+
##############################################################################
810

911
class ColorStyle(lv.style_t):
1012
def __init__(self, color):
@@ -34,6 +36,50 @@ def __init__(self):
3436
self.set_shadow_ofs_y(lv.STATE.DEFAULT, 3);
3537
self.set_shadow_spread(lv.STATE.DEFAULT, 0);
3638

39+
class ButtonStyle(lv.style_t):
40+
def __init__(self):
41+
super().__init__()
42+
self.set_radius(lv.STATE.DEFAULT, lv.dpx(8))
43+
self.set_shadow_opa(lv.STATE.DEFAULT, lv.OPA.COVER);
44+
self.set_shadow_width(lv.STATE.DEFAULT, lv.dpx(10));
45+
self.set_shadow_color(lv.STATE.DEFAULT, lv.color_hex3(0xAAA));
46+
self.set_shadow_ofs_x(lv.STATE.DEFAULT, lv.dpx(10));
47+
self.set_shadow_ofs_y(lv.STATE.DEFAULT, lv.dpx(10));
48+
self.set_shadow_spread(lv.STATE.DEFAULT, 0);
49+
50+
self.set_shadow_ofs_x(lv.STATE.PRESSED, lv.dpx(0));
51+
self.set_shadow_ofs_y(lv.STATE.PRESSED, lv.dpx(0));
52+
53+
54+
##############################################################################
55+
# Themes
56+
##############################################################################
57+
58+
class AdvancedDemoTheme(lv.theme_t):
59+
60+
def __init__(self):
61+
base_theme = lv.theme_get_act()
62+
63+
super().__init__({
64+
"color_primary": base_theme.color_primary,
65+
"color_secondary": base_theme.color_secondary,
66+
"flags": base_theme.flags,
67+
"font_small": base_theme.font_small,
68+
"font_normal": base_theme.font_normal,
69+
"font_subtitle": base_theme.font_subtitle,
70+
"font_title": base_theme.font_title,
71+
"apply_cb": self.apply})
72+
73+
self.set_base(base_theme)
74+
self.button = ButtonStyle()
75+
self.set_act()
76+
77+
def apply(self, theme, obj, name):
78+
if name == lv.THEME.BTN:
79+
obj.add_style(obj.PART.MAIN, self.button)
80+
81+
##############################################################################
82+
3783
def get_member_name(obj, value):
3884
for member in dir(obj):
3985
if getattr(obj, member) == value:
@@ -99,7 +145,6 @@ def __init__(self, app, page):
99145
self.counter_btn.align(self.page, lv.ALIGN.CENTER, 0, 0)
100146
self.counter_label = lv.label(self.counter_btn)
101147
self.counter_label.set_text('Count')
102-
self.counter_btn.add_style(self.counter_btn.PART.MAIN, ShadowStyle())
103148
self.counter_btn.set_event_cb(self.on_counter_btn)
104149
self.counter = 0
105150

@@ -206,6 +251,7 @@ class Screen_Main(lv.obj):
206251
def __init__(self, app, *args, **kwds):
207252
self.app = app
208253
super().__init__(*args, **kwds)
254+
self.theme = AdvancedDemoTheme()
209255

210256
self.tabview = lv.tabview(self)
211257
self.page_simple = Page_Simple(self.app, self.tabview.add_tab('Simple'))

lvgl

Submodule lvgl updated from b2603eb to aad9f4f

0 commit comments

Comments
 (0)
0