Files
cutdex/lib/integrations/platform/editor_window_chrome.dart
T
lingjhf abc1868550
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
2026-10-08 18:17:12 +00:00

102 lines
2.8 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,
});
// Native button centers are 19, 39 and 59; their frames end around x=66.
static const trafficLightWidth = 68.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,
),
),
],
),
),
);
}
}