quantumgui 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- quantumgui/__init__.py +9 -0
- quantumgui/__main__.py +6 -0
- quantumgui/cli.py +341 -0
- quantumgui/core/__init__.py +39 -0
- quantumgui/core/animation.py +221 -0
- quantumgui/core/audit.py +323 -0
- quantumgui/core/context.py +54 -0
- quantumgui/core/data_source.py +426 -0
- quantumgui/core/draw.py +428 -0
- quantumgui/core/enterprise.py +402 -0
- quantumgui/core/enterprise_app.py +419 -0
- quantumgui/core/events.py +34 -0
- quantumgui/core/geometry.py +108 -0
- quantumgui/core/native_dialogs.py +276 -0
- quantumgui/core/pdf_report.py +390 -0
- quantumgui/core/rules.py +284 -0
- quantumgui/core/state.py +42 -0
- quantumgui/core/task_runner.py +181 -0
- quantumgui/core/widget.py +498 -0
- quantumgui/core/window.py +920 -0
- quantumgui/core/xlsx_export.py +145 -0
- quantumgui/py.typed +0 -0
- quantumgui/theme/__init__.py +32 -0
- quantumgui/theme/hct.py +191 -0
- quantumgui/theme/theme.py +93 -0
- quantumgui/theme/tokens.py +423 -0
- quantumgui/ui.py +2142 -0
- quantumgui/widgets/__init__.py +168 -0
- quantumgui/widgets/advanced.py +499 -0
- quantumgui/widgets/button.py +224 -0
- quantumgui/widgets/charts.py +625 -0
- quantumgui/widgets/charts_bi.py +528 -0
- quantumgui/widgets/charts_extra.py +430 -0
- quantumgui/widgets/charts_pro.py +568 -0
- quantumgui/widgets/checkbox.py +199 -0
- quantumgui/widgets/chip.py +219 -0
- quantumgui/widgets/containers.py +321 -0
- quantumgui/widgets/data_controls.py +487 -0
- quantumgui/widgets/data_grid.py +956 -0
- quantumgui/widgets/data_table.py +551 -0
- quantumgui/widgets/date_picker.py +407 -0
- quantumgui/widgets/display_media.py +372 -0
- quantumgui/widgets/display_pro.py +407 -0
- quantumgui/widgets/drawer.py +252 -0
- quantumgui/widgets/enterprise_controls.py +934 -0
- quantumgui/widgets/fab.py +261 -0
- quantumgui/widgets/forms_pro.py +703 -0
- quantumgui/widgets/forms_pro_media.py +587 -0
- quantumgui/widgets/inputs.py +870 -0
- quantumgui/widgets/layout_pro.py +162 -0
- quantumgui/widgets/list_view.py +307 -0
- quantumgui/widgets/masked_input.py +131 -0
- quantumgui/widgets/master_detail.py +155 -0
- quantumgui/widgets/navigation.py +382 -0
- quantumgui/widgets/overlays.py +355 -0
- quantumgui/widgets/productivity.py +500 -0
- quantumgui/widgets/productivity_boards.py +544 -0
- quantumgui/widgets/radio.py +209 -0
- quantumgui/widgets/scroll_view.py +129 -0
- quantumgui/widgets/select.py +373 -0
- quantumgui/widgets/sheets.py +249 -0
- quantumgui/widgets/slider.py +209 -0
- quantumgui/widgets/switch.py +196 -0
- quantumgui/widgets/tabs.py +175 -0
- quantumgui/widgets/text.py +101 -0
- quantumgui/widgets/text_field.py +490 -0
- quantumgui/widgets/time_picker.py +499 -0
- quantumgui-1.0.0.dist-info/METADATA +137 -0
- quantumgui-1.0.0.dist-info/RECORD +73 -0
- quantumgui-1.0.0.dist-info/WHEEL +5 -0
- quantumgui-1.0.0.dist-info/entry_points.txt +2 -0
- quantumgui-1.0.0.dist-info/licenses/LICENSE +32 -0
- quantumgui-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
"""Material Design 3 DatePicker with interactive Calendar Overlay."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import calendar
|
|
6
|
+
from datetime import date
|
|
7
|
+
from typing import Callable, Literal
|
|
8
|
+
|
|
9
|
+
import skia
|
|
10
|
+
|
|
11
|
+
from ..core.animation import AnimatedValue
|
|
12
|
+
from ..core.draw import (
|
|
13
|
+
draw_elevation_shadow,
|
|
14
|
+
draw_icon,
|
|
15
|
+
draw_text_centered_y,
|
|
16
|
+
font_for_style,
|
|
17
|
+
get_font,
|
|
18
|
+
make_rrect,
|
|
19
|
+
make_rrect_spec,
|
|
20
|
+
measure_text,
|
|
21
|
+
resolve_color,
|
|
22
|
+
)
|
|
23
|
+
from ..core.events import MouseEvent
|
|
24
|
+
from ..core.geometry import Constraints, Rect, Size
|
|
25
|
+
from ..core.state import State
|
|
26
|
+
from ..core.widget import Widget
|
|
27
|
+
from ..theme import Theme
|
|
28
|
+
|
|
29
|
+
DatePickerVariant = Literal["outlined", "filled"]
|
|
30
|
+
|
|
31
|
+
_MONTHS = (
|
|
32
|
+
"",
|
|
33
|
+
"Enero",
|
|
34
|
+
"Febrero",
|
|
35
|
+
"Marzo",
|
|
36
|
+
"Abril",
|
|
37
|
+
"Mayo",
|
|
38
|
+
"Junio",
|
|
39
|
+
"Julio",
|
|
40
|
+
"Agosto",
|
|
41
|
+
"Septiembre",
|
|
42
|
+
"Octubre",
|
|
43
|
+
"Noviembre",
|
|
44
|
+
"Diciembre",
|
|
45
|
+
)
|
|
46
|
+
_WEEKDAYS = ("Lu", "Ma", "Mi", "Ju", "Vi", "Sá", "Do")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class _CalendarOverlay(Widget):
|
|
50
|
+
"""Floating Material Design 3 Calendar picker popup."""
|
|
51
|
+
|
|
52
|
+
interactive = True
|
|
53
|
+
auto_attach = False
|
|
54
|
+
cursor = "pointer"
|
|
55
|
+
|
|
56
|
+
POPUP_W = 312.0
|
|
57
|
+
POPUP_H = 344.0
|
|
58
|
+
|
|
59
|
+
def __init__(self, owner: DatePicker) -> None:
|
|
60
|
+
super().__init__()
|
|
61
|
+
self.owner = owner
|
|
62
|
+
ref = owner.value or date.today()
|
|
63
|
+
self.view_year = ref.year
|
|
64
|
+
self.view_month = ref.month
|
|
65
|
+
self._popup_rect = Rect(0.0, 0.0, 0.0, 0.0)
|
|
66
|
+
self._prev_rect = Rect(0.0, 0.0, 0.0, 0.0)
|
|
67
|
+
self._next_rect = Rect(0.0, 0.0, 0.0, 0.0)
|
|
68
|
+
self._hover_day: int | None = None
|
|
69
|
+
|
|
70
|
+
def layout(self, rect: Rect, theme: Theme) -> None:
|
|
71
|
+
self.rect = rect
|
|
72
|
+
anchor = self.owner.rect
|
|
73
|
+
x = max(8.0, min(rect.width - self.POPUP_W - 8.0, anchor.x))
|
|
74
|
+
y = anchor.y + self.owner.BOX_HEIGHT + 6.0
|
|
75
|
+
if y + self.POPUP_H > rect.height - 8.0 and anchor.y - self.POPUP_H - 6.0 >= 8.0:
|
|
76
|
+
y = anchor.y - self.POPUP_H - 6.0
|
|
77
|
+
self._popup_rect = Rect(x, y, self.POPUP_W, self.POPUP_H)
|
|
78
|
+
self._prev_rect = Rect(x + 12.0, y + 12.0, 36.0, 36.0)
|
|
79
|
+
self._next_rect = Rect(x + self.POPUP_W - 48.0, y + 12.0, 36.0, 36.0)
|
|
80
|
+
|
|
81
|
+
def hit_test(self, x: float, y: float) -> Widget | None:
|
|
82
|
+
return self if self._popup_rect.contains(x, y) else None
|
|
83
|
+
|
|
84
|
+
def _day_cells(self) -> list[tuple[int, Rect]]:
|
|
85
|
+
weeks = calendar.monthcalendar(self.view_year, self.view_month)
|
|
86
|
+
cell_w = (self.POPUP_W - 24.0) / 7.0
|
|
87
|
+
cell_h = 38.0
|
|
88
|
+
start_x = self._popup_rect.x + 12.0
|
|
89
|
+
start_y = self._popup_rect.y + 90.0
|
|
90
|
+
out: list[tuple[int, Rect]] = []
|
|
91
|
+
for wi, week in enumerate(weeks):
|
|
92
|
+
for di, day_num in enumerate(week):
|
|
93
|
+
if day_num > 0:
|
|
94
|
+
out.append((day_num, Rect(start_x + di * cell_w, start_y + wi * cell_h, cell_w, cell_h)))
|
|
95
|
+
return out
|
|
96
|
+
|
|
97
|
+
def _shift_month(self, delta: int) -> None:
|
|
98
|
+
m = self.view_month + delta
|
|
99
|
+
y = self.view_year
|
|
100
|
+
if m < 1:
|
|
101
|
+
m, y = 12, y - 1
|
|
102
|
+
elif m > 12:
|
|
103
|
+
m, y = 1, y + 1
|
|
104
|
+
self.view_month, self.view_year = m, y
|
|
105
|
+
self._hover_day = None
|
|
106
|
+
self.invalidate()
|
|
107
|
+
|
|
108
|
+
def on_mouse_move(self, event: MouseEvent) -> None:
|
|
109
|
+
found = None
|
|
110
|
+
for d, r in self._day_cells():
|
|
111
|
+
if r.contains(event.x, event.y):
|
|
112
|
+
found = d
|
|
113
|
+
break
|
|
114
|
+
if found != self._hover_day:
|
|
115
|
+
self._hover_day = found
|
|
116
|
+
self.invalidate()
|
|
117
|
+
|
|
118
|
+
def on_mouse_up(self, event: MouseEvent) -> None:
|
|
119
|
+
was_pressed = self.pressed
|
|
120
|
+
super().on_mouse_up(event)
|
|
121
|
+
if not was_pressed:
|
|
122
|
+
return
|
|
123
|
+
if self._prev_rect.contains(event.x, event.y):
|
|
124
|
+
self._shift_month(-1)
|
|
125
|
+
return
|
|
126
|
+
if self._next_rect.contains(event.x, event.y):
|
|
127
|
+
self._shift_month(1)
|
|
128
|
+
return
|
|
129
|
+
for d, r in self._day_cells():
|
|
130
|
+
if r.contains(event.x, event.y):
|
|
131
|
+
self.owner._pick_date(date(self.view_year, self.view_month, d))
|
|
132
|
+
self.owner.close_calendar()
|
|
133
|
+
return
|
|
134
|
+
|
|
135
|
+
def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
|
|
136
|
+
c = theme.colors
|
|
137
|
+
pr = self._popup_rect
|
|
138
|
+
radius = theme.shape.large
|
|
139
|
+
|
|
140
|
+
draw_elevation_shadow(canvas, pr, radius, 3, c.shadow)
|
|
141
|
+
canvas.drawRRect(make_rrect(pr, radius), skia.Paint(AntiAlias=True, Color=c.surface_container_high.to_skia()))
|
|
142
|
+
|
|
143
|
+
# Month/Year header
|
|
144
|
+
hdr_font = font_for_style(theme.font_family, theme.typography.title_medium)
|
|
145
|
+
title = f"{_MONTHS[self.view_month]} {self.view_year}"
|
|
146
|
+
tw = measure_text(hdr_font, title)
|
|
147
|
+
draw_text_centered_y(canvas, title, pr.center_x - tw * 0.5, pr.y + 30.0, hdr_font, c.on_surface)
|
|
148
|
+
|
|
149
|
+
draw_icon(canvas, "chevron_left", self._prev_rect.center_x, self._prev_rect.center_y, 18.0, c.on_surface_variant)
|
|
150
|
+
draw_icon(canvas, "chevron_right", self._next_rect.center_x, self._next_rect.center_y, 18.0, c.on_surface_variant)
|
|
151
|
+
|
|
152
|
+
# Weekday headers
|
|
153
|
+
wd_font = font_for_style(theme.font_family, theme.typography.label_medium)
|
|
154
|
+
cell_w = (self.POPUP_W - 24.0) / 7.0
|
|
155
|
+
for i, wd in enumerate(_WEEKDAYS):
|
|
156
|
+
cx = pr.x + 12.0 + (i + 0.5) * cell_w
|
|
157
|
+
w = measure_text(wd_font, wd)
|
|
158
|
+
draw_text_centered_y(canvas, wd, cx - w * 0.5, pr.y + 68.0, wd_font, c.on_surface_variant)
|
|
159
|
+
|
|
160
|
+
# Days
|
|
161
|
+
day_font = font_for_style(theme.font_family, theme.typography.body_medium)
|
|
162
|
+
today = date.today()
|
|
163
|
+
sel = self.owner.value
|
|
164
|
+
|
|
165
|
+
for d, r in self._day_cells():
|
|
166
|
+
cur = date(self.view_year, self.view_month, d)
|
|
167
|
+
is_sel = sel == cur
|
|
168
|
+
is_today = today == cur
|
|
169
|
+
|
|
170
|
+
if is_sel:
|
|
171
|
+
canvas.drawCircle(r.center_x, r.center_y, 17.0, skia.Paint(AntiAlias=True, Color=c.primary.to_skia()))
|
|
172
|
+
elif d == self._hover_day:
|
|
173
|
+
canvas.drawCircle(
|
|
174
|
+
r.center_x,
|
|
175
|
+
r.center_y,
|
|
176
|
+
17.0,
|
|
177
|
+
skia.Paint(AntiAlias=True, Color=c.on_surface.with_alpha(theme.state_layers.hover).to_skia()),
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
if is_today and not is_sel:
|
|
181
|
+
canvas.drawCircle(
|
|
182
|
+
r.center_x,
|
|
183
|
+
r.center_y,
|
|
184
|
+
17.0,
|
|
185
|
+
skia.Paint(
|
|
186
|
+
AntiAlias=True,
|
|
187
|
+
Color=c.primary.to_skia(),
|
|
188
|
+
Style=skia.Paint.kStroke_Style,
|
|
189
|
+
StrokeWidth=1.2,
|
|
190
|
+
),
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
fg = c.on_primary if is_sel else (c.primary if is_today else c.on_surface)
|
|
194
|
+
label = str(d)
|
|
195
|
+
lw = measure_text(day_font, label)
|
|
196
|
+
draw_text_centered_y(canvas, label, r.center_x - lw * 0.5, r.center_y, day_font, fg)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class DatePicker(Widget):
|
|
200
|
+
"""Official Material Design 3 DatePicker (`outlined` or `filled` trigger + Calendar overlay)."""
|
|
201
|
+
|
|
202
|
+
interactive = True
|
|
203
|
+
focusable = True
|
|
204
|
+
manages_own_box = True
|
|
205
|
+
cursor = "pointer"
|
|
206
|
+
|
|
207
|
+
BOX_HEIGHT = 56.0
|
|
208
|
+
SUPPORTING_HEIGHT = 20.0
|
|
209
|
+
|
|
210
|
+
def __init__(
|
|
211
|
+
self,
|
|
212
|
+
label: str = "Fecha",
|
|
213
|
+
*,
|
|
214
|
+
value: date | None = None,
|
|
215
|
+
variant: DatePickerVariant = "outlined",
|
|
216
|
+
supporting_text: str | None = None,
|
|
217
|
+
error_text: str | None = None,
|
|
218
|
+
disabled: bool = False,
|
|
219
|
+
bind: State[date | None] | None = None,
|
|
220
|
+
on_change: Callable[[date], None] | None = None,
|
|
221
|
+
) -> None:
|
|
222
|
+
super().__init__()
|
|
223
|
+
self.label = label
|
|
224
|
+
self.variant: DatePickerVariant = variant
|
|
225
|
+
self._bind = bind
|
|
226
|
+
self._value: date | None = bind.value if bind is not None else value
|
|
227
|
+
self.supporting_text = supporting_text
|
|
228
|
+
self._error_text = error_text
|
|
229
|
+
self.disabled = disabled
|
|
230
|
+
self.on_change = on_change
|
|
231
|
+
|
|
232
|
+
self._open = False
|
|
233
|
+
self._overlay: _CalendarOverlay | None = None
|
|
234
|
+
self._float_anim = AnimatedValue(1.0 if self._value is not None else 0.0, duration=0.16)
|
|
235
|
+
|
|
236
|
+
if bind is not None:
|
|
237
|
+
bind.subscribe(self._on_bound_change)
|
|
238
|
+
|
|
239
|
+
def _on_bound_change(self, new_val: date | None) -> None:
|
|
240
|
+
if new_val != self._value:
|
|
241
|
+
self._value = new_val
|
|
242
|
+
self._float_anim.animate_to(1.0 if (self._value is not None or self._open) else 0.0)
|
|
243
|
+
self.invalidate()
|
|
244
|
+
|
|
245
|
+
@property
|
|
246
|
+
def value(self) -> date | None:
|
|
247
|
+
return self._value
|
|
248
|
+
|
|
249
|
+
@value.setter
|
|
250
|
+
def value(self, val: date | None) -> None:
|
|
251
|
+
if val != self._value:
|
|
252
|
+
self._value = val
|
|
253
|
+
self._float_anim.animate_to(1.0 if (self._value is not None or self._open) else 0.0)
|
|
254
|
+
if self._bind is not None and self._bind.value != val:
|
|
255
|
+
self._bind.value = val
|
|
256
|
+
self.invalidate()
|
|
257
|
+
|
|
258
|
+
def _pick_date(self, picked: date) -> None:
|
|
259
|
+
self.value = picked
|
|
260
|
+
if self.on_change is not None:
|
|
261
|
+
self.on_change(picked)
|
|
262
|
+
|
|
263
|
+
def open_calendar(self) -> None:
|
|
264
|
+
if self.disabled or self.window is None:
|
|
265
|
+
return
|
|
266
|
+
self._open = True
|
|
267
|
+
self._float_anim.animate_to(1.0)
|
|
268
|
+
self._overlay = _CalendarOverlay(self)
|
|
269
|
+
self.window.open_overlay(self._overlay)
|
|
270
|
+
self.invalidate()
|
|
271
|
+
|
|
272
|
+
def close_calendar(self) -> None:
|
|
273
|
+
self._open = False
|
|
274
|
+
if self._overlay is not None and self.window is not None:
|
|
275
|
+
self.window.close_overlay(self._overlay)
|
|
276
|
+
self._overlay = None
|
|
277
|
+
self._float_anim.animate_to(1.0 if self._value is not None else 0.0)
|
|
278
|
+
self.invalidate()
|
|
279
|
+
|
|
280
|
+
def _has_footer(self) -> bool:
|
|
281
|
+
return bool(self._error_text or self.supporting_text)
|
|
282
|
+
|
|
283
|
+
def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
|
|
284
|
+
h = self.BOX_HEIGHT + (self.SUPPORTING_HEIGHT if self._has_footer() else 0.0)
|
|
285
|
+
w = 240.0 if constraints.max_width == float("inf") else min(240.0, constraints.max_width)
|
|
286
|
+
return Size(w, h)
|
|
287
|
+
|
|
288
|
+
def tick(self, now: float) -> bool:
|
|
289
|
+
if self._open and self.window is not None and self._overlay not in self.window._overlays:
|
|
290
|
+
self._open = False
|
|
291
|
+
self._overlay = None
|
|
292
|
+
self._float_anim.animate_to(1.0 if self._value is not None else 0.0)
|
|
293
|
+
return self._float_anim.update(now)
|
|
294
|
+
|
|
295
|
+
def on_mouse_up(self, event: MouseEvent) -> None:
|
|
296
|
+
was_pressed = self.pressed
|
|
297
|
+
super().on_mouse_up(event)
|
|
298
|
+
if self.disabled or not was_pressed or not self.rect.contains(event.x, event.y):
|
|
299
|
+
return
|
|
300
|
+
if self._open:
|
|
301
|
+
self.close_calendar()
|
|
302
|
+
else:
|
|
303
|
+
self.open_calendar()
|
|
304
|
+
|
|
305
|
+
def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
|
|
306
|
+
c = theme.colors
|
|
307
|
+
is_error = bool(self._error_text)
|
|
308
|
+
active = self._open or self.focused
|
|
309
|
+
box = Rect(self.rect.x, self.rect.y, self.rect.width, self.BOX_HEIGHT)
|
|
310
|
+
f_t = self._float_anim.current
|
|
311
|
+
|
|
312
|
+
if self.disabled:
|
|
313
|
+
outline_color = c.on_surface.with_alpha(0.12)
|
|
314
|
+
label_color = c.on_surface.with_alpha(0.38)
|
|
315
|
+
text_color = c.on_surface.with_alpha(0.38)
|
|
316
|
+
icon_color = c.on_surface.with_alpha(0.38)
|
|
317
|
+
elif is_error:
|
|
318
|
+
outline_color = c.error
|
|
319
|
+
label_color = c.error
|
|
320
|
+
text_color = c.on_surface
|
|
321
|
+
icon_color = c.error
|
|
322
|
+
elif active:
|
|
323
|
+
outline_color = c.primary
|
|
324
|
+
label_color = c.primary
|
|
325
|
+
text_color = c.on_surface
|
|
326
|
+
icon_color = c.primary
|
|
327
|
+
else:
|
|
328
|
+
outline_color = c.on_surface if self.hovered else c.outline
|
|
329
|
+
label_color = c.on_surface_variant
|
|
330
|
+
text_color = c.on_surface
|
|
331
|
+
icon_color = c.on_surface_variant
|
|
332
|
+
|
|
333
|
+
if not self.disabled and not is_error and not active and self._border_color_override is not None:
|
|
334
|
+
outline_color = resolve_color(self._border_color_override, theme, outline_color) or outline_color
|
|
335
|
+
if not self.disabled and self._fg_override is not None:
|
|
336
|
+
text_color = resolve_color(self._fg_override, theme, text_color) or text_color
|
|
337
|
+
border_w = self._border_width_override if self._border_width_override is not None else (2.0 if active else 1.0)
|
|
338
|
+
label_size = 16.0 - 4.0 * f_t
|
|
339
|
+
label_font = get_font(theme.font_family, label_size, 500 if active else 400)
|
|
340
|
+
label_w = measure_text(label_font, self.label)
|
|
341
|
+
|
|
342
|
+
if self.variant == "filled":
|
|
343
|
+
if self._elevation_override:
|
|
344
|
+
sh = resolve_color(self._shadow_color_override, theme, c.shadow)
|
|
345
|
+
assert sh is not None
|
|
346
|
+
draw_elevation_shadow(canvas, box, 4.0, self._elevation_override, sh)
|
|
347
|
+
rrect = skia.RRect()
|
|
348
|
+
rrect.setRectRadii(
|
|
349
|
+
skia.Rect.MakeXYWH(box.x, box.y, box.width, box.height),
|
|
350
|
+
[(4.0, 4.0), (4.0, 4.0), (0.0, 0.0), (0.0, 0.0)],
|
|
351
|
+
)
|
|
352
|
+
bg = resolve_color(self._bg_override, theme, c.surface_container_highest) or c.surface_container_highest
|
|
353
|
+
canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bg.to_skia()))
|
|
354
|
+
canvas.drawLine(
|
|
355
|
+
box.x,
|
|
356
|
+
box.bottom - border_w * 0.5,
|
|
357
|
+
box.right,
|
|
358
|
+
box.bottom - border_w * 0.5,
|
|
359
|
+
skia.Paint(AntiAlias=True, Color=outline_color.to_skia(), StrokeWidth=border_w),
|
|
360
|
+
)
|
|
361
|
+
label_cy = box.center_y * (1.0 - f_t) + (box.y + 15.0) * f_t
|
|
362
|
+
text_cy = box.y + 37.0
|
|
363
|
+
else:
|
|
364
|
+
rad_spec = self._shape_override if self._shape_override is not None else "extra_small"
|
|
365
|
+
rad_num = rad_spec[0] if isinstance(rad_spec, tuple) else theme.shape.resolve(rad_spec)
|
|
366
|
+
if self._elevation_override:
|
|
367
|
+
sh = resolve_color(self._shadow_color_override, theme, c.shadow)
|
|
368
|
+
assert sh is not None
|
|
369
|
+
draw_elevation_shadow(canvas, box, rad_num, self._elevation_override, sh)
|
|
370
|
+
rrect = make_rrect_spec(box, rad_spec, theme)
|
|
371
|
+
if self._bg_override is not None:
|
|
372
|
+
bg = resolve_color(self._bg_override, theme)
|
|
373
|
+
if bg is not None:
|
|
374
|
+
canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bg.to_skia()))
|
|
375
|
+
canvas.save()
|
|
376
|
+
if f_t > 0.05 and self.label:
|
|
377
|
+
notch_left = box.x + 12.0
|
|
378
|
+
notch_right = notch_left + label_w + 8.0
|
|
379
|
+
canvas.clipRect(
|
|
380
|
+
skia.Rect.MakeXYWH(notch_left, box.y - 4.0, notch_right - notch_left, 10.0),
|
|
381
|
+
skia.ClipOp.kDifference,
|
|
382
|
+
)
|
|
383
|
+
canvas.drawRRect(
|
|
384
|
+
rrect,
|
|
385
|
+
skia.Paint(
|
|
386
|
+
AntiAlias=True,
|
|
387
|
+
Color=outline_color.to_skia(),
|
|
388
|
+
Style=skia.Paint.kStroke_Style,
|
|
389
|
+
StrokeWidth=border_w,
|
|
390
|
+
),
|
|
391
|
+
)
|
|
392
|
+
canvas.restore()
|
|
393
|
+
label_cy = box.center_y * (1.0 - f_t) + box.y * f_t
|
|
394
|
+
text_cy = box.center_y
|
|
395
|
+
|
|
396
|
+
draw_icon(canvas, "calendar", box.right - 24.0, box.center_y, 18.0, icon_color)
|
|
397
|
+
if self.label:
|
|
398
|
+
draw_text_centered_y(canvas, self.label, box.x + 16.0, label_cy, label_font, label_color)
|
|
399
|
+
|
|
400
|
+
if self._value is not None:
|
|
401
|
+
body_font = font_for_style(theme.font_family, theme.typography.body_large)
|
|
402
|
+
draw_text_centered_y(canvas, self._value.strftime("%d/%m/%Y"), box.x + 16.0, text_cy, body_font, text_color)
|
|
403
|
+
|
|
404
|
+
if self._has_footer():
|
|
405
|
+
footer_font = font_for_style(theme.font_family, theme.typography.body_small)
|
|
406
|
+
msg = self._error_text if is_error else (self.supporting_text or "")
|
|
407
|
+
draw_text_centered_y(canvas, msg, box.x + 16.0, box.bottom + 12.0, footer_font, c.error if is_error else c.on_surface_variant)
|