quantumgui-fluent 0.1.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_fluent/__init__.py +10 -0
- quantumgui_fluent/core/__init__.py +15 -0
- quantumgui_fluent/core/fluent_draw.py +145 -0
- quantumgui_fluent/theme/__init__.py +3 -0
- quantumgui_fluent/theme/fluent_theme.py +338 -0
- quantumgui_fluent/ui.py +621 -0
- quantumgui_fluent/widgets/__init__.py +64 -0
- quantumgui_fluent/widgets/buttons.py +487 -0
- quantumgui_fluent/widgets/controls_extra.py +815 -0
- quantumgui_fluent/widgets/data_identity.py +367 -0
- quantumgui_fluent/widgets/feedback.py +445 -0
- quantumgui_fluent/widgets/inputs.py +591 -0
- quantumgui_fluent/widgets/inputs_advanced.py +270 -0
- quantumgui_fluent/widgets/menus_overlays.py +519 -0
- quantumgui_fluent/widgets/navigation.py +349 -0
- quantumgui_fluent/widgets/surfaces.py +313 -0
- quantumgui_fluent-0.1.0.dist-info/METADATA +32 -0
- quantumgui_fluent-0.1.0.dist-info/RECORD +21 -0
- quantumgui_fluent-0.1.0.dist-info/WHEEL +5 -0
- quantumgui_fluent-0.1.0.dist-info/licenses/LICENSE +190 -0
- quantumgui_fluent-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""QuantumGUI Fluent — 100% Microsoft Fluent 2 / WinUI 3 Native GPU GUI for Python."""
|
|
2
|
+
|
|
3
|
+
from . import ui
|
|
4
|
+
from .theme.fluent_theme import FluentTheme, FluentTokens
|
|
5
|
+
from quantumgui.core.state import State
|
|
6
|
+
from quantumgui.theme import Color
|
|
7
|
+
|
|
8
|
+
__version__ = "0.1.0"
|
|
9
|
+
|
|
10
|
+
__all__ = ["Color", "FluentTheme", "FluentTokens", "State", "__version__", "ui"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from .fluent_draw import (
|
|
2
|
+
draw_acrylic_surface,
|
|
3
|
+
draw_fluent_control_box,
|
|
4
|
+
draw_fluent_elevation_stroke,
|
|
5
|
+
draw_fluent_focus_ring,
|
|
6
|
+
draw_fluent_shadow,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"draw_acrylic_surface",
|
|
11
|
+
"draw_fluent_control_box",
|
|
12
|
+
"draw_fluent_elevation_stroke",
|
|
13
|
+
"draw_fluent_focus_ring",
|
|
14
|
+
"draw_fluent_shadow",
|
|
15
|
+
]
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Official Microsoft Fluent 2 Skia GPU rendering primitives (Elevation Stroke, Acrylic, Focus Ring)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import skia
|
|
6
|
+
|
|
7
|
+
from quantumgui.core.draw import make_rrect
|
|
8
|
+
from quantumgui.core.geometry import Rect
|
|
9
|
+
from quantumgui.theme import Color
|
|
10
|
+
from ..theme.fluent_theme import FluentTokens
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def draw_fluent_shadow(
|
|
14
|
+
canvas: skia.Canvas,
|
|
15
|
+
rect: Rect,
|
|
16
|
+
radius: float,
|
|
17
|
+
level: int,
|
|
18
|
+
tokens: FluentTokens,
|
|
19
|
+
) -> None:
|
|
20
|
+
"""Draw official Fluent 2 two-layer elevation shadow (Shadow4 / Shadow8 / Shadow16 / Shadow64)."""
|
|
21
|
+
if level <= 0:
|
|
22
|
+
return
|
|
23
|
+
# (key_y, key_blur, ambient_blur, alpha_scale)
|
|
24
|
+
specs = {
|
|
25
|
+
1: (1.0, 2.0, 1.0, 0.55), # Shadow2 / Shadow4 (Cards)
|
|
26
|
+
2: (4.0, 8.0, 2.0, 0.85), # Shadow8 (Flyouts, TeachingTip)
|
|
27
|
+
3: (8.0, 16.0, 3.0, 1.0), # Shadow16 (Menus, Dropdowns)
|
|
28
|
+
4: (16.0, 32.0, 6.0, 1.25), # Shadow64 (ContentDialog)
|
|
29
|
+
}
|
|
30
|
+
ky, kb, ab, asc = specs.get(level, specs[2])
|
|
31
|
+
rrect = make_rrect(rect, radius)
|
|
32
|
+
|
|
33
|
+
# Ambient layer
|
|
34
|
+
amb_paint = skia.Paint(
|
|
35
|
+
AntiAlias=True,
|
|
36
|
+
Color=tokens.shadow_ambient.with_alpha(min(1.0, (tokens.shadow_ambient.a / 255.0) * asc)).to_skia(),
|
|
37
|
+
MaskFilter=skia.MaskFilter.MakeBlur(skia.kNormal_BlurStyle, ab),
|
|
38
|
+
)
|
|
39
|
+
canvas.drawRRect(rrect, amb_paint)
|
|
40
|
+
|
|
41
|
+
# Key directional layer
|
|
42
|
+
key_rect = Rect(rect.x, rect.y + ky, rect.width, rect.height)
|
|
43
|
+
key_paint = skia.Paint(
|
|
44
|
+
AntiAlias=True,
|
|
45
|
+
Color=tokens.shadow_key.with_alpha(min(1.0, (tokens.shadow_key.a / 255.0) * asc)).to_skia(),
|
|
46
|
+
MaskFilter=skia.MaskFilter.MakeBlur(skia.kNormal_BlurStyle, kb),
|
|
47
|
+
)
|
|
48
|
+
canvas.drawRRect(make_rrect(key_rect, radius), key_paint)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def draw_fluent_elevation_stroke(
|
|
52
|
+
canvas: skia.Canvas,
|
|
53
|
+
rect: Rect,
|
|
54
|
+
radius: float,
|
|
55
|
+
top_color: Color,
|
|
56
|
+
bottom_color: Color,
|
|
57
|
+
*,
|
|
58
|
+
stroke_width: float = 1.0,
|
|
59
|
+
) -> None:
|
|
60
|
+
"""Draw the signature Windows 11 / Fluent 2 1px top-lit elevation border."""
|
|
61
|
+
inset = stroke_width * 0.5
|
|
62
|
+
inner = Rect(
|
|
63
|
+
rect.x + inset,
|
|
64
|
+
rect.y + inset,
|
|
65
|
+
max(0.0, rect.width - stroke_width),
|
|
66
|
+
max(0.0, rect.height - stroke_width),
|
|
67
|
+
)
|
|
68
|
+
shader = skia.GradientShader.MakeLinear(
|
|
69
|
+
points=[(inner.x, inner.y), (inner.x, inner.bottom)],
|
|
70
|
+
colors=[top_color.to_skia(), bottom_color.to_skia()],
|
|
71
|
+
positions=[0.0, 1.0],
|
|
72
|
+
)
|
|
73
|
+
paint = skia.Paint(
|
|
74
|
+
AntiAlias=True,
|
|
75
|
+
Style=skia.Paint.kStroke_Style,
|
|
76
|
+
StrokeWidth=stroke_width,
|
|
77
|
+
Shader=shader,
|
|
78
|
+
)
|
|
79
|
+
canvas.drawRRect(make_rrect(inner, max(0.0, radius - inset)), paint)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def draw_fluent_control_box(
|
|
83
|
+
canvas: skia.Canvas,
|
|
84
|
+
rect: Rect,
|
|
85
|
+
radius: float,
|
|
86
|
+
bg: Color | None,
|
|
87
|
+
tokens: FluentTokens,
|
|
88
|
+
*,
|
|
89
|
+
border_top: Color | None = None,
|
|
90
|
+
border_bottom: Color | None = None,
|
|
91
|
+
shadow_level: int = 0,
|
|
92
|
+
) -> None:
|
|
93
|
+
"""Draw a standard Fluent 2 control surface with optional elevation shadow and 1px elevation stroke."""
|
|
94
|
+
if shadow_level > 0:
|
|
95
|
+
draw_fluent_shadow(canvas, rect, radius, shadow_level, tokens)
|
|
96
|
+
if bg is not None:
|
|
97
|
+
canvas.drawRRect(make_rrect(rect, radius), skia.Paint(AntiAlias=True, Color=bg.to_skia()))
|
|
98
|
+
if border_top is not None or border_bottom is not None:
|
|
99
|
+
draw_fluent_elevation_stroke(
|
|
100
|
+
canvas,
|
|
101
|
+
rect,
|
|
102
|
+
radius,
|
|
103
|
+
border_top or tokens.elevation_top,
|
|
104
|
+
border_bottom or tokens.elevation_bottom,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def draw_acrylic_surface(
|
|
109
|
+
canvas: skia.Canvas,
|
|
110
|
+
rect: Rect,
|
|
111
|
+
radius: float,
|
|
112
|
+
tokens: FluentTokens,
|
|
113
|
+
*,
|
|
114
|
+
shadow_level: int = 2,
|
|
115
|
+
) -> None:
|
|
116
|
+
"""Draw a Fluent 2 Acrylic translucent overlay surface with subtle luminosity border."""
|
|
117
|
+
draw_fluent_shadow(canvas, rect, radius, shadow_level, tokens)
|
|
118
|
+
rrect = make_rrect(rect, radius)
|
|
119
|
+
canvas.drawRRect(rrect, skia.Paint(AntiAlias=True, Color=tokens.acrylic_tint.to_skia()))
|
|
120
|
+
draw_fluent_elevation_stroke(
|
|
121
|
+
canvas,
|
|
122
|
+
rect,
|
|
123
|
+
radius,
|
|
124
|
+
tokens.elevation_top,
|
|
125
|
+
tokens.stroke_1,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def draw_fluent_focus_ring(
|
|
130
|
+
canvas: skia.Canvas,
|
|
131
|
+
rect: Rect,
|
|
132
|
+
radius: float,
|
|
133
|
+
tokens: FluentTokens,
|
|
134
|
+
) -> None:
|
|
135
|
+
"""Draw the official Fluent 2 double-stroke keyboard focus ring."""
|
|
136
|
+
outer = Rect(rect.x - 2.0, rect.y - 2.0, rect.width + 4.0, rect.height + 4.0)
|
|
137
|
+
inner = Rect(rect.x - 0.5, rect.y - 0.5, rect.width + 1.0, rect.height + 1.0)
|
|
138
|
+
canvas.drawRRect(
|
|
139
|
+
make_rrect(outer, radius + 2.0),
|
|
140
|
+
skia.Paint(AntiAlias=True, Color=tokens.focus_outer.to_skia(), Style=skia.Paint.kStroke_Style, StrokeWidth=2.0),
|
|
141
|
+
)
|
|
142
|
+
canvas.drawRRect(
|
|
143
|
+
make_rrect(inner, radius + 0.5),
|
|
144
|
+
skia.Paint(AntiAlias=True, Color=tokens.focus_inner.to_skia(), Style=skia.Paint.kStroke_Style, StrokeWidth=1.0),
|
|
145
|
+
)
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"""Official Microsoft Fluent 2 Design System Theme & Tokens (Light & Dark)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Literal
|
|
7
|
+
|
|
8
|
+
from quantumgui.theme import Color, Theme
|
|
9
|
+
from quantumgui.theme.tokens import TextStyle
|
|
10
|
+
|
|
11
|
+
FluentBackdrop = Literal["none", "mica", "mica_alt", "acrylic"]
|
|
12
|
+
FluentDensity = Literal["standard", "compact"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _mix(a: Color, b: Color, t: float) -> Color:
|
|
16
|
+
t = max(0.0, min(1.0, float(t)))
|
|
17
|
+
return Color(
|
|
18
|
+
int(round(a.r + (b.r - a.r) * t)),
|
|
19
|
+
int(round(a.g + (b.g - a.g) * t)),
|
|
20
|
+
int(round(a.b + (b.b - a.b) * t)),
|
|
21
|
+
int(round(a.a + (b.a - a.a) * t)),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _darken(c: Color, amount: float) -> Color:
|
|
26
|
+
return _mix(c, Color(0, 0, 0, c.a), amount)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _lighten(c: Color, amount: float) -> Color:
|
|
30
|
+
return _mix(c, Color(255, 255, 255, c.a), amount)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True)
|
|
34
|
+
class FluentRadii:
|
|
35
|
+
"""Official Fluent 2 Corner Radius tokens (px)."""
|
|
36
|
+
|
|
37
|
+
none: float = 0.0
|
|
38
|
+
small: float = 2.0
|
|
39
|
+
medium: float = 4.0 # Buttons, TextBoxes, CheckBoxes, MenuItems
|
|
40
|
+
large: float = 6.0 # Badges, compact cards
|
|
41
|
+
x_large: float = 8.0 # Cards, Flyouts, ContentDialogs, InfoBars
|
|
42
|
+
xx_large: float = 12.0 # Large overlays
|
|
43
|
+
circular: float = 9999.0
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass(frozen=True)
|
|
47
|
+
class FluentTypography:
|
|
48
|
+
"""Official Fluent 2 Type Ramp (Segoe UI Variable)."""
|
|
49
|
+
|
|
50
|
+
caption2: TextStyle = TextStyle(size=10.0, line_height=14.0, weight=400)
|
|
51
|
+
caption1: TextStyle = TextStyle(size=12.0, line_height=16.0, weight=400)
|
|
52
|
+
caption1_strong: TextStyle = TextStyle(size=12.0, line_height=16.0, weight=600)
|
|
53
|
+
body1: TextStyle = TextStyle(size=14.0, line_height=20.0, weight=400)
|
|
54
|
+
body1_strong: TextStyle = TextStyle(size=14.0, line_height=20.0, weight=600)
|
|
55
|
+
body2: TextStyle = TextStyle(size=16.0, line_height=22.0, weight=400)
|
|
56
|
+
subtitle2: TextStyle = TextStyle(size=16.0, line_height=22.0, weight=600)
|
|
57
|
+
subtitle1: TextStyle = TextStyle(size=20.0, line_height=28.0, weight=600)
|
|
58
|
+
title3: TextStyle = TextStyle(size=24.0, line_height=32.0, weight=600)
|
|
59
|
+
title2: TextStyle = TextStyle(size=28.0, line_height=36.0, weight=600)
|
|
60
|
+
title1: TextStyle = TextStyle(size=32.0, line_height=40.0, weight=600)
|
|
61
|
+
display: TextStyle = TextStyle(size=68.0, line_height=92.0, weight=600)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@dataclass(frozen=True)
|
|
65
|
+
class FluentTokens:
|
|
66
|
+
"""Official Fluent 2 Semantic Color Tokens (fluent2.microsoft.design)."""
|
|
67
|
+
|
|
68
|
+
is_dark: bool
|
|
69
|
+
|
|
70
|
+
# Neutral Backgrounds (Mica canvas -> Layer cards -> Inputs -> Overlays)
|
|
71
|
+
canvas_bg: Color # Window Mica/Solid base (#F3F3F3 light / #202020 dark)
|
|
72
|
+
neutral_bg_1: Color # Primary card / layer surface (#FFFFFF / #2B2B2B)
|
|
73
|
+
neutral_bg_2: Color # Secondary subtle surface (#FAFAFA / #272727)
|
|
74
|
+
neutral_bg_3: Color # Tertiary surface (#F5F5F5 / #1F1F1F)
|
|
75
|
+
neutral_bg_4: Color # Flyout / Dialog / CommandBar (#FFFFFF / #2C2C2C)
|
|
76
|
+
neutral_bg_subtle_hover: Color
|
|
77
|
+
neutral_bg_subtle_pressed: Color
|
|
78
|
+
neutral_bg_selected: Color
|
|
79
|
+
|
|
80
|
+
# Control Fills (Buttons, Inputs, CheckBoxes)
|
|
81
|
+
control_fill: Color
|
|
82
|
+
control_fill_hover: Color
|
|
83
|
+
control_fill_pressed: Color
|
|
84
|
+
control_fill_disabled: Color
|
|
85
|
+
control_fill_input_active: Color
|
|
86
|
+
|
|
87
|
+
# Foreground Text & Icons
|
|
88
|
+
fg_1: Color # Primary text (#1A1A1A / #FFFFFF)
|
|
89
|
+
fg_2: Color # Secondary text (#5C5C5C / #CECECE)
|
|
90
|
+
fg_3: Color # Tertiary / placeholder (#707070 / #9E9E9E)
|
|
91
|
+
fg_disabled: Color # Disabled text
|
|
92
|
+
fg_on_brand: Color # Text on Accent/Brand (#FFFFFF / #000000)
|
|
93
|
+
|
|
94
|
+
# Strokes & Win11 Elevation Stroke (top-lit 1px borders)
|
|
95
|
+
stroke_1: Color # Standard control border
|
|
96
|
+
stroke_1_hover: Color
|
|
97
|
+
stroke_2: Color # Subtle card/divider border
|
|
98
|
+
stroke_accessible: Color # High-contrast input/checkbox border (#616161 / #999999)
|
|
99
|
+
elevation_top: Color # Top edge highlight of 1px elevation stroke
|
|
100
|
+
elevation_bottom: Color # Bottom edge shadow of 1px elevation stroke
|
|
101
|
+
focus_outer: Color # Fluent 2 outer focus ring
|
|
102
|
+
focus_inner: Color # Fluent 2 inner focus ring
|
|
103
|
+
|
|
104
|
+
# Brand / Accent Ramp
|
|
105
|
+
brand_bg: Color
|
|
106
|
+
brand_bg_hover: Color
|
|
107
|
+
brand_bg_pressed: Color
|
|
108
|
+
brand_bg_subtle: Color
|
|
109
|
+
brand_fg: Color
|
|
110
|
+
|
|
111
|
+
# Semantic Status (InfoBar, Badges, Validation)
|
|
112
|
+
info_bg: Color
|
|
113
|
+
info_fg: Color
|
|
114
|
+
info_border: Color
|
|
115
|
+
success_bg: Color
|
|
116
|
+
success_fg: Color
|
|
117
|
+
success_border: Color
|
|
118
|
+
warning_bg: Color
|
|
119
|
+
warning_fg: Color
|
|
120
|
+
warning_border: Color
|
|
121
|
+
danger_bg: Color
|
|
122
|
+
danger_fg: Color
|
|
123
|
+
danger_border: Color
|
|
124
|
+
|
|
125
|
+
# Shadows & Acrylic
|
|
126
|
+
shadow_key: Color
|
|
127
|
+
shadow_ambient: Color
|
|
128
|
+
acrylic_tint: Color
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def build_fluent_tokens(accent_hex: str = "#0078D4", *, dark: bool = False) -> FluentTokens:
|
|
132
|
+
"""Generate official Microsoft Fluent 2 semantic tokens from an accent color."""
|
|
133
|
+
base = Color.from_hex(accent_hex)
|
|
134
|
+
if not dark:
|
|
135
|
+
brand_bg = base
|
|
136
|
+
brand_hover = _darken(base, 0.10)
|
|
137
|
+
brand_pressed = _darken(base, 0.22)
|
|
138
|
+
brand_subtle = _lighten(base, 0.88)
|
|
139
|
+
brand_fg = _darken(base, 0.08)
|
|
140
|
+
return FluentTokens(
|
|
141
|
+
is_dark=False,
|
|
142
|
+
canvas_bg=Color.from_hex("#F3F3F3"),
|
|
143
|
+
neutral_bg_1=Color.from_hex("#FFFFFF"),
|
|
144
|
+
neutral_bg_2=Color.from_hex("#FBFBFB"),
|
|
145
|
+
neutral_bg_3=Color.from_hex("#F5F5F5"),
|
|
146
|
+
neutral_bg_4=Color.from_hex("#FFFFFF"),
|
|
147
|
+
neutral_bg_subtle_hover=Color(0, 0, 0, 10),
|
|
148
|
+
neutral_bg_subtle_pressed=Color(0, 0, 0, 16),
|
|
149
|
+
neutral_bg_selected=Color(0, 0, 0, 14),
|
|
150
|
+
control_fill=Color(255, 255, 255, 196),
|
|
151
|
+
control_fill_hover=Color(249, 249, 249, 210),
|
|
152
|
+
control_fill_pressed=Color(243, 243, 243, 180),
|
|
153
|
+
control_fill_disabled=Color(249, 249, 249, 110),
|
|
154
|
+
control_fill_input_active=Color.from_hex("#FFFFFF"),
|
|
155
|
+
fg_1=Color.from_hex("#1B1B1B"),
|
|
156
|
+
fg_2=Color.from_hex("#5D5D5D"),
|
|
157
|
+
fg_3=Color.from_hex("#767676"),
|
|
158
|
+
fg_disabled=Color(0, 0, 0, 92),
|
|
159
|
+
fg_on_brand=Color.from_hex("#FFFFFF"),
|
|
160
|
+
stroke_1=Color(0, 0, 0, 22),
|
|
161
|
+
stroke_1_hover=Color(0, 0, 0, 36),
|
|
162
|
+
stroke_2=Color(0, 0, 0, 15),
|
|
163
|
+
stroke_accessible=Color.from_hex("#616161"),
|
|
164
|
+
elevation_top=Color(0, 0, 0, 16),
|
|
165
|
+
elevation_bottom=Color(0, 0, 0, 44),
|
|
166
|
+
focus_outer=Color.from_hex("#1B1B1B"),
|
|
167
|
+
focus_inner=Color.from_hex("#FFFFFF"),
|
|
168
|
+
brand_bg=brand_bg,
|
|
169
|
+
brand_bg_hover=brand_hover,
|
|
170
|
+
brand_bg_pressed=brand_pressed,
|
|
171
|
+
brand_bg_subtle=brand_subtle,
|
|
172
|
+
brand_fg=brand_fg,
|
|
173
|
+
info_bg=Color.from_hex("#F4F4F4"),
|
|
174
|
+
info_fg=Color.from_hex("#005FB8"),
|
|
175
|
+
info_border=Color(0, 0, 0, 18),
|
|
176
|
+
success_bg=Color.from_hex("#DFF6DD"),
|
|
177
|
+
success_fg=Color.from_hex("#0F7B0F"),
|
|
178
|
+
success_border=Color.from_hex("#9FD89F"),
|
|
179
|
+
warning_bg=Color.from_hex("#FFF4CE"),
|
|
180
|
+
warning_fg=Color.from_hex("#9D5D00"),
|
|
181
|
+
warning_border=Color.from_hex("#F0D18A"),
|
|
182
|
+
danger_bg=Color.from_hex("#FDE7E9"),
|
|
183
|
+
danger_fg=Color.from_hex("#C42B1C"),
|
|
184
|
+
danger_border=Color.from_hex("#F1AEB5"),
|
|
185
|
+
shadow_key=Color(0, 0, 0, 36),
|
|
186
|
+
shadow_ambient=Color(0, 0, 0, 18),
|
|
187
|
+
acrylic_tint=Color(252, 252, 252, 218),
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
# Dark Mode (Official Windows 11 / Fluent 2 Dark)
|
|
191
|
+
brand_bg = _lighten(base, 0.28)
|
|
192
|
+
brand_hover = _lighten(base, 0.20)
|
|
193
|
+
brand_pressed = _lighten(base, 0.12)
|
|
194
|
+
brand_subtle = _darken(base, 0.58)
|
|
195
|
+
brand_fg = _lighten(base, 0.42)
|
|
196
|
+
return FluentTokens(
|
|
197
|
+
is_dark=True,
|
|
198
|
+
canvas_bg=Color.from_hex("#202020"),
|
|
199
|
+
neutral_bg_1=Color.from_hex("#2B2B2B"),
|
|
200
|
+
neutral_bg_2=Color.from_hex("#272727"),
|
|
201
|
+
neutral_bg_3=Color.from_hex("#1C1C1C"),
|
|
202
|
+
neutral_bg_4=Color.from_hex("#2C2C2C"),
|
|
203
|
+
neutral_bg_subtle_hover=Color(255, 255, 255, 15),
|
|
204
|
+
neutral_bg_subtle_pressed=Color(255, 255, 255, 10),
|
|
205
|
+
neutral_bg_selected=Color(255, 255, 255, 16),
|
|
206
|
+
control_fill=Color(255, 255, 255, 16),
|
|
207
|
+
control_fill_hover=Color(255, 255, 255, 22),
|
|
208
|
+
control_fill_pressed=Color(255, 255, 255, 10),
|
|
209
|
+
control_fill_disabled=Color(255, 255, 255, 11),
|
|
210
|
+
control_fill_input_active=Color.from_hex("#1F1F1F"),
|
|
211
|
+
fg_1=Color.from_hex("#FFFFFF"),
|
|
212
|
+
fg_2=Color.from_hex("#CECECE"),
|
|
213
|
+
fg_3=Color.from_hex("#9A9A9A"),
|
|
214
|
+
fg_disabled=Color(255, 255, 255, 92),
|
|
215
|
+
fg_on_brand=Color.from_hex("#000000"),
|
|
216
|
+
stroke_1=Color(255, 255, 255, 20),
|
|
217
|
+
stroke_1_hover=Color(255, 255, 255, 30),
|
|
218
|
+
stroke_2=Color(255, 255, 255, 14),
|
|
219
|
+
stroke_accessible=Color.from_hex("#9E9E9E"),
|
|
220
|
+
elevation_top=Color(255, 255, 255, 26),
|
|
221
|
+
elevation_bottom=Color(255, 255, 255, 14),
|
|
222
|
+
focus_outer=Color.from_hex("#FFFFFF"),
|
|
223
|
+
focus_inner=Color.from_hex("#1B1B1B"),
|
|
224
|
+
brand_bg=brand_bg,
|
|
225
|
+
brand_bg_hover=brand_hover,
|
|
226
|
+
brand_bg_pressed=brand_pressed,
|
|
227
|
+
brand_bg_subtle=brand_subtle,
|
|
228
|
+
brand_fg=brand_fg,
|
|
229
|
+
info_bg=Color.from_hex("#272727"),
|
|
230
|
+
info_fg=Color.from_hex("#60CDFF"),
|
|
231
|
+
info_border=Color(255, 255, 255, 18),
|
|
232
|
+
success_bg=Color.from_hex("#393D1B"),
|
|
233
|
+
success_fg=Color.from_hex("#6CCB5F"),
|
|
234
|
+
success_border=Color(108, 203, 95, 70),
|
|
235
|
+
warning_bg=Color.from_hex("#433519"),
|
|
236
|
+
warning_fg=Color.from_hex("#FCE100"),
|
|
237
|
+
warning_border=Color(252, 225, 0, 70),
|
|
238
|
+
danger_bg=Color.from_hex("#442726"),
|
|
239
|
+
danger_fg=Color.from_hex("#FF99A4"),
|
|
240
|
+
danger_border=Color(255, 153, 164, 70),
|
|
241
|
+
shadow_key=Color(0, 0, 0, 96),
|
|
242
|
+
shadow_ambient=Color(0, 0, 0, 56),
|
|
243
|
+
acrylic_tint=Color(44, 44, 44, 228),
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
class FluentTheme(Theme):
|
|
248
|
+
"""Official Microsoft Fluent 2 Theme compatible with `quantumgui.core.Window`.
|
|
249
|
+
|
|
250
|
+
Overrides base surface/background tokens so the entire window renders with
|
|
251
|
+
authentic Windows 11 / Fluent 2 colors, Segoe UI Variable typography, and
|
|
252
|
+
`theme.fluent` semantic tokens.
|
|
253
|
+
"""
|
|
254
|
+
|
|
255
|
+
def __init__(
|
|
256
|
+
self,
|
|
257
|
+
*,
|
|
258
|
+
accent: str = "#0078D4",
|
|
259
|
+
mode: Literal["light", "dark"] = "light",
|
|
260
|
+
backdrop: FluentBackdrop = "mica",
|
|
261
|
+
density: FluentDensity = "standard",
|
|
262
|
+
font_family: str = "Segoe UI",
|
|
263
|
+
) -> None:
|
|
264
|
+
self._accent = accent
|
|
265
|
+
self.backdrop: FluentBackdrop = backdrop
|
|
266
|
+
self.density: FluentDensity = density
|
|
267
|
+
self.radii = FluentRadii()
|
|
268
|
+
self.fluent_typography = FluentTypography()
|
|
269
|
+
self.fluent: FluentTokens = build_fluent_tokens(accent, dark=(mode == "dark"))
|
|
270
|
+
super().__init__(seed=accent, mode=mode, font_family=font_family)
|
|
271
|
+
self._sync_base_colors()
|
|
272
|
+
|
|
273
|
+
def _sync_base_colors(self) -> None:
|
|
274
|
+
"""Align underlying Theme.colors with Fluent 2 tokens so shared widgets (DataGrid, Charts, Window) match."""
|
|
275
|
+
self.fluent = build_fluent_tokens(self._accent, dark=(self.mode == "dark"))
|
|
276
|
+
f = self.fluent
|
|
277
|
+
c = self.colors
|
|
278
|
+
# Replace ColorScheme with Fluent 2 neutral/brand values
|
|
279
|
+
from dataclasses import replace
|
|
280
|
+
|
|
281
|
+
self.colors = replace(
|
|
282
|
+
c,
|
|
283
|
+
surface=f.canvas_bg,
|
|
284
|
+
surface_container_lowest=f.neutral_bg_1,
|
|
285
|
+
surface_container_low=f.neutral_bg_1,
|
|
286
|
+
surface_container=f.neutral_bg_2,
|
|
287
|
+
surface_container_high=f.neutral_bg_4,
|
|
288
|
+
surface_container_highest=f.neutral_bg_3,
|
|
289
|
+
on_surface=f.fg_1,
|
|
290
|
+
on_surface_variant=f.fg_2,
|
|
291
|
+
primary=f.brand_bg,
|
|
292
|
+
on_primary=f.fg_on_brand,
|
|
293
|
+
primary_container=f.brand_bg_subtle,
|
|
294
|
+
on_primary_container=f.brand_fg,
|
|
295
|
+
secondary=f.fg_2,
|
|
296
|
+
on_secondary=f.neutral_bg_1,
|
|
297
|
+
secondary_container=f.neutral_bg_3,
|
|
298
|
+
on_secondary_container=f.fg_1,
|
|
299
|
+
outline=f.stroke_accessible,
|
|
300
|
+
outline_variant=f.stroke_2,
|
|
301
|
+
error=f.danger_fg,
|
|
302
|
+
shadow=f.shadow_key,
|
|
303
|
+
)
|
|
304
|
+
# Align shared widget shape tokens with Fluent 2 4px/8px desktop radii
|
|
305
|
+
if hasattr(self, "shape"):
|
|
306
|
+
self.shape = replace(
|
|
307
|
+
self.shape,
|
|
308
|
+
extra_small=2.0,
|
|
309
|
+
small=4.0,
|
|
310
|
+
medium=6.0,
|
|
311
|
+
large=8.0,
|
|
312
|
+
extra_large=12.0,
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
@property
|
|
316
|
+
def accent(self) -> str:
|
|
317
|
+
return self._accent
|
|
318
|
+
|
|
319
|
+
@accent.setter
|
|
320
|
+
def accent(self, value: str) -> None:
|
|
321
|
+
self._accent = value
|
|
322
|
+
self._seed = value
|
|
323
|
+
self._sync_base_colors()
|
|
324
|
+
self._notify()
|
|
325
|
+
|
|
326
|
+
@Theme.mode.setter # type: ignore[attr-defined]
|
|
327
|
+
def mode(self, value: Literal["light", "dark"]) -> None:
|
|
328
|
+
if value != self._mode:
|
|
329
|
+
self._mode = value
|
|
330
|
+
self._sync_base_colors()
|
|
331
|
+
self._notify()
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def get_fluent_tokens(theme: Theme) -> FluentTokens:
|
|
335
|
+
"""Return `FluentTokens` from a `FluentTheme` or synthesize them for a plain `Theme`."""
|
|
336
|
+
if isinstance(theme, FluentTheme):
|
|
337
|
+
return theme.fluent
|
|
338
|
+
return build_fluent_tokens(dark=(theme.mode == "dark"))
|