fdc730422d
Phase 2.3 and 2.4 of docs/plans/floating-windows.md. A floating chat is a window of the chat kind over the app's WindowManager, built from the app-lifetime ChatRuntime, so it shows over every destination and at start without the Chat destination being built. Float and Dock move the same keyed view between the tiling and the window host. The pipelines app keeps one runtime and one ChatWindows; saved chatFloat records (v1 and v2) are brought over once. ChatFloatHost, ChatFloatWindow, the float frames and binding, the controller's float list and FloatingFocusRoot are gone; the workspace only asks whether a chat is out in a window. Every MenuAnchor targets the root overlay (guarded by a test), and menus and tooltips name the Alt chords.
100 lines
3.0 KiB
Dart
100 lines
3.0 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
/// A layer of floating windows painted in the app's root overlay, above the
|
|
/// page, while it keeps its place in the tree (its inherited widgets, focus
|
|
/// and state stay where it is built). Every [FloatingLayer] shares that one
|
|
/// overlay. Only the terminal's floating window still uses it; the app's
|
|
/// other windows are in the shell's window host.
|
|
///
|
|
/// [builder] returns the windows as [Positioned] children of a [Stack] the
|
|
/// size of [bounds]: this widget's own box, or the whole overlay when
|
|
/// [coverOverlay] is set. Space between windows takes no input. Without an
|
|
/// overlay (a bare widget test) the layer paints in place.
|
|
class FloatingLayer extends StatefulWidget {
|
|
const FloatingLayer({
|
|
super.key,
|
|
required this.builder,
|
|
this.open = true,
|
|
this.coverOverlay = false,
|
|
});
|
|
|
|
final List<Widget> Function(BuildContext context, Size bounds) builder;
|
|
|
|
/// Turning true brings the layer to the top, as its window opens.
|
|
final bool open;
|
|
|
|
final bool coverOverlay;
|
|
|
|
@override
|
|
State<FloatingLayer> createState() => _FloatingLayerState();
|
|
}
|
|
|
|
class _FloatingLayerState extends State<FloatingLayer> {
|
|
final OverlayPortalController _portal = OverlayPortalController(
|
|
debugLabel: 'floating layer',
|
|
);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_portal.show();
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant FloatingLayer oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (widget.open && !oldWidget.open) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => _raise());
|
|
}
|
|
}
|
|
|
|
void _raise() {
|
|
if (mounted) _portal.show();
|
|
}
|
|
|
|
Widget _layer(BuildContext context, Size bounds) => Listener(
|
|
behavior: HitTestBehavior.deferToChild,
|
|
onPointerDown: (_) => _raise(),
|
|
child: Focus(
|
|
canRequestFocus: false,
|
|
skipTraversal: true,
|
|
onFocusChange: (focused) {
|
|
if (focused) _raise();
|
|
},
|
|
child: SizedBox.fromSize(
|
|
size: bounds,
|
|
child: Stack(
|
|
clipBehavior: Clip.none,
|
|
children: widget.builder(context, bounds),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (Overlay.maybeOf(context, rootOverlay: true) == null) {
|
|
return LayoutBuilder(
|
|
builder: (context, constraints) => _layer(context, constraints.biggest),
|
|
);
|
|
}
|
|
return OverlayPortal.overlayChildLayoutBuilder(
|
|
controller: _portal,
|
|
overlayLocation: OverlayChildLocation.rootOverlay,
|
|
overlayChildBuilder: (context, info) => widget.coverOverlay
|
|
? Positioned.fill(child: _layer(context, info.overlaySize))
|
|
: Positioned(
|
|
left: 0,
|
|
top: 0,
|
|
width: info.childSize.width,
|
|
height: info.childSize.height,
|
|
child: Transform(
|
|
transform: info.childPaintTransform,
|
|
child: _layer(context, info.childSize),
|
|
),
|
|
),
|
|
child: const SizedBox.expand(),
|
|
);
|
|
}
|
|
}
|