230 lines
7.4 KiB
Dart
230 lines
7.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'app_design.dart';
|
|
import 'app_design_styles.dart';
|
|
|
|
export 'app_design_styles.dart';
|
|
|
|
/// The muted ANSI-style accents a design names for status and roles. The
|
|
/// Default design leaves them to its colour scheme; Terminal sets them, and
|
|
/// Paper sets ink-toned ones.
|
|
@immutable
|
|
class AnsiAccents {
|
|
const AnsiAccents({
|
|
required this.green,
|
|
required this.cyan,
|
|
required this.yellow,
|
|
required this.red,
|
|
required this.magenta,
|
|
required this.blue,
|
|
});
|
|
|
|
final Color green;
|
|
final Color cyan;
|
|
final Color yellow;
|
|
final Color red;
|
|
final Color magenta;
|
|
final Color blue;
|
|
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
other is AnsiAccents &&
|
|
other.green == green &&
|
|
other.cyan == cyan &&
|
|
other.yellow == yellow &&
|
|
other.red == red &&
|
|
other.magenta == magenta &&
|
|
other.blue == blue;
|
|
|
|
@override
|
|
int get hashCode => Object.hash(green, cyan, yellow, red, magenta, blue);
|
|
}
|
|
|
|
/// The design-specific facts widgets read instead of hard-coding one look:
|
|
/// corner shapes, whether surfaces are flat, frame colour, how the chat
|
|
/// transcript, the composer and the open list row are drawn, and the reading
|
|
/// typography. Every theme an [AppDesign] builds carries one; a theme without
|
|
/// one (a test's bare `ThemeData`) reads as [standard].
|
|
///
|
|
/// Adding a design: every field has a default that keeps the Default look,
|
|
/// so a new design sets only what it changes. Widgets branch on the named
|
|
/// styles ([transcript], [composer], [selectedRow]) rather than on [design],
|
|
/// so two designs can share a behaviour.
|
|
@immutable
|
|
class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
|
const AppDesignTokens({
|
|
required this.design,
|
|
this.radius,
|
|
this.flat = false,
|
|
this.frame,
|
|
this.panel,
|
|
this.ansi,
|
|
this.promptGlyph = '>',
|
|
this.transcript = TranscriptStyle.bubbles,
|
|
this.composer = ComposerStyle.pill,
|
|
this.selectedRow = SelectedRowStyle.tonal,
|
|
this.reading = const ReadingType(),
|
|
this.chatColorSaturation = 1,
|
|
this.density = DesignDensity.comfortable,
|
|
});
|
|
|
|
/// The Default design: every widget keeps its own shapes.
|
|
static const AppDesignTokens standard = AppDesignTokens(
|
|
design: AppDesign.standard,
|
|
);
|
|
|
|
final AppDesign design;
|
|
|
|
/// The corner radius of framed surfaces (cards, pills, the composer,
|
|
/// bubbles, thumbnails, badges); null keeps each widget's own shape.
|
|
final double? radius;
|
|
|
|
/// Whether surfaces are flat: no frosted glass, blur, highlight or shadow.
|
|
final bool flat;
|
|
|
|
/// The 1px frame colour around flat surfaces; null keeps each widget's own.
|
|
final Color? frame;
|
|
|
|
/// The fill of a flat design's own panels (settings groups, floating bars,
|
|
/// cards a widget draws itself); null keeps `surfaceContainerLow`.
|
|
final Color? panel;
|
|
|
|
/// The design's ANSI-style accents; null for a design that uses its colour
|
|
/// scheme's roles.
|
|
final AnsiAccents? ansi;
|
|
|
|
/// The glyph before the operator's prompt line and the composer's field.
|
|
final String promptGlyph;
|
|
|
|
/// How the chat transcript draws the operator's and the agent's turns.
|
|
final TranscriptStyle transcript;
|
|
|
|
/// How the chat composer frames its writing area.
|
|
final ComposerStyle composer;
|
|
|
|
/// How a list marks its open row.
|
|
final SelectedRowStyle selectedRow;
|
|
|
|
/// The face, line height and measure of reading text (chat, documents).
|
|
final ReadingType reading;
|
|
|
|
/// How much of a chat colour's saturation the transcript keeps: 1 for the
|
|
/// palette as is, lower to quieten it towards ink.
|
|
final double chatColorSaturation;
|
|
|
|
/// How tightly the interface is packed: spacing, icon and avatar sizes,
|
|
/// the rail and the window title bar ([DesignDensity.compact] for Compact).
|
|
final DesignDensity density;
|
|
|
|
/// Whether the transcript draws prompt and tool lines rather than bubbles.
|
|
bool get terminal => transcript == TranscriptStyle.prompt;
|
|
|
|
/// The tokens of the theme at [context]; [standard] when it has none.
|
|
static AppDesignTokens of(BuildContext context) =>
|
|
Theme.of(context).extension<AppDesignTokens>() ?? standard;
|
|
|
|
/// [designed] as this design draws it: the widget's own shape, or a
|
|
/// rectangle with [radius] corners.
|
|
OutlinedBorder shape(OutlinedBorder designed) {
|
|
final r = radius;
|
|
if (r == null) return designed;
|
|
return RoundedRectangleBorder(borderRadius: BorderRadius.circular(r));
|
|
}
|
|
|
|
/// [designed] corners, or [radius] corners under a design that sets it.
|
|
BorderRadius corners(BorderRadius designed) {
|
|
final r = radius;
|
|
return r == null ? designed : BorderRadius.circular(r);
|
|
}
|
|
|
|
/// [designed] corners, or [radius] corners under a dense design: for the
|
|
/// surfaces whose own corners the comfortable designs keep (floating
|
|
/// windows, search thumbnails), so only a dense design rounds them alike.
|
|
BorderRadius denseCorners(BorderRadius designed) =>
|
|
density.dense ? corners(designed) : designed;
|
|
|
|
/// [designed] (a widget's own fill) or, under a flat design, its [panel].
|
|
Color panelFill(ColorScheme scheme, Color designed) =>
|
|
flat ? panel ?? scheme.surfaceContainerLow : designed;
|
|
|
|
/// The hairline a flat design frames its panels with; null keeps none.
|
|
BorderSide? get frameSide {
|
|
final color = frame;
|
|
return color == null ? null : BorderSide(color: color);
|
|
}
|
|
|
|
@override
|
|
AppDesignTokens copyWith({
|
|
AppDesign? design,
|
|
double? radius,
|
|
bool? flat,
|
|
Color? frame,
|
|
Color? panel,
|
|
AnsiAccents? ansi,
|
|
String? promptGlyph,
|
|
TranscriptStyle? transcript,
|
|
ComposerStyle? composer,
|
|
SelectedRowStyle? selectedRow,
|
|
ReadingType? reading,
|
|
double? chatColorSaturation,
|
|
DesignDensity? density,
|
|
}) => AppDesignTokens(
|
|
design: design ?? this.design,
|
|
radius: radius ?? this.radius,
|
|
flat: flat ?? this.flat,
|
|
frame: frame ?? this.frame,
|
|
panel: panel ?? this.panel,
|
|
ansi: ansi ?? this.ansi,
|
|
promptGlyph: promptGlyph ?? this.promptGlyph,
|
|
transcript: transcript ?? this.transcript,
|
|
composer: composer ?? this.composer,
|
|
selectedRow: selectedRow ?? this.selectedRow,
|
|
reading: reading ?? this.reading,
|
|
chatColorSaturation: chatColorSaturation ?? this.chatColorSaturation,
|
|
density: density ?? this.density,
|
|
);
|
|
|
|
// Value equality keeps a rebuilt theme equal to the one it replaces, so
|
|
// Theme dependents do not rebuild and MaterialApp starts no theme
|
|
// animation when a host rebuilds for another reason.
|
|
@override
|
|
bool operator ==(Object other) =>
|
|
other is AppDesignTokens &&
|
|
other.design == design &&
|
|
other.radius == radius &&
|
|
other.flat == flat &&
|
|
other.frame == frame &&
|
|
other.panel == panel &&
|
|
other.ansi == ansi &&
|
|
other.promptGlyph == promptGlyph &&
|
|
other.transcript == transcript &&
|
|
other.composer == composer &&
|
|
other.selectedRow == selectedRow &&
|
|
other.reading == reading &&
|
|
other.chatColorSaturation == chatColorSaturation &&
|
|
other.density == density;
|
|
|
|
@override
|
|
int get hashCode => Object.hash(
|
|
design,
|
|
radius,
|
|
flat,
|
|
frame,
|
|
panel,
|
|
ansi,
|
|
promptGlyph,
|
|
transcript,
|
|
composer,
|
|
selectedRow,
|
|
reading,
|
|
chatColorSaturation,
|
|
density,
|
|
);
|
|
|
|
/// Designs switch whole: a theme animation snaps halfway rather than
|
|
/// blending two designs' shapes.
|
|
@override
|
|
AppDesignTokens lerp(AppDesignTokens? other, double t) =>
|
|
other == null || t < 0.5 ? this : other;
|
|
}
|