mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-05-30 03:31:42 -04:00
unify handling of themes
accessible theming/high contrast support
This commit is contained in:
parent
23ec185324
commit
4f02435964
41 changed files with 958 additions and 622 deletions
|
@ -2,14 +2,17 @@ import 'package:flutter/material.dart';
|
|||
|
||||
import 'scale_color.dart';
|
||||
|
||||
enum ScaleKind { primary, primaryAlpha, secondary, tertiary, gray, error }
|
||||
|
||||
class ScaleScheme extends ThemeExtension<ScaleScheme> {
|
||||
ScaleScheme(
|
||||
{required this.primaryScale,
|
||||
required this.primaryAlphaScale,
|
||||
required this.secondaryScale,
|
||||
required this.tertiaryScale,
|
||||
required this.grayScale,
|
||||
required this.errorScale});
|
||||
ScaleScheme({
|
||||
required this.primaryScale,
|
||||
required this.primaryAlphaScale,
|
||||
required this.secondaryScale,
|
||||
required this.tertiaryScale,
|
||||
required this.grayScale,
|
||||
required this.errorScale,
|
||||
});
|
||||
|
||||
final ScaleColor primaryScale;
|
||||
final ScaleColor primaryAlphaScale;
|
||||
|
@ -18,6 +21,23 @@ class ScaleScheme extends ThemeExtension<ScaleScheme> {
|
|||
final ScaleColor grayScale;
|
||||
final ScaleColor errorScale;
|
||||
|
||||
ScaleColor scale(ScaleKind kind) {
|
||||
switch (kind) {
|
||||
case ScaleKind.primary:
|
||||
return primaryScale;
|
||||
case ScaleKind.primaryAlpha:
|
||||
return primaryAlphaScale;
|
||||
case ScaleKind.secondary:
|
||||
return secondaryScale;
|
||||
case ScaleKind.tertiary:
|
||||
return tertiaryScale;
|
||||
case ScaleKind.gray:
|
||||
return grayScale;
|
||||
case ScaleKind.error:
|
||||
return errorScale;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
ScaleScheme copyWith(
|
||||
{ScaleColor? primaryScale,
|
||||
|
@ -50,4 +70,65 @@ class ScaleScheme extends ThemeExtension<ScaleScheme> {
|
|||
errorScale: ScaleColor.lerp(errorScale, other.errorScale, t),
|
||||
);
|
||||
}
|
||||
|
||||
ColorScheme toColorScheme(Brightness brightness) => ColorScheme(
|
||||
brightness: brightness,
|
||||
primary: primaryScale.primary, // reviewed
|
||||
onPrimary: primaryScale.primaryText, // reviewed
|
||||
// primaryContainer: primaryScale.hoverElementBackground,
|
||||
// onPrimaryContainer: primaryScale.subtleText,
|
||||
secondary: secondaryScale.primary,
|
||||
onSecondary: secondaryScale.primaryText,
|
||||
// secondaryContainer: secondaryScale.hoverElementBackground,
|
||||
// onSecondaryContainer: secondaryScale.subtleText,
|
||||
tertiary: tertiaryScale.primary,
|
||||
onTertiary: tertiaryScale.primaryText,
|
||||
// tertiaryContainer: tertiaryScale.hoverElementBackground,
|
||||
// onTertiaryContainer: tertiaryScale.subtleText,
|
||||
error: errorScale.primary,
|
||||
onError: errorScale.primaryText,
|
||||
// errorContainer: errorScale.hoverElementBackground,
|
||||
// onErrorContainer: errorScale.subtleText,
|
||||
background: grayScale.appBackground, // reviewed
|
||||
onBackground: grayScale.appText, // reviewed
|
||||
surface: primaryScale.primary, // reviewed
|
||||
onSurface: primaryScale.primaryText, // reviewed
|
||||
surfaceVariant: secondaryScale.primary,
|
||||
onSurfaceVariant: secondaryScale.primaryText, // ?? reviewed a little
|
||||
outline: primaryScale.border,
|
||||
outlineVariant: secondaryScale.border,
|
||||
shadow: const Color(0xFF000000),
|
||||
//scrim: primaryScale.background,
|
||||
// inverseSurface: primaryScale.subtleText,
|
||||
// onInverseSurface: primaryScale.subtleBackground,
|
||||
// inversePrimary: primaryScale.hoverBackground,
|
||||
// surfaceTint: primaryAlphaScale.hoverElementBackground,
|
||||
);
|
||||
}
|
||||
|
||||
class ScaleConfig extends ThemeExtension<ScaleConfig> {
|
||||
ScaleConfig({
|
||||
required this.useVisualIndicators,
|
||||
});
|
||||
|
||||
final bool useVisualIndicators;
|
||||
|
||||
@override
|
||||
ScaleConfig copyWith({
|
||||
bool? useVisualIndicators,
|
||||
}) =>
|
||||
ScaleConfig(
|
||||
useVisualIndicators: useVisualIndicators ?? this.useVisualIndicators,
|
||||
);
|
||||
|
||||
@override
|
||||
ScaleConfig lerp(ScaleConfig? other, double t) {
|
||||
if (other is! ScaleConfig) {
|
||||
return this;
|
||||
}
|
||||
return ScaleConfig(
|
||||
useVisualIndicators:
|
||||
t < .5 ? useVisualIndicators : other.useVisualIndicators,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue