Files
pipelines/app/lib/shell/windows/window_frame.dart
T
alan a99f7014f5 Add the shell window host with layering acceptance tests
Phase 1.3 and 1.4 of docs/plans/floating-windows.md. Windows are plain
children of the terminal stage's stack in the shell page, outside every
destination, so popups opened from one are above all of them. Each window
has its own page navigator: pushed pages open inside the window, and popup
routes go to the root navigator. One WindowFrame chrome (move, resize,
minimise, maximise, close), a focus scope per window, a ScaffoldMessenger
per window.

No feature uses it yet. The capture fixture opens probe windows with
?windows=N, and window_layering_test.dart covers every popup type from a
window over Chat and over another destination.
2026-11-10 20:48:31 +00:00

161 lines
4.9 KiB
Dart

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'window_kind.dart';
const double windowCornerRadius = 12;
/// The height of a window's title bar: a compact row of icon buttons, taller
/// with larger text.
double windowTitleBarHeight(BuildContext context) =>
MediaQuery.textScalerOf(context).scale(40).clamp(40.0, 64.0);
/// A floating window's card and title bar: the title (drag to move, double
/// click to maximise), the kind's actions, then Minimise, Maximise and
/// Close. The content is drawn over the card's body by the window's
/// navigator.
class WindowFrame extends StatelessWidget {
const WindowFrame({
super.key,
required this.title,
required this.icon,
required this.actions,
required this.maximized,
required this.onMove,
required this.onMoveEnd,
required this.onMinimize,
required this.onToggleMaximized,
required this.onClose,
});
final String title;
final IconData icon;
final List<WindowAction> actions;
final bool maximized;
final ValueChanged<Offset> onMove;
final VoidCallback onMoveEnd;
final VoidCallback onMinimize;
final VoidCallback onToggleMaximized;
final VoidCallback onClose;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final colors = theme.colorScheme;
return Material(
elevation: 8,
clipBehavior: Clip.antiAlias,
borderRadius: BorderRadius.circular(windowCornerRadius),
color: colors.surfaceContainer,
child: Align(
alignment: Alignment.topCenter,
child: SizedBox(
height: windowTitleBarHeight(context),
child: IconButtonTheme(
data: IconButtonThemeData(
style: IconButton.styleFrom(
visualDensity: VisualDensity.compact,
foregroundColor: colors.onSurfaceVariant,
),
),
child: Row(
children: [
Expanded(child: _title(theme)),
for (final action in actions)
IconButton(
tooltip: action.label,
onPressed: action.onPressed,
icon: Icon(action.icon),
),
IconButton(
tooltip: 'Minimise',
onPressed: onMinimize,
icon: const Icon(Icons.minimize),
),
IconButton(
tooltip: maximized ? 'Restore size' : 'Maximise',
onPressed: onToggleMaximized,
icon: Icon(
maximized ? Icons.fullscreen_exit : Icons.fullscreen,
),
),
IconButton(
tooltip: 'Close',
onPressed: onClose,
icon: const Icon(Icons.close),
),
const SizedBox(width: 4),
],
),
),
),
),
);
}
Widget _title(ThemeData theme) => MouseRegion(
cursor: maximized ? SystemMouseCursors.basic : SystemMouseCursors.move,
child: GestureDetector(
key: const ValueKey('window-title'),
behavior: HitTestBehavior.opaque,
// The window follows the pointer from where it went down.
dragStartBehavior: DragStartBehavior.down,
onPanUpdate: maximized ? null : (details) => onMove(details.delta),
onPanEnd: maximized ? null : (_) => onMoveEnd(),
onDoubleTap: onToggleMaximized,
child: Padding(
padding: const EdgeInsetsDirectional.only(start: 12, end: 8),
child: Row(
children: [
Icon(icon, size: 18, color: theme.colorScheme.onSurfaceVariant),
const SizedBox(width: 8),
Expanded(
child: Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.titleSmall,
),
),
],
),
),
),
);
}
/// The lower right corner of a window: drag to resize.
class WindowResizeCorner extends StatelessWidget {
const WindowResizeCorner({
super.key,
required this.onResize,
required this.onResizeEnd,
});
final ValueChanged<Offset> onResize;
final VoidCallback onResizeEnd;
@override
Widget build(BuildContext context) => Semantics(
label: 'Resize window',
child: MouseRegion(
cursor: SystemMouseCursors.resizeDownRight,
child: GestureDetector(
key: const ValueKey('window-resize'),
behavior: HitTestBehavior.opaque,
dragStartBehavior: DragStartBehavior.down,
onPanUpdate: (details) => onResize(details.delta),
onPanEnd: (_) => onResizeEnd(),
child: Padding(
padding: const EdgeInsets.all(2),
child: Icon(
Icons.south_east,
size: 16,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
),
);
}