101 lines
2.7 KiB
Dart
101 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'window_caption_controls.dart';
|
|
|
|
import 'package:cutdex_native/cutdex_native.dart';
|
|
|
|
/// Shared native titlebar layout; a close callback opts into editor navigation.
|
|
class EditorWindowChrome extends StatefulWidget {
|
|
const EditorWindowChrome({
|
|
super.key,
|
|
required this.headerHeight,
|
|
this.onCloseRequested,
|
|
required this.builder,
|
|
});
|
|
|
|
static const trafficLightWidth = 88.0;
|
|
static bool get isWindows => WindowChromeSession.isWindows;
|
|
static double get leadingWidth => isWindows ? 0 : trafficLightWidth;
|
|
final double headerHeight;
|
|
final VoidCallback? onCloseRequested;
|
|
final Widget Function(BuildContext context, bool integrated) builder;
|
|
|
|
@override
|
|
State<EditorWindowChrome> createState() => _EditorWindowChromeState();
|
|
}
|
|
|
|
class _EditorWindowChromeState extends State<EditorWindowChrome> {
|
|
late final _session = WindowChromeSession(
|
|
headerHeight: widget.headerHeight,
|
|
onCloseRequested: widget.onCloseRequested,
|
|
);
|
|
bool _integrated = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_session.addListener(_integrationChanged);
|
|
_session.attach();
|
|
}
|
|
|
|
void _integrationChanged() {
|
|
if (_integrated != _session.integrated) {
|
|
setState(() => _integrated = _session.integrated);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
super.didChangeDependencies();
|
|
_session.setInteractive(ModalRoute.of(context)?.isCurrent ?? true);
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant EditorWindowChrome oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
_session.configure(
|
|
headerHeight: widget.headerHeight,
|
|
onCloseRequested: widget.onCloseRequested,
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_session.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (!_integrated || !EditorWindowChrome.isWindows) {
|
|
return widget.builder(context, _integrated);
|
|
}
|
|
return LayoutBuilder(
|
|
builder: (context, constraints) => WindowHeaderLayout(
|
|
captionBounds: Rect.fromLTWH(
|
|
constraints.maxWidth - WindowCaptionControls.width,
|
|
0,
|
|
WindowCaptionControls.width,
|
|
WindowCaptionControls.buttonHeight,
|
|
),
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
Builder(builder: (context) => widget.builder(context, true)),
|
|
Positioned(
|
|
top: 0,
|
|
right: 0,
|
|
width: WindowCaptionControls.width,
|
|
height: WindowCaptionControls.buttonHeight,
|
|
child: WindowCaptionControls(
|
|
session: _session,
|
|
height: WindowCaptionControls.buttonHeight,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|