feat(appearance): add glass clarity controls and directional highlights

This commit is contained in:
zarzet committed 2026-09-30 23:42:20 +07:00
1 parent 9ebf98ff6c
commit ce13e29b71
12 files changed
+526 -225

No files matched your search

+2
View File
@@ -23,11 +23,13 @@ class DynamicColorWrapper extends ConsumerWidget {
Brightness.light,
accent: themeSettings.mornyeAccent,
useSystemFont: themeSettings.useSystemFont,
glassClarity: themeSettings.mornyeGlassClarity,
),
MornyeTheme.build(
Brightness.dark,
accent: themeSettings.mornyeAccent,
useSystemFont: themeSettings.useSystemFont,
glassClarity: themeSettings.mornyeGlassClarity,
),
themeSettings.themeMode,
);
+31 -2
View File
@@ -13,11 +13,17 @@ class MornyeTheme extends ThemeExtension<MornyeTheme> {
this.chromeSurface,
this.accent = MornyeAccent.red,
this.useSystemFont = false,
this.glassClarity = kDefaultMornyeGlassClarity,
});
final Color? chromeSurface;
final MornyeAccent accent;
final bool useSystemFont;
final double glassClarity;
static double glassClarityOf(BuildContext context) =>
Theme.of(context).extension<MornyeTheme>()?.glassClarity ??
kDefaultMornyeGlassClarity;
/// A single translucent fill for controls inside an existing glass surface.
static Color controlFill(BuildContext context, {bool enabled = true}) {
@@ -111,6 +117,7 @@ class MornyeTheme extends ThemeExtension<MornyeTheme> {
Color? chromeSurface,
MornyeAccent accent = MornyeAccent.red,
bool useSystemFont = false,
double glassClarity = kDefaultMornyeGlassClarity,
}) {
final key = (
defaultTargetPlatform,
@@ -122,7 +129,7 @@ class MornyeTheme extends ThemeExtension<MornyeTheme> {
final cached = _themeCache.remove(key);
if (cached != null) {
_themeCache[key] = cached;
return cached;
return _withGlassClarity(cached, glassClarity);
}
final theme = _build(
brightness,
@@ -134,7 +141,23 @@ class MornyeTheme extends ThemeExtension<MornyeTheme> {
_themeCache.remove(_themeCache.keys.first);
}
_themeCache[key] = theme;
return theme;
return _withGlassClarity(theme, glassClarity);
}
// Moving the clarity slider only changes the material, not typography or
// seeded colors. Keep the expensive base theme cached independently.
static ThemeData _withGlassClarity(ThemeData theme, double value) {
final clarity = normalizeMornyeGlassClarity(value);
if (theme.extension<MornyeTheme>()!.glassClarity == clarity) return theme;
return theme.copyWith(
extensions: [
for (final extension in theme.extensions.values)
if (extension is MornyeTheme)
extension.copyWith(glassClarity: clarity)
else
extension,
],
);
}
/// Rebuild local surfaces without losing the user's Mornye preferences.
@@ -150,6 +173,7 @@ class MornyeTheme extends ThemeExtension<MornyeTheme> {
chromeSurface: chromeSurface,
accent: preferences?.accent ?? MornyeAccent.red,
useSystemFont: preferences?.useSystemFont ?? false,
glassClarity: preferences?.glassClarity ?? kDefaultMornyeGlassClarity,
);
}
@@ -366,10 +390,12 @@ class MornyeTheme extends ThemeExtension<MornyeTheme> {
Color? chromeSurface,
MornyeAccent? accent,
bool? useSystemFont,
double? glassClarity,
}) => MornyeTheme(
chromeSurface: chromeSurface ?? this.chromeSurface,
accent: accent ?? this.accent,
useSystemFont: useSystemFont ?? this.useSystemFont,
glassClarity: glassClarity ?? this.glassClarity,
);
@override
@@ -379,6 +405,9 @@ class MornyeTheme extends ThemeExtension<MornyeTheme> {
useSystemFont: t < 0.5
? useSystemFont
: other?.useSystemFont ?? useSystemFont,
glassClarity:
glassClarity +
((other?.glassClarity ?? glassClarity) - glassClarity) * t,
);
}