|
4 | 4 |
|
5 | 5 | lv.init()
|
6 | 6 |
|
7 |
| -# Create a style based on style_plain but with a symbol font |
| 7 | +############################################################################## |
| 8 | +# Styles |
| 9 | +############################################################################## |
8 | 10 |
|
9 | 11 | class ColorStyle(lv.style_t):
|
10 | 12 | def __init__(self, color):
|
@@ -34,6 +36,50 @@ def __init__(self):
|
34 | 36 | self.set_shadow_ofs_y(lv.STATE.DEFAULT, 3);
|
35 | 37 | self.set_shadow_spread(lv.STATE.DEFAULT, 0);
|
36 | 38 |
|
| 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 | + |
37 | 83 | def get_member_name(obj, value):
|
38 | 84 | for member in dir(obj):
|
39 | 85 | if getattr(obj, member) == value:
|
@@ -99,7 +145,6 @@ def __init__(self, app, page):
|
99 | 145 | self.counter_btn.align(self.page, lv.ALIGN.CENTER, 0, 0)
|
100 | 146 | self.counter_label = lv.label(self.counter_btn)
|
101 | 147 | self.counter_label.set_text('Count')
|
102 |
| - self.counter_btn.add_style(self.counter_btn.PART.MAIN, ShadowStyle()) |
103 | 148 | self.counter_btn.set_event_cb(self.on_counter_btn)
|
104 | 149 | self.counter = 0
|
105 | 150 |
|
@@ -206,6 +251,7 @@ class Screen_Main(lv.obj):
|
206 | 251 | def __init__(self, app, *args, **kwds):
|
207 | 252 | self.app = app
|
208 | 253 | super().__init__(*args, **kwds)
|
| 254 | + self.theme = AdvancedDemoTheme() |
209 | 255 |
|
210 | 256 | self.tabview = lv.tabview(self)
|
211 | 257 | self.page_simple = Page_Simple(self.app, self.tabview.add_tab('Simple'))
|
|
0 commit comments