Skip to content

Commit f2c982e

Browse files
committed
style: sync zero-padded watchface objects
1 parent aba86e3 commit f2c982e

1 file changed

Lines changed: 74 additions & 49 deletions

File tree

assets/apps/watch.py

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

5151

52-
def _set_font(label, target_size):
53-
font, _ = _font_for(max(1, int(target_size)))
52+
def _clean_obj(parent):
53+
obj = lv.obj(parent)
54+
try:
55+
obj.remove_style_all()
56+
except AttributeError:
57+
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
71+
try:
72+
obj.remove_flag(lv.obj.FLAG.SCROLLABLE)
73+
except AttributeError:
74+
pass
75+
return obj
76+
77+
78+
def _clean_label(parent, text, color, font_size):
79+
lbl = lv.label(parent)
80+
try:
81+
lbl.remove_style_all()
82+
except AttributeError:
83+
pass
84+
lbl.set_text(text)
85+
font, _ = _font_for(font_size)
5486
if font is not None:
55-
label.set_style_text_font(font, 0)
56-
label.set_style_pad_all(0, 0)
57-
label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
87+
lbl.set_style_text_font(font, 0)
88+
lbl.set_style_text_color(_color(color), 0)
89+
lbl.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
90+
lbl.set_style_pad_all(0, 0)
91+
try:
92+
lbl.set_style_margin_all(0, 0)
93+
except AttributeError:
94+
pass
95+
try:
96+
lbl.set_style_border_width(0, 0)
97+
except AttributeError:
98+
pass
99+
try:
100+
lbl.set_style_outline_width(0, 0)
101+
except AttributeError:
102+
pass
103+
return lbl
58104

59105

60106
def _plain(obj):
61107
obj.set_style_border_width(0, 0)
62108
obj.set_style_pad_all(0, 0)
109+
try:
110+
obj.set_style_margin_all(0, 0)
111+
except AttributeError:
112+
pass
63113
obj.set_style_bg_opa(lv.OPA.TRANSP, 0)
64114
try:
65115
obj.remove_flag(lv.obj.FLAG.SCROLLABLE)
@@ -111,93 +161,79 @@ def _line(self, parent, color, width):
111161

112162
def _build_watch(self):
113163
size = self.size
114-
dial_size = int(size * 0.916)
164+
dial_size = int(size * 0.90)
115165
r = dial_size // 2
116166

117167
# 1. Base Screen Layer
118168
self.parent.set_style_bg_color(_color(0x0A0D10), 0)
119169
self.parent.set_style_bg_opa(lv.OPA.COVER, 0)
120170
self.parent.set_style_pad_all(0, 0)
171+
try:
172+
self.parent.set_style_margin_all(0, 0)
173+
except AttributeError:
174+
pass
121175
try:
122176
self.parent.remove_flag(lv.obj.FLAG.SCROLLABLE)
123177
except AttributeError:
124178
pass
125179

126180
# 2. Outer Watch Bezel / Casing
127-
self.bezel = lv.obj(self.parent)
181+
self.bezel = _clean_obj(self.parent)
128182
self.bezel.set_size(size, size)
129183
self.bezel.center()
130184
self.bezel.set_style_radius(lv.RADIUS_CIRCLE, 0)
131185
self.bezel.set_style_bg_color(_color(0x1E242B), 0)
132186
self.bezel.set_style_bg_grad_color(_color(0x101418), 0)
133187
self.bezel.set_style_bg_grad_dir(lv.GRAD_DIR.VER, 0)
188+
self.bezel.set_style_bg_opa(lv.OPA.COVER, 0)
134189
self.bezel.set_style_border_color(_color(0x3B444E), 0)
135190
self.bezel.set_style_border_width(max(2, int(size * 0.017)), 0)
136-
self.bezel.set_style_pad_all(0, 0)
137-
_plain(self.bezel)
138191

139192
# 3. Inner Metallic Bezel Ring with Subtle Amber Accent
140193
inner_bezel_size = int(size * 0.95)
141-
self.bezel_ring = lv.obj(self.parent)
194+
self.bezel_ring = _clean_obj(self.parent)
142195
self.bezel_ring.set_size(inner_bezel_size, inner_bezel_size)
143196
self.bezel_ring.center()
144197
self.bezel_ring.set_style_radius(lv.RADIUS_CIRCLE, 0)
145198
self.bezel_ring.set_style_bg_color(_color(0x151A20), 0)
199+
self.bezel_ring.set_style_bg_opa(lv.OPA.COVER, 0)
146200
self.bezel_ring.set_style_border_color(_color(0xF54E00), 0)
147201
self.bezel_ring.set_style_border_width(1, 0)
148202
self.bezel_ring.set_style_border_opa(lv.OPA._60, 0)
149-
self.bezel_ring.set_style_pad_all(0, 0)
150-
_plain(self.bezel_ring)
151203

152204
# 4. Dial Face (Underlay for background elements)
153-
self.face = lv.obj(self.parent)
205+
self.face = _clean_obj(self.parent)
154206
self.face.set_size(dial_size, dial_size)
155207
self.face.center()
156208
self.face.set_style_radius(lv.RADIUS_CIRCLE, 0)
157209
self.face.set_style_bg_color(_color(0x0E1115), 0)
158210
self.face.set_style_bg_grad_color(_color(0x181F26), 0)
159211
self.face.set_style_bg_grad_dir(lv.GRAD_DIR.VER, 0)
212+
self.face.set_style_bg_opa(lv.OPA.COVER, 0)
160213
self.face.set_style_border_color(_color(0x28323D), 0)
161214
self.face.set_style_border_width(1, 0)
162-
self.face.set_style_pad_all(0, 0)
163-
_plain(self.face)
164215

165216
# 5. Roman Hour Numerals (XII, III, VI, IX)
166217
# XII & VI: horizontal center aligned to parent (x_offset = 0), calculated y_offset
167218
# IX & III: vertical center aligned to parent (y_offset = 0), calculated x_offset
168219
num_inset = int(dial_size * 0.08)
169220

170-
self.lbl_xii = lv.label(self.face)
171-
self.lbl_xii.set_text("XII")
172-
self.lbl_xii.set_style_text_color(_color(0xE2E8F0), 0)
173-
_set_font(self.lbl_xii, 14)
221+
self.lbl_xii = _clean_label(self.face, "XII", 0xE2E8F0, 14)
174222
self.lbl_xii.align(lv.ALIGN.TOP_MID, 0, num_inset)
175223

176-
self.lbl_vi = lv.label(self.face)
177-
self.lbl_vi.set_text("VI")
178-
self.lbl_vi.set_style_text_color(_color(0xE2E8F0), 0)
179-
_set_font(self.lbl_vi, 14)
224+
self.lbl_vi = _clean_label(self.face, "VI", 0xE2E8F0, 14)
180225
self.lbl_vi.align(lv.ALIGN.BOTTOM_MID, 0, -num_inset)
181226

182-
self.lbl_ix = lv.label(self.face)
183-
self.lbl_ix.set_text("IX")
184-
self.lbl_ix.set_style_text_color(_color(0xE2E8F0), 0)
185-
_set_font(self.lbl_ix, 14)
227+
self.lbl_ix = _clean_label(self.face, "IX", 0xE2E8F0, 14)
186228
self.lbl_ix.align(lv.ALIGN.LEFT_MID, num_inset, 0)
187229

188-
self.lbl_iii = lv.label(self.face)
189-
self.lbl_iii.set_text("III")
190-
self.lbl_iii.set_style_text_color(_color(0xE2E8F0), 0)
191-
_set_font(self.lbl_iii, 14)
230+
self.lbl_iii = _clean_label(self.face, "III", 0xE2E8F0, 14)
192231
self.lbl_iii.align(lv.ALIGN.RIGHT_MID, -num_inset, 0)
193232

194233
# 6. Brand Label (Upper Dial Quadrant)
195234
# Horizontal center aligned to parent (x_offset = 0), calculated y_offset
196235
brand_top_offset = int(dial_size * 0.25)
197-
self.brand_lbl = lv.label(self.face)
198-
self.brand_lbl.set_text("PYDEVICES")
199-
self.brand_lbl.set_style_text_color(_color(0xF54E00), 0)
200-
_set_font(self.brand_lbl, 11)
236+
self.brand_lbl = _clean_label(self.face, "PYDEVICES", 0xF54E00, 11)
201237
self.brand_lbl.align(lv.ALIGN.TOP_MID, 0, brand_top_offset)
202238

203239
# 7. Digital Readout Sub-Dial (Lower Dial Quadrant) - Created on dial face behind hands
@@ -206,32 +242,21 @@ def _build_watch(self):
206242
pill_h = int(dial_size * 0.18)
207243
pill_bottom_offset = int(dial_size * 0.18)
208244

209-
self.pill = lv.obj(self.face)
245+
self.pill = _clean_obj(self.face)
210246
self.pill.set_size(pill_w, pill_h)
211247
self.pill.align(lv.ALIGN.BOTTOM_MID, 0, -pill_bottom_offset)
212248
self.pill.set_style_radius(max(4, int(pill_h * 0.18)), 0)
213249
self.pill.set_style_bg_color(_color(0x080B0E), 0)
214250
self.pill.set_style_bg_opa(lv.OPA._90, 0)
215251
self.pill.set_style_border_color(_color(0x28333E), 0)
216252
self.pill.set_style_border_width(1, 0)
217-
self.pill.set_style_pad_all(0, 0)
218-
try:
219-
self.pill.remove_flag(lv.obj.FLAG.SCROLLABLE)
220-
except AttributeError:
221-
pass
222253

223254
# Digital Time & Date inside sub-dial:
224255
# Both horizontal centers aligned to parent pill (x_offset = 0), calculated y_offsets
225-
self.digital_time = lv.label(self.pill)
226-
self.digital_time.set_text("00:00:00")
227-
self.digital_time.set_style_text_color(_color(0xF8FAFC), 0)
228-
_set_font(self.digital_time, 13)
256+
self.digital_time = _clean_label(self.pill, "00:00:00", 0xF8FAFC, 13)
229257
self.digital_time.align(lv.ALIGN.TOP_MID, 0, 4)
230258

231-
self.digital_date = lv.label(self.pill)
232-
self.digital_date.set_text("FRI OCT 24")
233-
self.digital_date.set_style_text_color(_color(0x94A3B8), 0)
234-
_set_font(self.digital_date, 10)
259+
self.digital_date = _clean_label(self.pill, "FRI OCT 24", 0x94A3B8, 10)
235260
self.digital_date.align(lv.ALIGN.BOTTOM_MID, 0, -4)
236261

237262
# 8. Scale for Ticks & Analog Needles - Created AFTER dial & digital sub-dial

0 commit comments

Comments
 (0)