440995e31f
Run 299 removed the model and mode buttons' horizontal padding on desktop so the island's gap sets the spacing, which left their text touching the pill's rounded ends. The island now insets its content by 12 px.
174 lines
6.1 KiB
Dart
174 lines
6.1 KiB
Dart
import '../../../core/servers/server_context.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../ui/adaptive/segmented_bar.dart';
|
|
import '../../../ui/adaptive/segmented_bar_overflow.dart';
|
|
import '../ui/sessions/chat_adaptive.dart';
|
|
import 'chat_bar_tint.dart';
|
|
import '../workspace/chat_workspace_pane_scope.dart';
|
|
|
|
/// The open conversation's bar: the app's [SegmentedBar] above the
|
|
/// transcript.
|
|
///
|
|
/// From the leading edge: a round Back (only where the page can go back), a
|
|
/// pill with the conversation's title and folder that opens the chat's
|
|
/// information, a selector island holding [controls] (model and mode),
|
|
/// then the Files action and a native More menu in a separate island.
|
|
/// Narrow panes keep the model/mode selectors as compact icons in the same row;
|
|
/// their semantic labels and native pickers continue to expose the values.
|
|
///
|
|
/// A chat with a [chatColor] carries it in the bar: each glass piece is
|
|
/// filled with its shade over the raised surface and its labels and icons
|
|
/// take the colour's foreground ([chatBarTintOf]), faded in an inactive split
|
|
/// pane. A chat with none keeps the neutral bar.
|
|
class ChatThreadHeader extends StatelessWidget {
|
|
const ChatThreadHeader({
|
|
super.key,
|
|
required this.title,
|
|
required this.folder,
|
|
required this.onInfo,
|
|
this.showBack = false,
|
|
this.onBack,
|
|
this.controls = const [],
|
|
this.actions = const [],
|
|
this.moreActions = const [],
|
|
this.chatColor,
|
|
this.identity,
|
|
});
|
|
|
|
final String title;
|
|
|
|
/// The working folder's name, shown beneath the title; empty for none.
|
|
final String folder;
|
|
final VoidCallback onInfo;
|
|
|
|
/// Whether the bar shows Back at all.
|
|
final bool showBack;
|
|
|
|
/// What Back does; null keeps the platform's stock action (pop the route).
|
|
final VoidCallback? onBack;
|
|
final List<Widget> controls;
|
|
final List<Widget> actions;
|
|
final List<Widget> moreActions;
|
|
|
|
/// The chat's colour name, or null for none.
|
|
final String? chatColor;
|
|
|
|
/// The chat's identity avatar, shown in the title on a phone.
|
|
final Widget? identity;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino =
|
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
|
final tint = chatBarTintOf(context, chatColor);
|
|
return LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final textScale = MediaQuery.textScalerOf(context).scale(14) / 14;
|
|
final compact = constraints.maxWidth / textScale < 800;
|
|
final actionChildren = [
|
|
...actions,
|
|
for (final action in moreActions)
|
|
if (action is! SegmentedOverflowable) action,
|
|
if (moreActions.whereType<SegmentedOverflowable>().isNotEmpty)
|
|
SegmentedMoreButton(
|
|
cupertino: cupertino,
|
|
entries: [
|
|
for (final action
|
|
in moreActions.whereType<SegmentedOverflowable>())
|
|
action.overflowEntry,
|
|
],
|
|
),
|
|
];
|
|
final Widget bar = SegmentedBar(
|
|
cupertino: cupertino,
|
|
pillColor: tint?.fill,
|
|
foregroundColor: tint?.foreground,
|
|
automaticallyImplyLeading: false,
|
|
// The platform's own Back, so it reads and behaves as every other
|
|
// page's Back; its key stays for finders.
|
|
leading: showBack
|
|
? SegmentedBackButton(
|
|
key: const Key('chat-back'),
|
|
cupertino: cupertino,
|
|
onPressed: onBack,
|
|
)
|
|
: null,
|
|
title: title.isEmpty ? 'Chat' : title,
|
|
titleLeading: identity,
|
|
subtitle: ServerContext.metadata(context, folder),
|
|
subtitleIcon: cupertino
|
|
? CupertinoIcons.folder
|
|
: Icons.folder_outlined,
|
|
onTitlePressed: onInfo,
|
|
titleSemanticLabel: 'Chat information',
|
|
titleKey: const Key('chat-info'),
|
|
separateActionIslands: true,
|
|
actions: [
|
|
if (controls.isNotEmpty)
|
|
ChatWorkspacePaneActionBar(
|
|
child: _ControlIsland(
|
|
key: const Key('chat-model-permission-island'),
|
|
gap: compact ? 0 : 8,
|
|
children: controls,
|
|
),
|
|
),
|
|
if (actions.isNotEmpty || moreActions.isNotEmpty)
|
|
ChatWorkspacePaneActionBar(
|
|
child: Row(
|
|
key: const Key('chat-actions-island'),
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
for (final (index, action) in actionChildren.indexed) ...[
|
|
if (index > 0 && !compact) const SizedBox(width: 8),
|
|
action,
|
|
],
|
|
],
|
|
),
|
|
),
|
|
],
|
|
bottomPadding: compact ? 8 : 16,
|
|
);
|
|
return ColoredBox(
|
|
color: cupertino
|
|
? CupertinoTheme.of(context).scaffoldBackgroundColor
|
|
: Theme.of(context).colorScheme.surface,
|
|
child: tint == null
|
|
? bar
|
|
: ChatBarTintScope(
|
|
key: const Key('chat-bar-tint'),
|
|
tint: tint,
|
|
cupertino: cupertino,
|
|
child: bar,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Related selectors share the available width. Each remains a real control;
|
|
/// they never migrate into the unrelated actions menu.
|
|
class _ControlIsland extends StatelessWidget {
|
|
const _ControlIsland({super.key, required this.children, required this.gap});
|
|
final List<Widget> children;
|
|
final double gap;
|
|
|
|
// With a gap (desktop) the buttons carry no horizontal padding of their
|
|
// own, so the island keeps the text off its pill's rounded ends.
|
|
@override
|
|
Widget build(BuildContext context) => Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: gap * 1.5),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
for (final (index, child) in children.indexed) ...[
|
|
if (index > 0) SizedBox(width: gap),
|
|
Flexible(child: child),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|