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:
@@ -67,7 +67,30 @@ class HudLayoutController extends StateNotifier<Map<HudMetric, HudWidgetLayout>>
|
||||
rowSpan: current.rowSpan,
|
||||
);
|
||||
}
|
||||
state = {...state, metric: current.copyWith(visible: visible)};
|
||||
final updated = {...state, metric: current.copyWith(visible: visible)};
|
||||
state = _reflowRow(updated, current.row);
|
||||
}
|
||||
|
||||
/// Spreads every visible widget in [row] evenly across the full grid width,
|
||||
/// left to right in their existing column order. A widget whose row has no other
|
||||
/// visible member is left alone -- there is nothing to redistribute.
|
||||
Map<HudMetric, HudWidgetLayout> _reflowRow(
|
||||
Map<HudMetric, HudWidgetLayout> layouts,
|
||||
int row,
|
||||
) {
|
||||
final members = layouts.values.where((l) => l.visible && l.row == row).toList()
|
||||
..sort((a, b) => a.col.compareTo(b.col));
|
||||
if (members.length < 2) return layouts;
|
||||
final baseSpan = hudGridColumns ~/ members.length;
|
||||
final extra = hudGridColumns % members.length;
|
||||
final result = Map<HudMetric, HudWidgetLayout>.from(layouts);
|
||||
var col = 0;
|
||||
for (var i = 0; i < members.length; i++) {
|
||||
final span = baseSpan + (i < extra ? 1 : 0);
|
||||
result[members[i].metric] = members[i].copyWith(col: col, colSpan: span);
|
||||
col += span;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<void> persist() async => _config?.setHudLayout(state);
|
||||
|
||||
Reference in New Issue
Block a user