diff --git a/app/lib/features/pipelines/widgets/pipeline_controls.dart b/app/lib/features/pipelines/widgets/pipeline_controls.dart index 87963657..27648e55 100644 --- a/app/lib/features/pipelines/widgets/pipeline_controls.dart +++ b/app/lib/features/pipelines/widgets/pipeline_controls.dart @@ -2,12 +2,14 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import '../../../ui/adaptive/host.dart'; + import '../pipeline_query.dart'; /// The one platform decision for this feature. The screen itself receives no /// platform flag, so tests and integration obey Flutter's target platform. bool useCupertinoControls(BuildContext context) => - defaultTargetPlatform == TargetPlatform.iOS; + usesCupertinoHost(context) || defaultTargetPlatform == TargetPlatform.iOS; /// Standard platform activity indicator with an accessible status label. class PipelineProgress extends StatelessWidget { diff --git a/app/lib/features/pipelines/widgets/pipeline_detail_styles.dart b/app/lib/features/pipelines/widgets/pipeline_detail_styles.dart index e993bea5..0e55f161 100644 --- a/app/lib/features/pipelines/widgets/pipeline_detail_styles.dart +++ b/app/lib/features/pipelines/widgets/pipeline_detail_styles.dart @@ -19,7 +19,9 @@ TextStyle? pipelineValueStyle(BuildContext context, {bool monospace = false}) { // merge the Cupertino system style with the ambient text style. ? CupertinoTheme.of(context).textTheme.textStyle.copyWith(inherit: true) : Theme.of(context).textTheme.bodyMedium; - return monospace ? base?.copyWith(fontFamily: 'monospace') : base; + // Metadata can identify code-like values, but the user requested native + // typography even for source/hash surfaces; do not replace the host font. + return base; } TextStyle? pipelineMutedStyle(BuildContext context) { diff --git a/app/lib/features/pipelines/widgets/pipeline_tab_row.dart b/app/lib/features/pipelines/widgets/pipeline_tab_row.dart deleted file mode 100644 index 5ec425e5..00000000 --- a/app/lib/features/pipelines/widgets/pipeline_tab_row.dart +++ /dev/null @@ -1,193 +0,0 @@ -import 'dart:math' as math; - -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; - -import 'pipeline_detail_tab.dart'; - -/// Horizontal inset a label needs on each side in the per-label row. -const double pipelineTabSegmentPadding = 8; - -/// The style the platform segmented control renders its labels in, so a -/// measured width is the width the label really paints. -TextStyle pipelineTabLabelStyle( - BuildContext context, { - required bool cupertino, -}) { - if (cupertino) return CupertinoTheme.of(context).textTheme.textStyle; - return Theme.of(context).textTheme.labelLarge ?? const TextStyle(); -} - -/// Measures every label for the current text style and text scaler. -List measurePipelineTabLabels(BuildContext context, TextStyle style) { - return [ - for (final tab in PipelineDetailTab.values) - _measureLabel(context, tab.label, style), - ]; -} - -Size _measureLabel(BuildContext context, String label, TextStyle style) { - final painter = TextPainter( - text: TextSpan(text: label, style: style), - textDirection: Directionality.of(context), - textScaler: MediaQuery.textScalerOf(context), - maxLines: 1, - )..layout(); - final size = painter.size; - painter.dispose(); - return size; -} - -/// A segmented row whose segments are as wide as their own labels. It keeps -/// the platform segmented control's shape and theme colors, but not its -/// equal-share sizing. -/// -/// [PipelineDetailTabs] uses it only when an equal share of the pane is too -/// narrow for the widest label or wider than the labels need together. -class PipelineTabRow extends StatelessWidget { - const PipelineTabRow({ - super.key, - required this.selected, - required this.onSelected, - required this.labelSizes, - required this.labelStyle, - required this.rowHeight, - required this.available, - required this.cupertino, - }); - - final PipelineDetailTab selected; - final ValueChanged onSelected; - final List labelSizes; - final TextStyle labelStyle; - final double rowHeight; - final double available; - final bool cupertino; - - @override - Widget build(BuildContext context) { - final scheme = Theme.of(context).colorScheme; - final CupertinoThemeData cupertinoTheme = CupertinoTheme.of(context); - final Color borderColor = cupertino - ? cupertinoTheme.primaryColor - : scheme.outline; - final Color selectedFill = cupertino - ? cupertinoTheme.primaryColor - : scheme.secondaryContainer; - final Color selectedText = cupertino - ? cupertinoTheme.primaryContrastingColor - : scheme.onSecondaryContainer; - final Color textColor = cupertino - ? CupertinoColors.label.resolveFrom(context) - : scheme.onSurface; - - final widths = [ - for (final size in labelSizes) size.width + 2 * pipelineTabSegmentPadding, - ]; - final content = widths.fold(0, (total, width) => total + width); - // The outer border takes one pixel on each side; spread any remaining - // width evenly so a row whose labels fit still fills the pane. - final inner = available.isFinite - ? math.max(0, available - 2) - : double.infinity; - final extra = content < inner ? (inner - content) / widths.length : 0; - - final tabs = PipelineDetailTab.values; - return Container( - decoration: BoxDecoration( - color: cupertino - ? cupertinoTheme.primaryContrastingColor - : scheme.surface, - border: Border.all(color: borderColor), - borderRadius: BorderRadius.circular(20), - ), - clipBehavior: Clip.antiAlias, - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - for (var index = 0; index < tabs.length; index++) - _PerLabelSegment( - tab: tabs[index], - width: widths[index] + extra, - height: rowHeight, - selected: tabs[index] == selected, - labelStyle: labelStyle.copyWith( - color: tabs[index] == selected ? selectedText : textColor, - ), - fillColor: tabs[index] == selected ? selectedFill : null, - dividerColor: index == tabs.length - 1 ? null : borderColor, - cupertino: cupertino, - onTap: () => onSelected(tabs[index]), - ), - ], - ), - ); - } -} - -class _PerLabelSegment extends StatelessWidget { - const _PerLabelSegment({ - required this.tab, - required this.width, - required this.height, - required this.selected, - required this.labelStyle, - required this.fillColor, - required this.dividerColor, - required this.cupertino, - required this.onTap, - }); - - final PipelineDetailTab tab; - final double width; - final double height; - final bool selected; - final TextStyle labelStyle; - final Color? fillColor; - final Color? dividerColor; - final bool cupertino; - final VoidCallback onTap; - - @override - Widget build(BuildContext context) { - final label = Padding( - padding: const EdgeInsets.symmetric( - horizontal: pipelineTabSegmentPadding, - ), - child: Text(tab.label, maxLines: 1, softWrap: false, style: labelStyle), - ); - final Widget button = cupertino - ? CupertinoButton( - padding: EdgeInsets.zero, - minimumSize: Size.zero, - onPressed: onTap, - child: label, - ) - : Material( - type: MaterialType.transparency, - child: InkWell( - onTap: onTap, - child: Center(child: label), - ), - ); - return SizedBox( - key: ValueKey('pipeline-tab-${tab.name}'), - width: width, - height: height, - child: DecoratedBox( - decoration: BoxDecoration( - color: fillColor, - border: dividerColor == null - ? null - : Border(right: BorderSide(color: dividerColor!)), - ), - child: Semantics( - button: true, - inMutuallyExclusiveGroup: true, - selected: selected, - child: button, - ), - ), - ); - } -} diff --git a/app/lib/features/pipelines/widgets/pipeline_tabs.dart b/app/lib/features/pipelines/widgets/pipeline_tabs.dart index ff7e8815..d37dcffa 100644 --- a/app/lib/features/pipelines/widgets/pipeline_tabs.dart +++ b/app/lib/features/pipelines/widgets/pipeline_tabs.dart @@ -1,23 +1,16 @@ -import 'dart:math' as math; - import 'package:flutter/cupertino.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'pipeline_controls.dart'; import 'pipeline_detail_tab.dart'; -import 'pipeline_tab_row.dart'; export 'pipeline_detail_tab.dart'; /// Platform tabs: a Material segmented button or a Cupertino segmented control. /// -/// Both platform controls give every segment the width of the widest label. At -/// narrow widths and scaled text that share is narrower than a label, so the -/// labels would wrap or be cut at the pane edge. When the equal share still -/// fits, the platform control is used unchanged. Otherwise a per-label row -/// gives every segment exactly its label's width and fills the pane when the -/// three labels fit; only a row that genuinely needs more room scrolls. +/// Keep the native control at every width. Horizontal scrolling gives scaled +/// labels their intrinsic width instead of squeezing or replacing the control. class PipelineDetailTabs extends StatelessWidget { const PipelineDetailTabs({ super.key, @@ -28,48 +21,16 @@ class PipelineDetailTabs extends StatelessWidget { final PipelineDetailTab selected; final ValueChanged onSelected; - /// A safe upper bound for the padding the platform segmented controls add - /// inside each segment; the equal-share layout is only used when every label - /// still fits with this much room. - static const double _controlSegmentPadding = 32; - - /// Smallest visual height, matching the platform controls at normal text. - static const double _minHeight = 32; - @override Widget build(BuildContext context) { final cupertino = useCupertinoControls(context); - final labelStyle = pipelineTabLabelStyle(context, cupertino: cupertino); - final labelSizes = measurePipelineTabLabels(context, labelStyle); return Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), - child: LayoutBuilder( - builder: (context, constraints) { - final available = constraints.hasBoundedWidth - ? constraints.maxWidth - : double.infinity; - final widest = labelSizes.map((size) => size.width).reduce(math.max); - final equalShareFits = - !available.isFinite || - available >= 3 * (widest + _controlSegmentPadding); - final control = equalShareFits - ? (cupertino ? _cupertinoControl() : _materialControl()) - : PipelineTabRow( - selected: selected, - onSelected: onSelected, - labelSizes: labelSizes, - labelStyle: labelStyle, - rowHeight: math.max(_minHeight, labelSizes.first.height), - available: available, - cupertino: cupertino, - ); - return _ScrollWhenOverflowing( - child: KeyedSubtree( - key: const Key('pipeline-detail-tabs'), - child: control, - ), - ); - }, + child: _ScrollWhenOverflowing( + child: KeyedSubtree( + key: const Key('pipeline-detail-tabs'), + child: cupertino ? _cupertinoControl() : _materialControl(), + ), ), ); } diff --git a/app/notes/P1.md b/app/notes/P1.md index c7bf937d..ef8e6023 100644 --- a/app/notes/P1.md +++ b/app/notes/P1.md @@ -1,5 +1,26 @@ # P1 — Pipelines list, detail, source and versions +## Manager native-default acceptance correction + +The original reviewed candidate remains at a44f31b9. Its custom per-label +segmented-control replacement was not acceptable under the user's native-only +constraint. Manager removed PipelineTabRow and all measured/fixed segment sizing. +Both narrow and wide layouts now keep the actual platform segmented control; +when scaled labels need extra width, horizontal mouse/touch scrolling reveals +them. No label wraps inside its word, and keyboard navigation reveals Source. +Removed the source/hash monospace font override as well. Host selection now +recognizes a real CupertinoApp, not just an iOS target override. + +Updated native-control/whole-label/selection/host-font tests pass. Fresh final +fixture builds passed7 baseline browser checks/9 captures and30 scale/history/ +keyboard checks/10 captures. At320px/2x, the native row intentionally scrolls; +the previous expectation that all labels must fit simultaneously is superseded, +not accomplished by replacing the native control. Evidence lives in approved +temp/pipelines-native-tabs-browser and pipelines-native-tabs-scaled. Manager +inspected scaled at-rest and Source-selected captures. Shell registration and +real Cupertino app composition remain a separate integration slice; mobile is +still unverified. Earlier evidence below describes the historical candidate. + Candidate implementation for run 34 / Task v6. All work is under `app/`; no commit, push, deployment or shell/main/pubspec edit was made. diff --git a/app/test/features/pipelines/pipeline_tabs_test.dart b/app/test/features/pipelines/pipeline_tabs_test.dart index 8b9964d5..35e81fc8 100644 --- a/app/test/features/pipelines/pipeline_tabs_test.dart +++ b/app/test/features/pipelines/pipeline_tabs_test.dart @@ -1,253 +1,96 @@ -import 'dart:math' as math; import 'dart:ui' show PointerDeviceKind; import 'package:flutter/cupertino.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/features/pipelines/widgets/pipeline_tabs.dart'; - -const double _paneInset = 16; - -/// A label that wrapped inside its word renders narrower than the width the -/// paragraph needs on one line. -void expectWholeLabel(WidgetTester tester, String label) { - final paragraph = tester.renderObject(find.text(label)); - expect( - paragraph.size.width, - greaterThanOrEqualTo( - paragraph.getMaxIntrinsicWidth(double.infinity) - 0.01, - ), - reason: '"$label" must not wrap inside the word', - ); -} - -double labelWidth(WidgetTester tester, String label) => - tester.getSize(find.text(label)).width; - -Rect tabRect(WidgetTester tester, PipelineDetailTab tab) => - tester.getRect(find.byKey(ValueKey('pipeline-tab-${tab.name}'))); - -Future pumpTabs( - WidgetTester tester, { - required double width, - required double textScale, - bool cupertino = false, - ValueChanged? onSelected, -}) async { - tester.view.physicalSize = Size(width, 640); - tester.view.devicePixelRatio = 1; - addTearDown(tester.view.resetPhysicalSize); - addTearDown(tester.view.resetDevicePixelRatio); - final tabs = StatefulBuilder( - builder: (context, setState) => PipelineDetailTabs( - selected: PipelineDetailTab.summary, - onSelected: (tab) { - onSelected?.call(tab); - setState(() {}); - }, - ), - ); - final content = Align(alignment: Alignment.topLeft, child: tabs); - Widget scaled(BuildContext context, Widget? child) => MediaQuery( - data: MediaQuery.of( - context, - ).copyWith(textScaler: TextScaler.linear(textScale)), - child: child!, - ); - await tester.pumpWidget( - cupertino - ? CupertinoApp( - builder: scaled, - home: CupertinoPageScaffold(child: content), - ) - : MaterialApp( - builder: scaled, - home: Scaffold(body: content), - ), - ); - await tester.pumpAndSettle(); -} +import 'package:pipelines_app/features/pipelines/widgets/pipeline_detail_styles.dart'; void main() { - for (final (width, scale) in [ - (320.0, 1.5), - (320.0, 2.0), - (390.0, 2.0), - (720.0, 2.0), - ]) { - testWidgets( - 'Material tab labels stay whole at ${width.toInt()}px and ${scale}x text', - (tester) async { - await pumpTabs(tester, width: width, textScale: scale); - expect(tester.takeException(), isNull); + testWidgets('code-like values still use native host typography', ( + tester, + ) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: Builder( + builder: (context) { + expect( + pipelineValueStyle(context, monospace: true), + Theme.of(context).textTheme.bodyMedium, + ); + return const SizedBox.shrink(); + }, + ), + ), + ), + ); + }); + + for (final cupertino in [false, true]) { + for (final width in [320.0, 390.0, 720.0, 1200.0]) { + testWidgets('native tabs at $width, 2x, Cupertino=$cupertino', ( + tester, + ) async { + tester.view.physicalSize = Size(width, 640); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.reset); + PipelineDetailTab? selected; + final body = Align( + alignment: Alignment.topLeft, + child: PipelineDetailTabs( + selected: PipelineDetailTab.summary, + onSelected: (value) => selected = value, + ), + ); + Widget scaled(BuildContext context, Widget? child) => MediaQuery( + data: MediaQuery.of( + context, + ).copyWith(textScaler: TextScaler.linear(2)), + child: child!, + ); + await tester.pumpWidget( + cupertino + ? CupertinoApp( + builder: scaled, + home: CupertinoPageScaffold(child: body), + ) + : MaterialApp( + builder: scaled, + home: Scaffold(body: body), + ), + ); + await tester.pumpAndSettle(); + expect( + cupertino + ? find.byType(CupertinoSegmentedControl) + : find.byType(SegmentedButton), + findsOneWidget, + ); for (final tab in PipelineDetailTab.values) { - expect(find.text(tab.label), findsOneWidget); - expectWholeLabel(tester, tab.label); + final paragraph = tester.renderObject( + find.text(tab.label), + ); + expect( + paragraph.size.width, + greaterThanOrEqualTo( + paragraph.getMaxIntrinsicWidth(double.infinity) - 0.01, + ), + reason: 'Whole labels must not be squeezed inside a native segment', + ); } - }, - ); + await tester.drag( + find.byType(SingleChildScrollView), + const Offset(-1000, 0), + kind: PointerDeviceKind.mouse, + ); + await tester.pumpAndSettle(); + await tester.tap(find.text('Source')); + await tester.pumpAndSettle(); + expect(selected, PipelineDetailTab.source); + expect(tester.takeException(), isNull); + }); + } } - - testWidgets('per-label segments size to their own labels', (tester) async { - await pumpTabs(tester, width: 320, textScale: 2); - final widths = { - for (final tab in PipelineDetailTab.values) - tab: tabRect(tester, tab).width, - }; - expect( - widths[PipelineDetailTab.summary], - isNot(widths[PipelineDetailTab.graph]), - ); - expect( - widths[PipelineDetailTab.graph], - isNot(widths[PipelineDetailTab.source]), - ); - for (final tab in PipelineDetailTab.values) { - expect( - widths[tab], - closeTo(labelWidth(tester, tab.label) + 2 * 8, 0.5), - reason: '"${tab.label}" must not get the widest-label share', - ); - } - }); - - testWidgets('a fitting tab row shows every label inside the pane', ( - tester, - ) async { - await pumpTabs(tester, width: 320, textScale: 2); - final contentWidth = - tabRect(tester, PipelineDetailTab.source).right - - tabRect(tester, PipelineDetailTab.summary).left; - final width = contentWidth + 2 * _paneInset + 2; - await pumpTabs(tester, width: width, textScale: 2); - expect(tester.takeException(), isNull); - for (final tab in PipelineDetailTab.values) { - expectWholeLabel(tester, tab.label); - final rect = tester.getRect(find.text(tab.label)); - expect(rect.left, greaterThanOrEqualTo(_paneInset - 0.5)); - expect(rect.right, lessThanOrEqualTo(width - _paneInset + 0.5)); - } - expect( - tester.getSize(find.byKey(const Key('pipeline-detail-tabs'))).width, - closeTo(width - 2 * _paneInset, 0.5), - reason: 'a row whose labels fit still fills the pane', - ); - }); - - testWidgets('a tab row that overflows only scrolls by the labels\' need', ( - tester, - ) async { - PipelineDetailTab? selected; - await pumpTabs(tester, width: 320, textScale: 2); - final contentWidth = - tabRect(tester, PipelineDetailTab.source).right - - tabRect(tester, PipelineDetailTab.summary).left; - final width = contentWidth + 2 * _paneInset - 20; - await pumpTabs( - tester, - width: width, - textScale: 2, - onSelected: (tab) => selected = tab, - ); - final paneRight = width - _paneInset; - final source = tester.getRect(find.text('Source')); - expect( - tabRect(tester, PipelineDetailTab.source).left, - lessThan(paneRight), - reason: 'the third tab must not be an empty cell', - ); - expect( - math.min(source.right, paneRight) - math.max(source.left, _paneInset), - greaterThan(20), - reason: 'a readable share of the last label stays in the pane', - ); - expect(source.right, greaterThan(paneRight)); - - final row = find.byType(SingleChildScrollView); - await tester.drag( - row, - const Offset(-400, 0), - kind: PointerDeviceKind.mouse, - ); - await tester.pumpAndSettle(); - expect( - tester.getRect(find.text('Source')).right, - lessThanOrEqualTo(paneRight + 0.01), - reason: 'the last tab is fully visible after dragging', - ); - await tester.tap(find.text('Source')); - await tester.pumpAndSettle(); - expect(selected, PipelineDetailTab.source); - }); - - testWidgets('720px at 2x text shows all three labels at rest', ( - tester, - ) async { - await pumpTabs(tester, width: 720, textScale: 2); - for (final tab in PipelineDetailTab.values) { - final rect = tester.getRect(find.text(tab.label)); - expect(rect.left, greaterThanOrEqualTo(_paneInset - 0.5)); - expect(rect.right, lessThanOrEqualTo(720 - _paneInset + 0.5)); - } - }); - - testWidgets('a fitting tab row still fills the pane at 1x', (tester) async { - await pumpTabs(tester, width: 400, textScale: 1); - expect( - tester.getSize(find.byKey(const Key('pipeline-detail-tabs'))).width, - closeTo(368, 0.5), - ); - }); - - testWidgets('the wide row keeps the platform Material control', ( - tester, - ) async { - await pumpTabs(tester, width: 1200, textScale: 1); - expect(find.byType(SegmentedButton), findsOneWidget); - expect( - tester.getSize(find.byKey(const Key('pipeline-detail-tabs'))).width, - closeTo(1168, 0.5), - ); - }); - - testWidgets('Cupertino tab labels stay whole at 320px and 2x text', ( - tester, - ) async { - debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - try { - await pumpTabs(tester, width: 320, textScale: 2, cupertino: true); - expect(tester.takeException(), isNull); - // The labels do not fit an equal-share control here, so the per-label - // row of standard Cupertino buttons is used. - expect( - find.byType(CupertinoButton), - findsNWidgets(PipelineDetailTab.values.length), - ); - for (final tab in PipelineDetailTab.values) { - expectWholeLabel(tester, tab.label); - } - } finally { - debugDefaultTargetPlatformOverride = null; - } - }); - - testWidgets('Cupertino keeps its native segmented control where it fits', ( - tester, - ) async { - debugDefaultTargetPlatformOverride = TargetPlatform.iOS; - try { - await pumpTabs(tester, width: 1200, textScale: 1, cupertino: true); - expect( - find.byType(CupertinoSegmentedControl), - findsOneWidget, - ); - for (final tab in PipelineDetailTab.values) { - expectWholeLabel(tester, tab.label); - } - } finally { - debugDefaultTargetPlatformOverride = null; - } - }); } diff --git a/app/tool/pipelines_probe_tabs_scale.mjs b/app/tool/pipelines_probe_tabs_scale.mjs index 6a5d41e7..1f4c726a 100644 --- a/app/tool/pipelines_probe_tabs_scale.mjs +++ b/app/tool/pipelines_probe_tabs_scale.mjs @@ -207,27 +207,25 @@ async function state({ name, width, height, fontPx, partialLast = false, theme } for (const label of LABELS) { if (!boxes[label]) throw new Error(`Tab ${label} missing at ${name}`); } - checkAtRest(name, boxes, width, { partialLast }); + if (boxes.Summary.width < 24 || boxes.Summary.x < PANE_INSET - 1) { + throw new Error(`${name}: first native segment is not readable`); + } + log.checks.push(`${name}: native controls retain one-line labels; overflow may scroll`); await capture(connection, captureDir, log, name); - if (!partialLast) { - // A box clipped by the scroll viewport still reports a right edge inside - // the pane, so scrolling the row to its limit must not uncover any extra - // label width. If it does, a label was cut at rest. + { + // A standard segmented control may need more width than the pane. That is + // intentionally scrollable, not replaced with a custom per-label control. await dragRow( boxes.Summary.x + boxes.Summary.width / 2, boxes.Summary.y + boxes.Summary.height / 2, -240, ); const scrolled = await tabBoxes(); - for (const label of LABELS) { - if (scrolled[label].width > boxes[label].width + 1) { - throw new Error( - `${name}: ${label} was clipped at rest ` + - `(${boxes[label].width} of ${scrolled[label].width}px visible)`, - ); - } + if (scrolled.Source.width < 24 || + scrolled.Source.x + scrolled.Source.width > paneRight(width) + 1) { + throw new Error(`${name}: scrolling failed to expose the last native segment`); } - log.checks.push(`${name}: scrolling exposes no hidden label width`); + log.checks.push(`${name}: last native segment is reachable after scrolling`); } const heights = LABELS.map((label) => boxes[label].height); log.states.push({