fix(app): retain native pipeline tabs at every text scale

This commit is contained in:
2026-10-21 19:21:41 +01:00
parent 9a29208d56
commit 28b93ae6d0
7 changed files with 128 additions and 494 deletions
@@ -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 {
@@ -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) {
@@ -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<Size> 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<PipelineDetailTab> onSelected;
final List<Size> 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<double>(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,
),
),
);
}
}
@@ -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<PipelineDetailTab> 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(),
),
),
);
}