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,199 @@
|
|
|
1
|
+
"""Material Design 3 Checkbox with optional tristate (`False` / `True` / `None`)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Callable
|
|
6
|
+
|
|
7
|
+
import glfw
|
|
8
|
+
import skia
|
|
9
|
+
|
|
10
|
+
from ..core.animation import AnimatedValue
|
|
11
|
+
from ..core.draw import draw_icon, draw_text_centered_y, font_for_style, make_rrect, measure_text, resolve_color
|
|
12
|
+
from ..core.events import KeyEvent, MouseEvent
|
|
13
|
+
from ..core.geometry import Constraints, Rect, Size
|
|
14
|
+
from ..core.state import State
|
|
15
|
+
from ..core.widget import Widget
|
|
16
|
+
from ..theme import Theme
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Checkbox(Widget):
|
|
20
|
+
"""Official Material Design 3 Checkbox (18x18dp box, 40dp touch target halo)."""
|
|
21
|
+
|
|
22
|
+
interactive = True
|
|
23
|
+
focusable = True
|
|
24
|
+
cursor = "pointer"
|
|
25
|
+
|
|
26
|
+
BOX_SIZE = 18.0
|
|
27
|
+
TARGET_SIZE = 32.0
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
*,
|
|
32
|
+
value: bool | None = False,
|
|
33
|
+
label: str | None = None,
|
|
34
|
+
tristate: bool = False,
|
|
35
|
+
error: bool = False,
|
|
36
|
+
disabled: bool = False,
|
|
37
|
+
bind: State[bool | None] | None = None,
|
|
38
|
+
on_change: Callable[[bool | None], None] | None = None,
|
|
39
|
+
) -> None:
|
|
40
|
+
super().__init__()
|
|
41
|
+
self._bind = bind
|
|
42
|
+
initial = bind.value if bind is not None else value
|
|
43
|
+
self._value: bool | None = initial if tristate else bool(initial)
|
|
44
|
+
self.label = label
|
|
45
|
+
self.tristate = tristate
|
|
46
|
+
self._error = error
|
|
47
|
+
self.disabled = disabled
|
|
48
|
+
self.on_change = on_change
|
|
49
|
+
|
|
50
|
+
self._fill_anim = AnimatedValue(1.0 if self._is_filled() else 0.0, duration=0.14)
|
|
51
|
+
|
|
52
|
+
if bind is not None:
|
|
53
|
+
bind.subscribe(self._on_bound_change)
|
|
54
|
+
|
|
55
|
+
def _is_filled(self) -> bool:
|
|
56
|
+
return self._value is True or self._value is None
|
|
57
|
+
|
|
58
|
+
def _on_bound_change(self, new_val: bool | None) -> None:
|
|
59
|
+
v = new_val if self.tristate else bool(new_val)
|
|
60
|
+
if v != self._value:
|
|
61
|
+
self._value = v
|
|
62
|
+
self._fill_anim.animate_to(1.0 if self._is_filled() else 0.0)
|
|
63
|
+
self.invalidate()
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def value(self) -> bool | None:
|
|
67
|
+
return self._value
|
|
68
|
+
|
|
69
|
+
@value.setter
|
|
70
|
+
def value(self, val: bool | None) -> None:
|
|
71
|
+
v = val if self.tristate else bool(val)
|
|
72
|
+
if v != self._value:
|
|
73
|
+
self._value = v
|
|
74
|
+
self._fill_anim.animate_to(1.0 if self._is_filled() else 0.0)
|
|
75
|
+
if self._bind is not None and self._bind.value != v:
|
|
76
|
+
self._bind.value = v
|
|
77
|
+
self.invalidate()
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def error(self) -> bool:
|
|
81
|
+
return self._error
|
|
82
|
+
|
|
83
|
+
@error.setter
|
|
84
|
+
def error(self, val: bool) -> None:
|
|
85
|
+
self._error = bool(val)
|
|
86
|
+
self.invalidate()
|
|
87
|
+
|
|
88
|
+
def toggle(self) -> None:
|
|
89
|
+
if self.disabled:
|
|
90
|
+
return
|
|
91
|
+
if self.tristate:
|
|
92
|
+
if self._value is False:
|
|
93
|
+
nxt: bool | None = True
|
|
94
|
+
elif self._value is True:
|
|
95
|
+
nxt = None
|
|
96
|
+
else:
|
|
97
|
+
nxt = False
|
|
98
|
+
else:
|
|
99
|
+
nxt = not bool(self._value)
|
|
100
|
+
self.value = nxt
|
|
101
|
+
if self.on_change is not None:
|
|
102
|
+
self.on_change(self._value)
|
|
103
|
+
|
|
104
|
+
def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
|
|
105
|
+
w = self.TARGET_SIZE
|
|
106
|
+
h = self.TARGET_SIZE
|
|
107
|
+
if self.label:
|
|
108
|
+
font = font_for_style(theme.font_family, theme.typography.body_large)
|
|
109
|
+
w += 8.0 + measure_text(font, self.label)
|
|
110
|
+
h = max(h, theme.typography.body_large.line_height)
|
|
111
|
+
return Size(w, h)
|
|
112
|
+
|
|
113
|
+
def tick(self, now: float) -> bool:
|
|
114
|
+
return self._fill_anim.update(now)
|
|
115
|
+
|
|
116
|
+
def on_mouse_up(self, event: MouseEvent) -> None:
|
|
117
|
+
was_pressed = self.pressed
|
|
118
|
+
super().on_mouse_up(event)
|
|
119
|
+
if not self.disabled and was_pressed and self.rect.contains(event.x, event.y):
|
|
120
|
+
self.toggle()
|
|
121
|
+
|
|
122
|
+
def on_key(self, event: KeyEvent) -> None:
|
|
123
|
+
if not self.disabled and event.action == glfw.PRESS and event.key in (
|
|
124
|
+
glfw.KEY_SPACE,
|
|
125
|
+
glfw.KEY_ENTER,
|
|
126
|
+
glfw.KEY_KP_ENTER,
|
|
127
|
+
):
|
|
128
|
+
self.toggle()
|
|
129
|
+
|
|
130
|
+
def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
|
|
131
|
+
c = theme.colors
|
|
132
|
+
cx = self.rect.x + self.TARGET_SIZE * 0.5
|
|
133
|
+
cy = self.rect.center_y
|
|
134
|
+
t = self._fill_anim.current
|
|
135
|
+
|
|
136
|
+
active_color = c.error if self._error else (resolve_color(self._fg_override, theme, c.primary) or c.primary)
|
|
137
|
+
on_active = c.on_error if self._error else c.on_primary
|
|
138
|
+
|
|
139
|
+
# State layer halo (40dp diameter -> 20dp radius)
|
|
140
|
+
if not self.disabled and (self.hovered or self.pressed or self.focused):
|
|
141
|
+
sl = theme.state_layers
|
|
142
|
+
alpha = sl.pressed if self.pressed else (sl.hover if self.hovered else sl.focus)
|
|
143
|
+
halo = active_color if self._is_filled() else c.on_surface
|
|
144
|
+
canvas.drawCircle(
|
|
145
|
+
cx,
|
|
146
|
+
cy,
|
|
147
|
+
18.0,
|
|
148
|
+
skia.Paint(AntiAlias=True, Color=halo.with_alpha(alpha).to_skia()),
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
box = Rect(cx - self.BOX_SIZE * 0.5, cy - self.BOX_SIZE * 0.5, self.BOX_SIZE, self.BOX_SIZE)
|
|
152
|
+
rrect = make_rrect(box, 2.0)
|
|
153
|
+
|
|
154
|
+
if self.disabled:
|
|
155
|
+
if self._is_filled():
|
|
156
|
+
canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=c.on_surface.with_alpha(0.38).to_skia()))
|
|
157
|
+
draw_icon(canvas, "check" if self._value is True else "minus", cx, cy, 14.0, c.surface)
|
|
158
|
+
else:
|
|
159
|
+
canvas.drawRRect(
|
|
160
|
+
rrect,
|
|
161
|
+
skia.Paint(
|
|
162
|
+
AntiAlias=True,
|
|
163
|
+
Color=c.on_surface.with_alpha(0.38).to_skia(),
|
|
164
|
+
Style=skia.Paint.kStroke_Style,
|
|
165
|
+
StrokeWidth=2.0,
|
|
166
|
+
),
|
|
167
|
+
)
|
|
168
|
+
else:
|
|
169
|
+
if t > 0.01:
|
|
170
|
+
canvas.drawRRect(
|
|
171
|
+
rrect,
|
|
172
|
+
skia.Paint(AntiAlias=True, Color=active_color.with_alpha(t).to_skia()),
|
|
173
|
+
)
|
|
174
|
+
if t < 0.99:
|
|
175
|
+
border_color = c.error if self._error else c.on_surface_variant
|
|
176
|
+
canvas.drawRRect(
|
|
177
|
+
rrect,
|
|
178
|
+
skia.Paint(
|
|
179
|
+
AntiAlias=True,
|
|
180
|
+
Color=border_color.with_alpha(1.0 - t).to_skia(),
|
|
181
|
+
Style=skia.Paint.kStroke_Style,
|
|
182
|
+
StrokeWidth=2.0,
|
|
183
|
+
),
|
|
184
|
+
)
|
|
185
|
+
if t > 0.25:
|
|
186
|
+
icon_name = "check" if self._value is True else "minus"
|
|
187
|
+
draw_icon(canvas, icon_name, cx, cy, 14.0, on_active.with_alpha(t))
|
|
188
|
+
|
|
189
|
+
if self.label:
|
|
190
|
+
font = font_for_style(theme.font_family, theme.typography.body_large)
|
|
191
|
+
fg = c.on_surface.with_alpha(0.38) if self.disabled else c.on_surface
|
|
192
|
+
draw_text_centered_y(
|
|
193
|
+
canvas,
|
|
194
|
+
self.label,
|
|
195
|
+
self.rect.x + self.TARGET_SIZE + 8.0,
|
|
196
|
+
cy,
|
|
197
|
+
font,
|
|
198
|
+
fg,
|
|
199
|
+
)
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"""Material Design 3 Chip (`filter`, `assist`, `input`, `suggestion`)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Callable, Literal
|
|
6
|
+
|
|
7
|
+
import skia
|
|
8
|
+
|
|
9
|
+
from ..core.animation import RippleController
|
|
10
|
+
from ..core.draw import (
|
|
11
|
+
draw_elevation_shadow,
|
|
12
|
+
draw_icon,
|
|
13
|
+
draw_state_layer_and_ripple,
|
|
14
|
+
draw_text_centered_y,
|
|
15
|
+
font_for_style,
|
|
16
|
+
make_rrect,
|
|
17
|
+
measure_text,
|
|
18
|
+
resolve_color,
|
|
19
|
+
)
|
|
20
|
+
from ..core.events import MouseEvent
|
|
21
|
+
from ..core.geometry import Constraints, Rect, Size
|
|
22
|
+
from ..core.state import State
|
|
23
|
+
from ..core.widget import Widget
|
|
24
|
+
from ..theme import Color, Theme
|
|
25
|
+
|
|
26
|
+
ChipVariant = Literal["filter", "assist", "input", "suggestion"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Chip(Widget):
|
|
30
|
+
"""Official Material Design 3 Chip (32dp height, 8dp `small` corner radius)."""
|
|
31
|
+
|
|
32
|
+
interactive = True
|
|
33
|
+
focusable = True
|
|
34
|
+
manages_own_box = True
|
|
35
|
+
cursor = "pointer"
|
|
36
|
+
|
|
37
|
+
HEIGHT = 32.0
|
|
38
|
+
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
label: str,
|
|
42
|
+
*,
|
|
43
|
+
variant: ChipVariant = "filter",
|
|
44
|
+
selected: bool = False,
|
|
45
|
+
elevated: bool = False,
|
|
46
|
+
icon: str | None = None,
|
|
47
|
+
closable: bool = False,
|
|
48
|
+
disabled: bool = False,
|
|
49
|
+
bind: State[bool] | None = None,
|
|
50
|
+
on_click: Callable[[bool], None] | None = None,
|
|
51
|
+
on_close: Callable[[], None] | None = None,
|
|
52
|
+
) -> None:
|
|
53
|
+
super().__init__()
|
|
54
|
+
self.label = label
|
|
55
|
+
self.variant: ChipVariant = variant
|
|
56
|
+
self.elevated = elevated
|
|
57
|
+
self._bind = bind
|
|
58
|
+
self._selected = bool(bind.value) if bind is not None else bool(selected)
|
|
59
|
+
self.icon = icon
|
|
60
|
+
self.closable = closable or (variant == "input" and on_close is not None)
|
|
61
|
+
self.disabled = disabled
|
|
62
|
+
self.on_click = on_click
|
|
63
|
+
self.on_close = on_close
|
|
64
|
+
self._ripple = RippleController()
|
|
65
|
+
|
|
66
|
+
if bind is not None:
|
|
67
|
+
bind.subscribe(self._on_bound_change)
|
|
68
|
+
|
|
69
|
+
def _on_bound_change(self, new_val: bool) -> None:
|
|
70
|
+
b = bool(new_val)
|
|
71
|
+
if b != self._selected:
|
|
72
|
+
self._selected = b
|
|
73
|
+
self.invalidate()
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def selected(self) -> bool:
|
|
77
|
+
return self._selected
|
|
78
|
+
|
|
79
|
+
@selected.setter
|
|
80
|
+
def selected(self, val: bool) -> None:
|
|
81
|
+
b = bool(val)
|
|
82
|
+
if b != self._selected:
|
|
83
|
+
self._selected = b
|
|
84
|
+
if self._bind is not None and self._bind.value != b:
|
|
85
|
+
self._bind.value = b
|
|
86
|
+
self.invalidate()
|
|
87
|
+
|
|
88
|
+
def _effective_leading_icon(self) -> str | None:
|
|
89
|
+
if self.variant == "filter" and self._selected:
|
|
90
|
+
return "check"
|
|
91
|
+
return self.icon
|
|
92
|
+
|
|
93
|
+
def _measure_content(self, constraints: Constraints, theme: Theme) -> Size:
|
|
94
|
+
font = font_for_style(theme.font_family, theme.typography.label_large)
|
|
95
|
+
text_w = measure_text(font, self.label)
|
|
96
|
+
leading = self._effective_leading_icon()
|
|
97
|
+
pad_l = 8.0 if leading else 16.0
|
|
98
|
+
pad_r = 8.0 if self.closable else 16.0
|
|
99
|
+
lead_w = (18.0 + 8.0) if leading else 0.0
|
|
100
|
+
trail_w = (8.0 + 18.0) if self.closable else 0.0
|
|
101
|
+
return Size(pad_l + lead_w + text_w + trail_w + pad_r, self.HEIGHT)
|
|
102
|
+
|
|
103
|
+
def tick(self, now: float) -> bool:
|
|
104
|
+
return self._ripple.update(now)
|
|
105
|
+
|
|
106
|
+
def on_mouse_down(self, event: MouseEvent) -> None:
|
|
107
|
+
if self.disabled:
|
|
108
|
+
return
|
|
109
|
+
super().on_mouse_down(event)
|
|
110
|
+
self._ripple.start(
|
|
111
|
+
event.x - self.rect.x,
|
|
112
|
+
event.y - self.rect.y,
|
|
113
|
+
self.rect.width,
|
|
114
|
+
self.rect.height,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
def on_mouse_up(self, event: MouseEvent) -> None:
|
|
118
|
+
was_pressed = self.pressed
|
|
119
|
+
super().on_mouse_up(event)
|
|
120
|
+
self._ripple.release()
|
|
121
|
+
if self.disabled or not was_pressed or not self.rect.contains(event.x, event.y):
|
|
122
|
+
return
|
|
123
|
+
|
|
124
|
+
# Check if user clicked on trailing close icon
|
|
125
|
+
if self.closable and event.x >= self.rect.right - 30.0:
|
|
126
|
+
if self.on_close is not None:
|
|
127
|
+
self.on_close()
|
|
128
|
+
else:
|
|
129
|
+
self.visible(False)
|
|
130
|
+
return
|
|
131
|
+
|
|
132
|
+
if self.variant in ("filter", "input"):
|
|
133
|
+
self.selected = not self._selected
|
|
134
|
+
if self.on_click is not None:
|
|
135
|
+
self.on_click(self._selected)
|
|
136
|
+
|
|
137
|
+
def _paint_self(self, canvas: skia.Canvas, theme: Theme, now: float) -> None:
|
|
138
|
+
c = theme.colors
|
|
139
|
+
radius = (
|
|
140
|
+
self._shape_override[0]
|
|
141
|
+
if isinstance(self._shape_override, tuple)
|
|
142
|
+
else theme.shape.resolve(self._shape_override or "small")
|
|
143
|
+
)
|
|
144
|
+
rrect = make_rrect(self.rect, radius)
|
|
145
|
+
is_selected = self._selected and self.variant in ("filter", "input")
|
|
146
|
+
|
|
147
|
+
if self.disabled:
|
|
148
|
+
bg: Color | None = c.on_surface.with_alpha(0.12) if (is_selected or self.elevated) else None
|
|
149
|
+
border: Color | None = None if (is_selected or self.elevated) else c.on_surface.with_alpha(0.12)
|
|
150
|
+
fg = c.on_surface.with_alpha(0.38)
|
|
151
|
+
icon_color = fg
|
|
152
|
+
elif is_selected:
|
|
153
|
+
bg = c.secondary_container
|
|
154
|
+
border = None
|
|
155
|
+
fg = c.on_secondary_container
|
|
156
|
+
icon_color = c.on_secondary_container
|
|
157
|
+
elif self.elevated:
|
|
158
|
+
bg = c.surface_container_low
|
|
159
|
+
border = None
|
|
160
|
+
fg = c.on_surface
|
|
161
|
+
icon_color = c.primary
|
|
162
|
+
else:
|
|
163
|
+
bg = None
|
|
164
|
+
border = c.outline
|
|
165
|
+
fg = c.on_surface_variant if self.variant != "assist" else c.on_surface
|
|
166
|
+
icon_color = c.primary if self.variant == "assist" else c.on_surface_variant
|
|
167
|
+
|
|
168
|
+
if not self.disabled:
|
|
169
|
+
if self._bg_override is not None:
|
|
170
|
+
bg = resolve_color(self._bg_override, theme, bg)
|
|
171
|
+
if self._fg_override is not None:
|
|
172
|
+
fg = resolve_color(self._fg_override, theme, fg) or fg
|
|
173
|
+
icon_color = fg
|
|
174
|
+
if self._border_color_override is not None:
|
|
175
|
+
border = resolve_color(self._border_color_override, theme, border)
|
|
176
|
+
|
|
177
|
+
elev = self._elevation_override if self._elevation_override is not None else (1 if self.elevated and not self.disabled else 0)
|
|
178
|
+
if elev > 0:
|
|
179
|
+
draw_elevation_shadow(canvas, self.rect, radius, elev, c.shadow)
|
|
180
|
+
|
|
181
|
+
if bg is not None:
|
|
182
|
+
canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=bg.to_skia()))
|
|
183
|
+
|
|
184
|
+
if not self.disabled:
|
|
185
|
+
sl = theme.state_layers
|
|
186
|
+
alpha = sl.pressed if self.pressed else (sl.hover if self.hovered else (sl.focus if self.focused else 0.0))
|
|
187
|
+
draw_state_layer_and_ripple(canvas, self.rect, radius, fg, alpha, self._ripple, now)
|
|
188
|
+
|
|
189
|
+
if border is not None:
|
|
190
|
+
bw = self._border_width_override if self._border_width_override is not None else 1.0
|
|
191
|
+
if bw > 0.0:
|
|
192
|
+
inset = min(bw * 0.5, self.rect.width * 0.5, self.rect.height * 0.5)
|
|
193
|
+
inner_rect = Rect(
|
|
194
|
+
self.rect.x + inset,
|
|
195
|
+
self.rect.y + inset,
|
|
196
|
+
max(0.0, self.rect.width - inset * 2.0),
|
|
197
|
+
max(0.0, self.rect.height - inset * 2.0),
|
|
198
|
+
)
|
|
199
|
+
canvas.drawRRect(
|
|
200
|
+
make_rrect(inner_rect, max(0.0, radius - inset)),
|
|
201
|
+
skia.Paint(
|
|
202
|
+
AntiAlias=True,
|
|
203
|
+
Color=border.to_skia(),
|
|
204
|
+
Style=skia.Paint.kStroke_Style,
|
|
205
|
+
StrokeWidth=bw,
|
|
206
|
+
),
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
leading = self._effective_leading_icon()
|
|
210
|
+
x = self.rect.x + (8.0 if leading else 16.0)
|
|
211
|
+
if leading:
|
|
212
|
+
draw_icon(canvas, leading, x + 9.0, self.rect.center_y, 16.0, icon_color)
|
|
213
|
+
x += 18.0 + 8.0
|
|
214
|
+
|
|
215
|
+
font = font_for_style(theme.font_family, theme.typography.label_large)
|
|
216
|
+
draw_text_centered_y(canvas, self.label, x, self.rect.center_y, font, fg)
|
|
217
|
+
|
|
218
|
+
if self.closable:
|
|
219
|
+
draw_icon(canvas, "close", self.rect.right - 17.0, self.rect.center_y, 14.0, icon_color)
|