Files
cutdex/lib/integrations/platform/window_caption_controls.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

101 lines
3.0 KiB
Dart

import 'dart:async';
import 'package:cutdex_ui/icons.dart';
import 'package:flutter/material.dart';
import '../../l10n/l10n.dart';
import 'package:cutdex_native/cutdex_native.dart';
/// Windows caption buttons; native window state only rebuilds this strip.
class WindowCaptionControls extends StatelessWidget {
const WindowCaptionControls({
super.key,
required this.session,
required this.height,
});
static const buttonWidth = 46.0;
static const buttonHeight = 38.0;
static const width = buttonWidth * 3;
final WindowChromeSession session;
final double height;
@override
Widget build(BuildContext context) => ListenableBuilder(
listenable: session,
builder: (context, _) => Material(
type: MaterialType.transparency,
child: Row(
children: [
_button(
context,
WindowCaptionCommand.minimize,
AppIcons.remove,
context.l10n.windowMinimize,
),
_button(
context,
WindowCaptionCommand.toggleMaximize,
session.maximized ? AppIcons.windowRestore : AppIcons.square,
session.maximized
? context.l10n.windowRestore
: context.l10n.windowMaximize,
role: HeaderControlRole.maximize,
hovered: session.maximizeHovered,
),
_button(
context,
WindowCaptionCommand.close,
AppIcons.close,
MaterialLocalizations.of(context).closeButtonTooltip,
),
],
),
),
);
Widget _button(
BuildContext context,
WindowCaptionCommand command,
IconData icon,
String label, {
HeaderControlRole role = HeaderControlRole.control,
bool hovered = false,
}) {
final colors = Theme.of(context).colorScheme;
final close = command == WindowCaptionCommand.close;
final key = command == WindowCaptionCommand.toggleMaximize
? 'maximize'
: command.name;
return HeaderControlRegion(
role: role,
child: SizedBox(
width: buttonWidth,
height: height,
child: IconButton(
key: Key('window-$key'),
tooltip: label,
onPressed: () => unawaited(session.perform(command)),
icon: Icon(icon, size: 16),
style: ButtonStyle(
padding: const WidgetStatePropertyAll(EdgeInsets.zero),
shape: const WidgetStatePropertyAll(RoundedRectangleBorder()),
backgroundColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.hovered) || hovered
? close
? const Color(0xffc42b1c)
: colors.onSurface.withValues(alpha: 0.08)
: Colors.transparent,
),
foregroundColor: WidgetStateProperty.resolveWith(
(states) => close && states.contains(WidgetState.hovered)
? Colors.white
: colors.onSurface,
),
),
),
),
);
}
}