Merge main (Compact design) into Glass
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import '../ui/adaptive/window_margins.dart';
|
||||
import '../ui/theme/app_design.dart';
|
||||
import '../ui/theme/app_design_controller.dart';
|
||||
import '../ui/theme/glass_backdrop.dart';
|
||||
import '../ui/theme/app_font_controller.dart';
|
||||
@@ -56,11 +55,12 @@ class MyApp extends StatelessWidget {
|
||||
final designs = this.designs ?? AppDesignController.instance;
|
||||
return ListenableBuilder(
|
||||
listenable: Listenable.merge([fonts, designs]),
|
||||
builder: (context, _) => _host(designs.design, fonts.family),
|
||||
builder: (context, _) => _host(designs, fonts.family),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _host(AppDesign design, String? fontFamily) {
|
||||
Widget _host(AppDesignController designs, String? fontFamily) {
|
||||
final design = designs.design;
|
||||
final router = routerConfig;
|
||||
if (router != null) {
|
||||
return MaterialApp.router(
|
||||
@@ -69,6 +69,7 @@ class MyApp extends StatelessWidget {
|
||||
builder: _scaled,
|
||||
theme: design.light(fontFamily: fontFamily),
|
||||
darkTheme: design.dark(fontFamily: fontFamily),
|
||||
themeAnimationDuration: designs.themeAnimationDuration,
|
||||
themeMode: ThemeMode.system,
|
||||
routerConfig: router,
|
||||
);
|
||||
@@ -79,6 +80,7 @@ class MyApp extends StatelessWidget {
|
||||
builder: _scaled,
|
||||
theme: design.light(fontFamily: fontFamily),
|
||||
darkTheme: design.dark(fontFamily: fontFamily),
|
||||
themeAnimationDuration: designs.themeAnimationDuration,
|
||||
themeMode: ThemeMode.system,
|
||||
home: AdaptiveShell(
|
||||
destinationBodies: destinationBodies,
|
||||
|
||||
@@ -28,6 +28,7 @@ import 'detached_route.dart';
|
||||
import 'detached_terminal.dart';
|
||||
import 'detached_window_body.dart';
|
||||
import 'detached_windows.dart';
|
||||
import '../../features/chat/speech/app_speech.dart';
|
||||
|
||||
/// A detached window's whole app: one item ([route]) over its own
|
||||
/// connection, without the shell (no navigation rail, lists, floating
|
||||
@@ -120,6 +121,9 @@ class _DetachedWindowAppState extends State<DetachedWindowApp> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// A reply read aloud belongs to this app's server: switching servers (a
|
||||
// fresh app) or closing the window ends it.
|
||||
unawaited(speechControllerIfCreated?.stop());
|
||||
_session.removeListener(_connectionChanged);
|
||||
widget.chatPool?.removeListener(_connectionChanged);
|
||||
_terminals?.dispose();
|
||||
@@ -226,6 +230,7 @@ class _DetachedWindowAppState extends State<DetachedWindowApp> {
|
||||
),
|
||||
theme: designs.design.light(fontFamily: fonts.family),
|
||||
darkTheme: designs.design.dark(fontFamily: fonts.family),
|
||||
themeAnimationDuration: designs.themeAnimationDuration,
|
||||
themeMode: ThemeMode.system,
|
||||
// The window's one page is named by its route, so the address bar
|
||||
// (and a reload) keeps the detached location instead of `/`.
|
||||
|
||||
@@ -84,6 +84,7 @@ import 'templates_destination.dart';
|
||||
import 'tab_locations.dart';
|
||||
import 'tab_locations_store.dart';
|
||||
import '../ui/input/keyboard_owner.dart';
|
||||
import '../features/chat/speech/app_speech.dart';
|
||||
|
||||
/// The application's return-to-foreground policy for the shared socket.
|
||||
///
|
||||
@@ -643,6 +644,9 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// A reply read aloud belongs to this app's server: switching servers (a
|
||||
// fresh app) or closing the window ends it.
|
||||
unawaited(speechControllerIfCreated?.stop());
|
||||
_stopAsking();
|
||||
_tabLocations.dispose();
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
|
||||
@@ -392,6 +392,7 @@ class _PipelinesRootState extends State<PipelinesRoot> {
|
||||
),
|
||||
theme: designs.design.light(fontFamily: fonts.family),
|
||||
darkTheme: designs.design.dark(fontFamily: fonts.family),
|
||||
themeAnimationDuration: designs.themeAnimationDuration,
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: flow,
|
||||
),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../ui/theme/app_design_tokens.dart';
|
||||
|
||||
/// The find-in-diff field `/` opens: the query, "3 of 12", previous and next
|
||||
/// match, and close. Enter goes to the next match, Shift+Enter to the
|
||||
/// previous one, Escape closes.
|
||||
@@ -38,7 +38,9 @@ class DiffSearchBar extends StatelessWidget {
|
||||
: '$position of $count';
|
||||
return Material(
|
||||
elevation: 3,
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
borderRadius: AppDesignTokens.of(
|
||||
context,
|
||||
).denseCorners(BorderRadius.circular(28)),
|
||||
color: AppDesignTokens.of(
|
||||
context,
|
||||
).solidFill(Theme.of(context).colorScheme.surfaceContainerHigh),
|
||||
|
||||
@@ -8,7 +8,10 @@ import 'chat_runtime.dart';
|
||||
import 'conversation/chat_seen_interaction.dart';
|
||||
import 'conversation/chat_thread_view.dart';
|
||||
import 'conversation/composer_focus_request.dart';
|
||||
import 'domain/chat_colors.dart';
|
||||
import 'ui/sessions/chat_color_palette.dart';
|
||||
import 'workspace/chat_pane_commands.dart';
|
||||
import 'workspace/chat_pane_focus_flash.dart';
|
||||
|
||||
/// Where an open chat is shown and what that place alone decides: its Back,
|
||||
/// its pane menu, whether it takes pastes, and what follows `/new` and
|
||||
@@ -81,54 +84,59 @@ Widget buildChatPaneContent({
|
||||
builder: (context) {
|
||||
final row = runtime.rowFor(sessionId);
|
||||
final start = runtime.startNotice;
|
||||
return ChatComposerFocusScope(
|
||||
return ChatPaneFocusFlash(
|
||||
sessionId: sessionId,
|
||||
requests: runtime.composerFocus,
|
||||
child: ServerContext.forServer(
|
||||
context,
|
||||
runtime.serverIdFor(sessionId),
|
||||
ChatSeenInteraction(
|
||||
sessionId: sessionId,
|
||||
onInteract: () => runtime.sessions.reportInteraction(sessionId),
|
||||
child: ChatThreadView(
|
||||
key: ValueKey<String>('chat-session-$sessionId'),
|
||||
gateway: runtime.gatewayFor(sessionId),
|
||||
requests: runtime.paneFlash,
|
||||
color: chatColorShade(context, chatSessionColor(row)),
|
||||
child: ChatComposerFocusScope(
|
||||
sessionId: sessionId,
|
||||
requests: runtime.composerFocus,
|
||||
child: ServerContext.forServer(
|
||||
context,
|
||||
runtime.serverIdFor(sessionId),
|
||||
ChatSeenInteraction(
|
||||
sessionId: sessionId,
|
||||
title: '${row?['title'] ?? ''}'.trim(),
|
||||
session: row,
|
||||
initialDraft: runtime.pendingDrafts.remove(sessionId),
|
||||
syncToken: placement.syncToken,
|
||||
scrollPositions: runtime.scrollPositions,
|
||||
transcripts: runtime.transcripts,
|
||||
initialNotice: start != null && start.id == sessionId
|
||||
? start.notice
|
||||
: null,
|
||||
onBack: placement.onBack,
|
||||
onModelChanged: (applied) =>
|
||||
runtime.modelChanged(sessionId, applied),
|
||||
onModeChanged: (mode, name) =>
|
||||
runtime.acceptMode(sessionId, mode, name),
|
||||
onEffortChanged: (state) =>
|
||||
runtime.acceptEffort(sessionId, state),
|
||||
onNewSession: placement.onNewSession,
|
||||
onSessionRenamed: (title) =>
|
||||
runtime.acceptRename(sessionId, title),
|
||||
onSessionClosed: placement.onSessionClosed,
|
||||
onColorSelected: (color) =>
|
||||
runtime.sessions.setColor(sessionId, color),
|
||||
onNextChat: placement.onNextChat,
|
||||
useNativeBack: placement.useNativeBack,
|
||||
pasteTarget: placement.pasteTarget,
|
||||
ownsPasteWhenFocused: placement.ownsPasteWhenFocused,
|
||||
showBackButton: placement.showBackButton,
|
||||
paneControls: placement.paneControls?.call(context) ?? const [],
|
||||
leadingControl: placement.leadingControl?.call(context),
|
||||
paneCommands: placement.paneCommands,
|
||||
onComposerFocus: placement.onComposerFocus,
|
||||
onComposerReady: (composer) =>
|
||||
runtime.registerComposer(sessionId, composer),
|
||||
onComposerDisposed: (composer) =>
|
||||
runtime.unregisterComposer(sessionId, composer),
|
||||
onInteract: () => runtime.sessions.reportInteraction(sessionId),
|
||||
child: ChatThreadView(
|
||||
key: ValueKey<String>('chat-session-$sessionId'),
|
||||
gateway: runtime.gatewayFor(sessionId),
|
||||
sessionId: sessionId,
|
||||
title: '${row?['title'] ?? ''}'.trim(),
|
||||
session: row,
|
||||
initialDraft: runtime.pendingDrafts.remove(sessionId),
|
||||
syncToken: placement.syncToken,
|
||||
scrollPositions: runtime.scrollPositions,
|
||||
transcripts: runtime.transcripts,
|
||||
initialNotice: start != null && start.id == sessionId
|
||||
? start.notice
|
||||
: null,
|
||||
onBack: placement.onBack,
|
||||
onModelChanged: (applied) =>
|
||||
runtime.modelChanged(sessionId, applied),
|
||||
onModeChanged: (mode, name) =>
|
||||
runtime.acceptMode(sessionId, mode, name),
|
||||
onEffortChanged: (state) =>
|
||||
runtime.acceptEffort(sessionId, state),
|
||||
onNewSession: placement.onNewSession,
|
||||
onSessionRenamed: (title) =>
|
||||
runtime.acceptRename(sessionId, title),
|
||||
onSessionClosed: placement.onSessionClosed,
|
||||
onColorSelected: (color) =>
|
||||
runtime.sessions.setColor(sessionId, color),
|
||||
onNextChat: placement.onNextChat,
|
||||
useNativeBack: placement.useNativeBack,
|
||||
pasteTarget: placement.pasteTarget,
|
||||
ownsPasteWhenFocused: placement.ownsPasteWhenFocused,
|
||||
showBackButton: placement.showBackButton,
|
||||
paneControls: placement.paneControls?.call(context) ?? const [],
|
||||
leadingControl: placement.leadingControl?.call(context),
|
||||
paneCommands: placement.paneCommands,
|
||||
onComposerFocus: placement.onComposerFocus,
|
||||
onComposerReady: (composer) =>
|
||||
runtime.registerComposer(sessionId, composer),
|
||||
onComposerDisposed: (composer) =>
|
||||
runtime.unregisterComposer(sessionId, composer),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -17,6 +17,7 @@ import 'data/chat_recency.dart';
|
||||
import 'data/chat_repository.dart';
|
||||
import 'ui/sessions/chat_sessions_body.dart';
|
||||
import 'ui/sessions/chat_sessions_controller.dart';
|
||||
import 'workspace/chat_pane_focus_flash.dart';
|
||||
|
||||
/// What open chats share for one server, wherever they are shown (the Chat
|
||||
/// destination's tiling or a floating window): the session list, the rows
|
||||
@@ -134,6 +135,9 @@ class ChatRuntime extends ChangeNotifier {
|
||||
/// Puts the keyboard in an opened chat's composer once it is built.
|
||||
final ChatComposerFocusRequests composerFocus = ChatComposerFocusRequests();
|
||||
|
||||
/// Flashes the focus ring of the pane the keyboard just moved to.
|
||||
final ChatPaneFlashRequests paneFlash = ChatPaneFlashRequests();
|
||||
|
||||
/// The Chat destination's quick switcher, toggled by Ctrl+K / Alt+K there.
|
||||
final ChatQuickSwitchRequests quickSwitch = ChatQuickSwitchRequests();
|
||||
|
||||
@@ -296,6 +300,7 @@ class ChatRuntime extends ChangeNotifier {
|
||||
sessions.dispose();
|
||||
folds.dispose();
|
||||
composerFocus.dispose();
|
||||
paneFlash.dispose();
|
||||
composers.clear();
|
||||
_pendingAppends.clear();
|
||||
super.dispose();
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
part of 'screen.dart';
|
||||
|
||||
/// A chat pane the keyboard can move to: a tiled pane or a floating window.
|
||||
class _PaneCycleTarget {
|
||||
const _PaneCycleTarget.pane(this.paneId, this.sessionId) : window = null;
|
||||
_PaneCycleTarget.window(WindowEntry this.window)
|
||||
: paneId = null,
|
||||
sessionId = window.contentId;
|
||||
|
||||
final String? paneId;
|
||||
final WindowEntry? window;
|
||||
final String sessionId;
|
||||
}
|
||||
|
||||
/// Alt+] and Alt+[ (also Cmd+] and Cmd+[ on Apple platforms, see
|
||||
/// [chatPaneCycleShortcut]) move the keyboard to the next or previous chat
|
||||
/// pane on screen: the tiled panes in their visual order (left to right,
|
||||
/// then top to bottom, as the split tree lays them out; the center stage's
|
||||
/// row in order), then the shown floating chat windows in the order they
|
||||
/// were opened, wrapping around. The pane's composer takes the keyboard and
|
||||
/// its focus ring flashes in the chat's colour. Nothing opens or closes.
|
||||
///
|
||||
/// It does nothing with one pane on screen, on a phone layout (the chat
|
||||
/// stack and the quick switcher own moving between chats there), over a
|
||||
/// popup or another destination, and while a terminal has the keyboard,
|
||||
/// which keeps its Alt keys. Handled before the focus tree, so it works from
|
||||
/// a composer and the web build stops the browser's own use of the keys.
|
||||
mixin _ChatScreenPaneCycle on State<ChatScreen>, _ChatScreenWorkspace {
|
||||
ChatRuntime get _runtime;
|
||||
|
||||
bool _paneCycleKey(KeyEvent event) {
|
||||
final step = chatPaneCycleShortcut(event, HardwareKeyboard.instance);
|
||||
if (step == null ||
|
||||
!mounted ||
|
||||
primaryFocusIsTypingSurface() ||
|
||||
!_workspaceVisible ||
|
||||
!showsListBesideDetail(context) ||
|
||||
!_chatOwnsKeyboard()) {
|
||||
return false;
|
||||
}
|
||||
final order = _paneCycleOrder();
|
||||
final target = chatPaneCycleTarget(order, _paneCycleCurrent(order), step);
|
||||
if (target == null) return false;
|
||||
// A held chord is swallowed; only its first press moves.
|
||||
if (event is KeyDownEvent) _focusPaneCycleTarget(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// The panes on screen, in cycling order.
|
||||
List<_PaneCycleTarget> _paneCycleOrder() {
|
||||
final visible = _visibleSidebarSessions;
|
||||
return [
|
||||
for (final pane in _workspace.panes)
|
||||
if (visible.contains(pane.sessionId))
|
||||
_PaneCycleTarget.pane(pane.id, pane.sessionId),
|
||||
for (final window
|
||||
in widget.windows?.shownInOpenOrder() ?? const <WindowEntry>[])
|
||||
_PaneCycleTarget.window(window),
|
||||
];
|
||||
}
|
||||
|
||||
/// Where the keyboard is in [order]: the floating chat window holding it,
|
||||
/// otherwise the active tiled pane (also while the chat list has it).
|
||||
int _paneCycleCurrent(List<_PaneCycleTarget> order) {
|
||||
final window = keyboardWindow()?.entry;
|
||||
if (window != null && window.kind == chatWindowKind) {
|
||||
return order.indexWhere((target) => target.window?.id == window.id);
|
||||
}
|
||||
final active = _workspace.activePaneId;
|
||||
return order.indexWhere((target) => target.paneId == active);
|
||||
}
|
||||
|
||||
void _focusPaneCycleTarget(_PaneCycleTarget target) {
|
||||
final window = target.window;
|
||||
final windows = widget.windows;
|
||||
if (window != null && windows != null) {
|
||||
windows.manager.raise(window.id);
|
||||
windows.kind.focusContent(window);
|
||||
} else if (target.paneId case final paneId?) {
|
||||
_workspace.activate(paneId);
|
||||
_composerFocus.request(target.sessionId);
|
||||
}
|
||||
_runtime.paneFlash.flash(target.sessionId);
|
||||
WidgetsBinding.instance.ensureVisualUpdate();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/theme/app_design_tokens.dart';
|
||||
import 'chat_bar_tint.dart';
|
||||
|
||||
/// The conversation bar's model and mode controls read as the bar's other
|
||||
@@ -18,7 +19,13 @@ ButtonStyle chatBarTextButtonStyle(
|
||||
// The same 12 px each side as an icon button's glyph inside its 48 px
|
||||
// target, so text sits off its hover/press shape as it does top and bottom.
|
||||
padding: compact ? null : chatBarButtonPadding,
|
||||
minimumSize: compact ? null : const Size.square(kMinInteractiveDimension),
|
||||
minimumSize: compact
|
||||
? null
|
||||
: Size.square(
|
||||
AppDesignTokens.of(context).density.dense
|
||||
? 32
|
||||
: kMinInteractiveDimension,
|
||||
),
|
||||
);
|
||||
|
||||
/// Horizontal padding inside the bar's text buttons (model, mode).
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import 'dart:async';
|
||||
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../core/error_reason.dart';
|
||||
import '../../../core/transport/connection_state.dart';
|
||||
import '../data/chat_repository.dart';
|
||||
import '../domain/chat_commands.dart';
|
||||
import '../speech/app_speech.dart';
|
||||
|
||||
/// Shows one local line in the conversation the command ran in.
|
||||
typedef ChatCommandNoticeCallback = void Function(String text, {bool failed});
|
||||
@@ -105,6 +108,8 @@ class ChatCommandActions {
|
||||
if (!await confirmClose()) return;
|
||||
try {
|
||||
await repository.close(sessionId);
|
||||
// Closing the chat ends its reply reading aloud.
|
||||
unawaited(speechControllerIfCreated?.stopScope(sessionId));
|
||||
onClosed?.call();
|
||||
} catch (error) {
|
||||
showNotice(_reason(error), failed: true);
|
||||
|
||||
@@ -1061,7 +1061,15 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
builder: (context, constraints) => Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
_attach(context),
|
||||
// A dense design's 32px attach centres
|
||||
// on the 40px send button's line.
|
||||
if (AppDesignTokens.of(context).density.dense)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: _attach(context),
|
||||
)
|
||||
else
|
||||
_attach(context),
|
||||
Expanded(
|
||||
child: Focus(
|
||||
canRequestFocus: false,
|
||||
@@ -1329,7 +1337,12 @@ class _ChatComposerBarState extends State<ChatComposerBar> {
|
||||
// The pill draws the field's surface; the field adds no border.
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 12),
|
||||
// A dense design's slim composer: one line as tall as the 40px send
|
||||
// button (every design pins it), so the pill is 48px. Its compact
|
||||
// density takes 4px off each of these 14.
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
vertical: AppDesignTokens.of(context).density.dense ? 14 : 12,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,9 @@ class _ChatFindBarState extends State<ChatFindBar> {
|
||||
color: AppDesignTokens.of(
|
||||
context,
|
||||
).solidFill(scheme.surfaceContainerHigh),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderRadius: AppDesignTokens.of(
|
||||
context,
|
||||
).denseCorners(BorderRadius.circular(8)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 12, end: 4),
|
||||
child: ListenableBuilder(
|
||||
|
||||
@@ -78,6 +78,7 @@ import '../../../ui/layout/wheel_scroll_forwarding.dart';
|
||||
import 'chat_reading_width.dart';
|
||||
import '../ui/transcript/chat_copy_gutter.dart';
|
||||
import '../speech/speech.dart';
|
||||
import '../ui/speech/chat_speaking_control.dart';
|
||||
import 'chat_pane_presentation.dart';
|
||||
import 'chat_thread_header.dart';
|
||||
import 'chat_transcript_anchor.dart';
|
||||
@@ -754,11 +755,10 @@ class _ChatThreadViewState extends State<ChatThreadView> with ChatFindHost {
|
||||
@override
|
||||
void didUpdateWidget(covariant ChatThreadView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.sessionId != widget.sessionId ||
|
||||
oldWidget.gateway != widget.gateway) {
|
||||
// A pane reused for another conversation stops reading the previous
|
||||
// one's reply, so neither its audio nor its highlight carries over.
|
||||
unawaited(speechController.stopScope(oldWidget.sessionId));
|
||||
// A reply keeps reading when its pane shows another conversation (the
|
||||
// reader is the app's); a rename relabels the reading.
|
||||
if (oldWidget.title != widget.title) {
|
||||
speechControllerIfCreated?.retitle(widget.sessionId, widget.title.trim());
|
||||
}
|
||||
if (!identical(oldWidget.paneCommands, widget.paneCommands)) {
|
||||
oldWidget.paneCommands?.removeListener(_takeCommands);
|
||||
@@ -862,9 +862,8 @@ class _ChatThreadViewState extends State<ChatThreadView> with ChatFindHost {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// Leaving or closing the conversation stops its reply reading aloud; a
|
||||
// reply another pane is reading carries on.
|
||||
unawaited(speechController.stopScope(widget.sessionId));
|
||||
// Leaving the conversation keeps its reply reading aloud: the reader is
|
||||
// the app's, and closing or deleting the chat is what stops it.
|
||||
_persistPosition();
|
||||
_saveTranscript(widget.transcripts, widget.sessionId, widget.gateway);
|
||||
widget.paneCommands?.removeListener(_takeCommands);
|
||||
@@ -1334,11 +1333,20 @@ class _ChatThreadViewState extends State<ChatThreadView> with ChatFindHost {
|
||||
pasteTarget: widget.pasteTarget,
|
||||
ownsPasteWhenFocused: widget.ownsPasteWhenFocused,
|
||||
runShell: _shellRuns.start,
|
||||
limitBanner: ChatUsageLimitBanner(
|
||||
thread: _controller,
|
||||
composer: _composer,
|
||||
accounts: _accounts,
|
||||
autoContinue: widget.autoContinue,
|
||||
limitBanner: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// The global Stop for a reading reply of any chat, shown
|
||||
// above the active pane's composer only.
|
||||
if (widget.pasteTarget) const ChatSpeakingControl(),
|
||||
ChatUsageLimitBanner(
|
||||
thread: _controller,
|
||||
composer: _composer,
|
||||
accounts: _accounts,
|
||||
autoContinue: widget.autoContinue,
|
||||
),
|
||||
],
|
||||
),
|
||||
backgroundTasks: ChatBackgroundTasks(
|
||||
key: ValueKey('chat-background-tasks-${widget.sessionId}'),
|
||||
@@ -1604,13 +1612,19 @@ class _ChatThreadViewState extends State<ChatThreadView> with ChatFindHost {
|
||||
],
|
||||
)
|
||||
: column;
|
||||
if (!inShellBar) return content;
|
||||
// The conversation draws its own floating bar; the page shows none.
|
||||
final title = widget.title.trim();
|
||||
// Read aloud labels a reading with this conversation.
|
||||
final origin = SpeechOrigin(
|
||||
scope: widget.sessionId,
|
||||
title: title,
|
||||
child: content,
|
||||
);
|
||||
if (!inShellBar) return origin;
|
||||
// The conversation draws its own floating bar; the page shows none.
|
||||
return ShellBar(
|
||||
barless: true,
|
||||
title: title.isEmpty ? null : title,
|
||||
child: content,
|
||||
child: origin,
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -23,11 +23,13 @@ import '../../core/api_gateway.dart';
|
||||
import '../../core/servers/server_context.dart';
|
||||
import '../../core/servers/server_scope.dart';
|
||||
import '../../shell/detached/detached_window_scope.dart';
|
||||
import '../../shell/windows/window_entry.dart';
|
||||
import '../../shell/windows/window_scope.dart';
|
||||
import 'shell/chat_shell_dismiss.dart';
|
||||
import '../terminal/terminal_open_action.dart';
|
||||
import 'ui/sessions/session_pane_menu.dart';
|
||||
import 'workspace/chat_pane_commands.dart';
|
||||
import 'workspace/chat_pane_cycle.dart';
|
||||
import 'workspace/chat_float_shortcut.dart';
|
||||
import 'workspace/chat_workspace_binding.dart';
|
||||
import 'workspace/chat_workspace_snapshot.dart';
|
||||
@@ -70,6 +72,7 @@ import '../../ui/input/keyboard_owner.dart';
|
||||
|
||||
part 'chat_screen_attention.dart';
|
||||
part 'chat_screen_float.dart';
|
||||
part 'chat_screen_pane_cycle.dart';
|
||||
part 'chat_screen_pane_menu.dart';
|
||||
part 'chat_screen_keys.dart';
|
||||
part 'chat_screen_list_toggle.dart';
|
||||
@@ -137,6 +140,7 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
_ChatScreenWorkspace,
|
||||
_ChatScreenKeys,
|
||||
_ChatScreenFloat,
|
||||
_ChatScreenPaneCycle,
|
||||
_ChatScreenPaneMenu,
|
||||
_ChatScreenQuickSwitch,
|
||||
_ChatScreenAttention,
|
||||
@@ -194,6 +198,7 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
_bindWorkspacePersistence();
|
||||
HardwareKeyboard.instance.addHandler(_cycleChatKey);
|
||||
HardwareKeyboard.instance.addHandler(_slashFocusKey);
|
||||
HardwareKeyboard.instance.addHandler(_paneCycleKey);
|
||||
// Seen from now on, so the press that chooses the first chat counts.
|
||||
LastPointerKind.instance;
|
||||
_sessions.addListener(_nextChanged);
|
||||
@@ -484,6 +489,7 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
_paneCommands.dispose();
|
||||
HardwareKeyboard.instance.removeHandler(_cycleChatKey);
|
||||
HardwareKeyboard.instance.removeHandler(_slashFocusKey);
|
||||
HardwareKeyboard.instance.removeHandler(_paneCycleKey);
|
||||
_page.dispose();
|
||||
_workspaceBinding?.dispose();
|
||||
_openWorkspace?.dispose();
|
||||
|
||||
@@ -72,7 +72,9 @@ class _ChatShellTerminalFindBarState extends State<ChatShellTerminalFindBar> {
|
||||
color: AppDesignTokens.of(
|
||||
context,
|
||||
).solidFill(scheme.surfaceContainerHigh),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderRadius: AppDesignTokens.of(
|
||||
context,
|
||||
).denseCorners(BorderRadius.circular(8)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 12, end: 4),
|
||||
child: ListenableBuilder(
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'speech_controller.dart';
|
||||
import 'speech_reading.dart';
|
||||
|
||||
/// The app's single reader, owned by the app (this window's engine), never by
|
||||
/// a conversation view: a reply keeps reading across chat switches, panes and
|
||||
/// the chat list. Each window (a detached window is its own app) has its own.
|
||||
SpeechController get speechController =>
|
||||
_speech ??= _bind<SpeechController>(SpeechController());
|
||||
|
||||
/// The app's reader if anything has used it yet. Code that only needs to stop
|
||||
/// or retitle a reading uses this, so it never creates a platform engine.
|
||||
SpeechController? get speechControllerIfCreated => _speech;
|
||||
|
||||
/// Replaces the app's reader (a fake engine in tests and capture fixtures);
|
||||
/// null restores the platform one.
|
||||
set debugSpeechController(SpeechController? controller) =>
|
||||
_speech = _bind(controller);
|
||||
|
||||
/// The conversation the app's reader is reading, for the speaking indicator
|
||||
/// and the global Stop. It follows the reader [debugSpeechController]
|
||||
/// installs, and stays null until a reader exists.
|
||||
ValueListenable<SpeechReading?> get speechReading => _reading;
|
||||
|
||||
SpeechController? _speech;
|
||||
final _reading = _AppSpeechReading();
|
||||
|
||||
T _bind<T extends SpeechController?>(T controller) {
|
||||
_reading.bind(controller);
|
||||
return controller;
|
||||
}
|
||||
|
||||
class _AppSpeechReading extends ChangeNotifier
|
||||
implements ValueListenable<SpeechReading?> {
|
||||
SpeechController? _source;
|
||||
|
||||
@override
|
||||
SpeechReading? get value => _source?.reading.value;
|
||||
|
||||
void bind(SpeechController? source) {
|
||||
final before = value;
|
||||
_source?.reading.removeListener(notifyListeners);
|
||||
_source = source;
|
||||
source?.reading.addListener(notifyListeners);
|
||||
// The reader is created lazily, often while a reply builds: a fresh one
|
||||
// reads nothing, so it changes nothing and must not notify mid-build.
|
||||
if (value != before) notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
export 'app_speech.dart';
|
||||
export 'speech_controller.dart';
|
||||
export 'speech_document.dart';
|
||||
export 'speech_engine.dart';
|
||||
export 'speech_origin.dart';
|
||||
export 'speech_preferences.dart';
|
||||
export 'speech_reading.dart';
|
||||
|
||||
@@ -7,11 +7,18 @@ import 'flutter_tts_speech_engine.dart'
|
||||
import 'speech_document.dart';
|
||||
import 'speech_engine.dart';
|
||||
import 'speech_preferences.dart';
|
||||
import 'speech_reading.dart';
|
||||
|
||||
enum SpeechState { idle, speaking, paused }
|
||||
|
||||
/// The app-wide reader: one reply speaks at a time. It notifies on state
|
||||
/// changes; the spoken word moves on the separate, frequent [word].
|
||||
///
|
||||
/// It belongs to the app (see [speechController]), not to the conversation
|
||||
/// that started it: leaving that chat, switching panes or opening the list
|
||||
/// keeps the reply reading. It ends when stopped, when it finishes, when
|
||||
/// another reply starts, when its chat is closed or deleted ([stopScope]),
|
||||
/// and when the app goes to the background or closes.
|
||||
class SpeechController extends ChangeNotifier with WidgetsBindingObserver {
|
||||
SpeechController({SpeechEngine? engine, SpeechPreferencesStore? store})
|
||||
: engine = engine ?? createSpeechEngine(),
|
||||
@@ -44,6 +51,10 @@ class SpeechController extends ChangeNotifier with WidgetsBindingObserver {
|
||||
/// The range of the word being spoken in [document]'s text, or null.
|
||||
final word = ValueNotifier<SpeechRange?>(null);
|
||||
|
||||
/// The conversation whose reply is reading (paused included), or null.
|
||||
/// It changes only when a reading starts, ends or its chat is renamed.
|
||||
final reading = ValueNotifier<SpeechReading?>(null);
|
||||
|
||||
bool get supported => engine.supported;
|
||||
SpeechState get state => _state;
|
||||
String? get messageId => _messageId;
|
||||
@@ -64,12 +75,25 @@ class SpeechController extends ChangeNotifier with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
/// Reads reply [id] made of markdown [parts], stopping any other reading.
|
||||
Future<void> read(String id, List<String> parts) async {
|
||||
/// [scope] is the reply's conversation (by default the part of [id] before
|
||||
/// its first `/`, see [speechMessageId]) and [title] its name, which the
|
||||
/// speaking indicator and the global Stop show.
|
||||
Future<void> read(
|
||||
String id,
|
||||
List<String> parts, {
|
||||
String? scope,
|
||||
String title = '',
|
||||
}) async {
|
||||
final document = speechDocumentFor(parts);
|
||||
await stop();
|
||||
await restore();
|
||||
if (document.text.isEmpty) return;
|
||||
await _speak(id, document, _voice);
|
||||
await _speak(
|
||||
id,
|
||||
document,
|
||||
_voice,
|
||||
SpeechReading(scope: scope ?? speechScopeOf(id), title: title),
|
||||
);
|
||||
}
|
||||
|
||||
/// Speaks a short sample in [voice] (or the chosen one) at the chosen rate.
|
||||
@@ -80,12 +104,19 @@ class SpeechController extends ChangeNotifier with WidgetsBindingObserver {
|
||||
speechSampleId,
|
||||
speechDocumentFor(['This is how replies will sound when read aloud.']),
|
||||
voice ?? _voice,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _speak(String id, SpeechDocument document, SpeechVoice? voice) {
|
||||
Future<void> _speak(
|
||||
String id,
|
||||
SpeechDocument document,
|
||||
SpeechVoice? voice,
|
||||
SpeechReading? origin,
|
||||
) {
|
||||
_messageId = id;
|
||||
_document = document;
|
||||
reading.value = origin;
|
||||
_awaitingStart = true;
|
||||
word.value = null;
|
||||
_set(SpeechState.speaking);
|
||||
@@ -131,13 +162,24 @@ class SpeechController extends ChangeNotifier with WidgetsBindingObserver {
|
||||
_clear();
|
||||
}
|
||||
|
||||
/// Stops reading when the reply being read has an id under [scope].
|
||||
/// Stops reading when the reply being read belongs to conversation
|
||||
/// [scope]: the chat was closed or deleted.
|
||||
Future<void> stopScope(String scope) async {
|
||||
if (_messageId?.startsWith(speechScopePrefix(scope)) ?? false) {
|
||||
if (reading.value?.scope == scope ||
|
||||
(_messageId?.startsWith(speechScopePrefix(scope)) ?? false)) {
|
||||
await stop();
|
||||
}
|
||||
}
|
||||
|
||||
/// Follows a rename of the conversation being read.
|
||||
void retitle(String scope, String title) {
|
||||
final current = reading.value;
|
||||
if (current == null || current.scope != scope || current.title == title) {
|
||||
return;
|
||||
}
|
||||
reading.value = SpeechReading(scope: scope, title: title);
|
||||
}
|
||||
|
||||
/// Sets the rate for the next reading; [save] false previews a slider drag.
|
||||
Future<void> setRate(double value, {bool save = true}) async {
|
||||
_rate = value.clamp(minSpeechRate, maxSpeechRate);
|
||||
@@ -219,6 +261,7 @@ class SpeechController extends ChangeNotifier with WidgetsBindingObserver {
|
||||
_messageId = null;
|
||||
_document = null;
|
||||
word.value = null;
|
||||
reading.value = null;
|
||||
_state = SpeechState.idle;
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -247,6 +290,7 @@ class SpeechController extends ChangeNotifier with WidgetsBindingObserver {
|
||||
..onProgress = null;
|
||||
if (_state != SpeechState.idle) unawaited(engine.stop().catchError((_) {}));
|
||||
word.dispose();
|
||||
reading.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -260,13 +304,8 @@ String speechScopePrefix(String scope) => '$scope/';
|
||||
/// A reply's id for the reader, unique across conversations.
|
||||
String speechMessageId(String scope, String rowId) => '$scope/$rowId';
|
||||
|
||||
SpeechController? _speechController;
|
||||
|
||||
/// The app's single reader.
|
||||
SpeechController get speechController =>
|
||||
_speechController ??= SpeechController();
|
||||
|
||||
/// Replaces the app's reader (a fake engine in tests and capture fixtures);
|
||||
/// null restores the platform one.
|
||||
set debugSpeechController(SpeechController? controller) =>
|
||||
_speechController = controller;
|
||||
/// The conversation part of a reader id made by [speechMessageId].
|
||||
String speechScopeOf(String id) {
|
||||
final slash = id.indexOf('/');
|
||||
return slash < 0 ? id : id.substring(0, slash);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// Names the conversation a subtree's replies belong to, so Read aloud can
|
||||
/// label the reading (the speaking indicator and the global Stop show it).
|
||||
/// Looked up when a reading starts; it rebuilds nothing.
|
||||
class SpeechOrigin extends InheritedWidget {
|
||||
const SpeechOrigin({
|
||||
super.key,
|
||||
required this.scope,
|
||||
required this.title,
|
||||
required super.child,
|
||||
});
|
||||
|
||||
final String scope;
|
||||
final String title;
|
||||
|
||||
static SpeechOrigin? maybeOf(BuildContext context) =>
|
||||
context.getInheritedWidgetOfExactType<SpeechOrigin>();
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(SpeechOrigin oldWidget) => false;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// The conversation a reading reply belongs to: [scope] is its chat id (the
|
||||
/// list row's `id`, a federated id in a combined list) and [title] its name.
|
||||
@immutable
|
||||
class SpeechReading {
|
||||
const SpeechReading({required this.scope, this.title = ''});
|
||||
|
||||
final String scope;
|
||||
final String title;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is SpeechReading && other.scope == scope && other.title == title;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(scope, title);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import '../../../../ui/adaptive/segmented_bar_overflow.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../ui/status/app_spinner.dart';
|
||||
import '../../../../ui/theme/app_design_tokens.dart';
|
||||
|
||||
class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
|
||||
const ChatBarAction({
|
||||
@@ -220,7 +221,9 @@ class ChatUndoBar extends StatelessWidget {
|
||||
);
|
||||
return Material(
|
||||
elevation: 3,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderRadius: AppDesignTokens.of(
|
||||
context,
|
||||
).denseCorners(BorderRadius.circular(8)),
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
child: content,
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../speech/app_speech.dart';
|
||||
import 'chat_session_state.dart';
|
||||
import 'session_activity_badge.dart';
|
||||
|
||||
@@ -14,7 +15,11 @@ class ChatCompactAvatar extends StatelessWidget {
|
||||
required this.backgroundTasks,
|
||||
this.awaitingOperator = 0,
|
||||
required this.unread,
|
||||
this.sessionId = '',
|
||||
});
|
||||
|
||||
/// The chat's id; its reply being read aloud shows the speaking badge.
|
||||
final String sessionId;
|
||||
final String title;
|
||||
final Color color;
|
||||
final bool active, visible, running, unread;
|
||||
@@ -45,13 +50,21 @@ class ChatCompactAvatar extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (chatSessionActivityBadge(
|
||||
running: running,
|
||||
backgroundTasks: backgroundTasks,
|
||||
awaitingOperator: awaitingOperator,
|
||||
)
|
||||
case final badge?)
|
||||
PositionedDirectional(bottom: -2, end: -3, child: badge),
|
||||
PositionedDirectional(
|
||||
bottom: -2,
|
||||
end: -3,
|
||||
child: ValueListenableBuilder(
|
||||
valueListenable: speechReading,
|
||||
builder: (context, reading, _) =>
|
||||
chatSessionActivityBadge(
|
||||
running: running,
|
||||
backgroundTasks: backgroundTasks,
|
||||
awaitingOperator: awaitingOperator,
|
||||
speaking: sessionId.isNotEmpty && reading?.scope == sessionId,
|
||||
) ??
|
||||
const SizedBox.shrink(),
|
||||
),
|
||||
),
|
||||
if (unread)
|
||||
PositionedDirectional(
|
||||
top: -2,
|
||||
|
||||
@@ -14,6 +14,7 @@ import 'session_row_style.dart';
|
||||
import '../../domain/chat_list_activity.dart';
|
||||
import 'chat_sessions_body.dart';
|
||||
import 'chat_sessions_controller.dart';
|
||||
import '../../../../ui/theme/app_design_tokens.dart';
|
||||
|
||||
/// A small, scrollable device-local rail. Full titles remain accessible.
|
||||
class ChatCompactSidebar extends StatelessWidget {
|
||||
@@ -102,6 +103,7 @@ class ChatCompactSidebar extends StatelessWidget {
|
||||
awaitingOperator: awaitingOperator,
|
||||
backgroundTasks: backgroundTasks,
|
||||
unread: unread,
|
||||
sessionId: id,
|
||||
),
|
||||
if (machineName case final name?)
|
||||
Text(
|
||||
@@ -147,7 +149,9 @@ class ChatCompactSidebar extends StatelessWidget {
|
||||
data: row,
|
||||
feedback: Material(
|
||||
elevation: 4,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderRadius: AppDesignTokens.of(
|
||||
context,
|
||||
).denseCorners(BorderRadius.circular(20)),
|
||||
child: Chip(
|
||||
avatar: ChatCompactAvatar(
|
||||
title: title,
|
||||
@@ -158,6 +162,7 @@ class ChatCompactSidebar extends StatelessWidget {
|
||||
awaitingOperator: awaitingOperator,
|
||||
backgroundTasks: backgroundTasks,
|
||||
unread: unread,
|
||||
sessionId: id,
|
||||
),
|
||||
label: Text(title),
|
||||
),
|
||||
|
||||
@@ -12,6 +12,7 @@ import '../../../attention/runtime/attention_ack_sync.dart';
|
||||
import '../../data/chat_repository.dart';
|
||||
import '../../domain/chat_list_activity.dart';
|
||||
import '../../domain/chat_sessions.dart';
|
||||
import '../../speech/app_speech.dart';
|
||||
import 'chat_seen_focus.dart';
|
||||
import 'chat_session_local.dart';
|
||||
import 'session_attention.dart';
|
||||
@@ -425,6 +426,7 @@ class ChatSessionsController extends ChangeNotifier {
|
||||
];
|
||||
_seedLocal();
|
||||
_loading = false;
|
||||
_stopEndedReading(dropped: held.keys.toSet());
|
||||
_notify();
|
||||
} catch (error) {
|
||||
if (generation != _generation) return;
|
||||
@@ -646,7 +648,22 @@ class ChatSessionsController extends ChangeNotifier {
|
||||
}
|
||||
|
||||
void _notify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
if (_disposed) return;
|
||||
_stopEndedReading();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// A reply read aloud ends with its chat: closed here or on another device
|
||||
/// (a refreshed row), or gone from a list that was read successfully
|
||||
/// ([dropped]: deleted, or its machine removed).
|
||||
void _stopEndedReading({Set<String> dropped = const {}}) {
|
||||
final scope = speechReading.value?.scope;
|
||||
if (scope == null) return;
|
||||
final row = _sessions.where((row) => '${row['id'] ?? ''}' == scope);
|
||||
final ended = row.isEmpty
|
||||
? dropped.contains(scope)
|
||||
: row.first['closed_at'] != null || row.first['closed'] == true;
|
||||
if (ended) unawaited(speechControllerIfCreated?.stopScope(scope));
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,16 +1,27 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../ui/status/app_spinner.dart';
|
||||
import '../speech/chat_speaking_glyph.dart';
|
||||
import 'chat_awaiting.dart';
|
||||
|
||||
/// The corner badge a chat's avatar wears for its live activity: the
|
||||
/// platform's activity indicator while a turn runs; otherwise, while
|
||||
/// background tasks still run, a quiet muted glyph (never a second spinner).
|
||||
/// Null when the chat is idle.
|
||||
/// Null when the chat is idle. While one of the chat's replies is read aloud
|
||||
/// ([speaking]) the badge is the speaking glyph instead, above everything
|
||||
/// else: it is the only place that says which chat is talking.
|
||||
Widget? chatSessionActivityBadge({
|
||||
required bool running,
|
||||
required int backgroundTasks,
|
||||
int awaitingOperator = 0,
|
||||
bool speaking = false,
|
||||
}) {
|
||||
if (speaking) {
|
||||
return Semantics(
|
||||
key: const Key('chat-row-speaking'),
|
||||
label: 'Reading aloud',
|
||||
child: const _BadgeDisc(child: ChatSpeakingGlyph()),
|
||||
);
|
||||
}
|
||||
// Waiting on the operator outranks everything: the agent is blocked.
|
||||
if (awaitingOperator > 0) return ChatAwaitingBadge(count: awaitingOperator);
|
||||
if (running) {
|
||||
|
||||
@@ -6,7 +6,6 @@ import '../../../../ui/layout/app_list_avatar.dart';
|
||||
import '../../../../ui/layout/app_list_row.dart';
|
||||
import '../../../../ui/text/relative_time_label.dart';
|
||||
import '../../../../ui/motion/container_transform_source.dart';
|
||||
import '../../../../ui/theme/app_design_tokens.dart';
|
||||
import '../../domain/chat_colors.dart';
|
||||
import '../../domain/chat_list_activity.dart';
|
||||
import '../../domain/chat_sessions.dart';
|
||||
@@ -14,11 +13,13 @@ import 'chat_color_palette.dart';
|
||||
import 'chat_visibility_marker.dart';
|
||||
import 'chat_session_state.dart';
|
||||
import 'session_actions.dart';
|
||||
import '../../speech/app_speech.dart';
|
||||
import 'session_activity_badge.dart';
|
||||
import 'session_harness_icon.dart';
|
||||
import 'session_pane_menu.dart';
|
||||
import 'session_row_style.dart';
|
||||
import 'chat_awaiting.dart';
|
||||
import '../../../../ui/theme/app_design_tokens.dart';
|
||||
|
||||
/// One chat in the list, in the app's shared row on both hosts: the harness
|
||||
/// avatar, the title with its recency, one muted line, and the actions menu.
|
||||
@@ -93,7 +94,9 @@ class ChatSessionRow extends StatelessWidget {
|
||||
data: session,
|
||||
feedback: Material(
|
||||
elevation: 4,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderRadius: AppDesignTokens.of(
|
||||
context,
|
||||
).denseCorners(BorderRadius.circular(20)),
|
||||
child: Chip(
|
||||
avatar: ChatSessionAvatar(session: session),
|
||||
label: Text(chatSessionTitle(session)),
|
||||
@@ -278,15 +281,24 @@ class ChatSessionAvatar extends StatelessWidget {
|
||||
: scheme.surfaceContainerHighest;
|
||||
mark = selected ? scheme.onPrimaryContainer : scheme.onSurfaceVariant;
|
||||
}
|
||||
return AppListAvatar(
|
||||
foreground: mark,
|
||||
background: fill,
|
||||
badge: chatSessionActivityBadge(
|
||||
running: running,
|
||||
backgroundTasks: backgroundTasks,
|
||||
awaitingOperator: awaitingOperator,
|
||||
final id = '${session['id'] ?? ''}';
|
||||
final icon = SessionHarnessIcon(session: session, color: mark);
|
||||
// The badge follows the app's reader: the chat whose reply is being read
|
||||
// aloud shows the speaking glyph, wherever its avatar is drawn.
|
||||
return ValueListenableBuilder(
|
||||
valueListenable: speechReading,
|
||||
child: icon,
|
||||
builder: (context, reading, icon) => AppListAvatar(
|
||||
foreground: mark,
|
||||
background: fill,
|
||||
badge: chatSessionActivityBadge(
|
||||
running: running,
|
||||
backgroundTasks: backgroundTasks,
|
||||
awaitingOperator: awaitingOperator,
|
||||
speaking: id.isNotEmpty && reading?.scope == id,
|
||||
),
|
||||
child: icon!,
|
||||
),
|
||||
child: SessionHarnessIcon(session: session, color: mark),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../ui/theme/app_design_tokens.dart';
|
||||
import '../../speech/speech.dart';
|
||||
|
||||
const chatSpeakingStopLabel = 'Stop speaking';
|
||||
|
||||
/// "Speaking · Chat name" and Stop for the reply the app is reading, from any
|
||||
/// chat: the reader is the app's, so a reply keeps reading after its chat is
|
||||
/// left, and this is the one place to stop it without going back. Nothing
|
||||
/// while no reply reads (the Settings voice sample included).
|
||||
class ChatSpeakingControl extends StatelessWidget {
|
||||
const ChatSpeakingControl({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ValueListenableBuilder(
|
||||
valueListenable: speechReading,
|
||||
builder: (context, reading, _) {
|
||||
final speech = speechControllerIfCreated;
|
||||
if (reading == null || speech == null) return const SizedBox.shrink();
|
||||
return ListenableBuilder(
|
||||
listenable: speech,
|
||||
builder: (context, _) => _pill(context, speech, reading),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Widget _pill(
|
||||
BuildContext context,
|
||||
SpeechController speech,
|
||||
SpeechReading reading,
|
||||
) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final state = speech.state == SpeechState.paused ? 'Paused' : 'Speaking';
|
||||
final title = reading.title.isEmpty ? 'a chat' : reading.title;
|
||||
final label = '$state · $title';
|
||||
final text = Theme.of(context).textTheme.labelMedium;
|
||||
return Padding(
|
||||
padding: const EdgeInsetsDirectional.only(bottom: 8),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Material(
|
||||
key: const Key('chat-speaking-control'),
|
||||
color: tokens.panelFill(scheme, scheme.surfaceContainerHigh),
|
||||
shape: tokens
|
||||
.shape(const StadiumBorder())
|
||||
.copyWith(side: tokens.frameSide),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 12),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.graphic_eq, size: 16, color: scheme.primary),
|
||||
const SizedBox(width: 8),
|
||||
Flexible(
|
||||
child: Semantics(
|
||||
liveRegion: true,
|
||||
child: Text(
|
||||
label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: text?.copyWith(color: scheme.onSurfaceVariant),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
key: const Key('chat-speaking-stop'),
|
||||
tooltip: chatSpeakingStopLabel,
|
||||
visualDensity: VisualDensity.compact,
|
||||
iconSize: 18,
|
||||
onPressed: () => unawaited(speech.stop()),
|
||||
icon: const Icon(Icons.stop),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// A chat's "speaking" mark: three sound-wave bars that rise and fall while
|
||||
/// one of its replies is read aloud. Under reduced motion it is a still
|
||||
/// speaker icon.
|
||||
class ChatSpeakingGlyph extends StatefulWidget {
|
||||
const ChatSpeakingGlyph({super.key, this.size = 12, this.color});
|
||||
|
||||
final double size;
|
||||
|
||||
/// Null takes the theme's primary colour.
|
||||
final Color? color;
|
||||
|
||||
@override
|
||||
State<ChatSpeakingGlyph> createState() => _ChatSpeakingGlyphState();
|
||||
}
|
||||
|
||||
class _ChatSpeakingGlyphState extends State<ChatSpeakingGlyph>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _wave = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 900),
|
||||
);
|
||||
|
||||
bool get _still => MediaQuery.maybeDisableAnimationsOf(context) ?? false;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (_still) {
|
||||
_wave.stop();
|
||||
} else if (!_wave.isAnimating) {
|
||||
_wave.repeat();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_wave.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = widget.color ?? Theme.of(context).colorScheme.primary;
|
||||
if (_still) {
|
||||
return Icon(
|
||||
Icons.volume_up,
|
||||
key: const Key('chat-speaking-still'),
|
||||
size: widget.size,
|
||||
color: color,
|
||||
);
|
||||
}
|
||||
// Its own layer: the bars repaint every frame without the row.
|
||||
return RepaintBoundary(
|
||||
child: CustomPaint(
|
||||
key: const Key('chat-speaking-wave'),
|
||||
size: Size.square(widget.size),
|
||||
painter: _WavePainter(_wave, color),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _WavePainter extends CustomPainter {
|
||||
_WavePainter(this.wave, this.color) : super(repaint: wave);
|
||||
|
||||
final Animation<double> wave;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
const bars = 3;
|
||||
final gap = size.width / (bars * 2 + 1);
|
||||
final paint = Paint()
|
||||
..color = color
|
||||
..strokeWidth = gap * 1.4
|
||||
..strokeCap = StrokeCap.round;
|
||||
for (var bar = 0; bar < bars; bar++) {
|
||||
final phase = (wave.value + bar / bars) * 2 * math.pi;
|
||||
// Each bar swings between a third and the full height, out of step.
|
||||
final height = size.height * (0.35 + 0.3 * (1 + math.sin(phase)));
|
||||
final x = gap * (bar * 2 + 1.5);
|
||||
final top = (size.height - height) / 2 + paint.strokeWidth / 2;
|
||||
final bottom = (size.height + height) / 2 - paint.strokeWidth / 2;
|
||||
canvas.drawLine(Offset(x, top), Offset(x, math.max(top, bottom)), paint);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(_WavePainter oldDelegate) =>
|
||||
oldDelegate.color != color || oldDelegate.wave != wave;
|
||||
}
|
||||
@@ -71,8 +71,10 @@ class ChatAutomatedPromptCard extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
);
|
||||
final transcript = AppDesignTokens.of(context).transcript;
|
||||
final glass = AppDesignTokens.of(context).glass;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final density = tokens.density;
|
||||
final transcript = tokens.transcript;
|
||||
final glass = tokens.glass;
|
||||
final card = transcript == TranscriptStyle.manuscript
|
||||
? PaperEditorialNote(
|
||||
label: label,
|
||||
@@ -90,16 +92,21 @@ class ChatAutomatedPromptCard extends StatelessWidget {
|
||||
// edge.
|
||||
shape: glass == null
|
||||
? RoundedRectangleBorder(
|
||||
borderRadius: _noteCorners,
|
||||
borderRadius: tokens.corners(_noteCorners),
|
||||
side: BorderSide(color: scheme.outlineVariant),
|
||||
)
|
||||
: GlassBorder(
|
||||
borderRadius: _noteCorners,
|
||||
borderRadius: tokens.corners(_noteCorners),
|
||||
highlight: glass.highlight,
|
||||
edge: glass.edge,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 8, 14, 10),
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
density.inset(14),
|
||||
density.space(8),
|
||||
density.inset(14),
|
||||
density.space(10),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
||||
@@ -166,7 +166,11 @@ class ChatCodeCopyRegion extends StatelessWidget {
|
||||
key: const Key('chat-code-header'),
|
||||
color: headerFill(context),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 12, end: 4),
|
||||
// Its label starts at the code's own inset (tighter when dense).
|
||||
padding: EdgeInsetsDirectional.only(
|
||||
start: AppDesignTokens.of(context).density.space(12),
|
||||
end: 4,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: label),
|
||||
|
||||
@@ -272,7 +272,9 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
code: code,
|
||||
label: Text(markdownCodeLabel(language), style: labelStyle),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
padding: EdgeInsets.all(
|
||||
AppDesignTokens.of(context).density.space(12),
|
||||
),
|
||||
child: ChatTranscriptHorizontalScrollView(
|
||||
label: 'code block',
|
||||
child: Text.rich(
|
||||
@@ -570,9 +572,15 @@ class _ChatMarkdownViewState extends State<ChatMarkdownView> {
|
||||
/// a tighter line, as a technical book does.
|
||||
TextStyle _codeStyle(BuildContext context) {
|
||||
const mono = TextStyle(fontFamily: appMonospaceFamily);
|
||||
final reading = AppDesignTokens.of(context).reading;
|
||||
if (reading.family == null) return mono;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final reading = tokens.reading;
|
||||
final size = DefaultTextStyle.of(context).style.fontSize ?? 16;
|
||||
// A dense design sets code at its body size (13 beside 14px prose): the
|
||||
// monospace runs wider than the prose face.
|
||||
if (reading.family == null && tokens.density.dense) {
|
||||
return mono.copyWith(fontSize: size * 13 / 14, height: 1.4);
|
||||
}
|
||||
if (reading.family == null) return mono;
|
||||
return mono.copyWith(
|
||||
fontSize: size * 0.82,
|
||||
height: 1.45,
|
||||
|
||||
@@ -59,7 +59,10 @@ class ChatUserBubble extends StatelessWidget {
|
||||
// scrolls, so it never filters what is behind it).
|
||||
final glass = AppDesignTokens.of(context).glass;
|
||||
// A Material surface (not a bare DecoratedBox) so a disclosure ListTile
|
||||
// inside the bubble keeps its ink and background.
|
||||
// inside the bubble keeps its ink and background. A dense design draws
|
||||
// a tighter bubble in its own corners.
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final density = tokens.density;
|
||||
return Material(
|
||||
color: chatBubbleFill(
|
||||
context,
|
||||
@@ -67,13 +70,21 @@ class ChatUserBubble extends StatelessWidget {
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
shape: glass == null
|
||||
? const RoundedRectangleBorder(borderRadius: _radius)
|
||||
? RoundedRectangleBorder(borderRadius: tokens.corners(_radius))
|
||||
: GlassBorder(
|
||||
borderRadius: _radius,
|
||||
borderRadius: tokens.corners(_radius),
|
||||
highlight: glass.highlight,
|
||||
edge: glass.edge,
|
||||
),
|
||||
child: Padding(padding: _padding, child: child),
|
||||
child: Padding(
|
||||
padding: density.dense
|
||||
? EdgeInsets.symmetric(
|
||||
horizontal: density.inset(_padding.left),
|
||||
vertical: density.space(_padding.top),
|
||||
)
|
||||
: _padding,
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -99,8 +110,10 @@ TextStyle? chatMessageTextStyle(BuildContext context) => AppDesignTokens.of(
|
||||
|
||||
/// The empty-line gap between two paragraphs of a reply: about one line of
|
||||
/// body text at [fontSize] (else the ambient text size), scaled by the
|
||||
/// operator's text scaling, so chunks read as separate paragraphs.
|
||||
/// operator's text scaling, so chunks read as separate paragraphs. A design
|
||||
/// may set a tighter gap ([ReadingType.paragraphGap]).
|
||||
double chatParagraphGap(BuildContext context, [double? fontSize]) {
|
||||
final size = fontSize ?? DefaultTextStyle.of(context).style.fontSize ?? 14;
|
||||
return MediaQuery.textScalerOf(context).scale(size) * 0.9;
|
||||
return MediaQuery.textScalerOf(context).scale(size) *
|
||||
AppDesignTokens.of(context).reading.paragraphGap;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import 'paper/paper_quote.dart';
|
||||
import 'terminal/terminal_glyphs.dart';
|
||||
import 'chat_message_timestamp.dart';
|
||||
import 'chat_read_aloud_button.dart';
|
||||
import '../../speech/speech_controller.dart';
|
||||
import '../../speech/speech.dart';
|
||||
|
||||
/// Builds an assistant text part; the default keeps the server's text exactly.
|
||||
typedef ChatMessageTextBuilder = Widget Function(BuildContext, String);
|
||||
@@ -83,7 +83,8 @@ class ChatMessageView extends StatelessWidget {
|
||||
// A terminal or manuscript transcript reads top to bottom: the
|
||||
// operator's prompt line or block quote starts at the same edge as the
|
||||
// answer and spans its column.
|
||||
final transcript = AppDesignTokens.of(context).transcript;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final transcript = tokens.transcript;
|
||||
final trailingUser =
|
||||
user && !automated && transcript == TranscriptStyle.bubbles;
|
||||
// No visible role label: side and surface say who spoke and the row's
|
||||
@@ -104,9 +105,12 @@ class ChatMessageView extends StatelessWidget {
|
||||
label: '$role message',
|
||||
child: Padding(
|
||||
// A manuscript leaves a little more air between turns, as a page
|
||||
// spaces its paragraphs, since no bubble sets them apart.
|
||||
// spaces its paragraphs, since no bubble sets them apart; a dense
|
||||
// design a little less.
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: transcript == TranscriptStyle.manuscript ? 12 : 6,
|
||||
vertical: transcript == TranscriptStyle.manuscript
|
||||
? 12
|
||||
: tokens.density.space(6),
|
||||
),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) => Align(
|
||||
|
||||
@@ -13,6 +13,8 @@ const chatStopReadingLabel = 'Stop reading';
|
||||
/// Read aloud for one reply, styled like its Copy button. While this reply
|
||||
/// reads it becomes Pause (or Resume) and Stop, laid out along [direction]
|
||||
/// (a column in the narrow copy gutter). Absent where speech is unsupported.
|
||||
/// The reader is the app's, so a reply still reading after its chat was left
|
||||
/// shows Pause and Stop again when the chat is reopened.
|
||||
class ChatReadAloudButton extends StatelessWidget {
|
||||
const ChatReadAloudButton({
|
||||
super.key,
|
||||
@@ -40,7 +42,19 @@ class ChatReadAloudButton extends StatelessWidget {
|
||||
key: const Key('chat-message-read-aloud'),
|
||||
style: style,
|
||||
tooltip: chatReadAloudLabel,
|
||||
onPressed: () => unawaited(speech.read(messageId, parts)),
|
||||
onPressed: () {
|
||||
// The conversation's name labels the reading wherever it is
|
||||
// shown (the avatar's indicator, the global Stop).
|
||||
final origin = SpeechOrigin.maybeOf(context);
|
||||
unawaited(
|
||||
speech.read(
|
||||
messageId,
|
||||
parts,
|
||||
scope: origin?.scope,
|
||||
title: origin?.title ?? '',
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.volume_up_outlined),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -123,7 +124,8 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
|
||||
: DateTime.now().difference(started);
|
||||
final seconds = duration.inSeconds.clamp(0, 2147483647);
|
||||
final label = '${data.label}${widget.streaming ? ' ${seconds}s' : ''}';
|
||||
switch (AppDesignTokens.of(context).transcript) {
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
switch (tokens.transcript) {
|
||||
case TranscriptStyle.prompt:
|
||||
return TerminalActivityRows(
|
||||
data: data,
|
||||
@@ -145,8 +147,12 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
|
||||
}
|
||||
// Desktop hover hugs the label; phones keep the full-width touch row.
|
||||
final compact = prefersCompactHitTargets(context);
|
||||
// A dense design draws the line slimmer on a pointer device; a touch
|
||||
// device keeps a 40px target.
|
||||
final density = tokens.density;
|
||||
final dense = density.dense;
|
||||
final content = ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: 32),
|
||||
constraints: BoxConstraints(minHeight: dense ? 20 : 32),
|
||||
child: Row(
|
||||
mainAxisSize: compact ? MainAxisSize.min : MainAxisSize.max,
|
||||
children: [
|
||||
@@ -157,7 +163,7 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
|
||||
child: const ChatResponsePending(),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
SizedBox(width: density.space(8)),
|
||||
],
|
||||
Flexible(
|
||||
child: Text(
|
||||
@@ -179,8 +185,13 @@ class _ChatTurnActivityViewState extends State<ChatTurnActivityView> {
|
||||
final button = TextButton(
|
||||
key: const Key('chat-turn-activity'),
|
||||
style: TextButton.styleFrom(
|
||||
minimumSize: const Size(0, 48),
|
||||
padding: const EdgeInsets.all(chatAgentContentInset),
|
||||
minimumSize: Size(0, dense ? math.max(28, density.minTouchRow) : 48),
|
||||
padding: dense
|
||||
? const EdgeInsets.symmetric(
|
||||
horizontal: chatAgentContentInset,
|
||||
vertical: 4,
|
||||
)
|
||||
: const EdgeInsets.all(chatAgentContentInset),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
),
|
||||
|
||||
@@ -113,9 +113,9 @@ class _ChatTurnChipState extends State<ChatTurnChip> {
|
||||
borderRadius: corners,
|
||||
onTap: _show,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: chatAgentContentInset,
|
||||
vertical: 6,
|
||||
vertical: AppDesignTokens.of(context).density.space(6),
|
||||
),
|
||||
child: content,
|
||||
),
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// The step Alt+] (1) or Alt+[ (-1) moves the keyboard between the chat
|
||||
/// panes on screen, or null for any other key. On Apple platforms Cmd+] and
|
||||
/// Cmd+[ do the same.
|
||||
///
|
||||
/// Why these keys:
|
||||
/// - Alt+Tab and Cmd+Tab are the system's window switchers, Ctrl+Tab cycles
|
||||
/// the open chats (and the browser keeps it), and Alt+` already cycles the
|
||||
/// floating windows.
|
||||
/// - Browsers use Alt+Left/Right for back and forward; nothing on GNOME,
|
||||
/// Hyprland, Windows or a browser binds Alt+[ or Alt+].
|
||||
/// - Option+] and Option+[ type quotes on a Mac, so with Alt the key is
|
||||
/// matched by its position (also catching layouts whose bracket keys type
|
||||
/// something else). Cmd+] and Cmd+[ are the Mac's own next/previous pair
|
||||
/// and leave Option free for typing.
|
||||
/// - AltGr is how several layouts type brackets, so it never matches.
|
||||
///
|
||||
/// Shift never matches: Alt+Shift+[ types braces. A focused terminal keeps
|
||||
/// these keys (Alt+[ is its escape prefix); the caller checks that.
|
||||
int? chatPaneCycleShortcut(
|
||||
KeyEvent event,
|
||||
HardwareKeyboard keyboard, {
|
||||
TargetPlatform? platform,
|
||||
}) {
|
||||
if (event is KeyUpEvent ||
|
||||
keyboard.isShiftPressed ||
|
||||
keyboard.isControlPressed ||
|
||||
keyboard.isLogicalKeyPressed(LogicalKeyboardKey.altGraph)) {
|
||||
return null;
|
||||
}
|
||||
final alt = keyboard.isAltPressed;
|
||||
final meta = keyboard.isMetaPressed;
|
||||
final int? step;
|
||||
if (alt && !meta) {
|
||||
step = switch (event.physicalKey) {
|
||||
PhysicalKeyboardKey.bracketRight => 1,
|
||||
PhysicalKeyboardKey.bracketLeft => -1,
|
||||
_ => null,
|
||||
};
|
||||
} else if (meta && !alt && _apple(platform ?? defaultTargetPlatform)) {
|
||||
step =
|
||||
event.logicalKey == LogicalKeyboardKey.bracketRight ||
|
||||
event.physicalKey == PhysicalKeyboardKey.bracketRight
|
||||
? 1
|
||||
: event.logicalKey == LogicalKeyboardKey.bracketLeft ||
|
||||
event.physicalKey == PhysicalKeyboardKey.bracketLeft
|
||||
? -1
|
||||
: null;
|
||||
} else {
|
||||
step = null;
|
||||
}
|
||||
return step;
|
||||
}
|
||||
|
||||
bool _apple(TargetPlatform platform) =>
|
||||
platform == TargetPlatform.macOS || platform == TargetPlatform.iOS;
|
||||
|
||||
/// The forward and backward chords as this platform reads them, for the
|
||||
/// shortcuts list.
|
||||
String chatPaneCycleShortcutLabel([TargetPlatform? platform]) =>
|
||||
_apple(platform ?? defaultTargetPlatform)
|
||||
? 'Option+], Option+[, Cmd+], Cmd+['
|
||||
: 'Alt+], Alt+[';
|
||||
|
||||
/// The entry [step] places from [current] in [order], wrapping around; null
|
||||
/// when there is no other entry to move to. A [current] outside [order]
|
||||
/// starts from the first entry going forward and the last going back.
|
||||
T? chatPaneCycleTarget<T>(List<T> order, int current, int step) {
|
||||
if (order.length < 2 || step == 0) return null;
|
||||
if (current < 0 || current >= order.length) {
|
||||
return step > 0 ? order.first : order.last;
|
||||
}
|
||||
return order[(current + step) % order.length];
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
|
||||
import '../../../ui/theme/app_design_tokens.dart';
|
||||
|
||||
/// Asks the chat pane showing a session to flash its focus ring, once the
|
||||
/// keyboard moved there by the pane-cycling chord (see
|
||||
/// [chatPaneCycleShortcut]). Shared by the tiling and the floating windows.
|
||||
class ChatPaneFlashRequests extends ChangeNotifier {
|
||||
String? _sessionId;
|
||||
int _serial = 0;
|
||||
|
||||
/// The session last asked to flash.
|
||||
String? get sessionId => _sessionId;
|
||||
|
||||
/// Advances on every request, so asking the same pane again flashes again.
|
||||
int get serial => _serial;
|
||||
|
||||
void flash(String sessionId) {
|
||||
_sessionId = sessionId;
|
||||
_serial++;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// How long the ring shows before it is gone.
|
||||
const chatPaneFlashDuration = Duration(milliseconds: 700);
|
||||
|
||||
/// The ring's width, in logical pixels.
|
||||
const chatPaneFlashWidth = 2.0;
|
||||
|
||||
/// One chat pane's focus cue: a ring in the chat's [color] drawn over the
|
||||
/// pane, fading out, when [requests] names [sessionId]. Under reduced motion
|
||||
/// the ring shows for the same time without fading. It also holds a focus
|
||||
/// node around the pane: when nothing inside the pane took the keyboard
|
||||
/// (the composer is not there or cannot be focused), the pane itself does.
|
||||
class ChatPaneFocusFlash extends StatefulWidget {
|
||||
const ChatPaneFocusFlash({
|
||||
super.key,
|
||||
required this.sessionId,
|
||||
required this.requests,
|
||||
required this.color,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final String sessionId;
|
||||
final ChatPaneFlashRequests requests;
|
||||
final Color? color;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<ChatPaneFocusFlash> createState() => _ChatPaneFocusFlashState();
|
||||
}
|
||||
|
||||
class _ChatPaneFocusFlashState extends State<ChatPaneFocusFlash>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _ring = AnimationController(
|
||||
vsync: this,
|
||||
duration: chatPaneFlashDuration,
|
||||
);
|
||||
final FocusNode _pane = FocusNode(
|
||||
debugLabel: 'Chat pane',
|
||||
skipTraversal: true,
|
||||
);
|
||||
int _seen = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_seen = widget.requests.serial;
|
||||
widget.requests.addListener(_requested);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ChatPaneFocusFlash oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.requests != widget.requests) {
|
||||
oldWidget.requests.removeListener(_requested);
|
||||
widget.requests.addListener(_requested);
|
||||
_seen = widget.requests.serial;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.requests.removeListener(_requested);
|
||||
_ring.dispose();
|
||||
_pane.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _requested() {
|
||||
final requests = widget.requests;
|
||||
if (requests.serial == _seen) return;
|
||||
_seen = requests.serial;
|
||||
if (requests.sessionId != widget.sessionId) return;
|
||||
_ring.forward(from: 0);
|
||||
// The composer takes its request after a frame; look a frame later.
|
||||
SchedulerBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
SchedulerBinding.instance
|
||||
..addPostFrameCallback((_) {
|
||||
if (mounted && !_pane.hasFocus) _pane.requestFocus();
|
||||
})
|
||||
..ensureVisualUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = widget.color ?? Theme.of(context).colorScheme.primary;
|
||||
final still = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
|
||||
final radius = AppDesignTokens.of(context).radius ?? 0;
|
||||
return Focus(
|
||||
focusNode: _pane,
|
||||
child: Stack(
|
||||
fit: StackFit.passthrough,
|
||||
children: [
|
||||
widget.child,
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: AnimatedBuilder(
|
||||
animation: _ring,
|
||||
builder: (context, _) {
|
||||
if (!_ring.isAnimating) return const SizedBox.shrink();
|
||||
final fade = still
|
||||
? 1.0
|
||||
: 1 - Curves.easeIn.transform(_ring.value);
|
||||
return DecoratedBox(
|
||||
key: const ValueKey('chat-pane-focus-flash'),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(radius),
|
||||
border: Border.all(
|
||||
color: color.withValues(alpha: color.a * fade),
|
||||
width: chatPaneFlashWidth,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -107,6 +107,7 @@ class _DefinitionGraphViewState extends State<DefinitionGraphView> {
|
||||
edges: edges,
|
||||
extents: extents,
|
||||
labelExtents: labelExtents,
|
||||
metrics: graphMetricsOf(context),
|
||||
);
|
||||
return (layout, routing);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/theme/app_design_tokens.dart';
|
||||
import '../layout/layout_models.dart';
|
||||
import '../layout/linear_graph_layout.dart';
|
||||
import '../routing/route_models.dart';
|
||||
|
||||
/// Centralized graph spacing, not component dimensions. Rank separation follows
|
||||
@@ -27,6 +29,25 @@ RoutingConfig graphCanvasRoutingConfig() => RoutingConfig(
|
||||
boundsPadding: 12,
|
||||
);
|
||||
|
||||
/// The drawing's spacings under the design at [context]: the web's metrics,
|
||||
/// or a dense design's tighter gaps, lanes and padding (Compact), so its
|
||||
/// smaller nodes are not left adrift in a comfortable layout.
|
||||
LinearGraphMetrics graphMetricsOf(BuildContext context) =>
|
||||
AppDesignTokens.of(context).density.dense
|
||||
? _denseGraphMetrics
|
||||
: const LinearGraphMetrics();
|
||||
|
||||
const LinearGraphMetrics _denseGraphMetrics = LinearGraphMetrics(
|
||||
hGap: 32,
|
||||
pad: 16,
|
||||
laneSpacing: 20,
|
||||
terminalGap: 16,
|
||||
trackStep: 16,
|
||||
portSpacing: 8,
|
||||
labelPadding: 6,
|
||||
labelGap: 2,
|
||||
);
|
||||
|
||||
/// The native theme roles one definition graph canvas needs.
|
||||
///
|
||||
/// No palette, font family or size is defined here: every value comes from the
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/status/run_status_icon.dart';
|
||||
import '../../../ui/theme/app_design_tokens.dart';
|
||||
import '../domain/graph_definition.dart';
|
||||
|
||||
/// One content-sized stage node as an ordinary native control.
|
||||
@@ -56,7 +59,7 @@ class GraphStageNode extends StatelessWidget {
|
||||
button: true,
|
||||
selected: selected,
|
||||
label: _label,
|
||||
child: _materialCard(onPressed, content),
|
||||
child: _materialCard(context, onPressed, content),
|
||||
),
|
||||
);
|
||||
return active ? StageActivityHalo(child: control) : control;
|
||||
@@ -66,13 +69,29 @@ class GraphStageNode extends StatelessWidget {
|
||||
/// which assumes one line and cuts into a wrapped label's first and last
|
||||
/// line. A card keeps the rounded-rectangle surface the web node uses, and
|
||||
/// [selected] only chooses between two stock emphasis levels.
|
||||
Widget _materialCard(VoidCallback onPressed, Widget content) {
|
||||
Widget _materialCard(
|
||||
BuildContext context,
|
||||
VoidCallback onPressed,
|
||||
Widget content,
|
||||
) {
|
||||
// A dense design draws a smaller node: half the inset and a 32px
|
||||
// least height on a pointer device (40px on touch).
|
||||
final density = AppDesignTokens.of(context).density;
|
||||
final body = InkWell(
|
||||
onTap: onPressed,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: kMinInteractiveDimension),
|
||||
constraints: BoxConstraints(
|
||||
minHeight: density.dense
|
||||
? math.max(32, density.minTouchRow)
|
||||
: kMinInteractiveDimension,
|
||||
),
|
||||
child: Padding(
|
||||
padding: _contentPadding,
|
||||
padding: density.dense
|
||||
? EdgeInsets.symmetric(
|
||||
horizontal: density.space(_contentPadding.left) + 4,
|
||||
vertical: density.space(_contentPadding.top),
|
||||
)
|
||||
: _contentPadding,
|
||||
child: Align(
|
||||
// A terminal box widens to give each incoming route its own port;
|
||||
// its label stays centred in it.
|
||||
|
||||
@@ -140,6 +140,7 @@ class _RunGraphViewState extends State<RunGraphView> {
|
||||
edges: edges,
|
||||
extents: extents,
|
||||
labelExtents: labelExtents,
|
||||
metrics: graphMetricsOf(context),
|
||||
);
|
||||
return (layout, routing);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import '../../../ui/status/run_status_icon.dart';
|
||||
import '../../../ui/text/monospace.dart';
|
||||
import '../../chat/ui/transcript/chat_markdown_view.dart';
|
||||
import '../domain/check_step_output.dart';
|
||||
import '../../../ui/theme/app_design_tokens.dart';
|
||||
|
||||
/// The note under a command whose recorded output the server cut short.
|
||||
const String checkOutputTruncated =
|
||||
@@ -99,7 +100,9 @@ class RunCheckCommandRow extends StatelessWidget {
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderRadius: AppDesignTokens.of(
|
||||
context,
|
||||
).denseCorners(BorderRadius.circular(8)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
|
||||
@@ -12,6 +12,7 @@ import '../../../ui/layout/sticky_section.dart';
|
||||
import '../../../ui/text/live_elapsed_builder.dart';
|
||||
import '../../../ui/text/monospace.dart';
|
||||
import '../../../ui/adaptive/floating_bar_layout.dart';
|
||||
import '../../../ui/theme/app_design_tokens.dart';
|
||||
|
||||
/// The Summary tab: the run's identity, the recorded facts as one grid,
|
||||
/// the stored original prompt with its copy control and the collapsible Input
|
||||
@@ -231,7 +232,9 @@ Widget _materialBlock(BuildContext context, DetailSummaryRow row) {
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderRadius: AppDesignTokens.of(
|
||||
context,
|
||||
).denseCorners(BorderRadius.circular(8)),
|
||||
),
|
||||
child: SelectableText(
|
||||
row.value,
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../../../ui/text/live_elapsed_builder.dart';
|
||||
import '../../pipelines/pipeline_format.dart' show formatDuration;
|
||||
import '../domain/run_models.dart';
|
||||
import 'run_detail_content.dart';
|
||||
import '../../../ui/theme/app_design_tokens.dart';
|
||||
|
||||
/// The Timeline tab's recorded visits, one shared list row per visit.
|
||||
///
|
||||
@@ -116,7 +117,9 @@ class RunTimelineRow extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.14),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderRadius: AppDesignTokens.of(
|
||||
context,
|
||||
).denseCorners(BorderRadius.circular(10)),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../../../core/transport/pipelines_client.dart'
|
||||
show configuredGatewayEndpoint;
|
||||
import '../../../ui/layout/app_list_avatar.dart';
|
||||
import '../../../ui/layout/app_overflow_menu.dart';
|
||||
import '../../../ui/theme/app_design_tokens.dart';
|
||||
import '../../artifacts/domain/artifact_kind.dart';
|
||||
import '../../artifacts/domain/artifact_record.dart';
|
||||
import '../../artifacts/ui/artifact_tile.dart';
|
||||
@@ -48,9 +49,11 @@ Widget? searchArtifactThumbnail(BuildContext context, JsonMap hit) {
|
||||
return null;
|
||||
}
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderRadius: AppDesignTokens.of(
|
||||
context,
|
||||
).denseCorners(BorderRadius.circular(8)),
|
||||
child: SizedBox.square(
|
||||
dimension: kAppListAvatarSize,
|
||||
dimension: appListAvatarSize(context),
|
||||
child: ArtifactThumbnail(
|
||||
key: ValueKey('search.thumbnail.${hit['target']}'),
|
||||
artifact: record,
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart';
|
||||
import '../chat/workspace/chat_center_stage_controller.dart';
|
||||
import '../chat/workspace/chat_float_shortcut.dart';
|
||||
import '../chat/workspace/chat_list_hidden_controller.dart';
|
||||
import '../chat/workspace/chat_pane_cycle.dart';
|
||||
import '../terminal/terminal_shortcuts.dart';
|
||||
import '../../shell/detached/detached_window_scope.dart';
|
||||
import '../../shell/windows/window_shortcuts.dart';
|
||||
@@ -197,6 +198,13 @@ class KeyboardShortcutRegistry {
|
||||
action: 'Focus the neighbouring chat pane',
|
||||
keys: _apple ? 'Cmd+Shift+Arrows' : 'Ctrl+Shift+Arrows',
|
||||
),
|
||||
KeyboardShortcutEntry(
|
||||
group: KeyboardShortcutGroup.chat,
|
||||
action: 'Next or previous chat pane on screen',
|
||||
keys: chatPaneCycleShortcutLabel(platform),
|
||||
caveat:
|
||||
'On a wide window with more than one chat shown: the tiled panes left to right, then top to bottom, then the floating chat windows, wrapping around. The pane\'s message input takes the keyboard and its border flashes. No chat opens or closes. In the terminal the keys go to the terminal.',
|
||||
),
|
||||
KeyboardShortcutEntry(
|
||||
group: KeyboardShortcutGroup.chat,
|
||||
action: 'Move the active chat pane',
|
||||
|
||||
@@ -56,6 +56,7 @@ class SettingsDesignSection extends StatelessWidget {
|
||||
subtitle: Text(design.description),
|
||||
secondary: DesignSwatchPreview(
|
||||
swatch: design.swatch(Theme.of(context).brightness),
|
||||
lines: design.swatchLines,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -64,12 +65,14 @@ class SettingsDesignSection extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// A design's small preview in the picker: its page with a line of its ink
|
||||
/// and a dot of its accent, framed by a hairline.
|
||||
/// A design's small preview in the picker: its page with [lines] lines of
|
||||
/// its ink (the last one short) and a dot of its accent, framed by a
|
||||
/// hairline. A dense design draws more, tighter lines in the same page.
|
||||
class DesignSwatchPreview extends StatelessWidget {
|
||||
const DesignSwatchPreview({super.key, required this.swatch});
|
||||
const DesignSwatchPreview({super.key, required this.swatch, this.lines = 2});
|
||||
|
||||
final DesignSwatch swatch;
|
||||
final int lines;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ExcludeSemantics(
|
||||
@@ -89,10 +92,14 @@ class DesignSwatchPreview extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(height: 2, color: swatch.ink),
|
||||
for (var line = 1; line < lines; line += 1)
|
||||
Container(height: lines > 2 ? 1 : 2, color: swatch.ink),
|
||||
FractionallySizedBox(
|
||||
widthFactor: 0.6,
|
||||
child: Container(height: 2, color: swatch.ink),
|
||||
child: Container(
|
||||
height: lines > 2 ? 1 : 2,
|
||||
color: swatch.ink,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -33,16 +33,17 @@ class SettingsGroup extends StatelessWidget {
|
||||
final footer = this.footer;
|
||||
final theme = Theme.of(context);
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final inset = settingsRowInsetOf(context);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
if (title != null)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(
|
||||
settingsRowInset,
|
||||
padding: EdgeInsetsDirectional.fromSTEB(
|
||||
inset,
|
||||
0,
|
||||
settingsRowInset,
|
||||
settingsTitleGap,
|
||||
inset,
|
||||
tokens.density.space(settingsTitleGap),
|
||||
),
|
||||
child: Semantics(
|
||||
header: true,
|
||||
@@ -74,7 +75,7 @@ class SettingsGroup extends StatelessWidget {
|
||||
Divider(
|
||||
height: 1,
|
||||
thickness: 1,
|
||||
indent: settingsRowInset,
|
||||
indent: inset,
|
||||
color: theme.colorScheme.outlineVariant,
|
||||
),
|
||||
child,
|
||||
@@ -92,11 +93,12 @@ class SettingsGroup extends StatelessWidget {
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
);
|
||||
final text = DefaultTextStyle.merge(style: style, child: footer);
|
||||
final inset = settingsRowInsetOf(context);
|
||||
return Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(
|
||||
settingsRowInset,
|
||||
settingsFieldGap + 2,
|
||||
settingsRowInset,
|
||||
padding: EdgeInsetsDirectional.fromSTEB(
|
||||
inset,
|
||||
AppDesignTokens.of(context).density.space(settingsFieldGap + 2),
|
||||
inset,
|
||||
0,
|
||||
),
|
||||
child: text,
|
||||
@@ -124,8 +126,8 @@ class SettingsGroupItem extends StatelessWidget {
|
||||
width: double.infinity,
|
||||
child: Padding(
|
||||
padding: EdgeInsetsDirectional.symmetric(
|
||||
horizontal: settingsRowInset,
|
||||
vertical: 12,
|
||||
horizontal: settingsRowInsetOf(context),
|
||||
vertical: AppDesignTokens.of(context).density.space(12),
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
/// at a reading width beside the section index.
|
||||
library;
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../../ui/theme/app_design_tokens.dart';
|
||||
|
||||
/// The widest the column of groups grows on a wide window.
|
||||
const double settingsContentMaxWidth = 720;
|
||||
|
||||
@@ -50,3 +54,12 @@ const double settingsPreloadViewports = 1;
|
||||
|
||||
/// How long a changing endpoint must settle before a server section reloads.
|
||||
const Duration settingsEndpointDebounce = Duration(milliseconds: 600);
|
||||
|
||||
/// [settingsSectionGap] under the design at [context] (tighter when dense).
|
||||
double settingsSectionGapOf(BuildContext context) =>
|
||||
AppDesignTokens.of(context).density.space(settingsSectionGap);
|
||||
|
||||
/// [settingsRowInset] under the design at [context]: a dense design's rows
|
||||
/// (its ListTiles' 12px padding) and their headers keep the same edge.
|
||||
double settingsRowInsetOf(BuildContext context) =>
|
||||
AppDesignTokens.of(context).density.inset(settingsRowInset);
|
||||
|
||||
@@ -34,7 +34,7 @@ class SettingsPageBody extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
for (final (index, child) in children.indexed) ...<Widget>[
|
||||
if (index > 0) const SizedBox(height: settingsSectionGap),
|
||||
if (index > 0) SizedBox(height: settingsSectionGapOf(context)),
|
||||
child,
|
||||
],
|
||||
],
|
||||
|
||||
@@ -44,7 +44,7 @@ import 'settings_keyboard_shortcuts_section.dart';
|
||||
import 'settings_keys.dart';
|
||||
import 'settings_row.dart';
|
||||
import 'settings_read_aloud_section.dart';
|
||||
import '../chat/speech/speech_controller.dart';
|
||||
import '../chat/speech/speech.dart';
|
||||
|
||||
import 'settings_open_in_chat_section.dart';
|
||||
part 'settings_page_sections.dart';
|
||||
|
||||
@@ -171,7 +171,7 @@ class _SettingsSearchPageState extends State<SettingsSearchPage> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: settingsSectionGap),
|
||||
SizedBox(height: settingsSectionGapOf(context)),
|
||||
Expanded(child: _list(visible, insets)),
|
||||
],
|
||||
),
|
||||
@@ -201,7 +201,7 @@ class _SettingsSearchPageState extends State<SettingsSearchPage> {
|
||||
Widget _list(List<SettingsSection> visible, EdgeInsets insets) {
|
||||
if (visible.isEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(settingsRowInset),
|
||||
padding: EdgeInsets.all(settingsRowInsetOf(context)),
|
||||
child: Text('No settings match "${_search.text.trim()}".'),
|
||||
);
|
||||
}
|
||||
@@ -222,7 +222,7 @@ class _SettingsSearchPageState extends State<SettingsSearchPage> {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
for (final (index, section) in visible.indexed) ...<Widget>[
|
||||
if (index > 0) const SizedBox(height: settingsSectionGap),
|
||||
if (index > 0) SizedBox(height: settingsSectionGapOf(context)),
|
||||
KeyedSubtree(
|
||||
key: _keyFor(section.id),
|
||||
child: _isActive(section)
|
||||
|
||||
@@ -354,7 +354,7 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
|
||||
child: ShellRailScope(
|
||||
shown: rail,
|
||||
bodyWidth: rail
|
||||
? media.size.width - kNavigationRailSpace
|
||||
? media.size.width - navigationRailSpaceOf(context)
|
||||
: null,
|
||||
child: scaffold,
|
||||
),
|
||||
|
||||
@@ -10,6 +10,15 @@ const double kNavigationRailWidth = 96;
|
||||
/// The rail with its divider: what the rail takes from a wide window's width.
|
||||
const double kNavigationRailSpace = kNavigationRailWidth + 1;
|
||||
|
||||
/// The rail's width under the design at [context]: [kNavigationRailWidth],
|
||||
/// or a dense design's narrower, icon-only rail.
|
||||
double navigationRailWidthOf(BuildContext context) =>
|
||||
AppDesignTokens.of(context).density.railWidth;
|
||||
|
||||
/// The rail with its divider under the design at [context].
|
||||
double navigationRailSpaceOf(BuildContext context) =>
|
||||
navigationRailWidthOf(context) + 1;
|
||||
|
||||
/// The narrowest window that shows the destination rail: the list-detail
|
||||
/// minimum for the body beside it, plus the rail and its divider (the space the
|
||||
/// shell takes from the window). Narrower windows keep the floating destination
|
||||
@@ -69,6 +78,7 @@ class ShellNavigationRail extends StatelessWidget {
|
||||
final surface =
|
||||
AppDesignTokens.of(context).glass?.rail ??
|
||||
Theme.of(context).colorScheme.surface;
|
||||
final density = AppDesignTokens.of(context).density;
|
||||
// The surface runs under the top inset too: the padding only moves the
|
||||
// rail's content below the system's top, so no unpainted strip shows above
|
||||
// the rail's background.
|
||||
@@ -78,11 +88,12 @@ class ShellNavigationRail extends StatelessWidget {
|
||||
child: Padding(
|
||||
padding: padding,
|
||||
child: SizedBox(
|
||||
width: kNavigationRailWidth,
|
||||
width: density.railWidth,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) => _rail(
|
||||
index,
|
||||
surface,
|
||||
density,
|
||||
pinSettings:
|
||||
constraints.maxHeight >=
|
||||
kNavigationRailPinnedSettingsMinHeight,
|
||||
@@ -93,39 +104,46 @@ class ShellNavigationRail extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _rail(int index, Color surface, {required bool pinSettings}) =>
|
||||
NavigationRail(
|
||||
key: const ValueKey('shell.navigation-rail'),
|
||||
backgroundColor: surface,
|
||||
minWidth: kNavigationRailWidth,
|
||||
labelType: NavigationRailLabelType.all,
|
||||
selectedIndex: index < 0 ? null : index,
|
||||
onDestinationSelected: (value) =>
|
||||
onSelected(shellTabDestinations[value]),
|
||||
destinations: [
|
||||
for (final destination in shellTabDestinations)
|
||||
NavigationRailDestination(
|
||||
icon: KeyedSubtree(
|
||||
key: ValueKey('shell.destination.${destination.name}'),
|
||||
// The bar it replaces named each tab in a tooltip too.
|
||||
// The destination's label already names it for assistive
|
||||
// technology; the tooltip must not repeat it.
|
||||
child: Tooltip(
|
||||
message: destinationDetails(destination).label,
|
||||
excludeFromSemantics: true,
|
||||
child: icon(destination),
|
||||
),
|
||||
),
|
||||
label: Text(destinationDetails(destination).label),
|
||||
Widget _rail(
|
||||
int index,
|
||||
Color surface,
|
||||
DesignDensity density, {
|
||||
required bool pinSettings,
|
||||
}) => NavigationRail(
|
||||
key: const ValueKey('shell.navigation-rail'),
|
||||
backgroundColor: surface,
|
||||
minWidth: density.railWidth,
|
||||
// An icon-only rail names each tab in its tooltip alone.
|
||||
labelType: density.railLabels
|
||||
? NavigationRailLabelType.all
|
||||
: NavigationRailLabelType.none,
|
||||
selectedIndex: index < 0 ? null : index,
|
||||
onDestinationSelected: (value) => onSelected(shellTabDestinations[value]),
|
||||
destinations: [
|
||||
for (final destination in shellTabDestinations)
|
||||
NavigationRailDestination(
|
||||
icon: KeyedSubtree(
|
||||
key: ValueKey('shell.destination.${destination.name}'),
|
||||
// The bar it replaces named each tab in a tooltip too.
|
||||
// The destination's label already names it for assistive
|
||||
// technology; the tooltip must not repeat it.
|
||||
child: Tooltip(
|
||||
message: destinationDetails(destination).label,
|
||||
excludeFromSemantics: true,
|
||||
child: icon(destination),
|
||||
),
|
||||
],
|
||||
scrollable: true,
|
||||
trailingAtBottom: pinSettings,
|
||||
trailing: _SettingsRailItem(
|
||||
selected: selected == AppDestination.settings,
|
||||
onTap: () => onSelected(AppDestination.settings),
|
||||
),
|
||||
label: Text(destinationDetails(destination).label),
|
||||
),
|
||||
);
|
||||
],
|
||||
scrollable: true,
|
||||
trailingAtBottom: pinSettings,
|
||||
trailing: _SettingsRailItem(
|
||||
density: density,
|
||||
selected: selected == AppDestination.settings,
|
||||
onTap: () => onSelected(AppDestination.settings),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Settings at the rail's foot, drawn as a [NavigationRailDestination] is: an
|
||||
@@ -133,8 +151,13 @@ class ShellNavigationRail extends StatelessWidget {
|
||||
/// It is not a [NavigationRailDestination] itself because the rail's
|
||||
/// destination list is the tabs, and `trailing` is what the rail pins.
|
||||
class _SettingsRailItem extends StatelessWidget {
|
||||
const _SettingsRailItem({required this.selected, required this.onTap});
|
||||
const _SettingsRailItem({
|
||||
required this.density,
|
||||
required this.selected,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final DesignDensity density;
|
||||
final bool selected;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@@ -149,6 +172,33 @@ class _SettingsRailItem extends StatelessWidget {
|
||||
color: foreground,
|
||||
fontWeight: selected ? FontWeight.w600 : FontWeight.w500,
|
||||
);
|
||||
final indicator = Container(
|
||||
width: 56,
|
||||
height: 32,
|
||||
alignment: Alignment.center,
|
||||
decoration: ShapeDecoration(
|
||||
shape: AppDesignTokens.of(context).shape(const StadiumBorder()),
|
||||
color: selected ? scheme.secondaryContainer : null,
|
||||
),
|
||||
child: Icon(item.icon, color: foreground),
|
||||
);
|
||||
final Widget mark = density.railLabels
|
||||
? Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
indicator,
|
||||
const SizedBox(height: 4),
|
||||
Text(item.label, style: textStyle),
|
||||
],
|
||||
)
|
||||
// An icon-only rail names Settings in a tooltip, as its tabs.
|
||||
: Center(
|
||||
child: Tooltip(
|
||||
message: item.label,
|
||||
excludeFromSemantics: true,
|
||||
child: indicator,
|
||||
),
|
||||
);
|
||||
return Semantics(
|
||||
button: true,
|
||||
selected: selected,
|
||||
@@ -158,28 +208,10 @@ class _SettingsRailItem extends StatelessWidget {
|
||||
key: const ValueKey('shell.destination.settings'),
|
||||
onTap: onTap,
|
||||
child: SizedBox(
|
||||
width: kNavigationRailWidth,
|
||||
width: density.railWidth,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 56,
|
||||
height: 32,
|
||||
alignment: Alignment.center,
|
||||
decoration: ShapeDecoration(
|
||||
shape: AppDesignTokens.of(
|
||||
context,
|
||||
).shape(const StadiumBorder()),
|
||||
color: selected ? scheme.secondaryContainer : null,
|
||||
),
|
||||
child: Icon(item.icon, color: foreground),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(item.label, style: textStyle),
|
||||
],
|
||||
),
|
||||
padding: EdgeInsets.symmetric(vertical: density.space(12)),
|
||||
child: mark,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -6,16 +6,25 @@ import 'window_kind.dart';
|
||||
|
||||
const double windowCornerRadius = 12;
|
||||
|
||||
/// A window's corner radius under the design at [context]: a glass design
|
||||
/// grows it with its other corners.
|
||||
double windowCornerRadiusOf(BuildContext context) =>
|
||||
AppDesignTokens.of(context).glass?.corner(windowCornerRadius) ??
|
||||
windowCornerRadius;
|
||||
/// A floating window's corners under the design at [context]:
|
||||
/// [windowCornerRadius], or a dense design's own corners, or a glass
|
||||
/// design's grown ones.
|
||||
BorderRadius windowCorners(BuildContext context) {
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
const designed = BorderRadius.all(Radius.circular(windowCornerRadius));
|
||||
return tokens.glass == null
|
||||
? tokens.denseCorners(designed)
|
||||
: tokens.corners(designed);
|
||||
}
|
||||
|
||||
/// The height of a window's title bar: a compact row of icon buttons, taller
|
||||
/// with larger text.
|
||||
double windowTitleBarHeight(BuildContext context) =>
|
||||
MediaQuery.textScalerOf(context).scale(40).clamp(40.0, 64.0);
|
||||
/// with larger text (a dense design's slimmer bar grows the same way).
|
||||
double windowTitleBarHeight(BuildContext context) {
|
||||
final height = AppDesignTokens.of(context).density.titleBarHeight;
|
||||
return MediaQuery.textScalerOf(
|
||||
context,
|
||||
).scale(height).clamp(height, height + 24);
|
||||
}
|
||||
|
||||
/// A floating window's card and title bar: the title (drag to move, double
|
||||
/// click to maximise), the kind's actions, then Maximise and the X. The X
|
||||
@@ -55,10 +64,11 @@ class WindowFrame extends StatelessWidget {
|
||||
// A glass design's window is an opaque glass card (its content is not
|
||||
// blurred, so nothing behind may show through).
|
||||
final glass = AppDesignTokens.of(context).glass;
|
||||
final dense = AppDesignTokens.of(context).density.dense;
|
||||
return Material(
|
||||
elevation: 8,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
borderRadius: BorderRadius.circular(windowCornerRadiusOf(context)),
|
||||
borderRadius: windowCorners(context),
|
||||
color: glass?.solid ?? colors.surfaceContainer,
|
||||
child: Align(
|
||||
alignment: Alignment.topCenter,
|
||||
@@ -73,7 +83,7 @@ class WindowFrame extends StatelessWidget {
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: _title(theme)),
|
||||
Expanded(child: _title(theme, dense)),
|
||||
for (final action in actions)
|
||||
IconButton(
|
||||
tooltip: action.label,
|
||||
@@ -101,7 +111,7 @@ class WindowFrame extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _title(ThemeData theme) => MouseRegion(
|
||||
Widget _title(ThemeData theme, bool dense) => MouseRegion(
|
||||
cursor: maximized ? SystemMouseCursors.basic : SystemMouseCursors.move,
|
||||
child: GestureDetector(
|
||||
key: const ValueKey('window-title'),
|
||||
@@ -114,11 +124,15 @@ class WindowFrame extends StatelessWidget {
|
||||
onPanEnd: maximized ? null : (_) => onMoveEnd(),
|
||||
onDoubleTap: onToggleMaximized,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 12, end: 8),
|
||||
padding: EdgeInsetsDirectional.only(start: dense ? 8 : 12, end: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 18, color: theme.colorScheme.onSurfaceVariant),
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
icon,
|
||||
size: dense ? 16 : 18,
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
SizedBox(width: dense ? 6 : 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
@@ -143,7 +157,7 @@ class WindowOutline extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final corners = BorderRadius.circular(windowCornerRadiusOf(context));
|
||||
final corners = windowCorners(context);
|
||||
final glass = AppDesignTokens.of(context).glass;
|
||||
return IgnorePointer(
|
||||
child: DecoratedBox(
|
||||
|
||||
@@ -133,7 +133,7 @@ class _WindowHostState extends State<WindowHost> {
|
||||
// right, so they never sit under the rail.
|
||||
// The shell takes the rail and its divider (kNavigationRailSpace).
|
||||
final leading = widget.reservesRail && showsNavigationRail(context)
|
||||
? kNavigationRailSpace
|
||||
? navigationRailSpaceOf(context)
|
||||
: 0.0;
|
||||
final bounds = Size(
|
||||
constraints.maxWidth - leading,
|
||||
|
||||
@@ -2,11 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
import 'window_frame.dart'
|
||||
show
|
||||
WindowOutline,
|
||||
WindowResizeGrip,
|
||||
windowCornerRadiusOf,
|
||||
windowTitleBarHeight;
|
||||
show WindowOutline, WindowResizeGrip, windowCorners, windowTitleBarHeight;
|
||||
import 'window_scope.dart';
|
||||
|
||||
/// A floating window's own page stack. Pages pushed from the window's
|
||||
@@ -122,15 +118,15 @@ class WindowPageBox extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final body = WindowBodyScope.maybeOf(context);
|
||||
if (body == null) return child;
|
||||
final radius = Radius.circular(windowCornerRadiusOf(context));
|
||||
final corners = windowCorners(context);
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned.fromRect(
|
||||
rect: body,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: radius,
|
||||
bottomRight: radius,
|
||||
bottomLeft: corners.bottomLeft,
|
||||
bottomRight: corners.bottomRight,
|
||||
),
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
|
||||
@@ -423,7 +423,9 @@ class _SegmentedBarState extends State<SegmentedBar> {
|
||||
titleShare ??
|
||||
(widget.separateActionIslands ? .10 : SegmentedBar.minTitleShare);
|
||||
final besideTitle =
|
||||
width - (leading == null ? 0 : segmentedPieceHeight() + 8) - 8;
|
||||
width -
|
||||
(leading == null ? 0 : segmentedPieceHeight(context) + 8) -
|
||||
8;
|
||||
// Actions that cannot move (a model picker) may take the room down
|
||||
// to the title's minimum share; the rest leave for the More menu
|
||||
// before the title goes under its own width.
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_design_tokens.dart';
|
||||
import 'glass_pill.dart';
|
||||
import 'segmented_bar_motion.dart';
|
||||
|
||||
/// The smallest height of every piece of a [SegmentedBar]: the platform's
|
||||
/// minimum touch target, so a round Back is a circle.
|
||||
double segmentedPieceHeight() => kMinInteractiveDimension;
|
||||
/// minimum touch target, so a round Back is a circle. Under a dense design
|
||||
/// at [context] the pieces are 40px: its 32px controls with a 4px edge, still
|
||||
/// a comfortable touch target.
|
||||
double segmentedPieceHeight([BuildContext? context]) =>
|
||||
context != null && AppDesignTokens.of(context).density.dense
|
||||
? 40
|
||||
: kMinInteractiveDimension;
|
||||
|
||||
/// One rounded piece of a segmented bar: a [GlassPill] at least the
|
||||
/// platform's touch-target size.
|
||||
@@ -19,7 +25,7 @@ class SegmentedPill extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final height = segmentedPieceHeight();
|
||||
final height = segmentedPieceHeight(context);
|
||||
// A stadium whose content is as wide as it is tall is a circle.
|
||||
return GlassPill(
|
||||
fill: fill,
|
||||
@@ -75,6 +81,10 @@ Widget? impliedSegmentedLeading(BuildContext context) {
|
||||
/// The title pill's horizontal padding on each side.
|
||||
const double segmentedTitlePadding = 16;
|
||||
|
||||
/// [segmentedTitlePadding] under the design at [context] (12px when dense).
|
||||
double segmentedTitlePaddingOf(BuildContext context) =>
|
||||
AppDesignTokens.of(context).density.inset(segmentedTitlePadding);
|
||||
|
||||
/// The width the title pill needs to show [title] and [subtitle] whole (at
|
||||
/// the text scale at [context]).
|
||||
double segmentedTitleWidth(
|
||||
@@ -113,7 +123,7 @@ double segmentedTitleWidth(
|
||||
measure(' ', subtitleStyle));
|
||||
final text = measure(title, titleStyle);
|
||||
return (text > subWidth ? text : subWidth).ceilToDouble() +
|
||||
segmentedTitlePadding * 2;
|
||||
segmentedTitlePaddingOf(context) * 2;
|
||||
}
|
||||
|
||||
/// The title, with an optional one-line subtitle, in one pill; pressing it
|
||||
@@ -156,8 +166,8 @@ class SegmentedTitlePill extends StatelessWidget {
|
||||
);
|
||||
final subtitle = this.subtitle ?? '';
|
||||
final content = Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: segmentedTitlePadding,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: segmentedTitlePaddingOf(context),
|
||||
vertical: 4,
|
||||
),
|
||||
child: Row(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme/app_design_tokens.dart';
|
||||
|
||||
/// The app's one search field.
|
||||
///
|
||||
@@ -53,8 +54,10 @@ class AppSearchField extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
const radius = BorderRadius.all(Radius.circular(28));
|
||||
const stadium = OutlineInputBorder(
|
||||
final radius = AppDesignTokens.of(
|
||||
context,
|
||||
).denseCorners(const BorderRadius.all(Radius.circular(28)));
|
||||
final stadium = OutlineInputBorder(
|
||||
borderRadius: radius,
|
||||
borderSide: BorderSide.none,
|
||||
);
|
||||
|
||||
@@ -5,6 +5,11 @@ import '../theme/app_design_tokens.dart';
|
||||
/// avatar ([CircleAvatar]'s default).
|
||||
const double kAppListAvatarSize = 40;
|
||||
|
||||
/// The leading avatar's size under the design at [context]:
|
||||
/// [kAppListAvatarSize], or a dense design's smaller one.
|
||||
double appListAvatarSize(BuildContext context) =>
|
||||
AppDesignTokens.of(context).density.avatarSize;
|
||||
|
||||
/// A list row's leading identity: an icon or an initial on a tinted circle,
|
||||
/// with an optional corner badge (a chat's activity indicator).
|
||||
///
|
||||
@@ -52,16 +57,19 @@ class AppListAvatar extends StatelessWidget {
|
||||
(foreground == null
|
||||
? Theme.of(context).colorScheme.surfaceContainerHighest
|
||||
: mark.withValues(alpha: 0.14));
|
||||
// The mark keeps the same proportion of the circle at every density.
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final size = tokens.density.avatarSize;
|
||||
final scale = size / kAppListAvatarSize;
|
||||
final initialStyle =
|
||||
(Theme.of(context).textTheme.titleMedium ?? const TextStyle()).copyWith(
|
||||
color: mark,
|
||||
fontSize: 18,
|
||||
fontSize: 18 * scale,
|
||||
fontWeight: FontWeight.w700,
|
||||
height: 1,
|
||||
);
|
||||
// A flat design (Terminal) frames the mark in a square box instead of a
|
||||
// tinted circle.
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final decoration = tokens.flat
|
||||
? BoxDecoration(
|
||||
border: Border.all(color: mark.withValues(alpha: 0.55)),
|
||||
@@ -69,18 +77,18 @@ class AppListAvatar extends StatelessWidget {
|
||||
)
|
||||
: BoxDecoration(color: fill, shape: BoxShape.circle);
|
||||
final circle = SizedBox.square(
|
||||
dimension: kAppListAvatarSize,
|
||||
dimension: size,
|
||||
child: DecoratedBox(
|
||||
decoration: decoration,
|
||||
child: Center(
|
||||
// The glyph is identity, not reading text: it scales down to stay
|
||||
// inside the circle under large text instead of overflowing it.
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
padding: EdgeInsets.all(8 * scale),
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: IconTheme.merge(
|
||||
data: IconThemeData(color: mark, size: 22),
|
||||
data: IconThemeData(color: mark, size: 22 * scale),
|
||||
child: DefaultTextStyle(style: initialStyle, child: child),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -157,6 +157,7 @@ class AppListRow extends StatelessWidget {
|
||||
selected: selected,
|
||||
emphasized: emphasized,
|
||||
);
|
||||
final metrics = _RowMetrics.of(context);
|
||||
return Semantics(
|
||||
container: true,
|
||||
selected: selected,
|
||||
@@ -167,14 +168,16 @@ class AppListRow extends StatelessWidget {
|
||||
final minimal = constraints.maxWidth < kAppListRowMinimalWidth;
|
||||
final showLeading = leading != null && !minimal;
|
||||
final showMenu = menu != null && !minimal;
|
||||
final start = compact ? 12.0 : kAppListRowInset;
|
||||
final avatarGap = compact ? _compactAvatarGap : _avatarGap;
|
||||
final start = compact ? metrics.compactInset : metrics.inset;
|
||||
final avatarGap = compact
|
||||
? metrics.compactAvatarGap
|
||||
: metrics.avatarGap;
|
||||
final content = Padding(
|
||||
padding: EdgeInsetsDirectional.only(
|
||||
start: start,
|
||||
end: showMenu ? 4 : kAppListRowInset,
|
||||
top: kAppListRowVerticalPadding,
|
||||
bottom: kAppListRowVerticalPadding,
|
||||
end: showMenu ? 4 : metrics.inset,
|
||||
top: metrics.vertical,
|
||||
bottom: metrics.vertical,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
@@ -188,7 +191,7 @@ class AppListRow extends StatelessWidget {
|
||||
padding: EdgeInsetsDirectional.only(end: avatarGap),
|
||||
child: leading,
|
||||
),
|
||||
Expanded(child: _text(styles, compact)),
|
||||
Expanded(child: _text(styles, metrics, compact)),
|
||||
if (showMenu)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 4),
|
||||
@@ -248,7 +251,12 @@ class AppListRow extends StatelessWidget {
|
||||
key: tapKey,
|
||||
onTap: onTap,
|
||||
onLongPress: onLongPress,
|
||||
child: content,
|
||||
child: metrics.minHeight > 0
|
||||
? ConstrainedBox(
|
||||
constraints: BoxConstraints(minHeight: metrics.minHeight),
|
||||
child: Center(widthFactor: 1, child: content),
|
||||
)
|
||||
: content,
|
||||
),
|
||||
);
|
||||
// The colour bar runs the row's whole height, divider included, and
|
||||
@@ -282,7 +290,7 @@ class AppListRow extends StatelessWidget {
|
||||
// not known here, so a selectable row's divider starts at the inset.
|
||||
final textStart = selectionControl != null
|
||||
? start
|
||||
: start + (showLeading ? kAppListAvatarSize + avatarGap : 0);
|
||||
: start + (showLeading ? metrics.avatar + avatarGap : 0);
|
||||
final line = Padding(
|
||||
padding: EdgeInsetsDirectional.only(start: textStart),
|
||||
child: SizedBox(
|
||||
@@ -327,7 +335,7 @@ class AppListRow extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _text(_RowStyles styles, bool compact) {
|
||||
Widget _text(_RowStyles styles, _RowMetrics metrics, bool compact) {
|
||||
final line = compact ? (compactSubtitle ?? subtitle) : subtitle;
|
||||
final time = _time(styles);
|
||||
final titleLine = LayoutBuilder(
|
||||
@@ -360,7 +368,7 @@ class AppListRow extends StatelessWidget {
|
||||
final detailLine = detail == null || (compact && !compactDetail)
|
||||
? null
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(top: _lineGap),
|
||||
padding: EdgeInsets.only(top: metrics.lineGap),
|
||||
child: DefaultTextStyle(
|
||||
style: styles.subtitle,
|
||||
maxLines: 1,
|
||||
@@ -375,7 +383,7 @@ class AppListRow extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
titleLine,
|
||||
const SizedBox(height: _lineGap),
|
||||
SizedBox(height: metrics.lineGap),
|
||||
timeLine,
|
||||
],
|
||||
);
|
||||
@@ -385,7 +393,7 @@ class AppListRow extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
titleLine,
|
||||
const SizedBox(height: _lineGap),
|
||||
SizedBox(height: metrics.lineGap),
|
||||
Row(
|
||||
children: [
|
||||
if (subtitleLeading != null)
|
||||
@@ -415,6 +423,57 @@ class AppListRow extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// The row's spacing under the design's density: the comfortable constants,
|
||||
/// or a dense design's tighter ones (a 36px single-line row and a ~52px
|
||||
/// two-line row on a pointer device; at least 40px on touch).
|
||||
class _RowMetrics {
|
||||
const _RowMetrics({
|
||||
required this.inset,
|
||||
required this.compactInset,
|
||||
required this.avatarGap,
|
||||
required this.compactAvatarGap,
|
||||
required this.vertical,
|
||||
required this.lineGap,
|
||||
required this.avatar,
|
||||
required this.minHeight,
|
||||
});
|
||||
|
||||
factory _RowMetrics.of(BuildContext context) {
|
||||
final density = AppDesignTokens.of(context).density;
|
||||
if (!density.dense) return _comfortable;
|
||||
return _RowMetrics(
|
||||
inset: density.inset(kAppListRowInset),
|
||||
compactInset: density.inset(12),
|
||||
avatarGap: density.space(_avatarGap),
|
||||
compactAvatarGap: density.space(_compactAvatarGap),
|
||||
vertical: density.space(kAppListRowVerticalPadding),
|
||||
lineGap: 0,
|
||||
avatar: density.avatarSize,
|
||||
minHeight: density.minTouchRow,
|
||||
);
|
||||
}
|
||||
|
||||
static const _comfortable = _RowMetrics(
|
||||
inset: kAppListRowInset,
|
||||
compactInset: 12,
|
||||
avatarGap: _avatarGap,
|
||||
compactAvatarGap: _compactAvatarGap,
|
||||
vertical: kAppListRowVerticalPadding,
|
||||
lineGap: _lineGap,
|
||||
avatar: kAppListAvatarSize,
|
||||
minHeight: 0,
|
||||
);
|
||||
|
||||
final double inset;
|
||||
final double compactInset;
|
||||
final double avatarGap;
|
||||
final double compactAvatarGap;
|
||||
final double vertical;
|
||||
final double lineGap;
|
||||
final double avatar;
|
||||
final double minHeight;
|
||||
}
|
||||
|
||||
/// The row's text styles, from the host's own type scale.
|
||||
class _RowStyles {
|
||||
const _RowStyles(this.title, this.subtitle, this.time, this.divider);
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_design_tokens.dart';
|
||||
import 'app_theme.dart';
|
||||
import 'compact_theme.dart';
|
||||
import 'glass_theme.dart';
|
||||
import 'paper_theme.dart';
|
||||
import 'terminal_theme.dart';
|
||||
@@ -52,6 +53,14 @@ enum AppDesign {
|
||||
'Warm paper, serif reading text and ink colours; calm for long reads.',
|
||||
),
|
||||
|
||||
/// The Classic look packed tight for a big monitor: smaller type, thin
|
||||
/// rows, 18px icons, an icon-only rail and modest corners.
|
||||
compact(
|
||||
'compact',
|
||||
'Compact',
|
||||
'Classic’s Material look, dense: small type, thin rows, more on screen.',
|
||||
),
|
||||
|
||||
/// Translucent frosted panes over a soft gradient: rounded cards, light
|
||||
/// glass edges and gentle depth.
|
||||
glass(
|
||||
@@ -109,9 +118,16 @@ enum AppDesign {
|
||||
(standard, Brightness.dark) => appDarkTheme(fontFamily: fontFamily),
|
||||
(terminal, _) => terminalTheme(brightness),
|
||||
(paper, _) => paperTheme(brightness, fontFamily: fontFamily),
|
||||
(compact, _) => compactTheme(brightness, fontFamily: fontFamily),
|
||||
(glass, _) => glassTheme(brightness, fontFamily: fontFamily),
|
||||
};
|
||||
|
||||
/// Whether this design packs the interface densely
|
||||
/// ([DesignDensity.dense]); its theme hosts switch to and from it without
|
||||
/// a blend ([AppDesignController.themeAnimationDuration]).
|
||||
bool get dense =>
|
||||
light().extension<AppDesignTokens>()?.density.dense ?? false;
|
||||
|
||||
/// Whether the device's interface font applies under this design (Paper
|
||||
/// keeps it for its interface text and sets reading text in its serif).
|
||||
bool get usesInterfaceFont => this != terminal;
|
||||
@@ -121,7 +137,7 @@ enum AppDesign {
|
||||
DesignSwatch swatch(Brightness brightness) {
|
||||
final dark = brightness == Brightness.dark;
|
||||
return switch (this) {
|
||||
standard =>
|
||||
standard || compact =>
|
||||
dark
|
||||
? const DesignSwatch(
|
||||
Color(0xFF141416),
|
||||
@@ -171,6 +187,10 @@ enum AppDesign {
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
/// How many lines of ink the picker's preview draws: Compact's packs more
|
||||
/// into the same page.
|
||||
int get swatchLines => this == compact ? 4 : 2;
|
||||
}
|
||||
|
||||
/// A design's three defining colours, for the picker's small preview.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart' show kThemeAnimationDuration;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'app_design.dart';
|
||||
@@ -87,7 +88,24 @@ class AppDesignController extends ChangeNotifier {
|
||||
void preview(AppDesign? design) {
|
||||
final shown = this.design;
|
||||
_preview = design;
|
||||
if (this.design != shown) notifyListeners();
|
||||
if (this.design != shown) _shown(shown);
|
||||
}
|
||||
|
||||
/// How long the theme hosts blend into the current design (their
|
||||
/// `themeAnimationDuration`): Material's blend between designs of the same
|
||||
/// density, none for a switch into or out of a dense design. A dense
|
||||
/// design's sizes (icons, controls) have no value in a comfortable theme to
|
||||
/// blend from, so a blend would pass every icon through size zero, and in
|
||||
/// the browser (skwasm) laying out the near-zero icon glyphs could hang.
|
||||
Duration get themeAnimationDuration =>
|
||||
_snapTheme ? Duration.zero : kThemeAnimationDuration;
|
||||
bool _snapTheme = false;
|
||||
|
||||
/// The shown design changed from [before]: decide the hosts' blend and
|
||||
/// tell them.
|
||||
void _shown(AppDesign before) {
|
||||
_snapTheme = before.dense || design.dense;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// The last choice could not be stored on this device.
|
||||
@@ -100,8 +118,9 @@ class AppDesignController extends ChangeNotifier {
|
||||
if (revision != _revision || id == null) return;
|
||||
final design = AppDesign.fromId(id);
|
||||
if (design == _design) return;
|
||||
final shown = this.design;
|
||||
_design = design;
|
||||
if (_preview == null) notifyListeners();
|
||||
if (_preview == null) _shown(shown);
|
||||
}
|
||||
|
||||
/// Applies [design] now and stores it.
|
||||
@@ -111,7 +130,7 @@ class AppDesignController extends ChangeNotifier {
|
||||
final shown = this.design;
|
||||
_preview = null;
|
||||
_design = design;
|
||||
if (design != shown) notifyListeners();
|
||||
if (design != shown) _shown(shown);
|
||||
final saved = await _store.save(design.id);
|
||||
if (revision != _revision || saved != _saveFailed) return;
|
||||
_saveFailed = !saved;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
|
||||
export 'design_density.dart';
|
||||
|
||||
/// How the chat transcript draws a conversation. Each design picks one; the
|
||||
/// transcript widgets branch on it, never on the design itself.
|
||||
enum TranscriptStyle {
|
||||
@@ -59,6 +61,7 @@ class ReadingType {
|
||||
this.measure,
|
||||
this.scale = 1,
|
||||
this.figureWidth = 0.5,
|
||||
this.paragraphGap = 0.9,
|
||||
});
|
||||
|
||||
/// The reading face; null keeps the theme's body face.
|
||||
@@ -78,6 +81,10 @@ class ReadingType {
|
||||
/// [measure] is worth (half an em for Source Serif's figures).
|
||||
final double figureWidth;
|
||||
|
||||
/// The gap between two paragraphs of an answer, in lines of reading text
|
||||
/// (before text scaling): about a line by default, less for a dense design.
|
||||
final double paragraphGap;
|
||||
|
||||
/// [base] in the reading face, size and line height.
|
||||
TextStyle? apply(TextStyle? base) {
|
||||
if (base == null) return null;
|
||||
@@ -103,8 +110,10 @@ class ReadingType {
|
||||
other.height == height &&
|
||||
other.measure == measure &&
|
||||
other.scale == scale &&
|
||||
other.figureWidth == figureWidth;
|
||||
other.figureWidth == figureWidth &&
|
||||
other.paragraphGap == paragraphGap;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(family, height, measure, scale, figureWidth);
|
||||
int get hashCode =>
|
||||
Object.hash(family, height, measure, scale, figureWidth, paragraphGap);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
this.reading = const ReadingType(),
|
||||
this.chatColorSaturation = 1,
|
||||
this.glass,
|
||||
this.density = DesignDensity.comfortable,
|
||||
});
|
||||
|
||||
/// The Classic design: every widget keeps its own shapes.
|
||||
@@ -120,6 +121,10 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
/// corners grow. Null for an opaque design (every surface keeps its fill).
|
||||
final GlassStyle? glass;
|
||||
|
||||
/// How tightly the interface is packed: spacing, icon and avatar sizes,
|
||||
/// the rail and the window title bar ([DesignDensity.compact] for Compact).
|
||||
final DesignDensity density;
|
||||
|
||||
/// Whether the transcript draws prompt and tool lines rather than bubbles.
|
||||
bool get terminal => transcript == TranscriptStyle.prompt;
|
||||
|
||||
@@ -154,6 +159,12 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
return glass?.corners(designed) ?? designed;
|
||||
}
|
||||
|
||||
/// [designed] corners, or [radius] corners under a dense design: for the
|
||||
/// surfaces whose own corners the comfortable designs keep (floating
|
||||
/// windows, search thumbnails), so only a dense design rounds them alike.
|
||||
BorderRadius denseCorners(BorderRadius designed) =>
|
||||
density.dense ? corners(designed) : designed;
|
||||
|
||||
/// [designed] (a widget's own fill) or, under a flat design, its [panel].
|
||||
Color panelFill(ColorScheme scheme, Color designed) =>
|
||||
flat ? panel ?? scheme.surfaceContainerLow : designed;
|
||||
@@ -188,6 +199,7 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
ReadingType? reading,
|
||||
double? chatColorSaturation,
|
||||
GlassStyle? glass,
|
||||
DesignDensity? density,
|
||||
}) => AppDesignTokens(
|
||||
design: design ?? this.design,
|
||||
radius: radius ?? this.radius,
|
||||
@@ -202,6 +214,7 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
reading: reading ?? this.reading,
|
||||
chatColorSaturation: chatColorSaturation ?? this.chatColorSaturation,
|
||||
glass: glass ?? this.glass,
|
||||
density: density ?? this.density,
|
||||
);
|
||||
|
||||
// Value equality keeps a rebuilt theme equal to the one it replaces, so
|
||||
@@ -222,7 +235,8 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
other.selectedRow == selectedRow &&
|
||||
other.reading == reading &&
|
||||
other.chatColorSaturation == chatColorSaturation &&
|
||||
other.glass == glass;
|
||||
other.glass == glass &&
|
||||
other.density == density;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
@@ -239,6 +253,7 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
reading,
|
||||
chatColorSaturation,
|
||||
glass,
|
||||
density,
|
||||
);
|
||||
|
||||
/// Designs switch whole: a theme animation snaps halfway rather than
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'compact_theme.dart';
|
||||
|
||||
const BorderRadius _corners = BorderRadius.all(Radius.circular(compactRadius));
|
||||
const RoundedRectangleBorder _rounded = RoundedRectangleBorder(
|
||||
borderRadius: _corners,
|
||||
);
|
||||
|
||||
/// [base] with Compact's controls: Default's Material components at dense
|
||||
/// heights, in [compactRadius] corners, with 4px-grid paddings. Their text
|
||||
/// keeps each component's own Material role (already at Compact's sizes):
|
||||
/// a component theme that sets a text-theme style cannot be lerped against
|
||||
/// Default's unset one, which breaks a live design switch. Floating
|
||||
/// surfaces (menus, dialogs, sheets, tooltips, snack bars) keep Material's
|
||||
/// elevation and fills; only their corners and insets change.
|
||||
ThemeData compactControls(ThemeData base) {
|
||||
final scheme = base.colorScheme;
|
||||
const icon = 18.0;
|
||||
// Buttons: 32px tall under compact density, 12px side padding, 18px icons.
|
||||
ButtonStyle buttons() => const ButtonStyle(
|
||||
shape: WidgetStatePropertyAll(_rounded),
|
||||
padding: WidgetStatePropertyAll(EdgeInsets.symmetric(horizontal: 12)),
|
||||
iconSize: WidgetStatePropertyAll(icon),
|
||||
);
|
||||
final menu = MenuStyle(
|
||||
shape: const WidgetStatePropertyAll(_rounded),
|
||||
padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(vertical: 4)),
|
||||
visualDensity: VisualDensity.compact,
|
||||
);
|
||||
return base.copyWith(
|
||||
filledButtonTheme: FilledButtonThemeData(style: buttons()),
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(style: buttons()),
|
||||
outlinedButtonTheme: OutlinedButtonThemeData(style: buttons()),
|
||||
textButtonTheme: TextButtonThemeData(
|
||||
style: buttons().copyWith(
|
||||
padding: const WidgetStatePropertyAll(
|
||||
EdgeInsets.symmetric(horizontal: 8),
|
||||
),
|
||||
),
|
||||
),
|
||||
// Material 3's icon button ignores the theme's density unless its own
|
||||
// style sets one: 32px drawn, its target padded to 40px on touch.
|
||||
iconButtonTheme: const IconButtonThemeData(
|
||||
style: ButtonStyle(
|
||||
visualDensity: VisualDensity.compact,
|
||||
iconSize: WidgetStatePropertyAll(icon),
|
||||
// A square 32px button around its 18px icon.
|
||||
padding: WidgetStatePropertyAll(EdgeInsets.all(7)),
|
||||
shape: WidgetStatePropertyAll(_rounded),
|
||||
),
|
||||
),
|
||||
segmentedButtonTheme: SegmentedButtonThemeData(
|
||||
style: buttons().copyWith(visualDensity: VisualDensity.compact),
|
||||
),
|
||||
// A 40px action (Material's small FAB) and a 40px extended one.
|
||||
floatingActionButtonTheme: FloatingActionButtonThemeData(
|
||||
shape: _rounded,
|
||||
iconSize: icon,
|
||||
sizeConstraints: const BoxConstraints.tightFor(width: 40, height: 40),
|
||||
// Only a least height: a larger text scale still grows the label.
|
||||
extendedSizeConstraints: const BoxConstraints(
|
||||
minHeight: 40,
|
||||
minWidth: 64,
|
||||
),
|
||||
extendedPadding: const EdgeInsetsDirectional.only(start: 12, end: 16),
|
||||
extendedIconLabelSpacing: 8,
|
||||
),
|
||||
menuTheme: MenuThemeData(style: menu),
|
||||
dropdownMenuTheme: DropdownMenuThemeData(
|
||||
menuStyle: menu,
|
||||
inputDecorationTheme: const InputDecorationTheme(isDense: true),
|
||||
),
|
||||
menuButtonTheme: MenuButtonThemeData(
|
||||
style: MenuItemButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
minimumSize: const Size(0, 32),
|
||||
iconSize: icon,
|
||||
),
|
||||
),
|
||||
popupMenuTheme: PopupMenuThemeData(
|
||||
shape: _rounded,
|
||||
menuPadding: const EdgeInsets.symmetric(vertical: 4),
|
||||
),
|
||||
dialogTheme: DialogThemeData(
|
||||
shape: _rounded,
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||
actionsPadding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
||||
),
|
||||
bottomSheetTheme: const BottomSheetThemeData(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(
|
||||
top: Radius.circular(compactRadius),
|
||||
),
|
||||
),
|
||||
),
|
||||
snackBarTheme: SnackBarThemeData(
|
||||
shape: _rounded,
|
||||
insetPadding: const EdgeInsets.fromLTRB(12, 4, 12, 12),
|
||||
),
|
||||
tooltipTheme: TooltipThemeData(
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.inverseSurface,
|
||||
borderRadius: _corners,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
waitDuration: const Duration(milliseconds: 400),
|
||||
),
|
||||
// A hairline on every card variant: the theme's shape replaces each
|
||||
// variant's own, so an outlined card (a graph node) keeps its outline.
|
||||
cardTheme: CardThemeData(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: _corners,
|
||||
side: BorderSide(color: scheme.outlineVariant),
|
||||
),
|
||||
margin: const EdgeInsets.all(4),
|
||||
),
|
||||
chipTheme: ChipThemeData(
|
||||
shape: _rounded,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||
labelPadding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
iconTheme: const IconThemeData(size: 16),
|
||||
),
|
||||
inputDecorationTheme: const InputDecorationTheme(
|
||||
isDense: true,
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
),
|
||||
searchBarTheme: SearchBarThemeData(
|
||||
shape: const WidgetStatePropertyAll(_rounded),
|
||||
constraints: const BoxConstraints(minWidth: 240, minHeight: 36),
|
||||
padding: const WidgetStatePropertyAll(
|
||||
EdgeInsets.symmetric(horizontal: 12),
|
||||
),
|
||||
),
|
||||
listTileTheme: const ListTileThemeData(
|
||||
dense: true,
|
||||
visualDensity: VisualDensity.compact,
|
||||
contentPadding: EdgeInsets.symmetric(horizontal: 12),
|
||||
horizontalTitleGap: 12,
|
||||
minLeadingWidth: 20,
|
||||
minVerticalPadding: 6,
|
||||
shape: _rounded,
|
||||
),
|
||||
expansionTileTheme: const ExpansionTileThemeData(
|
||||
tilePadding: EdgeInsets.symmetric(horizontal: 12),
|
||||
childrenPadding: EdgeInsets.symmetric(horizontal: 12),
|
||||
shape: Border(),
|
||||
collapsedShape: Border(),
|
||||
),
|
||||
navigationRailTheme: NavigationRailThemeData(
|
||||
minWidth: 64,
|
||||
labelType: NavigationRailLabelType.none,
|
||||
indicatorShape: _rounded,
|
||||
indicatorColor: scheme.secondaryContainer,
|
||||
selectedIconTheme: IconThemeData(
|
||||
size: icon,
|
||||
color: scheme.onSecondaryContainer,
|
||||
),
|
||||
unselectedIconTheme: IconThemeData(
|
||||
size: icon,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
groupAlignment: -1,
|
||||
),
|
||||
navigationBarTheme: NavigationBarThemeData(
|
||||
height: 64,
|
||||
indicatorShape: _rounded,
|
||||
iconTheme: const WidgetStatePropertyAll(IconThemeData(size: icon)),
|
||||
),
|
||||
tabBarTheme: TabBarThemeData(
|
||||
labelPadding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
),
|
||||
dividerTheme: const DividerThemeData(space: 8, thickness: 1),
|
||||
badgeTheme: BadgeThemeData(
|
||||
smallSize: 6,
|
||||
largeSize: 14,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
),
|
||||
checkboxTheme: const CheckboxThemeData(
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
radioTheme: const RadioThemeData(visualDensity: VisualDensity.compact),
|
||||
scrollbarTheme: const ScrollbarThemeData(
|
||||
radius: Radius.circular(3),
|
||||
thickness: WidgetStatePropertyAll(6),
|
||||
),
|
||||
drawerTheme: const DrawerThemeData(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.horizontal(
|
||||
right: Radius.circular(compactRadius),
|
||||
),
|
||||
),
|
||||
),
|
||||
datePickerTheme: const DatePickerThemeData(shape: _rounded),
|
||||
timePickerTheme: const TimePickerThemeData(shape: _rounded),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_design.dart';
|
||||
import 'app_design_tokens.dart';
|
||||
import 'app_theme.dart';
|
||||
import 'compact_controls.dart';
|
||||
import 'compact_typography.dart';
|
||||
|
||||
/// Compact's corner radius: every card, field, button, chip, menu, dialog,
|
||||
/// sheet, tooltip, snack bar, bubble and window takes it.
|
||||
const double compactRadius = 6;
|
||||
|
||||
/// The Compact design's theme: Default's Material 3 colours and surfaces,
|
||||
/// packed for a big monitor and long runs and chats. A smaller type scale
|
||||
/// ([compactTextTheme]), Material's compact visual density, 18px icons, and
|
||||
/// [compactRadius] corners on every surface. On a touch device controls keep
|
||||
/// a 40px tap target (Material's padded target under compact density); on a
|
||||
/// pointer device they shrink to their drawn size.
|
||||
ThemeData compactTheme(Brightness brightness, {String? fontFamily}) {
|
||||
final standard = brightness == Brightness.dark
|
||||
? appDarkTheme(fontFamily: fontFamily)
|
||||
: appLightTheme(fontFamily: fontFamily);
|
||||
final textTheme = compactTextTheme(standard.textTheme);
|
||||
final themed = standard.copyWith(
|
||||
visualDensity: VisualDensity.compact,
|
||||
materialTapTargetSize: DesignDensity.pointerPlatform
|
||||
? MaterialTapTargetSize.shrinkWrap
|
||||
: MaterialTapTargetSize.padded,
|
||||
textTheme: textTheme,
|
||||
primaryTextTheme: compactTextTheme(standard.primaryTextTheme),
|
||||
iconTheme: standard.iconTheme.copyWith(
|
||||
size: DesignDensity.compact.iconSize,
|
||||
),
|
||||
primaryIconTheme: standard.primaryIconTheme.copyWith(
|
||||
size: DesignDensity.compact.iconSize,
|
||||
),
|
||||
extensions: const [
|
||||
AppDesignTokens(
|
||||
design: AppDesign.compact,
|
||||
radius: compactRadius,
|
||||
reading: compactReading,
|
||||
density: DesignDensity.compact,
|
||||
),
|
||||
],
|
||||
);
|
||||
return compactControls(themed);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_design_styles.dart';
|
||||
|
||||
/// Compact's reading type: the interface face at the dense body size
|
||||
/// (`bodyLarge`, 14px), a little more line height than the role's so long
|
||||
/// answers stay easy to follow, and about two thirds of a line between
|
||||
/// paragraphs.
|
||||
const ReadingType compactReading = ReadingType(height: 1.5, paragraphGap: 0.6);
|
||||
|
||||
/// [base] (Material 3's type scale, in the device's interface face) at
|
||||
/// Compact's sizes: body 13px, labels 11-12px, list and dialog titles 14 and
|
||||
/// 18px. Line heights sit on a 2px step so rows of mixed roles still line up
|
||||
/// on the 4px grid. Weights, colours, families and tracking stay Material's;
|
||||
/// text scaling still applies on top.
|
||||
TextTheme compactTextTheme(TextTheme base) {
|
||||
TextStyle? sized(TextStyle? style, double size, double line) =>
|
||||
style?.copyWith(fontSize: size, height: line / size);
|
||||
return base.copyWith(
|
||||
displayLarge: sized(base.displayLarge, 44, 52),
|
||||
displayMedium: sized(base.displayMedium, 36, 44),
|
||||
displaySmall: sized(base.displaySmall, 28, 36),
|
||||
headlineLarge: sized(base.headlineLarge, 26, 32),
|
||||
headlineMedium: sized(base.headlineMedium, 22, 28),
|
||||
headlineSmall: sized(base.headlineSmall, 20, 26),
|
||||
titleLarge: sized(base.titleLarge, 18, 24),
|
||||
titleMedium: sized(base.titleMedium, 14, 20),
|
||||
titleSmall: sized(base.titleSmall, 13, 18),
|
||||
bodyLarge: sized(base.bodyLarge, 14, 20),
|
||||
bodyMedium: sized(base.bodyMedium, 13, 18),
|
||||
bodySmall: sized(base.bodySmall, 11.5, 16),
|
||||
labelLarge: sized(base.labelLarge, 13, 18),
|
||||
labelMedium: sized(base.labelMedium, 12, 16),
|
||||
labelSmall: sized(base.labelSmall, 11, 14),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// How tightly a design packs the interface: the spacing inside and between
|
||||
/// components, icon and avatar sizes, the navigation rail's width and labels
|
||||
/// and the floating window title bar. [comfortable] is the Default look;
|
||||
/// every widget that reads a density keeps its own value under it, so the
|
||||
/// comfortable designs draw exactly as before.
|
||||
///
|
||||
/// A dense design sets [spacing] below 1: [space] then scales a widget's own
|
||||
/// spacing and snaps it to the 4px grid, so every component tightens by the
|
||||
/// same proportion instead of each picking its own number.
|
||||
@immutable
|
||||
class DesignDensity {
|
||||
const DesignDensity({
|
||||
this.spacing = 1,
|
||||
this.iconSize,
|
||||
this.avatarSize = 40,
|
||||
this.railWidth = 96,
|
||||
this.railLabels = true,
|
||||
this.titleBarHeight = 40,
|
||||
});
|
||||
|
||||
/// The Default density.
|
||||
static const DesignDensity comfortable = DesignDensity();
|
||||
|
||||
/// The Compact density: spacing at 60% on the 4px grid, 18px icons, 28px
|
||||
/// avatars, an icon-only 64px rail and a 32px window title bar.
|
||||
static const DesignDensity compact = DesignDensity(
|
||||
spacing: 0.6,
|
||||
iconSize: 18,
|
||||
avatarSize: 28,
|
||||
railWidth: 64,
|
||||
railLabels: false,
|
||||
titleBarHeight: 32,
|
||||
);
|
||||
|
||||
/// The proportion of a widget's own spacing this density keeps.
|
||||
final double spacing;
|
||||
|
||||
/// The interface's icon size; null keeps Material's 24.
|
||||
final double? iconSize;
|
||||
|
||||
/// A list row's leading avatar.
|
||||
final double avatarSize;
|
||||
|
||||
/// The destination rail's width on a wide window.
|
||||
final double railWidth;
|
||||
|
||||
/// Whether the rail labels its destinations under their icons; without
|
||||
/// them the rail shows icons with tooltips.
|
||||
final bool railLabels;
|
||||
|
||||
/// A floating window's title bar height, before text scaling.
|
||||
final double titleBarHeight;
|
||||
|
||||
/// Whether this density is tighter than [comfortable].
|
||||
bool get dense => spacing < 1;
|
||||
|
||||
/// [comfortable] spacing under this density: unchanged at [spacing] 1,
|
||||
/// otherwise scaled and snapped to the 4px grid (a gap under 4px keeps a
|
||||
/// 2px step, so a hairline gap never collapses to nothing).
|
||||
double space(double comfortable) {
|
||||
if (spacing == 1 || comfortable <= 0) return comfortable;
|
||||
final scaled = comfortable * spacing;
|
||||
if (scaled < 4) return scaled < 3 ? 2 : 4;
|
||||
return (scaled / 4).round() * 4.0;
|
||||
}
|
||||
|
||||
/// [comfortable] edge inset (a row's or a panel's side padding) under this
|
||||
/// density: halfway between [space] and the comfortable value, on the 4px
|
||||
/// grid, so a dense row's text still keeps clear of the pane's edge
|
||||
/// (16px becomes 12px at Compact).
|
||||
double inset(double comfortable) {
|
||||
if (spacing == 1 || comfortable <= 0) return comfortable;
|
||||
final scaled = comfortable * (1 + spacing) / 2;
|
||||
return scaled < 4 ? 4 : (scaled / 4).round() * 4.0;
|
||||
}
|
||||
|
||||
/// The least height a tappable row keeps under this density: nothing
|
||||
/// beyond its content when comfortable (its own padding already gives
|
||||
/// room) or on a pointer device, and 40px on a touch device, so a dense
|
||||
/// row stays easy to hit with a finger.
|
||||
double get minTouchRow {
|
||||
if (!dense) return 0;
|
||||
return pointerPlatform ? 0 : 40;
|
||||
}
|
||||
|
||||
/// Whether the device drives the app with a pointer (desktop, including a
|
||||
/// desktop browser). Reads the device's platform, not the theme's: web
|
||||
/// themes are pinned to Android.
|
||||
static bool get pointerPlatform => switch (defaultTargetPlatform) {
|
||||
TargetPlatform.macOS ||
|
||||
TargetPlatform.linux ||
|
||||
TargetPlatform.windows => true,
|
||||
TargetPlatform.android ||
|
||||
TargetPlatform.iOS ||
|
||||
TargetPlatform.fuchsia => false,
|
||||
};
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is DesignDensity &&
|
||||
other.spacing == spacing &&
|
||||
other.iconSize == iconSize &&
|
||||
other.avatarSize == avatarSize &&
|
||||
other.railWidth == railWidth &&
|
||||
other.railLabels == railLabels &&
|
||||
other.titleBarHeight == titleBarHeight;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
spacing,
|
||||
iconSize,
|
||||
avatarSize,
|
||||
railWidth,
|
||||
railLabels,
|
||||
titleBarHeight,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
# Cycling the chat panes on screen
|
||||
|
||||
Alt+] and Alt+[ move the keyboard to the next or previous chat pane on screen
|
||||
(wide layouts only). On macOS and iOS, Cmd+] and Cmd+[ do the same.
|
||||
|
||||
## Keys
|
||||
|
||||
- Alt+Tab and Cmd+Tab belong to the OS window switcher. Ctrl+Tab already
|
||||
cycles the open chats, and Alt+` cycles the floating windows.
|
||||
Alt+Y, Alt+K, Alt+L, Alt+T and Ctrl+B are also taken.
|
||||
- Browsers use Alt+Left and Alt+Right for back and forward. GNOME, Hyprland,
|
||||
Windows and browsers do not bind Alt+[ or Alt+]. The web build handles the
|
||||
key, so Flutter calls `preventDefault`. The capture's keydown recorder shows
|
||||
this (`prevented: true`).
|
||||
- On a Mac, Option+] and Option+[ type quotes. With Alt, the shortcut matches
|
||||
the key's position, as Option+Y does. Cmd+] and Cmd+[ are the macOS
|
||||
next/previous pair, so Option stays free for typing. On the web, Cmd+[ is
|
||||
Back, and the app prevents that default.
|
||||
- The shortcut never matches with Shift (Alt+Shift+[ types a brace), Ctrl or
|
||||
AltGr. AltGr is how several layouts type brackets.
|
||||
- A focused terminal (any `TypingSurface`) keeps the keys. Alt+[ is its
|
||||
escape prefix.
|
||||
|
||||
## Behaviour
|
||||
|
||||
- Order: the tiled panes in split-tree order, which is visual order (left
|
||||
before right, top before bottom; the center stage's row in order). Then
|
||||
come the shown floating chat windows in the order they were opened. The
|
||||
cycle wraps around. The shortcut never opens, closes, hides or moves a
|
||||
chat.
|
||||
- The target's composer takes focus. If nothing in the pane takes focus, a
|
||||
pane-level focus node takes it. The pane's border flashes in the chat
|
||||
colour for 700 ms (`ChatPaneFocusFlash`). The flash uses the design's
|
||||
corner radius. Under reduced motion it shows for the same time without
|
||||
fading.
|
||||
- It does nothing in these cases: one pane on screen, a phone layout (the
|
||||
stack and the quick switcher handle chats there), a popup or another
|
||||
destination open, or a focused terminal.
|
||||
- The shortcut is listed in the keyboard shortcuts list (Settings and the
|
||||
Ctrl+? cheatsheet) as "Next or previous chat pane on screen".
|
||||
|
||||
## Evidence
|
||||
|
||||
- Tests: `test/features/chat/chat_pane_cycle_test.dart` (three tiles plus a
|
||||
window, forward, backward and wrapping; two tiles plus a window; no-op
|
||||
with one pane and on a phone; terminal keeps the keys) and
|
||||
`test/features/chat/workspace/chat_pane_cycle_test.dart` (key matching,
|
||||
labels, wrap).
|
||||
- Capture: `tool/capture/examples/chat-pane-cycle.json` with
|
||||
`CHROME_PATH=/usr/bin/chromium`, at 1600x900. `chat-pane-cycle/before.png`
|
||||
shows the left pane focused. `chat-pane-cycle/after-alt-bracket.png` was
|
||||
taken 120 ms after Alt+]: the right pane (api refactor) is active, its
|
||||
composer has the caret, and its purple ring is fading.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 122 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 122 KiB |
@@ -0,0 +1,94 @@
|
||||
# Compact design
|
||||
|
||||
Classic's (formerly Default's) Material 3 look, packed tight for a big monitor and long runs and
|
||||
chats (Settings > Design > Compact). It has the same colours and glass bars
|
||||
as Default. Type is smaller: body 13px, labels 11-12px, chat reading 14px on a
|
||||
1.5 line. Spacing sits on a 4px grid. Rows are 36px with one line and about
|
||||
54px with two. Icons are 18px, avatars 28px, and every corner is 6px.
|
||||
|
||||
## Tokens
|
||||
|
||||
- `density` (`DesignDensity`, `design_density.dart`; `comfortable` for every
|
||||
other design). It holds `spacing` (0.6), `iconSize` (18), `avatarSize`
|
||||
(28), `railWidth` (64), `railLabels` (false) and `titleBarHeight` (32).
|
||||
- `space(v)` scales a widget's own spacing and snaps it to the 4px grid.
|
||||
- `inset(v)` does the same for side insets, halfway between: 16 becomes 12.
|
||||
- `minTouchRow` is 40 on touch devices and 0 on pointer devices.
|
||||
- `dense` and `pointerPlatform` are also available. All of them return the
|
||||
input unchanged when the density is comfortable, so other designs keep
|
||||
their numbers.
|
||||
- `ReadingType.paragraphGap` is the gap between paragraphs of an answer, in
|
||||
lines. Default is 0.9; Compact is 0.6.
|
||||
- `AppDesignTokens.denseCorners(r)` gives the design's radius only under a
|
||||
dense design. It is for surfaces whose own corners the comfortable designs
|
||||
keep: floating windows (12), search thumbnails, find bars, run detail
|
||||
boxes and the search field stadium.
|
||||
- `AppDesign.dense` and `AppDesign.swatchLines` (the picker preview draws 4
|
||||
thin lines for Compact).
|
||||
|
||||
## Themed surfaces
|
||||
|
||||
- `compact_theme.dart`, `compact_controls.dart`, `compact_typography.dart`:
|
||||
- visual density is `compact`;
|
||||
- the tap target is `shrinkWrap` on desktop and `padded` (40px) on touch;
|
||||
- Material 3 icon buttons need their own `visualDensity`, otherwise they
|
||||
ignore the theme's; they are 32px with a padding of 7;
|
||||
- buttons, chips, fields, the search bar, list tiles, menus, popups,
|
||||
dialogs, sheets, snack bars, tooltips, FABs (40px), the rail, the
|
||||
navigation bar, tabs, badges, the scrollbar, date and time pickers all
|
||||
take 6px corners and dense paddings;
|
||||
- cards get a hairline, so `Card.outlined` (graph nodes) keeps its outline.
|
||||
- `AppListRow` / `AppListAvatar`: dense insets, padding and avatar size, plus
|
||||
the touch minimum.
|
||||
- `ShellNavigationRail`: 64px wide, icons only with tooltips. Settings uses
|
||||
the same 56x32 indicator as the tabs.
|
||||
- The shell and window host read the rail width through
|
||||
`navigationRailSpaceOf`.
|
||||
- Chat:
|
||||
- the operator bubble has 6px corners and 12/8 padding;
|
||||
- turn gaps and the paragraph gap are tighter;
|
||||
- the activity line is 28px (40px on touch);
|
||||
- turn chips, follow-up and automatic-continue cards are tighter;
|
||||
- code blocks use 8px insets with monospace at 13/14;
|
||||
- the composer is a 40px pill, and its field padding is 10 because
|
||||
density takes 4px off each side.
|
||||
- Top bars: segmented pieces are 40px (`segmentedPieceHeight(context)`) and
|
||||
title pill padding is 12. Chat bar text buttons have a 32px minimum.
|
||||
- Floating windows: a 32px title bar with 16px icons and 6px corners on the
|
||||
frame, outline and page clip.
|
||||
- Graph: nodes use 12/8 insets with a 32px minimum height.
|
||||
`graphMetricsOf(context)` tightens the gaps, lanes and padding.
|
||||
- Settings: `settingsSectionGapOf` and `settingsRowInsetOf` give 16 and 12,
|
||||
and the group header, footer and item paddings are dense.
|
||||
|
||||
## Live switch
|
||||
|
||||
A switch into or out of a dense design does not blend
|
||||
(`AppDesignController.themeAnimationDuration` is zero). The reason:
|
||||
`ThemeData.lerp` takes a component theme's unset size as 0, so every icon
|
||||
(and any text style set in a component theme) passes through size 0. In
|
||||
skwasm, laying out glyphs at nearly zero size hung the page. This was
|
||||
bisected with `tool/perf/design_bench.mjs`, and the pause stack showed
|
||||
`paragraph_layout`.
|
||||
|
||||
For the same reason, Compact's component themes set no text styles. Each
|
||||
component keeps its Material role, which is already at Compact's size.
|
||||
`test/ui/theme/compact_switch_test.dart` checks every frame of a switch.
|
||||
|
||||
Default, Terminal and Paper keep their blend.
|
||||
|
||||
## Perf budget changes
|
||||
|
||||
- `test/perf/design_bench_test.dart` budgets `scrollRebuildsPerRow`, not
|
||||
per frame. A denser design shows more rows in each 120px step.
|
||||
- `design_bench.mjs` gives the chat-switch clicks per-design points
|
||||
(`compact: [x, y]`), checked with `tool/capture`.
|
||||
|
||||
## Still Default
|
||||
|
||||
- Sliders and switches keep their size.
|
||||
- Tab heights are not themeable.
|
||||
- The walkthrough's bullet dot sits off the baseline in every design.
|
||||
- The glass bar margins (`kFloatingBarMargin`) and `GlassBarMetrics` (artifact
|
||||
viewer, chevron pager) keep 48px.
|
||||
- Fields that set their own `OutlineInputBorder()` keep 4px corners.
|
||||
+46
-6
@@ -16,17 +16,52 @@ they are saved on the device.
|
||||
- `flutter_tts_speech_engine.dart`: the `flutter_tts` implementation. The rate
|
||||
is a multiplier (1.0 = normal); Apple platforms get half of it on their 0..1
|
||||
scale. Linux reports unsupported, so the button and section are hidden.
|
||||
- `speech_controller.dart`: the app's single reader (`speechController`, a fake
|
||||
in tests via `debugSpeechController`). State changes notify the controller;
|
||||
the spoken word is the separate `word` notifier. Stops on `hidden`, `paused`
|
||||
or `detached` (not `inactive`, which is only a lost focus).
|
||||
- `speech_controller.dart`: the reader. State changes notify the controller;
|
||||
the spoken word is the separate `word` notifier and the reading's
|
||||
conversation (`SpeechReading`: chat id and name) the `reading` notifier.
|
||||
Stops on `hidden`, `paused` or `detached` (not `inactive`, which is only a
|
||||
lost focus): the phone app backgrounded keeps that behaviour.
|
||||
- `app_speech.dart`: the app's single reader (`speechController`, a fake in
|
||||
tests via `debugSpeechController`), `speechControllerIfCreated` for code that
|
||||
only stops or relabels, and `speechReading`, the app-level listenable the
|
||||
avatars and the global control follow.
|
||||
- `speech_document.dart`: Markdown to sentences, with each spoken character's
|
||||
part and source offset. Code blocks (``` and ~~~) are "Code block.", tables
|
||||
"Table." then cells; rules are skipped.
|
||||
- `chat_markdown_speech.dart`: highlight spans and the reveal scroll for
|
||||
`ChatMarkdownView`.
|
||||
- Reader ids are `<sessionId>/<row id>` so a chat that closes or is swapped
|
||||
for another stops only its own reply (`stopScope`).
|
||||
- Reader ids are `<sessionId>/<row id>`; `SpeechOrigin` (put by the thread
|
||||
view) gives Read aloud the chat id and name when a reading starts.
|
||||
|
||||
## Keeps reading across chats
|
||||
|
||||
The reader belongs to the app, not the thread view: switching chats or panes,
|
||||
opening the chat list or another destination keeps the reply reading, and
|
||||
reopening the chat shows its Pause/Stop again. A reading ends when it is
|
||||
stopped (the reply's Stop or the global one), finishes, another reply starts,
|
||||
its chat is closed (`/close`, the row's Close, or a refreshed row closed
|
||||
elsewhere) or deleted (gone from a successful list read, which includes its
|
||||
machine being removed), and when the app closes or is backgrounded.
|
||||
|
||||
- Indicator: `chatSessionActivityBadge(speaking:)` draws
|
||||
`ChatSpeakingGlyph` (three animated bars; a still speaker under reduced
|
||||
motion) in the avatar's bottom-right badge, ahead of the operator wait, the
|
||||
running spinner and the background-task count. `ChatSessionAvatar` (list,
|
||||
quick switch, phone chat stack, pane header) and `ChatCompactAvatar`
|
||||
(compact sidebar) follow `speechReading`.
|
||||
- Global stop: `ChatSpeakingControl`, "Speaking · <chat>" (or "Paused") with
|
||||
Stop speaking, sits above the composer of the active pane (`pasteTarget`)
|
||||
of any chat, so one copy shows whatever the layout. It uses the design's
|
||||
panel fill, frame and corner tokens.
|
||||
- Servers: federated chat ids carry their machine, so moving between machines
|
||||
in the combined list keeps reading. Switching the server profile (native)
|
||||
remounts `PipelinesApp`, whose dispose stops the reader; on the web a server
|
||||
switch loads another page, which ends speech.
|
||||
- Detached windows are separate processes (desktop) or browser windows (web),
|
||||
each with its own reader: speech belongs to the window that started it,
|
||||
shows only there, and stops when that window closes.
|
||||
- Web: the utterance is held by `WebSpeechEngine`, owned by the app reader,
|
||||
never by a widget.
|
||||
|
||||
## Platform notes
|
||||
|
||||
@@ -49,7 +84,12 @@ Tests (fake engine): `test/features/chat/speech/`,
|
||||
`test/features/chat/ui/transcript/chat_read_aloud_button_test.dart`,
|
||||
`chat_markdown_read_aloud_test.dart`,
|
||||
`test/features/chat/conversation/chat_thread_read_aloud_test.dart`,
|
||||
`test/features/chat/ui/sessions/chat_speaking_badge_test.dart`,
|
||||
`chat_sessions_speech_test.dart`,
|
||||
`test/features/settings/settings_read_aloud_section_test.dart`.
|
||||
|
||||
Captures (`speech=fake`, Terminal and Classic, wide and phone) show the badge
|
||||
on the reading chat after switching to another one, and the global control.
|
||||
|
||||
Not verified on a device: real speech output, word boundaries and voices on
|
||||
Android, macOS and browsers.
|
||||
|
||||
@@ -0,0 +1,329 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/servers/server_scope.dart';
|
||||
import 'package:pipelines_app/features/chat/chat_runtime.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/windows/chat_windows.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_pane_focus_flash.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_host.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_kind.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_manager.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_store.dart';
|
||||
import 'package:pipelines_app/ui/input/keyboard_owner.dart';
|
||||
|
||||
import 'conversation/chat_thread_fixtures.dart';
|
||||
|
||||
const _ids = ['a', 'b', 'c', 'd'];
|
||||
|
||||
class _Gateway extends FakeChatGateway {
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type == 'chat_sessions') {
|
||||
return Future.value({
|
||||
'chat_sessions': [
|
||||
for (final id in _ids)
|
||||
{'id': id, 'title': 'Chat $id', 'directory': '/home/$id'},
|
||||
],
|
||||
});
|
||||
}
|
||||
if (type == 'chat_shells') return Future.value({'chat_shells': []});
|
||||
return super.call(type, fields);
|
||||
}
|
||||
}
|
||||
|
||||
class _Store implements WindowStore {
|
||||
String? value;
|
||||
@override
|
||||
Future<String?> read() async => value;
|
||||
@override
|
||||
Future<bool> write(String record) async {
|
||||
value = record;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Finder _thread(String id) => find.byWidgetPredicate(
|
||||
(widget) => widget is ChatThreadView && widget.sessionId == id,
|
||||
skipOffstage: false,
|
||||
);
|
||||
Finder _input(String id) => find.descendant(
|
||||
of: find.byKey(ValueKey('chat-composer-$id'), skipOffstage: false),
|
||||
matching: find.byType(EditableText, skipOffstage: false),
|
||||
skipOffstage: false,
|
||||
);
|
||||
bool _composerFocused(WidgetTester tester, String id) =>
|
||||
tester.widget<EditableText>(_input(id)).focusNode.hasPrimaryFocus;
|
||||
ChatWorkspaceController _workspace(WidgetTester tester) => tester
|
||||
.widget<ChatWorkspace>(find.byType(ChatWorkspace, skipOffstage: false))
|
||||
.controller;
|
||||
|
||||
/// The chats whose focus ring is showing.
|
||||
List<String> _flashing(WidgetTester tester) => [
|
||||
for (final id in _ids)
|
||||
if (find
|
||||
.descendant(
|
||||
of: find.ancestor(
|
||||
of: _thread(id),
|
||||
matching: find.byType(ChatPaneFocusFlash),
|
||||
),
|
||||
matching: find.byKey(const ValueKey('chat-pane-focus-flash')),
|
||||
)
|
||||
.evaluate()
|
||||
.isNotEmpty)
|
||||
id,
|
||||
];
|
||||
|
||||
/// Saves a horizontal layout of [ids], left to right.
|
||||
void _saved(List<String> ids) {
|
||||
final layout = ChatWorkspaceController()..open(ids.first);
|
||||
for (final id in ids.skip(1)) {
|
||||
layout.splitActive(id, ChatSplitAxis.horizontal);
|
||||
}
|
||||
SharedPreferences.setMockInitialValues({
|
||||
scopedServerKey(chatWorkspacePreferenceKey, 'server-a'): layout
|
||||
.snapshot()!
|
||||
.encode(),
|
||||
});
|
||||
}
|
||||
|
||||
/// The Chat destination with its floating windows over it, and optionally a
|
||||
/// terminal that takes typing.
|
||||
class _App {
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
late final ChatRuntime runtime;
|
||||
late final WindowManager manager;
|
||||
late final ChatWindows windows;
|
||||
final terminalFocus = FocusNode(debugLabel: 'test terminal');
|
||||
final terminalTyped = <LogicalKeyboardKey>[];
|
||||
|
||||
Future<void> start(
|
||||
WidgetTester tester, {
|
||||
Size size = const Size(1800, 1000),
|
||||
bool terminal = false,
|
||||
}) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
bindServerIdentity(gateway, 'server-a');
|
||||
runtime = ChatRuntime(gateway: gateway, serverKey: 'server-a');
|
||||
manager = WindowManager(
|
||||
kinds: WindowKinds(),
|
||||
store: _Store(),
|
||||
server: 'server-a',
|
||||
);
|
||||
windows = ChatWindows(
|
||||
manager: manager,
|
||||
runtime: runtime,
|
||||
openInChat: (_) {},
|
||||
)..start();
|
||||
await manager.restore();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
ChatScreen(
|
||||
gateway: gateway,
|
||||
persistWorkspace: true,
|
||||
runtime: runtime,
|
||||
windows: windows,
|
||||
),
|
||||
if (terminal)
|
||||
Positioned(
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: 10,
|
||||
height: 10,
|
||||
child: TypingSurface(
|
||||
child: Focus(
|
||||
focusNode: terminalFocus,
|
||||
onKeyEvent: (node, event) {
|
||||
if (event is KeyDownEvent) {
|
||||
terminalTyped.add(event.logicalKey);
|
||||
}
|
||||
return KeyEventResult.handled;
|
||||
},
|
||||
child: const SizedBox(),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned.fill(child: WindowHost(manager: manager)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> stop(WidgetTester tester) async {
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
windows.dispose();
|
||||
runtime.dispose();
|
||||
manager.dispose();
|
||||
terminalFocus.dispose();
|
||||
gateway.close();
|
||||
}
|
||||
|
||||
List<String> get floating => [for (final w in windows.windows) w.contentId];
|
||||
}
|
||||
|
||||
/// Floats [session] from its pane menu.
|
||||
Future<void> _float(WidgetTester tester, String session) async {
|
||||
await tester.tap(
|
||||
find
|
||||
.descendant(
|
||||
of: _thread(session),
|
||||
matching: find.byTooltip('More actions'),
|
||||
)
|
||||
.hitTestable(),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Float (Alt+Y)').last);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
/// Alt+] (or Alt+[ with [back]), leaving the focus ring mid-flash.
|
||||
Future<void> _cycle(WidgetTester tester, {bool back = false}) async {
|
||||
await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);
|
||||
final physical = back
|
||||
? PhysicalKeyboardKey.bracketLeft
|
||||
: PhysicalKeyboardKey.bracketRight;
|
||||
final logical = back
|
||||
? LogicalKeyboardKey.bracketLeft
|
||||
: LogicalKeyboardKey.bracketRight;
|
||||
await tester.sendKeyDownEvent(logical, physicalKey: physical);
|
||||
await tester.sendKeyUpEvent(logical, physicalKey: physical);
|
||||
await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft);
|
||||
for (var i = 0; i < 3; i++) {
|
||||
await tester.pump();
|
||||
}
|
||||
}
|
||||
|
||||
/// Lets the flash finish.
|
||||
Future<void> _settle(WidgetTester tester) async {
|
||||
await tester.pump(chatPaneFlashDuration);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('Alt+] and Alt+[ cycle three tiled panes and a floating '
|
||||
'window, wrapping, each composer focused and its ring flashing', (
|
||||
tester,
|
||||
) async {
|
||||
_saved(['a', 'b', 'c', 'd']);
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
await _float(tester, 'd');
|
||||
final workspace = _workspace(tester);
|
||||
expect(workspace.panes.map((p) => p.sessionId), ['a', 'b', 'c']);
|
||||
expect(app.floating, ['d']);
|
||||
|
||||
await tester.tapAt(tester.getCenter(_input('a')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_composerFocused(tester, 'a'), isTrue);
|
||||
|
||||
// Forward: the tiles left to right, then the window, then around.
|
||||
for (final id in ['b', 'c', 'd', 'a']) {
|
||||
await _cycle(tester);
|
||||
expect(_composerFocused(tester, id), isTrue, reason: id);
|
||||
expect(_flashing(tester), [id]);
|
||||
if (id != 'd') expect(workspace.activePane?.sessionId, id);
|
||||
await _settle(tester);
|
||||
expect(_flashing(tester), isEmpty);
|
||||
}
|
||||
|
||||
// Back: around to the window, then the tiles right to left.
|
||||
for (final id in ['d', 'c', 'b', 'a']) {
|
||||
await _cycle(tester, back: true);
|
||||
expect(_composerFocused(tester, id), isTrue, reason: id);
|
||||
expect(_flashing(tester), [id]);
|
||||
await _settle(tester);
|
||||
}
|
||||
|
||||
// Nothing opened, closed or moved.
|
||||
expect(workspace.panes.map((p) => p.sessionId), ['a', 'b', 'c']);
|
||||
expect(app.floating, ['d']);
|
||||
expect(tester.takeException(), isNull);
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('two tiled panes and a floating window cycle in the same order', (
|
||||
tester,
|
||||
) async {
|
||||
_saved(['a', 'b', 'c']);
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
await _float(tester, 'c');
|
||||
await tester.tapAt(tester.getCenter(_input('b')));
|
||||
await tester.pumpAndSettle();
|
||||
for (final id in ['c', 'a', 'b']) {
|
||||
await _cycle(tester);
|
||||
expect(_composerFocused(tester, id), isTrue, reason: id);
|
||||
await _settle(tester);
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('with one pane on screen the keys do nothing', (tester) async {
|
||||
_saved(['a']);
|
||||
final app = _App();
|
||||
await app.start(tester);
|
||||
await tester.tapAt(tester.getCenter(_input('a')));
|
||||
await tester.pumpAndSettle();
|
||||
await _cycle(tester);
|
||||
await _cycle(tester, back: true);
|
||||
expect(_composerFocused(tester, 'a'), isTrue);
|
||||
expect(_flashing(tester), isEmpty);
|
||||
expect(_workspace(tester).paneCount, 1);
|
||||
expect(tester.takeException(), isNull);
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('on a phone layout the keys do nothing', (tester) async {
|
||||
_saved(['a', 'b']);
|
||||
final app = _App();
|
||||
await app.start(tester, size: const Size(400, 800));
|
||||
final workspace = _workspace(tester);
|
||||
final active = workspace.activePane?.sessionId;
|
||||
await _cycle(tester);
|
||||
await _cycle(tester);
|
||||
expect(workspace.activePane?.sessionId, active);
|
||||
expect(_flashing(tester), isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
await app.stop(tester);
|
||||
});
|
||||
|
||||
testWidgets('a focused terminal keeps Alt+] and Alt+[', (tester) async {
|
||||
_saved(['a', 'b']);
|
||||
final app = _App();
|
||||
await app.start(tester, terminal: true);
|
||||
final workspace = _workspace(tester);
|
||||
await tester.tapAt(tester.getCenter(_input('a')));
|
||||
await tester.pumpAndSettle();
|
||||
app.terminalFocus.requestFocus();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await _cycle(tester);
|
||||
await _cycle(tester, back: true);
|
||||
expect(app.terminalTyped, [
|
||||
LogicalKeyboardKey.altLeft,
|
||||
LogicalKeyboardKey.bracketRight,
|
||||
LogicalKeyboardKey.altLeft,
|
||||
LogicalKeyboardKey.bracketLeft,
|
||||
]);
|
||||
expect(app.terminalFocus.hasPrimaryFocus, isTrue);
|
||||
expect(workspace.activePane?.sessionId, 'a');
|
||||
expect(_flashing(tester), isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
await app.stop(tester);
|
||||
});
|
||||
}
|
||||
@@ -2,21 +2,34 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/speech/speech.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/speech/chat_speaking_control.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_read_aloud_button.dart';
|
||||
|
||||
import '../speech/fake_speech_engine.dart';
|
||||
import 'chat_thread_fixtures.dart';
|
||||
|
||||
Widget _thread(FakeChatGateway gateway, String sessionId) => MaterialApp(
|
||||
Widget _thread(
|
||||
FakeChatGateway gateway,
|
||||
String sessionId, {
|
||||
String title = '',
|
||||
bool pasteTarget = true,
|
||||
}) => MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(
|
||||
body: ChatThreadView(gateway: gateway, sessionId: sessionId, onBack: () {}),
|
||||
body: ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: sessionId,
|
||||
title: title,
|
||||
pasteTarget: pasteTarget,
|
||||
onBack: () {},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Future<(FakeSpeechEngine, SpeechController, FakeChatGateway)> _reading(
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
WidgetTester tester, {
|
||||
String title = 'Alpha',
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(800, 1600);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
@@ -33,42 +46,78 @@ Future<(FakeSpeechEngine, SpeechController, FakeChatGateway)> _reading(
|
||||
],
|
||||
),
|
||||
]);
|
||||
await tester.pumpWidget(_thread(gateway, 's1'));
|
||||
await tester.pumpWidget(_thread(gateway, 's1', title: title));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip(chatReadAloudLabel));
|
||||
await tester.pump();
|
||||
engine.onStart!();
|
||||
await tester.pump();
|
||||
expect(engine.spoken, ['Hello from the agent.']);
|
||||
expect(speech.messageId, startsWith(speechScopePrefix('s1')));
|
||||
expect(speech.reading.value, SpeechReading(scope: 's1', title: title));
|
||||
return (engine, speech, gateway);
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('switching the pane to another chat stops reading', (
|
||||
testWidgets('switching the pane to another chat keeps reading', (
|
||||
tester,
|
||||
) async {
|
||||
final (engine, speech, gateway) = await _reading(tester);
|
||||
await tester.pumpWidget(_thread(gateway, 's2'));
|
||||
await tester.pumpWidget(_thread(gateway, 's2', title: 'Beta'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(speech.state, SpeechState.idle);
|
||||
expect(engine.calls, contains('stop'));
|
||||
expect(speech.state, SpeechState.speaking);
|
||||
expect(engine.calls, isNot(contains('stop')));
|
||||
expect(speechReading.value?.scope, 's1');
|
||||
|
||||
// Back in the chat, its reply shows the reading's Pause and Stop again.
|
||||
await tester.pumpWidget(_thread(gateway, 's1', title: 'Alpha'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byTooltip(chatStopReadingLabel), findsOneWidget);
|
||||
expect(find.byTooltip(chatPauseReadingLabel), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('closing the chat stops reading', (tester) async {
|
||||
testWidgets('leaving the conversation keeps its reply reading', (
|
||||
tester,
|
||||
) async {
|
||||
final (engine, speech, _) = await _reading(tester);
|
||||
await tester.pumpWidget(const MaterialApp(home: SizedBox()));
|
||||
await tester.pumpAndSettle();
|
||||
expect(speech.state, SpeechState.idle);
|
||||
expect(engine.calls.last, 'stop');
|
||||
});
|
||||
|
||||
testWidgets('closing a chat leaves another chat reading', (tester) async {
|
||||
final (engine, speech, _) = await _reading(tester);
|
||||
await speech.read(speechMessageId('elsewhere', 'b1'), ['Other reply']);
|
||||
engine.onStart!();
|
||||
await tester.pumpWidget(const MaterialApp(home: SizedBox()));
|
||||
await tester.pumpAndSettle();
|
||||
expect(speech.state, SpeechState.speaking);
|
||||
expect(speech.messageId, speechMessageId('elsewhere', 'b1'));
|
||||
expect(engine.calls, isNot(contains('stop')));
|
||||
});
|
||||
|
||||
testWidgets('another chat names the reading and its Stop ends it', (
|
||||
tester,
|
||||
) async {
|
||||
final (engine, speech, gateway) = await _reading(tester);
|
||||
expect(find.text('Speaking · Alpha'), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(_thread(gateway, 's2', title: 'Beta'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Speaking · Alpha'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byTooltip(chatSpeakingStopLabel));
|
||||
await tester.pumpAndSettle();
|
||||
expect(speech.state, SpeechState.idle);
|
||||
expect(engine.calls.last, 'stop');
|
||||
expect(find.byKey(const Key('chat-speaking-control')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('the control follows a pause and a rename', (tester) async {
|
||||
final (_, speech, gateway) = await _reading(tester);
|
||||
await speech.pause();
|
||||
await tester.pump();
|
||||
expect(find.text('Paused · Alpha'), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(_thread(gateway, 's1', title: 'Renamed'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Paused · Renamed'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('only the active pane shows the global control', (tester) async {
|
||||
final (_, _, gateway) = await _reading(tester);
|
||||
await tester.pumpWidget(_thread(gateway, 's2', pasteTarget: false));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-speaking-control')), findsNothing);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -143,6 +143,29 @@ void main() {
|
||||
expect(speech.state, SpeechState.idle);
|
||||
});
|
||||
|
||||
testWidgets('reading names the conversation until the reply ends', (
|
||||
tester,
|
||||
) async {
|
||||
reader();
|
||||
await speech.read(speechMessageId('chat-1', 'm1'), ['Hi'], title: 'One');
|
||||
expect(
|
||||
speech.reading.value,
|
||||
const SpeechReading(scope: 'chat-1', title: 'One'),
|
||||
);
|
||||
speech.retitle('chat-2', 'Other');
|
||||
expect(speech.reading.value?.title, 'One');
|
||||
speech.retitle('chat-1', 'Renamed');
|
||||
expect(speech.reading.value?.title, 'Renamed');
|
||||
|
||||
// Another reply replaces it; finishing clears it.
|
||||
await speech.read(speechMessageId('chat-2', 'm1'), ['Yo'], title: 'Two');
|
||||
expect(speech.reading.value?.scope, 'chat-2');
|
||||
engine.onStart!();
|
||||
engine.onCompletion!();
|
||||
expect(speech.reading.value, isNull);
|
||||
expect(speech.state, SpeechState.idle);
|
||||
});
|
||||
|
||||
testWidgets('voice and rate are applied and persist across a reload', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/data/chat_repository.dart';
|
||||
import 'package:pipelines_app/features/chat/speech/speech.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_controller.dart';
|
||||
|
||||
import '../../speech/fake_speech_engine.dart';
|
||||
import 'chat_test_harness.dart';
|
||||
import 'fake_chat_gateway.dart';
|
||||
|
||||
JsonMap _row(String id, {bool closed = false}) => {
|
||||
'id': id,
|
||||
'title': id,
|
||||
'directory': '/w',
|
||||
if (closed) 'closed_at': '2026-12-03T10:00:00Z',
|
||||
};
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
late FakeChatGateway gateway;
|
||||
late ChatSessionsController controller;
|
||||
late SpeechController speech;
|
||||
|
||||
setUp(() async {
|
||||
speech = installFakeSpeech(FakeSpeechEngine());
|
||||
gateway = FakeChatGateway()
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [_row('s1'), _row('s2')],
|
||||
}
|
||||
..actionHandler = (_, _) async => const {};
|
||||
controller = ChatSessionsController(
|
||||
ChatRepository(gateway),
|
||||
localStore: MemoryChatSessionLocalStore(),
|
||||
);
|
||||
addTearDown(controller.dispose);
|
||||
await controller.refresh();
|
||||
await speech.read(speechMessageId('s1', 'r1'), ['Hello.']);
|
||||
expect(speech.state, SpeechState.speaking);
|
||||
});
|
||||
|
||||
test('closing the reading chat stops it', () async {
|
||||
await controller.close('s1');
|
||||
await pumpEventQueue();
|
||||
expect(speech.state, SpeechState.idle);
|
||||
});
|
||||
|
||||
test('closing another chat keeps reading', () async {
|
||||
await controller.close('s2');
|
||||
await pumpEventQueue();
|
||||
expect(speech.state, SpeechState.speaking);
|
||||
});
|
||||
|
||||
test('a chat closed on another device stops it on the next read', () async {
|
||||
gateway.sessionsReply = {
|
||||
'chat_sessions': [_row('s1', closed: true), _row('s2')],
|
||||
};
|
||||
await controller.refresh();
|
||||
await pumpEventQueue();
|
||||
expect(speech.state, SpeechState.idle);
|
||||
});
|
||||
|
||||
test('a deleted chat stops it; a failed read does not', () async {
|
||||
gateway.sessionsHandler = () async => throw StateError('offline');
|
||||
await controller.refresh();
|
||||
await pumpEventQueue();
|
||||
expect(speech.state, SpeechState.speaking);
|
||||
|
||||
gateway
|
||||
..sessionsHandler = null
|
||||
..sessionsReply = {
|
||||
'chat_sessions': [_row('s2')],
|
||||
};
|
||||
await controller.refresh();
|
||||
await pumpEventQueue();
|
||||
expect(speech.state, SpeechState.idle);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/speech/speech.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_awaiting.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_compact_avatar.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
|
||||
|
||||
import '../../speech/fake_speech_engine.dart';
|
||||
|
||||
const _speaking = Key('chat-row-speaking');
|
||||
|
||||
Widget _avatars({bool reduceMotion = false}) => MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(disableAnimations: reduceMotion),
|
||||
child: const Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
ChatSessionAvatar(
|
||||
key: Key('one'),
|
||||
session: {'id': 's1', 'title': 'One'},
|
||||
running: true,
|
||||
awaitingOperator: 2,
|
||||
),
|
||||
ChatSessionAvatar(
|
||||
key: Key('two'),
|
||||
session: {'id': 's2', 'title': 'Two'},
|
||||
),
|
||||
ChatCompactAvatar(
|
||||
key: Key('two-compact'),
|
||||
sessionId: 's2',
|
||||
title: 'Two',
|
||||
color: Colors.blue,
|
||||
active: false,
|
||||
visible: false,
|
||||
running: false,
|
||||
backgroundTasks: 0,
|
||||
unread: false,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Finder _badgeOf(String avatar) => find.descendant(
|
||||
of: find.byKey(Key(avatar)),
|
||||
matching: find.byKey(_speaking),
|
||||
);
|
||||
|
||||
Future<void> _read(WidgetTester tester, SpeechController speech, String chat) =>
|
||||
tester.runAsync(() => speech.read(speechMessageId(chat, 'r1'), ['Hi.']));
|
||||
|
||||
void main() {
|
||||
testWidgets('the reading chat wears the speaking badge, and it moves', (
|
||||
tester,
|
||||
) async {
|
||||
final speech = installFakeSpeech(FakeSpeechEngine());
|
||||
await tester.pumpWidget(_avatars());
|
||||
expect(find.byKey(_speaking), findsNothing);
|
||||
|
||||
await _read(tester, speech, 's1');
|
||||
await tester.pump();
|
||||
expect(_badgeOf('one'), findsOneWidget);
|
||||
expect(_badgeOf('two'), findsNothing);
|
||||
expect(_badgeOf('two-compact'), findsNothing);
|
||||
// Speaking outranks the operator wait and the running spinner.
|
||||
expect(find.byKey(const Key('chat-row-working')), findsNothing);
|
||||
expect(find.byType(ChatAwaitingBadge), findsNothing);
|
||||
|
||||
await _read(tester, speech, 's2');
|
||||
await tester.pump();
|
||||
expect(_badgeOf('one'), findsNothing);
|
||||
expect(_badgeOf('two'), findsOneWidget);
|
||||
expect(_badgeOf('two-compact'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-speaking-wave')), findsNWidgets(2));
|
||||
|
||||
await tester.runAsync(speech.stop);
|
||||
await tester.pump();
|
||||
expect(find.byKey(_speaking), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a Settings voice sample marks no chat', (tester) async {
|
||||
final speech = installFakeSpeech(FakeSpeechEngine());
|
||||
await tester.pumpWidget(_avatars());
|
||||
await tester.runAsync(speech.sample);
|
||||
await tester.pump();
|
||||
expect(speech.state, SpeechState.speaking);
|
||||
expect(find.byKey(_speaking), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('reduced motion shows a still speaker', (tester) async {
|
||||
final speech = installFakeSpeech(FakeSpeechEngine());
|
||||
await tester.pumpWidget(_avatars(reduceMotion: true));
|
||||
// The first chat's spinner gives way to the speaking badge.
|
||||
await _read(tester, speech, 's1');
|
||||
await tester.pump();
|
||||
expect(_badgeOf('one'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-speaking-still')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-speaking-wave')), findsNothing);
|
||||
// Nothing ticks: settling finishes with the badge still shown.
|
||||
await tester.pumpAndSettle();
|
||||
expect(_badgeOf('one'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_pane_cycle.dart';
|
||||
|
||||
KeyEvent _down(
|
||||
PhysicalKeyboardKey physical,
|
||||
LogicalKeyboardKey logical, {
|
||||
String? character,
|
||||
}) => KeyDownEvent(
|
||||
physicalKey: physical,
|
||||
logicalKey: logical,
|
||||
character: character,
|
||||
timeStamp: Duration.zero,
|
||||
);
|
||||
|
||||
final _right = _down(
|
||||
PhysicalKeyboardKey.bracketRight,
|
||||
LogicalKeyboardKey.bracketRight,
|
||||
);
|
||||
final _left = _down(
|
||||
PhysicalKeyboardKey.bracketLeft,
|
||||
LogicalKeyboardKey.bracketLeft,
|
||||
);
|
||||
|
||||
int? _step(
|
||||
KeyEvent event,
|
||||
Set<LogicalKeyboardKey> held, [
|
||||
TargetPlatform platform = TargetPlatform.linux,
|
||||
]) => chatPaneCycleShortcut(event, _FakeKeyboard(held), platform: platform);
|
||||
|
||||
void main() {
|
||||
test('Alt+] goes forward and Alt+[ back on every platform', () {
|
||||
for (final platform in TargetPlatform.values) {
|
||||
expect(_step(_right, {LogicalKeyboardKey.altLeft}, platform), 1);
|
||||
expect(_step(_left, {LogicalKeyboardKey.altLeft}, platform), -1);
|
||||
}
|
||||
});
|
||||
|
||||
test('Option+] types a quote on a Mac: it matches by key position', () {
|
||||
final quote = _down(
|
||||
PhysicalKeyboardKey.bracketRight,
|
||||
const LogicalKeyboardKey(0x2018),
|
||||
character: '‘',
|
||||
);
|
||||
expect(_step(quote, {LogicalKeyboardKey.altLeft}, TargetPlatform.macOS), 1);
|
||||
});
|
||||
|
||||
test('Cmd+] and Cmd+[ only on Apple platforms', () {
|
||||
expect(
|
||||
_step(_right, {LogicalKeyboardKey.metaLeft}, TargetPlatform.macOS),
|
||||
1,
|
||||
);
|
||||
expect(_step(_left, {LogicalKeyboardKey.metaLeft}, TargetPlatform.iOS), -1);
|
||||
expect(_step(_right, {LogicalKeyboardKey.metaLeft}), isNull);
|
||||
expect(
|
||||
_step(_right, {LogicalKeyboardKey.metaLeft}, TargetPlatform.windows),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('plain brackets type; Shift, Ctrl, AltGr and key-up do not match', () {
|
||||
expect(_step(_right, {}), isNull);
|
||||
for (final extra in [
|
||||
LogicalKeyboardKey.shiftLeft,
|
||||
LogicalKeyboardKey.controlLeft,
|
||||
LogicalKeyboardKey.metaLeft,
|
||||
LogicalKeyboardKey.altGraph,
|
||||
]) {
|
||||
expect(
|
||||
_step(_right, {LogicalKeyboardKey.altLeft, extra}),
|
||||
isNull,
|
||||
reason: '$extra',
|
||||
);
|
||||
}
|
||||
expect(
|
||||
_step(
|
||||
const KeyUpEvent(
|
||||
physicalKey: PhysicalKeyboardKey.bracketRight,
|
||||
logicalKey: LogicalKeyboardKey.bracketRight,
|
||||
timeStamp: Duration.zero,
|
||||
),
|
||||
{LogicalKeyboardKey.altLeft},
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
// A key typing "[" elsewhere on the keyboard is not the chord.
|
||||
expect(
|
||||
_step(_down(PhysicalKeyboardKey.digit8, LogicalKeyboardKey.bracketLeft), {
|
||||
LogicalKeyboardKey.altLeft,
|
||||
}),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('labels name the chords this platform answers', () {
|
||||
expect(chatPaneCycleShortcutLabel(TargetPlatform.linux), 'Alt+], Alt+[');
|
||||
expect(chatPaneCycleShortcutLabel(TargetPlatform.windows), 'Alt+], Alt+[');
|
||||
expect(
|
||||
chatPaneCycleShortcutLabel(TargetPlatform.macOS),
|
||||
'Option+], Option+[, Cmd+], Cmd+[',
|
||||
);
|
||||
});
|
||||
|
||||
test('targets wrap both ways; one entry or none has no target', () {
|
||||
const order = ['a', 'b', 'c'];
|
||||
expect(chatPaneCycleTarget(order, 0, 1), 'b');
|
||||
expect(chatPaneCycleTarget(order, 2, 1), 'a');
|
||||
expect(chatPaneCycleTarget(order, 0, -1), 'c');
|
||||
expect(chatPaneCycleTarget(order, 1, -1), 'a');
|
||||
expect(chatPaneCycleTarget(order, -1, 1), 'a');
|
||||
expect(chatPaneCycleTarget(order, -1, -1), 'c');
|
||||
expect(chatPaneCycleTarget(['a'], 0, 1), isNull);
|
||||
expect(chatPaneCycleTarget(<String>[], -1, 1), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
class _FakeKeyboard extends HardwareKeyboard {
|
||||
_FakeKeyboard(this.pressed);
|
||||
final Set<LogicalKeyboardKey> pressed;
|
||||
@override
|
||||
bool isLogicalKeyPressed(LogicalKeyboardKey key) => pressed.contains(key);
|
||||
}
|
||||
@@ -24,8 +24,13 @@ void main() {
|
||||
});
|
||||
|
||||
test('scattered letters in a long note do not match', () {
|
||||
// `float` occurs only as scattered letters in other entries' notes.
|
||||
expect(actions('float'), everyElement(contains('floating')));
|
||||
// `float` occurs as scattered letters in many entries' notes; only the
|
||||
// entries that say "floating" match.
|
||||
final found = [
|
||||
for (final match in filterShortcuts(registry.entries, 'float'))
|
||||
'${match.entry.action} ${match.entry.caveat ?? ''}',
|
||||
];
|
||||
expect(found, everyElement(contains('floating')));
|
||||
});
|
||||
|
||||
test('keys are searchable with or without the plus', () {
|
||||
|
||||
@@ -117,4 +117,40 @@ void main() {
|
||||
await next.restore();
|
||||
expect(next.design, AppDesign.paper);
|
||||
});
|
||||
|
||||
testWidgets('choosing Compact stores it, densifies the page live, draws '
|
||||
'a denser swatch and is restored on the next launch', (tester) async {
|
||||
final store = MemoryAppDesignStore();
|
||||
final designs = AppDesignController(store: store);
|
||||
await _pump(tester, designs);
|
||||
|
||||
final swatch = tester.widget<DesignSwatchPreview>(
|
||||
find.descendant(
|
||||
of: find.byKey(settingsDesignKey(AppDesign.compact)),
|
||||
matching: find.byType(DesignSwatchPreview),
|
||||
),
|
||||
);
|
||||
expect(swatch.lines, greaterThan(2));
|
||||
expect(find.text(AppDesign.compact.description), findsOneWidget);
|
||||
final before = tester.getSize(
|
||||
find.byKey(settingsDesignKey(AppDesign.paper)),
|
||||
);
|
||||
|
||||
await tester.tap(find.text(AppDesign.compact.label));
|
||||
await tester.pumpAndSettle();
|
||||
expect(store.id, 'compact');
|
||||
expect(designs.design, AppDesign.compact);
|
||||
final tokens = _tokens(tester);
|
||||
expect(tokens.density.dense, isTrue);
|
||||
expect(tokens.transcript, TranscriptStyle.bubbles);
|
||||
// The rows themselves tighten at once.
|
||||
final after = tester.getSize(
|
||||
find.byKey(settingsDesignKey(AppDesign.paper)),
|
||||
);
|
||||
expect(after.height, lessThan(before.height));
|
||||
|
||||
final next = AppDesignController(store: MemoryAppDesignStore(store.id));
|
||||
await next.restore();
|
||||
expect(next.design, AppDesign.compact);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -257,6 +257,13 @@ void main() {
|
||||
row['scrollFrameUs'] = watch.elapsedMicroseconds ~/ frames;
|
||||
rebuilds.uninstall();
|
||||
row['scrollRebuildsPerFrame'] = rebuilds.count / frames;
|
||||
// A denser design shows more rows in the same 120px, so it builds
|
||||
// more per frame for the same per-row cost: the budget is per row
|
||||
// scrolled past (rows over the transcript's whole extent).
|
||||
final position = controller.position;
|
||||
final extent = position.maxScrollExtent + position.viewportDimension;
|
||||
final rowsScrolled = frames * 120 * _rows.length / extent;
|
||||
row['scrollRebuildsPerRow'] = rebuilds.count / rowsScrolled;
|
||||
row['scrollLayersPerFrame'] = _sum(layers) / frames;
|
||||
row['scrollSaveLayersPerFrame'] =
|
||||
_sum(layers, (k) => !k.startsWith('clip')) / frames;
|
||||
@@ -277,7 +284,7 @@ void main() {
|
||||
// Counts are deterministic: a design may not exceed Default's by more
|
||||
// than a quarter (its own rows are allowed to differ a little).
|
||||
for (final key in [
|
||||
'scrollRebuildsPerFrame',
|
||||
'scrollRebuildsPerRow',
|
||||
'scrollLayersPerFrame',
|
||||
'scrollSaveLayersPerFrame',
|
||||
'switchFramesPerSwitch',
|
||||
|
||||
@@ -265,6 +265,7 @@ void main() {
|
||||
(AppDesign.standard, false, true),
|
||||
(AppDesign.terminal, true, false),
|
||||
(AppDesign.paper, false, false),
|
||||
(AppDesign.compact, false, true),
|
||||
]) {
|
||||
testWidgets('${design.label}: the open row is clearly marked', (
|
||||
tester,
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
|
||||
ThemeData _theme(AppDesign design, Brightness brightness, {String? font}) =>
|
||||
brightness == Brightness.dark
|
||||
? design.dark(fontFamily: font)
|
||||
: design.light(fontFamily: font);
|
||||
|
||||
BorderRadius? _radiusOf(ShapeBorder? shape) =>
|
||||
(shape as RoundedRectangleBorder?)?.borderRadius as BorderRadius?;
|
||||
|
||||
void main() {
|
||||
const six = BorderRadius.all(Radius.circular(6));
|
||||
|
||||
test('Compact is listed with a stable id, a label and one line', () {
|
||||
expect(AppDesign.fromId('compact'), AppDesign.compact);
|
||||
expect(AppDesign.compact.label, 'Compact');
|
||||
expect(AppDesign.compact.description, isNot(contains('\n')));
|
||||
expect(AppDesign.compact.usesInterfaceFont, isTrue);
|
||||
expect(AppDesign.compact.swatchLines, greaterThan(2));
|
||||
for (final design in AppDesign.values) {
|
||||
if (design != AppDesign.compact) expect(design.swatchLines, 2);
|
||||
}
|
||||
});
|
||||
|
||||
test('Compact tokens: Default chat and composer, tonal rows, 6px corners, '
|
||||
'the compact density and tighter paragraphs', () {
|
||||
for (final brightness in Brightness.values) {
|
||||
final tokens = _theme(
|
||||
AppDesign.compact,
|
||||
brightness,
|
||||
).extension<AppDesignTokens>()!;
|
||||
expect(tokens.design, AppDesign.compact);
|
||||
expect(tokens.radius, 6);
|
||||
expect(tokens.flat, isFalse);
|
||||
expect(tokens.frame, isNull);
|
||||
expect(tokens.transcript, TranscriptStyle.bubbles);
|
||||
expect(tokens.composer, ComposerStyle.pill);
|
||||
expect(tokens.selectedRow, SelectedRowStyle.tonal);
|
||||
expect(tokens.density, DesignDensity.compact);
|
||||
expect(tokens.density.dense, isTrue);
|
||||
expect(tokens.density.iconSize, 18);
|
||||
expect(tokens.density.railLabels, isFalse);
|
||||
expect(tokens.density.railWidth, lessThan(96));
|
||||
expect(tokens.reading.family, isNull);
|
||||
expect(tokens.reading.paragraphGap, lessThan(0.9));
|
||||
expect(tokens.denseCorners(BorderRadius.circular(12)), six);
|
||||
}
|
||||
});
|
||||
|
||||
test('the comfortable designs keep the comfortable density', () {
|
||||
for (final design in [AppDesign.terminal, AppDesign.paper]) {
|
||||
final tokens = design.light().extension<AppDesignTokens>()!;
|
||||
expect(tokens.density, DesignDensity.comfortable);
|
||||
expect(tokens.reading.paragraphGap, 0.9);
|
||||
final twelve = BorderRadius.circular(12);
|
||||
expect(tokens.denseCorners(twelve), twelve);
|
||||
}
|
||||
expect(AppDesignTokens.standard.density, DesignDensity.comfortable);
|
||||
// Default still builds its exact themes, with no tokens at all.
|
||||
expect(AppDesign.standard.light(), appLightTheme());
|
||||
expect(AppDesign.standard.dark(), appDarkTheme());
|
||||
});
|
||||
|
||||
test('density spacing: unchanged when comfortable, 4px grid when dense', () {
|
||||
const comfortable = DesignDensity.comfortable;
|
||||
for (final value in [2.0, 4.0, 6.0, 10.0, 13.0, 16.0, 24.0]) {
|
||||
expect(comfortable.space(value), value);
|
||||
expect(comfortable.inset(value), value);
|
||||
}
|
||||
expect(comfortable.minTouchRow, 0);
|
||||
const compact = DesignDensity.compact;
|
||||
expect(compact.space(16), 8);
|
||||
expect(compact.space(13), 8);
|
||||
expect(compact.space(12), 8);
|
||||
expect(compact.space(8), 4);
|
||||
expect(compact.space(6), 4);
|
||||
expect(compact.space(4), 2);
|
||||
expect(compact.space(24), 16);
|
||||
expect(compact.inset(16), 12);
|
||||
expect(compact.inset(12), 8);
|
||||
for (final value in [8.0, 12.0, 16.0, 24.0, 32.0]) {
|
||||
expect(compact.space(value) % 4, 0, reason: 'on the 4px grid');
|
||||
expect(compact.space(value), lessThan(value));
|
||||
}
|
||||
});
|
||||
|
||||
test('Compact keeps Default colours and packs type, icons and density', () {
|
||||
for (final brightness in Brightness.values) {
|
||||
final theme = _theme(AppDesign.compact, brightness, font: 'Inter');
|
||||
final standard = _theme(AppDesign.standard, brightness, font: 'Inter');
|
||||
expect(theme.colorScheme, standard.colorScheme);
|
||||
expect(theme.scaffoldBackgroundColor, standard.scaffoldBackgroundColor);
|
||||
final text = theme.textTheme;
|
||||
expect(text.bodyMedium?.fontSize, 13);
|
||||
expect(text.bodyLarge?.fontSize, 14);
|
||||
expect(text.labelMedium?.fontSize, 12);
|
||||
expect(text.labelSmall?.fontSize, 11);
|
||||
expect(text.titleMedium?.fontSize, 14);
|
||||
for (final style in [text.bodyMedium, text.titleLarge, text.labelLarge]) {
|
||||
// The device's interface font still applies.
|
||||
expect(style?.fontFamily, 'Inter');
|
||||
expect(style?.fontSize, lessThan(20));
|
||||
// Line heights on a 2px step.
|
||||
expect((style!.fontSize! * style.height!) % 2, closeTo(0, 0.01));
|
||||
}
|
||||
expect(theme.visualDensity, VisualDensity.compact);
|
||||
expect(theme.iconTheme.size, 18);
|
||||
expect(
|
||||
theme.iconButtonTheme.style?.visualDensity,
|
||||
VisualDensity.compact,
|
||||
reason: 'Material 3 icon buttons ignore the theme density otherwise',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('every floating and framed surface takes the same 6px corners', () {
|
||||
final theme = AppDesign.compact.light();
|
||||
expect(_radiusOf(theme.dialogTheme.shape), six);
|
||||
expect(_radiusOf(theme.popupMenuTheme.shape), six);
|
||||
expect(_radiusOf(theme.snackBarTheme.shape), six);
|
||||
expect(_radiusOf(theme.cardTheme.shape), six);
|
||||
expect(_radiusOf(theme.chipTheme.shape), six);
|
||||
expect(_radiusOf(theme.floatingActionButtonTheme.shape), six);
|
||||
expect(_radiusOf(theme.listTileTheme.shape), six);
|
||||
expect(_radiusOf(theme.navigationRailTheme.indicatorShape), six);
|
||||
expect(_radiusOf(theme.menuTheme.style?.shape?.resolve(const {})), six);
|
||||
expect(
|
||||
_radiusOf(theme.filledButtonTheme.style?.shape?.resolve(const {})),
|
||||
six,
|
||||
);
|
||||
expect(
|
||||
_radiusOf(theme.iconButtonTheme.style?.shape?.resolve(const {})),
|
||||
six,
|
||||
);
|
||||
expect(
|
||||
(theme.tooltipTheme.decoration as BoxDecoration?)?.borderRadius,
|
||||
six,
|
||||
);
|
||||
final sheet = _radiusOf(theme.bottomSheetTheme.shape)!;
|
||||
expect(sheet.topLeft, const Radius.circular(6));
|
||||
expect(sheet.bottomLeft, Radius.zero);
|
||||
// A card keeps its outline under the theme's shape (outlined graph
|
||||
// nodes would otherwise lose it).
|
||||
final card = theme.cardTheme.shape! as RoundedRectangleBorder;
|
||||
expect(card.side.color, theme.colorScheme.outlineVariant);
|
||||
});
|
||||
|
||||
test('pointer devices shrink targets; touch devices keep 40px', () {
|
||||
for (final (platform, pointer) in [
|
||||
(TargetPlatform.linux, true),
|
||||
(TargetPlatform.macOS, true),
|
||||
(TargetPlatform.windows, true),
|
||||
(TargetPlatform.android, false),
|
||||
(TargetPlatform.iOS, false),
|
||||
]) {
|
||||
debugDefaultTargetPlatformOverride = platform;
|
||||
// Built afresh: the cached theme is the device's, built once.
|
||||
final theme = AppDesign.compact.build(Brightness.light);
|
||||
expect(
|
||||
theme.materialTapTargetSize,
|
||||
pointer
|
||||
? MaterialTapTargetSize.shrinkWrap
|
||||
: MaterialTapTargetSize.padded,
|
||||
);
|
||||
expect(DesignDensity.compact.minTouchRow, pointer ? 0 : 40);
|
||||
}
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
test(
|
||||
'a switch into or out of Compact snaps; others keep the blend',
|
||||
() async {
|
||||
final designs = AppDesignController(store: MemoryAppDesignStore());
|
||||
expect(AppDesign.compact.dense, isTrue);
|
||||
for (final design in [
|
||||
AppDesign.standard,
|
||||
AppDesign.terminal,
|
||||
AppDesign.paper,
|
||||
]) {
|
||||
expect(design.dense, isFalse);
|
||||
}
|
||||
expect(designs.themeAnimationDuration, kThemeAnimationDuration);
|
||||
await designs.select(AppDesign.terminal);
|
||||
expect(designs.themeAnimationDuration, kThemeAnimationDuration);
|
||||
await designs.select(AppDesign.compact);
|
||||
expect(designs.themeAnimationDuration, Duration.zero);
|
||||
await designs.select(AppDesign.paper);
|
||||
expect(designs.themeAnimationDuration, Duration.zero);
|
||||
await designs.select(AppDesign.standard);
|
||||
expect(designs.themeAnimationDuration, kThemeAnimationDuration);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/shell/navigation_rail.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_frame.dart';
|
||||
import 'package:pipelines_app/ui/layout/app_list_avatar.dart';
|
||||
import 'package:pipelines_app/ui/layout/app_list_row.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
|
||||
|
||||
/// Compact as drawn: thin rows, a narrow icon-only rail, 32px icon buttons
|
||||
/// (40px targets on touch), tight bubbles, a slim window title bar, and no
|
||||
/// clipping at a large text scale.
|
||||
void main() {
|
||||
tearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
|
||||
Future<void> pump(
|
||||
WidgetTester tester,
|
||||
Widget child, {
|
||||
AppDesign design = AppDesign.compact,
|
||||
double textScale = 1,
|
||||
double width = 560,
|
||||
}) async {
|
||||
tester.view.physicalSize = Size(width, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
// Built afresh, so the platform this test sets is the theme's.
|
||||
theme: design.build(Brightness.light),
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(
|
||||
size: Size(width, 900),
|
||||
textScaler: TextScaler.linear(textScale),
|
||||
),
|
||||
child: Scaffold(body: child),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Widget rows() => ListView(
|
||||
children: [
|
||||
AppListRow(
|
||||
key: const Key('one'),
|
||||
title: const Text('Release train'),
|
||||
time: '09:12',
|
||||
onTap: () {},
|
||||
),
|
||||
AppListRow(
|
||||
key: const Key('two'),
|
||||
leading: AppListAvatar.initial('Release', color: Colors.teal),
|
||||
title: const Text('Release notes'),
|
||||
subtitle: const Text('claude-opus · /workspace/demo'),
|
||||
time: '10m',
|
||||
selected: true,
|
||||
onTap: () {},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
testWidgets('pointer: a 36px single-line row and a ~52px two-line row', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
await pump(tester, rows());
|
||||
// Each row includes its 1px divider.
|
||||
expect(tester.getSize(find.byKey(const Key('one'))).height, 37);
|
||||
final two = tester.getSize(find.byKey(const Key('two'))).height;
|
||||
expect(two, inInclusiveRange(50, 56));
|
||||
expect(
|
||||
tester.getSize(find.byType(AppListAvatar)).height,
|
||||
DesignDensity.compact.avatarSize,
|
||||
);
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
testWidgets('touch: rows keep a 40px target', (tester) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
||||
await pump(tester, rows());
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('one'))).height,
|
||||
greaterThanOrEqualTo(41),
|
||||
);
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
testWidgets('Default rows keep their comfortable size', (tester) async {
|
||||
await pump(tester, rows(), design: AppDesign.standard);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('one'))).height,
|
||||
greaterThan(48),
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byType(AppListAvatar)).height,
|
||||
kAppListAvatarSize,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('rows and bubbles do not clip at 2x text', (tester) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
await pump(
|
||||
tester,
|
||||
Column(
|
||||
children: [
|
||||
SizedBox(height: 300, child: rows()),
|
||||
const ChatUserBubble(child: Text('Summarise the release notes.')),
|
||||
],
|
||||
),
|
||||
textScale: 2,
|
||||
width: 360,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
final one = tester.getSize(find.byKey(const Key('one'))).height;
|
||||
expect(one, greaterThan(37), reason: 'the row grows with its text');
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
testWidgets('icon buttons: 32px on a pointer device, 40px target on touch', (
|
||||
tester,
|
||||
) async {
|
||||
Widget button() => IconButton(
|
||||
key: const Key('b'),
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.add),
|
||||
);
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
await pump(tester, Center(child: button()));
|
||||
expect(tester.getSize(find.byKey(const Key('b'))), const Size(32, 32));
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.android;
|
||||
await pump(tester, Center(child: button()));
|
||||
expect(tester.getSize(find.byKey(const Key('b'))), const Size(40, 40));
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
testWidgets('the rail is narrow and icon-only, each icon with a tooltip', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(
|
||||
tester,
|
||||
Row(
|
||||
children: [
|
||||
ShellNavigationRail(
|
||||
selected: AppDestination.runs,
|
||||
icon: (d) => Icon(destinationDetails(d).icon),
|
||||
onSelected: (_) {},
|
||||
),
|
||||
const Expanded(child: SizedBox()),
|
||||
],
|
||||
),
|
||||
width: 1200,
|
||||
);
|
||||
final rail = find.byKey(const ValueKey('shell.navigation-rail.surface'));
|
||||
expect(tester.getSize(rail).width, DesignDensity.compact.railWidth);
|
||||
expect(
|
||||
tester.widget<NavigationRail>(find.byType(NavigationRail)).labelType,
|
||||
NavigationRailLabelType.none,
|
||||
);
|
||||
for (final destination in shellTabDestinations) {
|
||||
expect(
|
||||
find.byTooltip(destinationDetails(destination).label),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
expect(find.byTooltip('Settings'), findsOneWidget);
|
||||
// Settings' indicator matches the tabs' 56x32 rather than the rail.
|
||||
final indicator = find.descendant(
|
||||
of: find.byKey(const ValueKey('shell.destination.settings')),
|
||||
matching: find.byType(Container),
|
||||
);
|
||||
expect(tester.getSize(indicator.first), const Size(56, 32));
|
||||
});
|
||||
|
||||
testWidgets('the operator bubble is tight, in the design corners', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(tester, const ChatUserBubble(child: Text('Ship it')));
|
||||
final material = tester.widget<Material>(
|
||||
find.descendant(
|
||||
of: find.byType(ChatUserBubble),
|
||||
matching: find.byType(Material),
|
||||
),
|
||||
);
|
||||
final shape = material.shape! as RoundedRectangleBorder;
|
||||
expect(shape.borderRadius, BorderRadius.circular(6));
|
||||
final padding = tester.widget<Padding>(
|
||||
find.descendant(
|
||||
of: find.byType(ChatUserBubble),
|
||||
matching: find.byType(Padding),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
padding.padding,
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
);
|
||||
final gap = chatParagraphGap(tester.element(find.text('Ship it')), 14);
|
||||
expect(gap, closeTo(14 * 0.6, 0.01));
|
||||
});
|
||||
|
||||
testWidgets('a floating window has a 32px title bar and 6px corners', (
|
||||
tester,
|
||||
) async {
|
||||
late BuildContext context;
|
||||
await pump(
|
||||
tester,
|
||||
Builder(
|
||||
builder: (c) {
|
||||
context = c;
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
);
|
||||
expect(windowTitleBarHeight(context), 32);
|
||||
expect(windowCorners(context), BorderRadius.circular(6));
|
||||
await pump(
|
||||
tester,
|
||||
Builder(
|
||||
builder: (c) {
|
||||
context = c;
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
design: AppDesign.paper,
|
||||
);
|
||||
expect(windowTitleBarHeight(context), 40);
|
||||
expect(windowCorners(context), BorderRadius.circular(windowCornerRadius));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
|
||||
final _rows = transcriptRows([
|
||||
for (var i = 0; i < 6; i++) ...[
|
||||
{
|
||||
'id': 'u$i',
|
||||
'role': 'user',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Step $i'},
|
||||
],
|
||||
},
|
||||
{
|
||||
'id': 'a$i',
|
||||
'role': 'assistant',
|
||||
'parts': [
|
||||
{
|
||||
'type': 'tool',
|
||||
'id': 't$i',
|
||||
'name': 'Bash',
|
||||
'state': {
|
||||
'status': 'completed',
|
||||
'input': {'command': 'go test'},
|
||||
},
|
||||
},
|
||||
{'type': 'text', 'text': 'Fixed `x`.\n\n- one\n\n```go\nreturn 1\n```'},
|
||||
],
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
/// A live design switch to and from Compact animates the theme without an
|
||||
/// error in any frame. A component theme that set a text-theme style failed
|
||||
/// to lerp against Default's unset one, and in the browser the broken
|
||||
/// frames stopped the app drawing.
|
||||
void main() {
|
||||
testWidgets('switching to and from Compact lerps every frame cleanly', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
final design = ValueNotifier(AppDesign.compact);
|
||||
await tester.pumpWidget(
|
||||
ValueListenableBuilder<AppDesign>(
|
||||
valueListenable: design,
|
||||
builder: (_, d, _) => MaterialApp(
|
||||
theme: d.dark(),
|
||||
darkTheme: d.dark(),
|
||||
home: Scaffold(
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('New run'),
|
||||
),
|
||||
body: Row(
|
||||
children: [
|
||||
NavigationRail(
|
||||
destinations: const [
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.add),
|
||||
label: Text('a'),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.add),
|
||||
label: Text('b'),
|
||||
),
|
||||
],
|
||||
selectedIndex: 0,
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
IconButton(onPressed: () {}, icon: const Icon(Icons.add)),
|
||||
IconButton.filled(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
Checkbox(value: true, onChanged: (_) {}),
|
||||
Switch(value: true, onChanged: (_) {}),
|
||||
const ListTile(title: Text('t'), subtitle: Text('s')),
|
||||
const TextField(),
|
||||
Chip(label: const Text('c'), onDeleted: () {}),
|
||||
SegmentedButton<int>(
|
||||
segments: const [
|
||||
ButtonSegment(value: 1, label: Text('one')),
|
||||
ButtonSegment(value: 2, label: Text('two')),
|
||||
],
|
||||
selected: const {1},
|
||||
),
|
||||
for (final row in _rows) ChatMessageView(row: row),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
for (var round = 0; round < 3; round++) {
|
||||
for (final other in [
|
||||
AppDesign.standard,
|
||||
AppDesign.terminal,
|
||||
AppDesign.paper,
|
||||
AppDesign.compact,
|
||||
]) {
|
||||
design.value = other;
|
||||
for (var f = 0; f < 20; f++) {
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
final e = tester.takeException();
|
||||
if (e != null) fail('to ${other.id} frame $f: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"size": "1600x900",
|
||||
"params": "chats=3&colors=1",
|
||||
"steps": [
|
||||
{ "open": "/chat/perf-chat-0" },
|
||||
{ "wait": 1500 },
|
||||
{ "click": "Chat actions for api refactor" },
|
||||
{ "click": "Open to the right", "wait": 1500 },
|
||||
{ "eval": "(window.__k = [], window.addEventListener('keydown', (e) => { if (e.altKey) setTimeout(() => window.__k.push({ code: e.code, prevented: e.defaultPrevented })); }, true), true)", "name": "record" },
|
||||
{ "click": "xy:800,850", "wait": 800 },
|
||||
{ "shot": "before" },
|
||||
{ "keys": [
|
||||
{ "type": "keyDown", "key": "Alt", "code": "AltLeft", "windowsVirtualKeyCode": 18, "modifiers": 1 },
|
||||
{ "type": "keyDown", "key": "]", "code": "BracketRight", "windowsVirtualKeyCode": 221, "modifiers": 1 },
|
||||
{ "type": "keyUp", "key": "]", "code": "BracketRight", "windowsVirtualKeyCode": 221, "modifiers": 1 },
|
||||
{ "type": "keyUp", "key": "Alt", "code": "AltLeft", "windowsVirtualKeyCode": 18, "modifiers": 0 }
|
||||
], "wait": 120 },
|
||||
{ "shot": "after-alt-bracket" },
|
||||
{ "eval": "JSON.stringify(window.__k)", "name": "keydown-defaults" },
|
||||
{ "expect": "window.__k.some((k) => k.code === 'BracketRight' && k.prevented)", "name": "alt-bracket-default-prevented" },
|
||||
{ "wait": 1200 },
|
||||
{ "labels": "settled" }
|
||||
]
|
||||
}
|
||||
@@ -29,7 +29,7 @@ Per design it checks and prints (`BENCH <design> {...}` in the log):
|
||||
animation (one frame each).
|
||||
- `switchFramesPerSwitch`: frames to settle a live design switch; after the
|
||||
switches, no listener is left on the design controller.
|
||||
- Scrolling a 120-row CLI transcript: `scrollRebuildsPerFrame`,
|
||||
- Scrolling a 120-row CLI transcript: `scrollRebuildsPerRow`,
|
||||
`scrollLayersPerFrame` and `scrollSaveLayersPerFrame` (opacity, backdrop,
|
||||
image/colour filter and shader-mask layers), plus the layer kinds.
|
||||
- `themeBuildUs` (one uncached build) and `scrollFrameUs` are informational
|
||||
@@ -70,7 +70,13 @@ designs with each other, not with a device.
|
||||
|
||||
Click points assume the chat list's row positions at 1280x800 (chats at
|
||||
y=170/260/335); a design that changes list density a lot should check
|
||||
with `tool/capture` that those points still open the chats.
|
||||
with `tool/capture` that those points still open the chats, and give the
|
||||
step its own point keyed by design id (Compact: y=150/210/266).
|
||||
|
||||
The widget test budgets transcript rebuilds per row scrolled past
|
||||
(`scrollRebuildsPerRow`), not per frame: a denser design shows more rows in
|
||||
each 120px step for the same per-row cost. `scrollRebuildsPerFrame` stays
|
||||
informational.
|
||||
|
||||
## Rules the budget enforces
|
||||
|
||||
|
||||
@@ -43,7 +43,13 @@ const SCENARIOS = [
|
||||
{ name: 'scroll', label: 'scroll a 200-message transcript', ...CHAT,
|
||||
act: [{ wheel: [860, 400, -240, 40] }, { wheel: [860, 400, 240, 20] }] },
|
||||
{ name: 'switch', label: 'switch chats', ...CHAT,
|
||||
act: [{ click: [300, 260] }, { click: [300, 335] }, { click: [300, 170] }] },
|
||||
// Chat 2, chat 3, chat 1. Compact's thinner rows sit higher (verified
|
||||
// with tool/capture at 1280x800), so it names its own points.
|
||||
act: [
|
||||
{ click: [300, 260], compact: [300, 210] },
|
||||
{ click: [300, 335], compact: [300, 266] },
|
||||
{ click: [300, 170], compact: [300, 150] },
|
||||
] },
|
||||
{ name: 'runs', label: 'scroll 400 runs', size: '560x900', route: '/runs', q: { runs: '400' },
|
||||
act: [{ wheel: [280, 450, 240, 40] }] },
|
||||
{ name: 'graph', label: 'open and pan the run graph', size: '560x900', route: '/runs/7', q: { graph: '1' },
|
||||
@@ -88,9 +94,11 @@ async function drag([x, y, dx, dy]) {
|
||||
}
|
||||
await send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: x + dx, y: y + dy, button: 'left', clickCount: 1 });
|
||||
}
|
||||
async function run(steps) {
|
||||
// A step's point under [design]: its own (`step[design]`) when the design
|
||||
// moves the target, else the shared one.
|
||||
async function run(steps, design) {
|
||||
for (const step of steps ?? []) {
|
||||
if (step.click) { await tap(step.click); await delay(1000); }
|
||||
if (step.click) { await tap(step[design] ?? step.click); await delay(1000); }
|
||||
if (step.drag) { await drag(step.drag); await delay(400); }
|
||||
if (step.wheel) {
|
||||
const [x, y, deltaY, count] = step.wheel;
|
||||
@@ -146,7 +154,7 @@ async function measure(s, design, others) {
|
||||
out.switches = Number(opts.switches) * others.length * 2;
|
||||
out.heapGrowthMB = (await heapMB()) - before;
|
||||
} else {
|
||||
await run(s.act);
|
||||
await run(s.act, design);
|
||||
await settle();
|
||||
}
|
||||
fetchesBy[design] ??= new Set();
|
||||
|
||||
Reference in New Issue
Block a user