feat(garage_ui): PageHeading, a real extraBold, and a mono that chains
The weight helpers went through _StyledText, which merges a style naming one property and lets everything else in scope stand. That works for a colour and it doesnt work for a weight: google_fonts encodes the weight in the family NAME, so merging w800 over an already resolved family changes no font file and skia synthesises instead. Skia has one fake bold, so w600, w700 and w800 all came out the same stroke and extraBold was indistinguishable from bold. They re-resolve the family now, keeping whichever face is in scope, so .mono().bold() and .bold().mono() both land on the real mono bold. PageHeading is lifted out of the hub, where it was drawn by hand above every section. A&A's licence page wanted the same block and a lookalike drifts from the original inside a day. pageGutter and propertiesSectionGap are new density tokens. Both were local magic numbers - `fontSize * 3` copied into every app that copied the hub, and a flat gapLg that a dense editor pane full of sections wears badly. garage_auth takes an optional handoff code on signIn/beginSignIn and sends it as _handoff, so a desktop build can hand its user to the web one without a second sign in. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FkzfwZf59HNP6R8jXcC1NR
This commit is contained in:
@@ -35,6 +35,7 @@ export "misc.dart";
|
||||
export "color_input.dart";
|
||||
export "date_input.dart";
|
||||
export "panel.dart";
|
||||
export "page_heading.dart";
|
||||
export "editor_chrome.dart";
|
||||
export "context_menu.dart";
|
||||
export "properties.dart";
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import "package:flutter/widgets.dart";
|
||||
|
||||
import "surface.dart";
|
||||
import "theme/garage_theme.dart";
|
||||
import "theme/theme_data.dart";
|
||||
|
||||
/// The heading a page wears above its content.
|
||||
///
|
||||
/// The name a step up, a muted line under it saying what youre looking at,
|
||||
/// both left aligned on the same margin as whatever follows. Promoted out of
|
||||
/// the hub, where it was drawn over every section, because A&A's licence page
|
||||
/// wanted the same thing and a lookalike drifts from the real one within a day
|
||||
/// of being written.
|
||||
///
|
||||
/// Its a heading, not a bar - nothing chrome coloured, no rule under it, no
|
||||
/// height of its own beyond what the two lines need. A pane that wants a strip
|
||||
/// across the top of it wants [ChromeBar] instead.
|
||||
class PageHeading extends StatelessWidget {
|
||||
/// How tall this comes out, for a page that needs to know what room is
|
||||
/// left under it.
|
||||
///
|
||||
/// Derived rather than measured: title on [Density.textLg] over a subtitle
|
||||
/// on the ambient font, both on Geist's own line box, with a gapXs between.
|
||||
/// A layout that has to wait for a frame to find this out cant use it on
|
||||
/// the frame it needs it.
|
||||
static double heightIn(Density d) =>
|
||||
(d.textLg * Density.geistLineRatio).roundToDouble() +
|
||||
d.gapXs +
|
||||
(d.fontSize * Density.geistLineRatio).roundToDouble();
|
||||
|
||||
const PageHeading({
|
||||
required this.title,
|
||||
this.subtitle,
|
||||
this.trailing,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
|
||||
/// Sits at the far end of the heading, vertically centred on the whole
|
||||
/// block rather than on the title line.
|
||||
///
|
||||
/// For the one action that belongs to the SUBJECT rather than to a section
|
||||
/// of it - Disconnect on an agent, and the like.
|
||||
final Widget? trailing;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = GarageTheme.of(context);
|
||||
final density = theme.density;
|
||||
|
||||
final heading = Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(title, style: theme.typography.normal).large(),
|
||||
if (subtitle != null) ...[
|
||||
const Gap.xs(),
|
||||
Text(
|
||||
subtitle!,
|
||||
style: TextStyle(color: theme.colorScheme.mutedForeground),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
// Nudged in by gapXs: thats the side margin a PropertiesSection carries on
|
||||
// itself, and without it a heading starts LEFT of the sections it
|
||||
// introduces - the sort of thing you cant unsee once youve seen it.
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: density.gapXs),
|
||||
child: trailing == null
|
||||
? heading
|
||||
: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(child: heading),
|
||||
Gap(density.gapMd),
|
||||
trailing!,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -519,19 +519,18 @@ class PropertiesSection extends StatelessWidget {
|
||||
color: scheme.mutedForeground,
|
||||
);
|
||||
return Container(
|
||||
// bottom is gapLg, not gapXs: this margin is what separates one section
|
||||
// from the NEXT one, and gapXs is the step used between ROWS INSIDE a
|
||||
// section - so at gapXs a run of sections read as one striped block
|
||||
// rather than as separate subjects, which is the whole point of giving
|
||||
// each one its own. Three times the inner step, so the boundary between
|
||||
// two sections is unambiguously bigger than the boundary between two
|
||||
// rows. The sides stay gapXs; thats an inset from the pane edge, a
|
||||
// different job.
|
||||
// bottom is its own token, not gapXs: this margin is what separates one
|
||||
// section from the NEXT one, and gapXs is the step used between ROWS
|
||||
// INSIDE a section - so at gapXs a run of sections read as one striped
|
||||
// block rather than as separate subjects, which is the whole point of
|
||||
// giving each one its own. It used to be gapLg flat, which a dense
|
||||
// editor pane full of sections wears badly, hence the dial. The sides
|
||||
// stay gapXs; thats an inset from the pane edge, a different job.
|
||||
margin: EdgeInsets.fromLTRB(
|
||||
density.gapXs,
|
||||
0,
|
||||
density.gapXs,
|
||||
density.gapLg,
|
||||
density.propertiesSectionGap,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.card,
|
||||
|
||||
@@ -96,6 +96,7 @@ class Density {
|
||||
// ---- container-level spacing (panels, popovers, dialogs) ----
|
||||
this.containerGap = 8.0,
|
||||
this.containerPadding = 16.0,
|
||||
this.propertiesSectionGap = 6.0,
|
||||
|
||||
// ---- optical ----
|
||||
this.controlTextOffset = 0.0,
|
||||
@@ -123,6 +124,7 @@ class Density {
|
||||
listRowIndent = 12.0,
|
||||
containerGap = 10.0,
|
||||
containerPadding = 20.0,
|
||||
propertiesSectionGap = 15.0,
|
||||
controlTextOffset = 0.0;
|
||||
|
||||
/// The product tier - for the Garage web apps rather than for A&A.
|
||||
@@ -156,6 +158,7 @@ class Density {
|
||||
listRowIndent = 10.0,
|
||||
containerGap = 10.0,
|
||||
containerPadding = 20.0,
|
||||
propertiesSectionGap = 15.0,
|
||||
controlTextOffset = 0.0;
|
||||
|
||||
/// Which tier this token set represents.
|
||||
@@ -230,6 +233,19 @@ class Density {
|
||||
/// and `baseContainerPadding`, which always held the same value.)
|
||||
final double containerPadding;
|
||||
|
||||
/// What separates one properties section from the NEXT one.
|
||||
///
|
||||
/// Its own token rather than a step off the gap ladder, because the right
|
||||
/// answer genuinely isnt the same at every density. A dashboard has a
|
||||
/// handful of sections and wants air around each so they read as separate
|
||||
/// subjects; an editor pane stacks eight of them down a 300px column and
|
||||
/// the air is the thing thats in short supply. Same widget, opposite
|
||||
/// pressures - so the number is a dial, not a derivation.
|
||||
///
|
||||
/// Whatever its set to it must stay clearly bigger than the gap between two
|
||||
/// ROWS inside a section, or a run of sections reads as one striped block.
|
||||
final double propertiesSectionGap;
|
||||
|
||||
// ---- optical ----
|
||||
|
||||
/// Downward nudge applied to control content so it sits on its optical
|
||||
@@ -443,6 +459,14 @@ class Density {
|
||||
|
||||
/// The largest step - page-level separation, above the panel scale.
|
||||
double get gapXxl => controlGap * 6;
|
||||
|
||||
/// The inset a page's reading column takes either side, beside a rail.
|
||||
///
|
||||
/// Off the font, not the gap ladder: its measured against the text it
|
||||
/// frames, 48 at product. Wrong on a phone - a 390pt screen loses a quarter
|
||||
/// of itself to it - so a phone page wants [gapMd] instead. Was a local
|
||||
/// `fontSize * 3` in the hub and in every app copying the hub.
|
||||
double get pageGutter => fontSize * 3;
|
||||
}
|
||||
|
||||
/// Icon sizes. `small` is the control icon and is derived from the density's
|
||||
|
||||
@@ -70,23 +70,89 @@ extension TextStyleExtension on Widget {
|
||||
style: (t) => TextStyle(fontSize: t.density.textLg),
|
||||
);
|
||||
|
||||
Widget medium() => _StyledText(
|
||||
child: this,
|
||||
style: (t) => const TextStyle(fontWeight: FontWeight.w500),
|
||||
);
|
||||
Widget semiBold() => _StyledText(
|
||||
child: this,
|
||||
style: (t) => const TextStyle(fontWeight: FontWeight.w600),
|
||||
);
|
||||
Widget bold() => _StyledText(
|
||||
child: this,
|
||||
style: (t) => const TextStyle(fontWeight: FontWeight.w700),
|
||||
);
|
||||
// these DONT go through _StyledText. Merging `fontWeight: w800` over an
|
||||
// already resolved google_fonts family changes nothing about which font
|
||||
// FILE gets used - the file is the weight - so skia synthesises instead,
|
||||
// and skia has exactly one fake bold. w600, w700 and w800 all came out the
|
||||
// same stroke, which is how extraBold ended up looking identical to bold.
|
||||
Widget medium() => _WeightText(child: this, weight: FontWeight.w500);
|
||||
Widget semiBold() => _WeightText(child: this, weight: FontWeight.w600);
|
||||
Widget bold() => _WeightText(child: this, weight: FontWeight.w700);
|
||||
|
||||
/// Top of the ladder. A display weight - for a figure or a name somebody is
|
||||
/// meant to read across a desk, not for body copy.
|
||||
Widget extraBold() => _WeightText(child: this, weight: FontWeight.w800);
|
||||
|
||||
Widget muted() => _StyledText(
|
||||
child: this,
|
||||
style: (t) => TextStyle(color: t.colorScheme.mutedForeground),
|
||||
);
|
||||
|
||||
/// Geist Mono, keeping whatever size, weight and colour are already in
|
||||
/// scope.
|
||||
///
|
||||
/// Chains in either order - `.mono().bold()` and `.bold().mono()` both land
|
||||
/// on the real mono bold, because the weight helpers re-resolve whichever
|
||||
/// family they find in scope rather than assuming sans.
|
||||
///
|
||||
/// Only w300 and w700 are in main.dart's `pendingFonts`. Any other weight
|
||||
/// resolves fine and lands a frame or two late.
|
||||
Widget mono() => _MonoText(child: this);
|
||||
}
|
||||
|
||||
// mono cant ride on _StyledText the way the weights do. those merge a style
|
||||
// naming ONE property and dont care what else is in scope, so they compose in
|
||||
// any order. A family out of google_fonts isnt one property - the family name
|
||||
// encodes the weight - so this one has to read the inherited style first and
|
||||
// hand the whole thing over to be re-resolved.
|
||||
// re-resolves the family for the weight it's setting, keeping whichever face
|
||||
// is already in scope. sans unless somebody put mono there first.
|
||||
class _WeightText extends StatelessWidget {
|
||||
const _WeightText({required this.child, required this.weight});
|
||||
|
||||
final Widget child;
|
||||
final FontWeight weight;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = GarageTheme.of(context);
|
||||
final inherited = DefaultTextStyle.of(context).style;
|
||||
final wanted = inherited.copyWith(fontWeight: weight);
|
||||
|
||||
// google_fonts names a family "<Family>_<weight>", so the bit before the
|
||||
// underscore is the face. taken off typography.mono rather than spelled
|
||||
// out, so renaming the font doesnt quietly turn every .bold() on a mono
|
||||
// run back into sans.
|
||||
String? face(String? family) => family?.split("_").first;
|
||||
final isMono = face(inherited.fontFamily) == face(theme.typography.mono.fontFamily);
|
||||
|
||||
return DefaultTextStyle.merge(
|
||||
style: isMono
|
||||
? theme.typography.monoStyle(wanted)
|
||||
: theme.typography.sansStyle(wanted),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MonoText extends StatelessWidget {
|
||||
const _MonoText({required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = GarageTheme.of(context);
|
||||
|
||||
// .of(context), not the theme: this is the point of the class. everything
|
||||
// a caller stacked ABOVE this widget is already merged into here.
|
||||
final inherited = DefaultTextStyle.of(context).style;
|
||||
|
||||
return DefaultTextStyle.merge(
|
||||
style: theme.typography.monoStyle(inherited),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
typedef _StyleFromTheme = TextStyle Function(ThemeData theme);
|
||||
|
||||
Reference in New Issue
Block a user