diff --git a/app/lib/features/settings/settings_controls.dart b/app/lib/features/settings/settings_controls.dart index 2c652823..0f5a639f 100644 --- a/app/lib/features/settings/settings_controls.dart +++ b/app/lib/features/settings/settings_controls.dart @@ -8,9 +8,10 @@ export 'settings_theme.dart'; /// A native text field with a label and one supporting line. Both platforms lay /// the label out as wrapping text above the field; Material uses an outlined -/// [TextField] and iOS a [CupertinoTextField]. Labels and helper/error copy are -/// never line-capped, so large text cannot truncate them. No font sizes, heights -/// or colours are fixed here. +/// [TextField] and iOS a [CupertinoTextField]. The label is a compact secondary +/// line (like the web field label) while the section title carries the weight. +/// Labels and helper/error copy are never line-capped, so large text cannot +/// truncate them. No font sizes, heights or colours are fixed here. class SettingsTextField extends StatelessWidget { const SettingsTextField({ super.key, @@ -35,13 +36,17 @@ class SettingsTextField extends StatelessWidget { final hasError = error.trim().isNotEmpty; // The label is laid out as normal wrapping text on both platforms. A // Material floating label is single-line and ellipsizes the workspace label - // at narrow widths or large text, dropping required words. + // at narrow widths or large text, dropping required words. It is a compact + // secondary line, matching the web field label, so the section title is the + // one emphasised line in the group. final labelWidget = ExcludeSemantics( child: Text( label, style: usesCupertinoControls(context) - ? settingsTextStyle(context) - : theme.textTheme.titleSmall, + ? settingsTextStyle(context, secondary: true) + : theme.textTheme.labelMedium?.copyWith( + color: theme.colorScheme.onSurfaceVariant, + ), ), ); if (!usesCupertinoControls(context)) { diff --git a/app/lib/features/settings/settings_layout.dart b/app/lib/features/settings/settings_layout.dart index dd9a59cf..10ab480c 100644 --- a/app/lib/features/settings/settings_layout.dart +++ b/app/lib/features/settings/settings_layout.dart @@ -3,25 +3,35 @@ /// Everything else (control heights, font sizes, colours, button padding) comes /// from the active Material or Cupertino theme, so text scaling and platform /// defaults are never overridden here. +/// +/// The rhythm follows the web Settings page: one centred column, an 8px gap +/// between a section's compact title and its grouped body, and 16px between +/// sections. The web's 12px field label and helper lines are secondary type in +/// [settingsTextStyle]/[SettingsTextField], not fixed sizes. library; /// A comfortable reading width on wide windows; the body is centred inside it. const double settingsContentMaxWidth = 720; -/// Space between the Settings sections. -const double settingsSectionGap = 24; +/// Space between the Settings sections (web `.settings` grid gap). +const double settingsSectionGap = 16; -/// Space between a section title and its controls. -const double settingsTitleGap = 12; +/// Space between a compact section title and its grouped body, and between the +/// blocks inside a section (web `.settings-section` grid gap). +const double settingsTitleGap = 8; -/// Space between a field and its supporting text. -const double settingsFieldGap = 6; +/// Space between a field label and its field, and between stacked secondary +/// lines (web `.settings-field` gap). +const double settingsFieldGap = 4; /// Space between wrapped action buttons. const double settingsControlGap = 8; -/// Padding around the page body on narrow windows. -const double settingsPagePadding = 16; +/// Page insets on narrow windows: a little more room above the first title, +/// and a clear run-out below the last section (web `.settings` padding). +const double settingsPageTopPadding = 20; +const double settingsPageSidePadding = 16; +const double settingsPageBottomPadding = 32; /// Padding inside a standard Material card / Cupertino inset row. const double settingsCardPadding = 16; diff --git a/app/lib/features/settings/settings_screen.dart b/app/lib/features/settings/settings_screen.dart index a247a0d2..c0bfd8f8 100644 --- a/app/lib/features/settings/settings_screen.dart +++ b/app/lib/features/settings/settings_screen.dart @@ -116,7 +116,14 @@ class _SettingsScreenState extends State { Widget build(BuildContext context) { final content = SafeArea( child: SingleChildScrollView( - padding: const EdgeInsets.all(settingsPagePadding), + // Web `.settings` page insets: 20 above the title, 16 at the sides and + // a clear 32 below the last section. + padding: const EdgeInsetsDirectional.fromSTEB( + settingsPageSidePadding, + settingsPageTopPadding, + settingsPageSidePadding, + settingsPageBottomPadding, + ), child: Center( child: ConstrainedBox( constraints: const BoxConstraints( @@ -125,38 +132,48 @@ class _SettingsScreenState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - const _SectionTitle('Connection'), - const SizedBox(height: settingsTitleGap), - SettingsConnectionSection( - controller: _controller, - serverUrlField: _serverUrlField, + _SettingsSection( + title: 'Connection', + child: SettingsConnectionSection( + controller: _controller, + serverUrlField: _serverUrlField, + ), ), const SizedBox(height: settingsSectionGap), - const _SectionTitle('Workspace'), - const SizedBox(height: settingsTitleGap), - SettingsWorkspaceSection( - controller: _controller, - workspaceField: _workspaceField, + _SettingsSection( + title: 'Workspace', + child: SettingsWorkspaceSection( + controller: _controller, + workspaceField: _workspaceField, + ), ), if (widget.notifications != null) ...[ const SizedBox(height: settingsSectionGap), - const _SectionTitle('Notifications'), - const SizedBox(height: settingsTitleGap), - SettingsNotificationsSection( - controller: widget.notifications!, + // The permission tile draws its own compact title row, so + // Settings must not add a second "Notifications" heading. + _SettingsSection( + child: SettingsNotificationsSection( + controller: widget.notifications!, + ), ), ], if (widget.onOpenSchedules != null) ...[ const SizedBox(height: settingsSectionGap), - const _SectionTitle('Schedules'), - const SizedBox(height: settingsTitleGap), - SettingsSchedulesSection(onOpen: widget.onOpenSchedules!), + _SettingsSection( + title: 'Schedules', + child: SettingsSchedulesSection( + onOpen: widget.onOpenSchedules!, + ), + ), ], if (widget.onOpenTemplates != null) ...[ const SizedBox(height: settingsSectionGap), - const _SectionTitle('Templates'), - const SizedBox(height: settingsTitleGap), - SettingsTemplatesSection(onOpen: widget.onOpenTemplates!), + _SettingsSection( + title: 'Templates', + child: SettingsTemplatesSection( + onOpen: widget.onOpenTemplates!, + ), + ), ], ], ), @@ -178,13 +195,27 @@ class _SettingsScreenState extends State { } } -class _SectionTitle extends StatelessWidget { - const _SectionTitle(this.title); +/// One grouped Settings section: a compact title followed by its body at the +/// web's 8px title gap. Sections are separated by [settingsSectionGap]. A null +/// title lets a body (the notification tile) draw its own compact heading. +class _SettingsSection extends StatelessWidget { + const _SettingsSection({required this.child, this.title}); - final String title; + final String? title; + final Widget child; @override Widget build(BuildContext context) { - return Text(title, style: settingsTextStyle(context, title: true)); + final title = this.title; + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + if (title != null) ...[ + Text(title, style: settingsTextStyle(context, title: true)), + const SizedBox(height: settingsTitleGap), + ], + child, + ], + ); } } diff --git a/app/test/features/settings/settings_layout_test.dart b/app/test/features/settings/settings_layout_test.dart new file mode 100644 index 00000000..d2ad241a --- /dev/null +++ b/app/test/features/settings/settings_layout_test.dart @@ -0,0 +1,99 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/core/transport/pipelines_client.dart' + as transport; +import 'package:pipelines_app/features/attention/notify/notification_controller.dart'; +import 'package:pipelines_app/features/attention/notify/notification_store.dart'; +import 'package:pipelines_app/features/settings/settings_layout.dart'; +import 'package:pipelines_app/features/settings/settings_screen.dart'; +import 'package:pipelines_app/features/settings/settings_store.dart'; +import 'package:pipelines_app/features/settings/settings_trust_warning.dart'; + +import 'fake_channel.dart'; + +void main() { + testWidgets('sections use one centred column and the web rhythm', ( + tester, + ) async { + await _pump(tester); + + final connection = tester.getRect(find.text('Connection')); + final serverUrlLabel = tester.getRect(find.text('Server URL')); + final warning = tester.getRect(find.byType(SettingsTrustWarning)); + final workspace = tester.getRect(find.text('Workspace')); + + // One column: the 720px reading width is centred in an 800px window. + expect(connection.left, closeTo(40, 0.01)); + expect(connection.right, closeTo(760, 0.01)); + + // The compact title sits 8px above its grouped body, and sections are 16px + // apart, as on the web Settings page. + expect( + serverUrlLabel.top - connection.bottom, + closeTo(settingsTitleGap, 0.01), + ); + expect(workspace.top - warning.bottom, closeTo(settingsSectionGap, 0.01)); + + // The field label is a compact secondary line, not a second title. + final label = tester.widget(find.text('Server URL')); + final theme = Theme.of(tester.element(find.text('Server URL'))); + expect(label.style?.color, theme.colorScheme.onSurfaceVariant); + expect(label.style?.fontSize, theme.textTheme.labelMedium?.fontSize); + expect( + label.style?.fontSize, + lessThan(theme.textTheme.titleMedium!.fontSize!), + ); + }); + + testWidgets('the notification tile is the section\'s only title', ( + tester, + ) async { + final notifications = NotificationController( + store: MemoryNotificationStore(), + ); + addTearDown(notifications.dispose); + await _pump(tester, notifications: notifications); + + expect(find.text('Notifications'), findsOneWidget); + expect(find.text('Connection'), findsOneWidget); + }); + + testWidgets('Cupertino keeps the compact secondary field label', ( + tester, + ) async { + await _pump(tester, platform: TargetPlatform.iOS); + + final label = tester.widget(find.text('Server URL')); + final context = tester.element(find.text('Server URL')); + expect( + label.style?.color, + CupertinoColors.secondaryLabel.resolveFrom(context), + ); + expect(find.byType(CupertinoTextField), findsNWidgets(2)); + }); +} + +Future _pump( + WidgetTester tester, { + TargetPlatform platform = TargetPlatform.android, + NotificationController? notifications, +}) async { + await tester.binding.setSurfaceSize(const Size(800, 1600)); + addTearDown(() => tester.binding.setSurfaceSize(null)); + final factory = FakeChannelFactory(); + final client = transport.PipelinesClient(channelFactory: factory.call); + addTearDown(client.dispose); + await tester.pumpWidget( + MaterialApp( + theme: ThemeData(platform: platform), + home: SettingsScreen( + client: client, + store: MemorySettingsStore(), + notifications: notifications, + ), + ), + ); + await tester.pump(); + await tester.pump(); +}