FB-08: reflow HUD row widgets when a metric is hidden or shown

setVisible now calls a new _reflowRow helper on the toggled metric's row,
spreading the remaining (or newly added) visible widgets evenly across the
4-column grid instead of leaving a blank cell where a hidden metric used to
be. Reflow is scoped to setVisible only; drag/resize behavior is unchanged.
This commit is contained in:
2026-08-24 23:33:05 -05:00
parent 08f2cfbf02
commit 1a2e69cbf3
3 changed files with 255 additions and 1 deletions

View File

@@ -110,6 +110,80 @@ void main() {
}
});
test('hiding one of four same-row metrics reflows the remaining three to fill '
'the row with no gap', () async {
final controller = HudLayoutController(await freshConfig());
controller.setVisible(HudMetric.avgSpeed, false);
final remaining = [HudMetric.speed, HudMetric.distance, HudMetric.elapsedTime]
.map((m) => controller.state[m]!)
.toList()
..sort((a, b) => a.col.compareTo(b.col));
final totalSpan = remaining.fold<int>(0, (sum, l) => sum + l.colSpan);
expect(totalSpan, hudGridColumns);
// baseSpan = 4 ~/ 3 = 1, extra = 1 -- the first (leftmost) member absorbs it.
expect(remaining[0].colSpan, 2);
expect(remaining[1].colSpan, 1);
expect(remaining[2].colSpan, 1);
expect(controller.state[HudMetric.avgSpeed]!.visible, isFalse);
});
test('hiding a metric whose row has no other visible member leaves every '
'other metric untouched', () async {
final controller = HudLayoutController(await freshConfig());
// Row 4 is unused by any default layout -- move speed there alone.
controller.updatePosition(HudMetric.speed, 0, 4);
final others = {
for (final m in HudMetric.values.where((m) => m != HudMetric.speed))
m: controller.state[m]!,
};
controller.setVisible(HudMetric.speed, false);
for (final entry in others.entries) {
final after = controller.state[entry.key]!;
expect(after.col, entry.value.col, reason: '${entry.key} col changed');
expect(after.row, entry.value.row, reason: '${entry.key} row changed');
expect(after.colSpan, entry.value.colSpan,
reason: '${entry.key} colSpan changed');
}
});
test('showing a previously-hidden metric back into a row with existing '
'members reflows that row to fit it', () async {
final controller = HudLayoutController(await freshConfig());
// maxSpeed and movingTime both default to row 2, hidden, at adjacent columns.
controller.setVisible(HudMetric.maxSpeed, true);
controller.setVisible(HudMetric.movingTime, true);
final maxSpeed = controller.state[HudMetric.maxSpeed]!;
final movingTime = controller.state[HudMetric.movingTime]!;
expect(maxSpeed.row, movingTime.row,
reason: 'test setup assumes both land in the same row');
expect(maxSpeed.colSpan + movingTime.colSpan, hudGridColumns);
});
test('toggling a metric in one row leaves a different row\'s members '
'untouched', () async {
final controller = HudLayoutController(await freshConfig());
final row2Before = {
for (final m in [HudMetric.maxSpeed, HudMetric.movingTime, HudMetric.elevationGain])
m: controller.state[m]!,
};
controller.setVisible(HudMetric.avgSpeed, false);
for (final entry in row2Before.entries) {
final after = controller.state[entry.key]!;
expect(after.col, entry.value.col, reason: '${entry.key} col changed');
expect(after.colSpan, entry.value.colSpan,
reason: '${entry.key} colSpan changed');
}
});
test('persist writes the current state to Config', () async {
final config = await freshConfig();
final controller = HudLayoutController(config);