Files
pipelines/app/lib/shell/navigation_rail.dart
T
alan b59ab5fad7 Terminal round 3: readable palettes, panel and card sizing, rail, tabs
- Colours: terminal background is the theme's lowest surface; the 16 ANSI
  colours come from a chosen palette (Theme colours, Classic, Calm, Vivid;
  Settings > Terminal > Colours, saved as `palette`) adjusted in lightness
  to the background: colours 4.5:1, bright ones lighter than normal,
  white light and black dark in both themes so white-on-red/blue/magenta
  and black-on-green/yellow/cyan (ls setuid, setgid, sticky) keep 3:1.
  Selection, find matches and the current match keep text at 4.5:1.
- Bottom panel opens at 40% of the window, at least 16 rows, until
  dragged; the dragged height is remembered (old saved 300 px default
  reads as never resized).
- Navigation rail scrolls its tabs (and below 240 px Settings too), so
  items never overlap under a tall panel.
- Chat command cards: Expand / Collapse grows a live terminal to 60% of
  the window (finished output only to its rows); collapsed stays 12 rows.
- Terminal tabs: ellipsised titles (220 px) with the whole title in the
  tooltip, selected tab filled, outlined and bold, close buttons are
  IconButtons (48 px touch, 40 px desktop).
- Capture fixture: ?terminalColors=1 and ?terminalPalette=.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 02:25:16 +00:00

181 lines
6.7 KiB
Dart

import 'package:flutter/material.dart';
import 'destination.dart';
import 'list_detail_policy.dart';
/// The width of the destination rail on a wide window.
const double kNavigationRailWidth = 96;
/// The rail with its divider: what the rail takes from a wide window's width.
const double kNavigationRailSpace = kNavigationRailWidth + 1;
/// The narrowest window that shows the destination rail: the list-detail
/// minimum for the body beside it, plus the rail and its divider (the space the
/// shell takes from the window). Narrower windows keep the floating destination
/// bar, unchanged.
const double kNavigationRailMinWindowWidth =
kListDetailMinWidth + kNavigationRailSpace;
/// The rail's height below which Settings scrolls with the tabs instead of
/// staying pinned to the rail's foot: room for Settings and about two tabs.
const double kNavigationRailPinnedSettingsMinHeight = 240;
/// Whether the window at [context] shows the destination rail. Read from the
/// window's own [MediaQuery], so the shell and the floating windows layer
/// (which sits above the shell) agree.
bool showsNavigationRail(BuildContext context) =>
MediaQuery.sizeOf(context).width >= kNavigationRailMinWindowWidth;
/// Whether the window shows the floating tab bar alone: wide enough for a list
/// beside an open item, too narrow for the rail. That bar lists the tabs only,
/// so there Settings is reached from the Pipelines bar's gear.
bool showsFloatingTabBarOnly(BuildContext context) =>
showsListBesideDetail(context) && !showsNavigationRail(context);
/// The wide layout's left-edge navigation: a Material [NavigationRail] with
/// an icon and a label per tab, the selected tab marked by the rail's
/// indicator, and Settings pinned to its bottom.
///
/// The tabs scroll when the rail is too short for them (a tall terminal
/// panel shrinks the app above it), and on a very short rail Settings
/// scrolls with them, so items never overlap at any height.
///
/// [icon] builds each tab's icon (its running or unread badge included), so
/// the rail shows the same counts the floating bar did. [selected] is the
/// shell's destination: Settings (a page, not a tab) selects no tab but its
/// own item.
class ShellNavigationRail extends StatelessWidget {
const ShellNavigationRail({
super.key,
required this.selected,
required this.icon,
required this.onSelected,
this.padding = EdgeInsets.zero,
});
final AppDestination selected;
final Widget Function(AppDestination destination) icon;
final ValueChanged<AppDestination> onSelected;
/// The system insets the rail keeps clear of: the status bar above and the
/// navigation bar below.
final EdgeInsets padding;
@override
Widget build(BuildContext context) {
final index = shellTabDestinations.indexOf(selected);
final surface = Theme.of(context).colorScheme.surface;
// The surface runs under the top inset too: the padding only moves the
// rail's content below the system's top, so no unpainted strip shows above
// the rail's background.
return ColoredBox(
key: const ValueKey('shell.navigation-rail.surface'),
color: surface,
child: Padding(
padding: padding,
child: SizedBox(
width: kNavigationRailWidth,
child: LayoutBuilder(
builder: (context, constraints) => _rail(
index,
surface,
pinSettings:
constraints.maxHeight >=
kNavigationRailPinnedSettingsMinHeight,
),
),
),
),
);
}
Widget _rail(int index, Color surface, {required bool pinSettings}) =>
NavigationRail(
key: const ValueKey('shell.navigation-rail'),
backgroundColor: surface,
minWidth: kNavigationRailWidth,
labelType: NavigationRailLabelType.all,
selectedIndex: index < 0 ? null : index,
onDestinationSelected: (value) =>
onSelected(shellTabDestinations[value]),
destinations: [
for (final destination in shellTabDestinations)
NavigationRailDestination(
icon: KeyedSubtree(
key: ValueKey('shell.destination.${destination.name}'),
// The bar it replaces named each tab in a tooltip too.
child: Tooltip(
message: destinationDetails(destination).label,
child: icon(destination),
),
),
label: Text(destinationDetails(destination).label),
),
],
scrollable: true,
trailingAtBottom: pinSettings,
trailing: _SettingsRailItem(
selected: selected == AppDestination.settings,
onTap: () => onSelected(AppDestination.settings),
),
);
}
/// Settings at the rail's foot, drawn as a [NavigationRailDestination] is: an
/// icon on a stadium indicator with its label under it, and the same colours.
/// It is not a [NavigationRailDestination] itself because the rail's
/// destination list is the tabs, and `trailing` is what the rail pins.
class _SettingsRailItem extends StatelessWidget {
const _SettingsRailItem({required this.selected, required this.onTap});
final bool selected;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final item = destinationDetails(AppDestination.settings);
final foreground = selected
? scheme.onSecondaryContainer
: scheme.onSurfaceVariant;
final textStyle = Theme.of(context).textTheme.labelMedium?.copyWith(
color: foreground,
fontWeight: selected ? FontWeight.w600 : FontWeight.w500,
);
return Semantics(
button: true,
selected: selected,
label: item.label,
child: ExcludeSemantics(
child: InkWell(
key: const ValueKey('shell.destination.settings'),
onTap: onTap,
child: SizedBox(
width: kNavigationRailWidth,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 56,
height: 32,
alignment: Alignment.center,
decoration: ShapeDecoration(
shape: const StadiumBorder(),
color: selected ? scheme.secondaryContainer : null,
),
child: Icon(item.icon, color: foreground),
),
const SizedBox(height: 4),
Text(item.label, style: textStyle),
],
),
),
),
),
),
);
}
}