Files
pipelines/app/lib/shell/windows/window_frame.dart
T
alan ef1c120f57 Add the Windows menu, window cycling, edge snapping and size per kind
Phase 4 of docs/plans/floating-windows.md. A bar button lists the app's
windows on every tab (show one, Show all, Minimise all, Close all). Alt+`
and Alt+Shift+` bring the next or previous window to the front. Dropping a
title at the left or right edge fills that half, at the top it maximises.
A new window of a kind opens at the size that kind was last given.
2026-11-11 00:05:16 +00:00

165 lines
5.0 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;
/// The drag's delta and the pointer's global position.
final void Function(Offset delta, Offset globalPosition) 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, details.globalPosition),
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,
),
),
),
),
);
}