Files
cutdex/lib/integrations/platform/window_caption_controls.dart
T
lingjhf 1f73765745
Gitea CI / Windows x64 and Android (pull_request) Successful in 16m21s
Gitea CI / Gitea CI passed (pull_request) Successful in 3s
refactor(desktop): reorganize workspace panels and navigation
2026-10-06 12:11:59 +08:00

100 lines
3.0 KiB
Dart

import 'dart:async';
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,
Icons.remove,
context.l10n.windowMinimize,
),
_button(
context,
WindowCaptionCommand.toggleMaximize,
session.maximized ? Icons.filter_none : Icons.crop_square,
session.maximized
? context.l10n.windowRestore
: context.l10n.windowMaximize,
role: HeaderControlRole.maximize,
hovered: session.maximizeHovered,
),
_button(
context,
WindowCaptionCommand.close,
Icons.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,
),
),
),
),
);
}
}