Keep chat titles readable in narrow headers

Prioritize the conversation title on narrow chat bars, move compact controls and overflow actions into More, and omit the duplicate title in floating windows. Add focused widget coverage for title sizing, icon dimensions, menus, and floating chrome.
This commit is contained in:
2026-11-12 10:42:43 +00:00
parent 24618964ce
commit 7d9b6c1d1b
9 changed files with 431 additions and 85 deletions
@@ -1,20 +1,36 @@
import 'dart:async';
import 'package:flutter/material.dart';
import '../../../core/servers/server_context.dart';
import '../../../ui/adaptive/app_popups.dart';
import '../../../ui/adaptive/segmented_bar.dart';
import '../../../ui/adaptive/segmented_bar_overflow.dart';
import 'chat_bar_tint.dart';
import '../workspace/chat_workspace_pane_scope.dart';
/// Below this width (in text-scaled logical pixels) the selectors leave the
/// bar for its More menu's settings entry, so the title keeps
/// [chatHeaderTitleShare].
const double chatHeaderNarrowWidth = 600;
/// The share of a narrow bar the conversation's title always keeps.
const double chatHeaderTitleShare = 0.6;
/// 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.
/// information, a selector island holding [controls] (model, mode and
/// thinking), then the Files action and a native More menu in a separate
/// island.
///
/// A narrow bar ([chatHeaderNarrowWidth]) keeps the title at
/// [chatHeaderTitleShare] of the bar: the [controls] join the More menu as one
/// "Chat settings" entry that opens them in a sheet, and the overflowable
/// actions join it too. A floating chat passes [showTitle] false, since its window bar names
/// the chat.
///
/// 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
@@ -26,6 +42,7 @@ class ChatThreadHeader extends StatelessWidget {
required this.title,
required this.folder,
required this.onInfo,
this.showTitle = true,
this.showBack = false,
this.onBack,
this.controls = const [],
@@ -41,6 +58,10 @@ class ChatThreadHeader extends StatelessWidget {
final String folder;
final VoidCallback onInfo;
/// Whether the title pill (and its folder) shows; false in a floating
/// window, whose own bar names the chat.
final bool showTitle;
/// Whether the bar shows Back at all.
final bool showBack;
@@ -62,21 +83,36 @@ class ChatThreadHeader extends StatelessWidget {
return LayoutBuilder(
builder: (context, constraints) {
final textScale = MediaQuery.textScalerOf(context).scale(14) / 14;
final compact = constraints.maxWidth / textScale < 800;
final scaledWidth = constraints.maxWidth / textScale;
final compact = scaledWidth < 800;
final narrow = scaledWidth < chatHeaderNarrowWidth;
// A narrow bar moves the selectors, and the overflowable actions, into
// its More menu; the others stay in the bar.
final menuActions = [
if (narrow) ...actions.whereType<SegmentedOverflowable>(),
...moreActions.whereType<SegmentedOverflowable>(),
];
final settingsEntry = narrow && controls.isNotEmpty
? SegmentedOverflowEntry(
label: 'Chat settings',
icon: Icons.tune,
onPressed: () => unawaited(_showSettings(context, controls)),
)
: null;
final actionChildren = [
...actions,
for (final action in actions)
if (!narrow || action is! SegmentedOverflowable) action,
for (final action in moreActions)
if (action is! SegmentedOverflowable) action,
if (moreActions.whereType<SegmentedOverflowable>().isNotEmpty)
if (settingsEntry != null || menuActions.isNotEmpty)
SegmentedMoreButton(
entries: [
for (final action
in moreActions.whereType<SegmentedOverflowable>())
action.overflowEntry,
?settingsEntry,
for (final action in menuActions) action.overflowEntry,
],
),
];
final Widget bar = SegmentedBar(
final bar = SegmentedBar(
pillColor: tint?.fill,
foregroundColor: tint?.foreground,
automaticallyImplyLeading: false,
@@ -88,16 +124,17 @@ class ChatThreadHeader extends StatelessWidget {
onPressed: onBack,
)
: null,
title: title.isEmpty ? 'Chat' : title,
titleLeading: identity,
subtitle: ServerContext.metadata(context, folder),
title: !showTitle ? '' : (title.isEmpty ? 'Chat' : title),
titleLeading: showTitle ? identity : null,
subtitle: showTitle ? ServerContext.metadata(context, folder) : null,
subtitleIcon: Icons.folder_outlined,
onTitlePressed: onInfo,
onTitlePressed: showTitle ? onInfo : null,
titleSemanticLabel: 'Chat information',
titleKey: const Key('chat-info'),
separateActionIslands: true,
titleShare: narrow && showTitle ? chatHeaderTitleShare : null,
actions: [
if (controls.isNotEmpty)
if (controls.isNotEmpty && !narrow)
ChatWorkspacePaneActionBar(
child: _ControlIsland(
key: const Key('chat-model-permission-island'),
@@ -105,7 +142,7 @@ class ChatThreadHeader extends StatelessWidget {
children: controls,
),
),
if (actions.isNotEmpty || moreActions.isNotEmpty)
if (actionChildren.isNotEmpty)
ChatWorkspacePaneActionBar(
child: Row(
key: const Key('chat-actions-island'),
@@ -136,6 +173,24 @@ class ChatThreadHeader extends StatelessWidget {
}
}
/// A narrow bar's selectors (model, mode and thinking), each with its label,
/// in a sheet opened from the More menu.
Future<void> _showSettings(BuildContext context, List<Widget> controls) =>
showAppChoiceMenu<void>(
context,
semanticLabel: 'Chat settings',
builder: (_) => SafeArea(
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: controls,
),
),
),
);
/// Related selectors share the available width. Each remains a real control;
/// they never migrate into the unrelated actions menu.
class _ControlIsland extends StatelessWidget {
@@ -1428,15 +1428,23 @@ class _ChatThreadViewState extends State<ChatThreadView> {
? ModalRoute.of(context)?.impliesAppBarDismissal ?? false
: true);
final answeredBy = latestReplyModel(_controller.messages);
return _chrome.widgetFor('header', answeredBy, [
widget,
inShellBar,
canGoBack,
// The thinking control says when a turn is running.
_controller.running,
// The More menu offers Dismiss all finished commands only with one.
_shellRuns.finishedIds.isNotEmpty,
], () => _buildHeader(session, inShellBar, canGoBack, answeredBy));
// A floating window's own bar names the chat, so the header omits it.
final inWindow = WindowScope.maybeOf(context) != null;
return _chrome.widgetFor(
'header',
answeredBy,
[
widget,
inShellBar,
canGoBack,
inWindow,
// The thinking control says when a turn is running.
_controller.running,
// The More menu offers Dismiss all finished commands only with one.
_shellRuns.finishedIds.isNotEmpty,
],
() => _buildHeader(session, inShellBar, canGoBack, answeredBy, inWindow),
);
}
Widget _buildHeader(
@@ -1444,6 +1452,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
bool inShellBar,
bool canGoBack,
String answeredBy,
bool inWindow,
) {
final hasModel =
session != null && supportsChatModels('${session['backend'] ?? ''}');
@@ -1466,6 +1475,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
? null
: ChatSessionAvatar(session: session, selected: true),
onInfo: _openInfo,
showTitle: !inWindow,
showBack: canGoBack,
// A pushed page keeps the platform's stock Back (pop this route); a
// standalone conversation calls its owner.
@@ -1518,6 +1528,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
),
],
controls: [
// Labelled, so a narrow bar's settings sheet shows their names.
if (hasModel)
ChatModelControl(
key: ValueKey<String>('chat-model-${widget.sessionId}'),
@@ -1526,6 +1537,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
session: session,
onChanged: widget.onModelChanged,
answeredBy: answeredBy,
showLabel: true,
),
if (hasMode) _modeControl(),
// Only a model with levels gets the control (and its pill).
@@ -1537,6 +1549,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
session: session,
running: _controller.running,
onChanged: widget.onEffortChanged,
showLabel: true,
),
],
);
@@ -1551,6 +1564,7 @@ class _ChatThreadViewState extends State<ChatThreadView> {
mode: '${widget.session?['mode'] ?? ''}'.trim(),
modeName: '${widget.session?['mode_name'] ?? ''}'.trim(),
onChanged: widget.onModeChanged,
showLabel: true,
);
/// Stops the running turn, as the composer's `/stop` does.