Files
pipelines/app/lib/ui/theme/glass_style.dart
T

174 lines
4.9 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart';
/// One soft glow of a [GlassBackdropMesh]: a radial wash of [color] centred
/// at [center] (alignment over the window) reaching [radius] of the window's
/// longer side, fading to nothing at its edge.
@immutable
class GlassGlow {
const GlassGlow(this.center, this.radius, this.color);
final Alignment center;
final double radius;
final Color color;
@override
bool operator ==(Object other) =>
other is GlassGlow &&
other.center == center &&
other.radius == radius &&
other.color == color;
@override
int get hashCode => Object.hash(center, radius, color);
}
/// The still gradient a glass design paints behind the whole app: a [base]
/// with a few large, soft [glows] laid over it, like a mesh gradient. It is
/// painted once per page and never animates.
@immutable
class GlassBackdropMesh {
const GlassBackdropMesh({required this.base, required this.glows});
final Color base;
final List<GlassGlow> glows;
@override
bool operator ==(Object other) =>
other is GlassBackdropMesh &&
other.base == base &&
listEquals(other.glows, glows);
@override
int get hashCode => Object.hash(base, Object.hashAll(glows));
}
/// A glass design's translucent surfaces ([AppDesignTokens.glass]): what it
/// paints behind the app, the tints of its panes and bars, the fill and edge
/// of the cards inset in them, the glow of an open row, and how far it grows
/// the corners widgets draw.
///
/// Only the bars, the composer and floating pieces blur what is behind them
/// (`GlassPill`); panes, cards and bubbles are tints over the backdrop, so
/// a list or a transcript scrolls without any backdrop filter.
@immutable
class GlassStyle {
const GlassStyle({
required this.backdrop,
required this.rail,
required this.pane,
required this.detail,
required this.bar,
required this.solid,
required this.card,
required this.highlight,
required this.edge,
required this.shadow,
required this.slab,
this.glow = 0.4,
this.cornerScale = 1.5,
this.cornerCap = 20,
});
/// The gradient behind every page.
final GlassBackdropMesh backdrop;
/// The navigation rail's tint over the backdrop; clear when the backdrop
/// already carries it.
final Color rail;
/// A list pane's tint over the backdrop; clear when the backdrop already
/// carries it (cheaper: no full-window blend per frame).
final Color pane;
/// The open item's (reading) pane: a stronger tint, so long text reads on
/// an even ground.
final Color detail;
/// The fill of a frosted bar, the composer and floating pieces, over the
/// blur of what is behind them.
final Color bar;
/// An opaque stand-in for the translucent fills where nothing may show
/// through (high contrast, a piece floating over unrelated content).
final Color solid;
/// The fill of a glass card inset in a pane: code blocks, follow-up notes,
/// the tool-activity chip.
final Color card;
/// The thin light line along a glass surface's top edge.
final Color highlight;
/// The faint hairline around the rest of a glass surface.
final Color edge;
/// The soft shadow under a raised glass surface.
final Color shadow;
/// The open list row's brighter slab.
final Color slab;
/// How strong an open row's glow ring is, as the accent's alpha.
final double glow;
/// How much a widget's own corner radius grows (outer > inner is kept:
/// every radius grows by the same factor), up to [cornerCap]; a radius
/// already past the cap is kept.
final double cornerScale;
final double cornerCap;
/// [radius] grown by [cornerScale] up to [cornerCap].
double corner(double radius) {
if (radius >= cornerCap) return radius;
final grown = radius * cornerScale;
return grown > cornerCap ? cornerCap : grown;
}
/// [designed] with every corner grown by [corner].
BorderRadius corners(BorderRadius designed) => BorderRadius.only(
topLeft: _grow(designed.topLeft),
topRight: _grow(designed.topRight),
bottomLeft: _grow(designed.bottomLeft),
bottomRight: _grow(designed.bottomRight),
);
Radius _grow(Radius r) => Radius.elliptical(corner(r.x), corner(r.y));
@override
bool operator ==(Object other) =>
other is GlassStyle &&
other.backdrop == backdrop &&
other.rail == rail &&
other.pane == pane &&
other.detail == detail &&
other.bar == bar &&
other.solid == solid &&
other.card == card &&
other.highlight == highlight &&
other.edge == edge &&
other.shadow == shadow &&
other.slab == slab &&
other.glow == glow &&
other.cornerScale == cornerScale &&
other.cornerCap == cornerCap;
@override
int get hashCode => Object.hash(
backdrop,
rail,
pane,
detail,
bar,
solid,
card,
highlight,
edge,
shadow,
slab,
glow,
cornerScale,
cornerCap,
);
}