Skip to content

Commit a9fa4e0

Browse files
committed
style: sync multi-part zero-style stripping
1 parent d2ccdfc commit a9fa4e0

1 file changed

Lines changed: 52 additions & 35 deletions

File tree

assets/apps/watch.py

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,62 @@ def _font_for(size):
4949
return (font, 14) if font is not None else (None, 0)
5050

5151

52-
def _clean_obj(parent):
53-
obj = lv.obj(parent)
52+
def _zero_styles(obj):
5453
try:
5554
obj.remove_style_all()
5655
except AttributeError:
5756
pass
58-
obj.set_style_pad_all(0, 0)
59-
try:
60-
obj.set_style_margin_all(0, 0)
61-
except AttributeError:
62-
pass
63-
try:
64-
obj.set_style_border_width(0, 0)
65-
except AttributeError:
66-
pass
67-
try:
68-
obj.set_style_outline_width(0, 0)
69-
except AttributeError:
70-
pass
57+
parts = (
58+
0,
59+
getattr(lv.PART, "MAIN", 0),
60+
getattr(lv.PART, "ITEMS", 0),
61+
getattr(lv.PART, "INDICATOR", 0),
62+
getattr(lv.PART, "ANY", 0),
63+
)
64+
methods = (
65+
"set_style_pad_all",
66+
"set_style_pad_top",
67+
"set_style_pad_bottom",
68+
"set_style_pad_left",
69+
"set_style_pad_right",
70+
"set_style_pad_row",
71+
"set_style_pad_column",
72+
"set_style_margin_all",
73+
"set_style_margin_top",
74+
"set_style_margin_bottom",
75+
"set_style_margin_left",
76+
"set_style_margin_right",
77+
"set_style_border_width",
78+
"set_style_outline_width",
79+
"set_style_outline_pad",
80+
"set_style_shadow_width",
81+
"set_style_shadow_spread",
82+
"set_style_shadow_ofs_x",
83+
"set_style_shadow_ofs_y",
84+
"set_style_text_letter_space",
85+
"set_style_text_line_space",
86+
)
87+
for part in parts:
88+
for m in methods:
89+
fn = getattr(obj, m, None)
90+
if fn is not None:
91+
try:
92+
fn(0, part)
93+
except (TypeError, AttributeError):
94+
try:
95+
fn(0)
96+
except (TypeError, AttributeError):
97+
pass
7198
try:
7299
obj.remove_flag(lv.obj.FLAG.SCROLLABLE)
73100
except AttributeError:
74101
pass
102+
return obj
103+
104+
105+
def _clean_obj(parent):
106+
obj = lv.obj(parent)
107+
_zero_styles(obj)
75108
try:
76109
obj.update_layout()
77110
except AttributeError:
@@ -81,28 +114,12 @@ def _clean_obj(parent):
81114

82115
def _clean_label(parent, text, color, font_size):
83116
lbl = lv.label(parent)
84-
try:
85-
lbl.remove_style_all()
86-
except AttributeError:
87-
pass
117+
_zero_styles(lbl)
88118
font, _ = _font_for(font_size)
89119
if font is not None:
90120
lbl.set_style_text_font(font, 0)
91121
lbl.set_style_text_color(_color(color), 0)
92122
lbl.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
93-
lbl.set_style_pad_all(0, 0)
94-
try:
95-
lbl.set_style_margin_all(0, 0)
96-
except AttributeError:
97-
pass
98-
try:
99-
lbl.set_style_border_width(0, 0)
100-
except AttributeError:
101-
pass
102-
try:
103-
lbl.set_style_outline_width(0, 0)
104-
except AttributeError:
105-
pass
106123
lbl.set_text(text)
107124
try:
108125
lbl.update_layout()
@@ -318,9 +335,9 @@ def _build_watch(self):
318335
# 8. Scale for Ticks & Analog Needles - Created AFTER dial & digital sub-dial
319336
# This guarantees that the tick ring and all rotating hands draw in FRONT of the digital display!
320337
self.scale = lv.scale(self.face)
338+
_zero_styles(self.scale)
321339
self.scale.set_size(dial_size, dial_size)
322340
self.scale.center()
323-
_plain(self.scale)
324341
self.scale.set_mode(lv.scale.MODE.ROUND_INNER)
325342
self.scale.set_range(0, 3600)
326343
self.scale.set_angle_range(360)
@@ -369,16 +386,16 @@ def _build_watch(self):
369386

370387
# 10. Center Hub Cap - Created on top of the hands
371388
hub_size = max(10, int(dial_size * 0.065))
372-
self.hub = lv.obj(self.face)
389+
self.hub = _clean_obj(self.face)
373390
self.hub.set_size(hub_size, hub_size)
374391
self.hub.center()
375392
self.hub.set_style_radius(lv.RADIUS_CIRCLE, 0)
376393
self.hub.set_style_bg_color(_color(0xF54E00), 0)
377394
self.hub.set_style_bg_grad_color(_color(0x9A3412), 0)
378395
self.hub.set_style_bg_grad_dir(lv.GRAD_DIR.VER, 0)
396+
self.hub.set_style_bg_opa(lv.OPA.COVER, 0)
379397
self.hub.set_style_border_color(_color(0xFFF7ED), 0)
380398
self.hub.set_style_border_width(1, 0)
381-
_plain(self.hub)
382399

383400
# First update and timer (~30 FPS: 33ms)
384401
self.update_time()

0 commit comments

Comments
 (0)