FB-03: grid-snapped HUD widgets with auto-fit, centered text
Replace free-form fractional HUD widget positioning with a 4x8 int grid (col/row/colSpan/rowSpan), reject drag/resize moves that would overlap another visible widget, and re-place a re-enabled metric into the next free grid slot instead of stacking it on an occupier. Drag/resize now track a local pixel offset during the gesture and only snap/commit once at gesture end. HUD widget text is wrapped in FittedBox(scaleDown) so it never overflows and stays centered at any grid size.
This commit is contained in:
@@ -96,10 +96,10 @@ void main() {
|
||||
...config.hudLayout,
|
||||
HudMetric.speed: const HudWidgetLayout(
|
||||
metric: HudMetric.speed,
|
||||
x: 0.33,
|
||||
y: 0.44,
|
||||
width: 0.25,
|
||||
height: 0.1,
|
||||
col: 2,
|
||||
row: 3,
|
||||
colSpan: 2,
|
||||
rowSpan: 1,
|
||||
visible: true,
|
||||
),
|
||||
};
|
||||
@@ -107,12 +107,27 @@ void main() {
|
||||
await config.setHudLayout(edited);
|
||||
final reloaded = config.hudLayout;
|
||||
|
||||
expect(reloaded[HudMetric.speed]!.x, 0.33);
|
||||
expect(reloaded[HudMetric.speed]!.y, 0.44);
|
||||
expect(reloaded[HudMetric.speed]!.col, 2);
|
||||
expect(reloaded[HudMetric.speed]!.row, 3);
|
||||
});
|
||||
|
||||
test('a metric missing from a saved layout (e.g. one added in a later app '
|
||||
'version) falls back to its default rather than being omitted', () async {
|
||||
SharedPreferences.setMockInitialValues({
|
||||
'hud_layout': '{"speed": {"col": 1, "row": 1, "colSpan": 1, "rowSpan": 2, '
|
||||
'"visible": true}}',
|
||||
});
|
||||
final config = await Config.load();
|
||||
final layout = config.hudLayout;
|
||||
|
||||
expect(layout.keys.toSet(), HudMetric.values.toSet());
|
||||
final expectedDefault = HudWidgetLayout.defaultFor(HudMetric.distance);
|
||||
expect(layout[HudMetric.distance]!.col, expectedDefault.col);
|
||||
expect(layout[HudMetric.distance]!.visible, expectedDefault.visible);
|
||||
});
|
||||
|
||||
test('an old-shaped (pre-grid) saved layout falls back to defaults rather than '
|
||||
'crashing', () async {
|
||||
SharedPreferences.setMockInitialValues({
|
||||
'hud_layout': '{"speed": {"x": 0.1, "y": 0.1, "width": 0.2, "height": 0.1, '
|
||||
'"visible": true}}',
|
||||
@@ -121,9 +136,8 @@ void main() {
|
||||
final layout = config.hudLayout;
|
||||
|
||||
expect(layout.keys.toSet(), HudMetric.values.toSet());
|
||||
final expectedDefault = HudWidgetLayout.defaultFor(HudMetric.distance);
|
||||
expect(layout[HudMetric.distance]!.x, expectedDefault.x);
|
||||
expect(layout[HudMetric.distance]!.visible, expectedDefault.visible);
|
||||
final expectedDefault = HudWidgetLayout.defaultFor(HudMetric.speed);
|
||||
expect(layout[HudMetric.speed]!.col, expectedDefault.col);
|
||||
});
|
||||
|
||||
test('corrupted stored JSON falls back to defaults rather than crashing',
|
||||
|
||||
Reference in New Issue
Block a user