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,490 @@
|
|
|
1
|
+
"""Material Design 3 TextField (`outlined` and `filled` variants)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
from typing import Callable, Literal
|
|
7
|
+
|
|
8
|
+
import glfw
|
|
9
|
+
import skia
|
|
10
|
+
|
|
11
|
+
from ..core.animation import AnimatedValue
|
|
12
|
+
from ..core.draw import (
|
|
13
|
+
draw_icon,
|
|
14
|
+
draw_text_centered_y,
|
|
15
|
+
font_for_style,
|
|
16
|
+
get_font,
|
|
17
|
+
make_rrect,
|
|
18
|
+
measure_text,
|
|
19
|
+
resolve_color,
|
|
20
|
+
)
|
|
21
|
+
from ..core.events import CharEvent, KeyEvent, MouseEvent
|
|
22
|
+
from ..core.geometry import Constraints, Rect, Size
|
|
23
|
+
from ..core.state import State
|
|
24
|
+
from ..core.widget import Widget
|
|
25
|
+
from ..theme import Theme
|
|
26
|
+
|
|
27
|
+
TextFieldVariant = Literal["outlined", "filled"]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class TextField(Widget):
|
|
31
|
+
"""Official Material Design 3 TextField (`outlined` or `filled`).
|
|
32
|
+
|
|
33
|
+
Features:
|
|
34
|
+
- Animated floating label (with notched outline cut for `outlined`)
|
|
35
|
+
- Leading/trailing icons, prefix/suffix, password masking
|
|
36
|
+
- Supporting text, error state (`error_text`), and `max_length` counter
|
|
37
|
+
- Exact click-to-position caret, mouse drag selection, Shift+Arrow selection
|
|
38
|
+
- Clipboard shortcuts (Ctrl+C/V/X/A) and optional two-way binding (`bind`)
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
interactive = True
|
|
42
|
+
focusable = True
|
|
43
|
+
manages_own_box = True
|
|
44
|
+
cursor = "ibeam"
|
|
45
|
+
|
|
46
|
+
BOX_HEIGHT = 56.0
|
|
47
|
+
SUPPORTING_HEIGHT = 20.0
|
|
48
|
+
|
|
49
|
+
def __init__(
|
|
50
|
+
self,
|
|
51
|
+
label: str,
|
|
52
|
+
*,
|
|
53
|
+
variant: TextFieldVariant = "outlined",
|
|
54
|
+
value: str = "",
|
|
55
|
+
placeholder: str = "",
|
|
56
|
+
supporting_text: str | None = None,
|
|
57
|
+
error_text: str | None = None,
|
|
58
|
+
leading_icon: str | None = None,
|
|
59
|
+
trailing_icon: str | None = None,
|
|
60
|
+
prefix: str | None = None,
|
|
61
|
+
suffix: str | None = None,
|
|
62
|
+
password: bool = False,
|
|
63
|
+
max_length: int | None = None,
|
|
64
|
+
disabled: bool = False,
|
|
65
|
+
bind: State[str] | None = None,
|
|
66
|
+
on_change: Callable[[str], None] | None = None,
|
|
67
|
+
on_submit: Callable[[str], None] | None = None,
|
|
68
|
+
) -> None:
|
|
69
|
+
super().__init__()
|
|
70
|
+
self.label = label
|
|
71
|
+
self.variant: TextFieldVariant = variant
|
|
72
|
+
self._bind = bind
|
|
73
|
+
initial = str(bind.value) if bind is not None else str(value)
|
|
74
|
+
self._value = initial
|
|
75
|
+
self.placeholder = placeholder
|
|
76
|
+
self._supporting_text = supporting_text
|
|
77
|
+
self._error_text = error_text
|
|
78
|
+
self.leading_icon = leading_icon
|
|
79
|
+
self.trailing_icon = trailing_icon
|
|
80
|
+
self.prefix = prefix
|
|
81
|
+
self.suffix = suffix
|
|
82
|
+
self.password = password
|
|
83
|
+
self.max_length = max_length
|
|
84
|
+
self.disabled = disabled
|
|
85
|
+
self.on_change = on_change
|
|
86
|
+
self.on_submit = on_submit
|
|
87
|
+
|
|
88
|
+
self._cursor: int = len(self._value)
|
|
89
|
+
self._sel_anchor: int | None = None
|
|
90
|
+
self._blink_start: float = time.perf_counter()
|
|
91
|
+
self._float_anim = AnimatedValue(1.0 if self._should_float() else 0.0, duration=0.16)
|
|
92
|
+
self._last_text_origin_x: float = 0.0
|
|
93
|
+
self._last_font: skia.Font | None = None
|
|
94
|
+
|
|
95
|
+
if bind is not None:
|
|
96
|
+
bind.subscribe(self._on_bound_change)
|
|
97
|
+
|
|
98
|
+
def _should_float(self) -> bool:
|
|
99
|
+
return bool(self.focused or self._value or self.placeholder)
|
|
100
|
+
|
|
101
|
+
def _on_bound_change(self, new_val: str) -> None:
|
|
102
|
+
s = str(new_val)
|
|
103
|
+
if s != self._value:
|
|
104
|
+
self._value = s
|
|
105
|
+
self._cursor = min(self._cursor, len(self._value))
|
|
106
|
+
self._sel_anchor = None
|
|
107
|
+
self._float_anim.animate_to(1.0 if self._should_float() else 0.0)
|
|
108
|
+
self.invalidate()
|
|
109
|
+
|
|
110
|
+
@property
|
|
111
|
+
def value(self) -> str:
|
|
112
|
+
return self._value
|
|
113
|
+
|
|
114
|
+
@value.setter
|
|
115
|
+
def value(self, val: str) -> None:
|
|
116
|
+
s = str(val)
|
|
117
|
+
if self.max_length is not None:
|
|
118
|
+
s = s[: self.max_length]
|
|
119
|
+
if s != self._value:
|
|
120
|
+
self._value = s
|
|
121
|
+
self._cursor = min(self._cursor, len(self._value))
|
|
122
|
+
self._sel_anchor = None
|
|
123
|
+
self._float_anim.animate_to(1.0 if self._should_float() else 0.0)
|
|
124
|
+
if self._bind is not None and self._bind.value != s:
|
|
125
|
+
self._bind.value = s
|
|
126
|
+
self.invalidate()
|
|
127
|
+
|
|
128
|
+
@property
|
|
129
|
+
def error_text(self) -> str | None:
|
|
130
|
+
return self._error_text
|
|
131
|
+
|
|
132
|
+
@error_text.setter
|
|
133
|
+
def error_text(self, val: str | None) -> None:
|
|
134
|
+
self._error_text = val
|
|
135
|
+
self.invalidate()
|
|
136
|
+
|
|
137
|
+
@property
|
|
138
|
+
def supporting_text(self) -> str | None:
|
|
139
|
+
return self._supporting_text
|
|
140
|
+
|
|
141
|
+
@supporting_text.setter
|
|
142
|
+
def supporting_text(self, val: str | None) -> None:
|
|
143
|
+
self._supporting_text = val
|
|
144
|
+
self.invalidate()
|
|
145
|
+
|
|
146
|
+
def _selection_range(self) -> tuple[int, int] | None:
|
|
147
|
+
if self._sel_anchor is None or self._sel_anchor == self._cursor:
|
|
148
|
+
return None
|
|
149
|
+
return (min(self._sel_anchor, self._cursor), max(self._sel_anchor, self._cursor))
|
|
150
|
+
|
|
151
|
+
def _display_text(self) -> str:
|
|
152
|
+
return ("•" * len(self._value)) if self.password else self._value
|
|
153
|
+
|
|
154
|
+
def _has_footer(self) -> bool:
|
|
155
|
+
return bool(self._error_text or self._supporting_text or self.max_length is not None)
|
|
156
|
+
|
|
157
|
+
def _index_for_x(self, px: float) -> int:
|
|
158
|
+
disp = self._display_text()
|
|
159
|
+
if not disp or self._last_font is None:
|
|
160
|
+
return len(disp)
|
|
161
|
+
rel_x = px - self._last_text_origin_x
|
|
162
|
+
if rel_x <= 0.0:
|
|
163
|
+
return 0
|
|
164
|
+
best_idx = len(disp)
|
|
165
|
+
best_dist = float("inf")
|
|
166
|
+
for i in range(len(disp) + 1):
|
|
167
|
+
w = measure_text(self._last_font, disp[:i])
|
|
168
|
+
d = abs(rel_x - w)
|
|
169
|
+
if d < best_dist:
|
|
170
|
+
best_dist = d
|
|
171
|
+
best_idx = i
|
|
172
|
+
return best_idx
|
|
173
|
+
|
|
174
|
+
def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
|
|
175
|
+
h = self.BOX_HEIGHT + (self.SUPPORTING_HEIGHT if self._has_footer() else 0.0)
|
|
176
|
+
w = 280.0 if constraints.max_width == float("inf") else min(280.0, constraints.max_width)
|
|
177
|
+
return Size(w, h)
|
|
178
|
+
|
|
179
|
+
def tick(self, now: float) -> bool:
|
|
180
|
+
anim = self._float_anim.update(now)
|
|
181
|
+
return anim or self.focused
|
|
182
|
+
|
|
183
|
+
def on_focus(self) -> None:
|
|
184
|
+
super().on_focus()
|
|
185
|
+
self._blink_start = time.perf_counter()
|
|
186
|
+
self._float_anim.animate_to(1.0)
|
|
187
|
+
|
|
188
|
+
def on_blur(self) -> None:
|
|
189
|
+
super().on_blur()
|
|
190
|
+
self._sel_anchor = None
|
|
191
|
+
self._float_anim.animate_to(1.0 if self._should_float() else 0.0)
|
|
192
|
+
|
|
193
|
+
def on_mouse_down(self, event: MouseEvent) -> None:
|
|
194
|
+
if self.disabled:
|
|
195
|
+
return
|
|
196
|
+
super().on_mouse_down(event)
|
|
197
|
+
idx = self._index_for_x(event.x)
|
|
198
|
+
if event.mods & glfw.MOD_SHIFT:
|
|
199
|
+
if self._sel_anchor is None:
|
|
200
|
+
self._sel_anchor = self._cursor
|
|
201
|
+
self._cursor = idx
|
|
202
|
+
else:
|
|
203
|
+
self._cursor = idx
|
|
204
|
+
self._sel_anchor = idx
|
|
205
|
+
self._blink_start = time.perf_counter()
|
|
206
|
+
|
|
207
|
+
def on_mouse_move(self, event: MouseEvent) -> None:
|
|
208
|
+
if self.disabled or not self.pressed:
|
|
209
|
+
return
|
|
210
|
+
idx = self._index_for_x(event.x)
|
|
211
|
+
if idx != self._cursor:
|
|
212
|
+
self._cursor = idx
|
|
213
|
+
self._blink_start = time.perf_counter()
|
|
214
|
+
self.invalidate()
|
|
215
|
+
|
|
216
|
+
def on_mouse_up(self, event: MouseEvent) -> None:
|
|
217
|
+
super().on_mouse_up(event)
|
|
218
|
+
if self._sel_anchor == self._cursor:
|
|
219
|
+
self._sel_anchor = None
|
|
220
|
+
|
|
221
|
+
def _commit_text(self, new_text: str, new_cursor: int) -> None:
|
|
222
|
+
if self.max_length is not None:
|
|
223
|
+
new_text = new_text[: self.max_length]
|
|
224
|
+
self._value = new_text
|
|
225
|
+
self._cursor = max(0, min(new_cursor, len(self._value)))
|
|
226
|
+
self._sel_anchor = None
|
|
227
|
+
self._blink_start = time.perf_counter()
|
|
228
|
+
self._float_anim.animate_to(1.0 if self._should_float() else 0.0)
|
|
229
|
+
if self._bind is not None and self._bind.value != self._value:
|
|
230
|
+
self._bind.value = self._value
|
|
231
|
+
if self.on_change is not None:
|
|
232
|
+
self.on_change(self._value)
|
|
233
|
+
self.invalidate()
|
|
234
|
+
|
|
235
|
+
def _insert_text(self, text: str) -> None:
|
|
236
|
+
sel = self._selection_range()
|
|
237
|
+
if sel is not None:
|
|
238
|
+
a, b = sel
|
|
239
|
+
self._commit_text(self._value[:a] + text + self._value[b:], a + len(text))
|
|
240
|
+
else:
|
|
241
|
+
self._commit_text(
|
|
242
|
+
self._value[: self._cursor] + text + self._value[self._cursor :],
|
|
243
|
+
self._cursor + len(text),
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
def on_char(self, event: CharEvent) -> None:
|
|
247
|
+
if self.disabled or not self.focused:
|
|
248
|
+
return
|
|
249
|
+
self._insert_text(event.char)
|
|
250
|
+
|
|
251
|
+
def _move_cursor(self, new_pos: int, extend_selection: bool) -> None:
|
|
252
|
+
new_pos = max(0, min(len(self._value), new_pos))
|
|
253
|
+
if extend_selection:
|
|
254
|
+
if self._sel_anchor is None:
|
|
255
|
+
self._sel_anchor = self._cursor
|
|
256
|
+
else:
|
|
257
|
+
self._sel_anchor = None
|
|
258
|
+
self._cursor = new_pos
|
|
259
|
+
self._blink_start = time.perf_counter()
|
|
260
|
+
|
|
261
|
+
def on_key(self, event: KeyEvent) -> None:
|
|
262
|
+
if self.disabled or not self.focused or event.action == glfw.RELEASE:
|
|
263
|
+
return
|
|
264
|
+
ctrl = bool(event.mods & glfw.MOD_CONTROL)
|
|
265
|
+
shift = bool(event.mods & glfw.MOD_SHIFT)
|
|
266
|
+
|
|
267
|
+
if ctrl and event.key == glfw.KEY_A:
|
|
268
|
+
self._sel_anchor = 0
|
|
269
|
+
self._cursor = len(self._value)
|
|
270
|
+
self.invalidate()
|
|
271
|
+
return
|
|
272
|
+
if ctrl and event.key == glfw.KEY_C:
|
|
273
|
+
if self.window and not self.password:
|
|
274
|
+
sel = self._selection_range()
|
|
275
|
+
txt = self._value[sel[0] : sel[1]] if sel is not None else self._value
|
|
276
|
+
self.window.set_clipboard(txt)
|
|
277
|
+
return
|
|
278
|
+
if ctrl and event.key == glfw.KEY_X:
|
|
279
|
+
if self.window and not self.password:
|
|
280
|
+
sel = self._selection_range()
|
|
281
|
+
if sel is not None:
|
|
282
|
+
self.window.set_clipboard(self._value[sel[0] : sel[1]])
|
|
283
|
+
self._commit_text(self._value[: sel[0]] + self._value[sel[1] :], sel[0])
|
|
284
|
+
else:
|
|
285
|
+
self.window.set_clipboard(self._value)
|
|
286
|
+
self._commit_text("", 0)
|
|
287
|
+
return
|
|
288
|
+
if ctrl and event.key == glfw.KEY_V:
|
|
289
|
+
if self.window:
|
|
290
|
+
clip = self.window.get_clipboard().replace("\r", "").replace("\n", " ")
|
|
291
|
+
if clip:
|
|
292
|
+
self._insert_text(clip)
|
|
293
|
+
return
|
|
294
|
+
|
|
295
|
+
if event.key == glfw.KEY_BACKSPACE:
|
|
296
|
+
sel = self._selection_range()
|
|
297
|
+
if sel is not None:
|
|
298
|
+
self._commit_text(self._value[: sel[0]] + self._value[sel[1] :], sel[0])
|
|
299
|
+
elif self._cursor > 0:
|
|
300
|
+
self._commit_text(
|
|
301
|
+
self._value[: self._cursor - 1] + self._value[self._cursor :],
|
|
302
|
+
self._cursor - 1,
|
|
303
|
+
)
|
|
304
|
+
elif event.key == glfw.KEY_DELETE:
|
|
305
|
+
sel = self._selection_range()
|
|
306
|
+
if sel is not None:
|
|
307
|
+
self._commit_text(self._value[: sel[0]] + self._value[sel[1] :], sel[0])
|
|
308
|
+
elif self._cursor < len(self._value):
|
|
309
|
+
self._commit_text(
|
|
310
|
+
self._value[: self._cursor] + self._value[self._cursor + 1 :],
|
|
311
|
+
self._cursor,
|
|
312
|
+
)
|
|
313
|
+
elif event.key == glfw.KEY_LEFT:
|
|
314
|
+
self._move_cursor(self._cursor - 1, shift)
|
|
315
|
+
elif event.key == glfw.KEY_RIGHT:
|
|
316
|
+
self._move_cursor(self._cursor + 1, shift)
|
|
317
|
+
elif event.key == glfw.KEY_HOME:
|
|
318
|
+
self._move_cursor(0, shift)
|
|
319
|
+
elif event.key == glfw.KEY_END:
|
|
320
|
+
self._move_cursor(len(self._value), shift)
|
|
321
|
+
elif event.key in (glfw.KEY_ENTER, glfw.KEY_KP_ENTER):
|
|
322
|
+
if self.on_submit is not None:
|
|
323
|
+
self.on_submit(self._value)
|
|
324
|
+
|
|
325
|
+
def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
|
|
326
|
+
c = theme.colors
|
|
327
|
+
is_error = bool(self._error_text)
|
|
328
|
+
box = Rect(self.rect.x, self.rect.y, self.rect.width, self.BOX_HEIGHT)
|
|
329
|
+
f_t = self._float_anim.current
|
|
330
|
+
|
|
331
|
+
if self.disabled:
|
|
332
|
+
outline_color = c.on_surface.with_alpha(0.12)
|
|
333
|
+
label_color = c.on_surface.with_alpha(0.38)
|
|
334
|
+
text_color = c.on_surface.with_alpha(0.38)
|
|
335
|
+
icon_color = c.on_surface.with_alpha(0.38)
|
|
336
|
+
elif is_error:
|
|
337
|
+
outline_color = c.error
|
|
338
|
+
label_color = c.error
|
|
339
|
+
text_color = c.on_surface
|
|
340
|
+
icon_color = c.error
|
|
341
|
+
elif self.focused:
|
|
342
|
+
outline_color = c.primary
|
|
343
|
+
label_color = c.primary
|
|
344
|
+
text_color = c.on_surface
|
|
345
|
+
icon_color = c.on_surface_variant
|
|
346
|
+
else:
|
|
347
|
+
outline_color = c.on_surface if self.hovered else c.outline
|
|
348
|
+
label_color = c.on_surface_variant
|
|
349
|
+
text_color = c.on_surface
|
|
350
|
+
icon_color = c.on_surface_variant
|
|
351
|
+
|
|
352
|
+
pad_left = 48.0 if self.leading_icon else 16.0
|
|
353
|
+
pad_right = 48.0 if self.trailing_icon else 16.0
|
|
354
|
+
if not self.disabled and not is_error and not self.focused and self._border_color_override is not None:
|
|
355
|
+
outline_color = resolve_color(self._border_color_override, theme, outline_color) or outline_color
|
|
356
|
+
if not self.disabled and self._fg_override is not None:
|
|
357
|
+
text_color = resolve_color(self._fg_override, theme, text_color) or text_color
|
|
358
|
+
border_w = self._border_width_override if self._border_width_override is not None else (2.0 if self.focused else 1.0)
|
|
359
|
+
|
|
360
|
+
label_size = 16.0 - 4.0 * f_t
|
|
361
|
+
label_font = get_font(theme.font_family, label_size, 500 if self.focused else 400)
|
|
362
|
+
label_w = measure_text(label_font, self.label)
|
|
363
|
+
|
|
364
|
+
if self.variant == "filled":
|
|
365
|
+
rrect = skia.RRect()
|
|
366
|
+
rrect.setRectRadii(
|
|
367
|
+
skia.Rect.MakeXYWH(box.x, box.y, box.width, box.height),
|
|
368
|
+
[(4.0, 4.0), (4.0, 4.0), (0.0, 0.0), (0.0, 0.0)],
|
|
369
|
+
)
|
|
370
|
+
bg = resolve_color(self._bg_override, theme, c.surface_container_highest) or c.surface_container_highest
|
|
371
|
+
if self.hovered and not self.disabled:
|
|
372
|
+
bg = bg.blend(c.on_surface, theme.state_layers.hover)
|
|
373
|
+
canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bg.to_skia()))
|
|
374
|
+
|
|
375
|
+
canvas.drawLine(
|
|
376
|
+
box.x,
|
|
377
|
+
box.bottom - border_w * 0.5,
|
|
378
|
+
box.right,
|
|
379
|
+
box.bottom - border_w * 0.5,
|
|
380
|
+
skia.Paint(AntiAlias=True, Color=outline_color.to_skia(), StrokeWidth=border_w),
|
|
381
|
+
)
|
|
382
|
+
label_x = box.x + pad_left
|
|
383
|
+
label_cy = box.center_y * (1.0 - f_t) + (box.y + 15.0) * f_t
|
|
384
|
+
text_cy = box.y + 37.0
|
|
385
|
+
else:
|
|
386
|
+
radius = self._shape_override[0] if isinstance(self._shape_override, tuple) else theme.shape.resolve(self._shape_override or "extra_small")
|
|
387
|
+
rrect = make_rrect(box, radius)
|
|
388
|
+
if self._bg_override is not None:
|
|
389
|
+
bg = resolve_color(self._bg_override, theme)
|
|
390
|
+
if bg is not None:
|
|
391
|
+
canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bg.to_skia()))
|
|
392
|
+
canvas.save()
|
|
393
|
+
if f_t > 0.05 and self.label:
|
|
394
|
+
notch_left = box.x + 12.0
|
|
395
|
+
notch_right = notch_left + label_w + 8.0
|
|
396
|
+
canvas.clipRect(
|
|
397
|
+
skia.Rect.MakeXYWH(notch_left, box.y - 4.0, notch_right - notch_left, 10.0),
|
|
398
|
+
skia.ClipOp.kDifference,
|
|
399
|
+
)
|
|
400
|
+
canvas.drawRRect(
|
|
401
|
+
rrect,
|
|
402
|
+
skia.Paint(
|
|
403
|
+
AntiAlias=True,
|
|
404
|
+
Color=outline_color.to_skia(),
|
|
405
|
+
Style=skia.Paint.kStroke_Style,
|
|
406
|
+
StrokeWidth=border_w,
|
|
407
|
+
),
|
|
408
|
+
)
|
|
409
|
+
canvas.restore()
|
|
410
|
+
|
|
411
|
+
label_x = (box.x + pad_left) * (1.0 - f_t) + (box.x + 16.0) * f_t
|
|
412
|
+
label_cy = box.center_y * (1.0 - f_t) + box.y * f_t
|
|
413
|
+
text_cy = box.center_y
|
|
414
|
+
|
|
415
|
+
if self.leading_icon:
|
|
416
|
+
draw_icon(canvas, self.leading_icon, box.x + 24.0, box.center_y, 20.0, icon_color)
|
|
417
|
+
if self.trailing_icon:
|
|
418
|
+
draw_icon(canvas, self.trailing_icon, box.right - 24.0, box.center_y, 20.0, icon_color)
|
|
419
|
+
|
|
420
|
+
if self.label:
|
|
421
|
+
draw_text_centered_y(canvas, self.label, label_x, label_cy, label_font, label_color)
|
|
422
|
+
|
|
423
|
+
body_font = font_for_style(theme.font_family, theme.typography.body_large)
|
|
424
|
+
disp = self._display_text()
|
|
425
|
+
text_x = box.x + pad_left
|
|
426
|
+
clip_w = max(0.0, box.width - pad_left - pad_right)
|
|
427
|
+
|
|
428
|
+
canvas.save()
|
|
429
|
+
canvas.clipRect(skia.Rect.MakeXYWH(text_x, box.y + 4.0, clip_w, box.height - 8.0))
|
|
430
|
+
|
|
431
|
+
if self.prefix and (self._value or self.focused):
|
|
432
|
+
draw_text_centered_y(canvas, self.prefix, text_x, text_cy, body_font, c.on_surface_variant)
|
|
433
|
+
text_x += measure_text(body_font, self.prefix) + 4.0
|
|
434
|
+
|
|
435
|
+
self._last_text_origin_x = text_x
|
|
436
|
+
self._last_font = body_font
|
|
437
|
+
|
|
438
|
+
if disp:
|
|
439
|
+
sel = self._selection_range()
|
|
440
|
+
if sel is not None and self.focused:
|
|
441
|
+
sx1 = text_x + measure_text(body_font, disp[: sel[0]])
|
|
442
|
+
sx2 = text_x + measure_text(body_font, disp[: sel[1]])
|
|
443
|
+
canvas.drawRect(
|
|
444
|
+
skia.Rect.MakeXYWH(sx1, text_cy - 10.0, max(2.0, sx2 - sx1), 20.0),
|
|
445
|
+
skia.Paint(AntiAlias=True, Color=c.primary_container.to_skia()),
|
|
446
|
+
)
|
|
447
|
+
draw_text_centered_y(canvas, disp, text_x, text_cy, body_font, text_color)
|
|
448
|
+
elif self.placeholder and (self.focused or f_t > 0.8):
|
|
449
|
+
draw_text_centered_y(
|
|
450
|
+
canvas,
|
|
451
|
+
self.placeholder,
|
|
452
|
+
text_x,
|
|
453
|
+
text_cy,
|
|
454
|
+
body_font,
|
|
455
|
+
c.on_surface_variant.with_alpha(0.65),
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
if self.focused and not self.disabled:
|
|
459
|
+
blink_on = int((now - self._blink_start) / 0.53) % 2 == 0
|
|
460
|
+
if blink_on:
|
|
461
|
+
caret_x = text_x + measure_text(body_font, disp[: self._cursor])
|
|
462
|
+
caret_color = c.error if is_error else c.primary
|
|
463
|
+
canvas.drawLine(
|
|
464
|
+
caret_x,
|
|
465
|
+
text_cy - 10.0,
|
|
466
|
+
caret_x,
|
|
467
|
+
text_cy + 10.0,
|
|
468
|
+
skia.Paint(AntiAlias=True, Color=caret_color.to_skia(), StrokeWidth=1.8),
|
|
469
|
+
)
|
|
470
|
+
|
|
471
|
+
canvas.restore()
|
|
472
|
+
|
|
473
|
+
if self._has_footer():
|
|
474
|
+
footer_font = font_for_style(theme.font_family, theme.typography.body_small)
|
|
475
|
+
footer_cy = box.bottom + 12.0
|
|
476
|
+
msg = self._error_text if is_error else (self._supporting_text or "")
|
|
477
|
+
msg_color = c.error if is_error else c.on_surface_variant
|
|
478
|
+
if msg:
|
|
479
|
+
draw_text_centered_y(canvas, msg, box.x + 16.0, footer_cy, footer_font, msg_color)
|
|
480
|
+
if self.max_length is not None:
|
|
481
|
+
counter = f"{len(self._value)}/{self.max_length}"
|
|
482
|
+
cw = measure_text(footer_font, counter)
|
|
483
|
+
draw_text_centered_y(
|
|
484
|
+
canvas,
|
|
485
|
+
counter,
|
|
486
|
+
box.right - 16.0 - cw,
|
|
487
|
+
footer_cy,
|
|
488
|
+
footer_font,
|
|
489
|
+
msg_color,
|
|
490
|
+
)
|