mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
fix(ui): rails take obstacles across the middle together, so their order never picks the side
Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
31a7b6a0a5
commit
feedd88614
7 files changed
+99
-45
No files matched your search
@@ -1,3 +1,4 @@
|
||||
- Keep the left and right panel rails clear of an obstacle across the middle
|
||||
of a short window, such as the World Timeline or a card: the panels take
|
||||
the side of it with more room (manjunath22466, samehkhamis, #1837).
|
||||
- Keep the left and right panel rails clear of obstacles across the middle
|
||||
of a short window, such as the World Timeline or a card: both rails put
|
||||
the panels on the side with more room, whatever order the obstacles come
|
||||
in (manjunath22466, samehkhamis, #1837).
|
||||
@@ -1197,11 +1197,11 @@ Cesium's credit box wraps from 1200px, as before; the phone shell, clean
|
||||
view, recording and scene playback lay the line out themselves.
|
||||
The left rail treats the centered World Timeline and voice control as
|
||||
obstacles only where they reach a laid-out panel, not the stack's
|
||||
transparent gutter. Both rails keep clear of every obstacle they reach: one
|
||||
above the middle of the window pushes the panels down, one below it pulls
|
||||
them up, and one across the middle (common in short windows) puts them on
|
||||
whichever side of it has more room. When neither side has room, the rails
|
||||
keep their usual minimum height rather than overlap it.
|
||||
transparent gutter. Obstacles across the middle of the window (common in
|
||||
short windows) are taken together, from the highest top to the lowest
|
||||
bottom, and both rails put their panels on whichever side of that span has
|
||||
more room, above it on a tie, whatever order the obstacles come in. With no
|
||||
room on either side the panels keep their place, as before.
|
||||
|
||||
Wind appears in the Weather group before Audio. The surface-weather prototype
|
||||
uses keyless NOAA GFS or ECMWF IFS forecasts on an approximately 1° display grid.
|
||||
|
||||
@@ -1010,7 +1010,7 @@ test('an expanded Cockpit left panel stays above Contact, HUD, and attribution',
|
||||
assert.ok(leftLayout, 'left accordion layout pass is missing');
|
||||
assert.match(
|
||||
leftLayout,
|
||||
/rect\.top >= baseTop\) \{\s*\n\s*bottomObstacles\.push\(\{ top: rect\.top \}\);/,
|
||||
/\} else \{\s*\n\s*bottomObstacles\.push\(\{ top: rect\.top \}\);\s*\n\s*\}\s*\n\s*\}/,
|
||||
'every rendered lower-lane obstacle must constrain the panel corridor',
|
||||
);
|
||||
assert.match(
|
||||
|
||||
@@ -321,7 +321,7 @@ test('HUD rail layout keeps a short window clear of an obstacle across its midpo
|
||||
assert(below.top >= 270);
|
||||
});
|
||||
|
||||
test('HUD rail layout keeps its zero-height fallback when a straddling obstacle leaves no room', () => {
|
||||
test('HUD rail layout leaves the band as it is when an obstacle across the midpoint leaves no room', () => {
|
||||
const layout = resolveHudRailLayout({
|
||||
viewportHeight: 480,
|
||||
panelHeight: 120,
|
||||
@@ -332,10 +332,30 @@ test('HUD rail layout keeps its zero-height fallback when a straddling obstacle
|
||||
gap: 10,
|
||||
obstacles: [{ left: 0, right: 400, top: 80, bottom: 420 }],
|
||||
});
|
||||
assert.equal(layout.maxHeight, 0);
|
||||
assert.equal(layout.constrained, true);
|
||||
assert.equal(layout.safeTop, 100);
|
||||
assert.equal(layout.safeBottom, 100);
|
||||
assert.equal(layout.safeBottom, 400);
|
||||
});
|
||||
|
||||
test('HUD rail layout reads several obstacles across the midpoint the same in any order', () => {
|
||||
const a = { left: 0, right: 400, top: 100, bottom: 260 };
|
||||
const b = { left: 0, right: 400, top: 200, bottom: 470 };
|
||||
const layoutWith = (obstacles) =>
|
||||
resolveHudRailLayout({
|
||||
viewportHeight: 480,
|
||||
panelHeight: 120,
|
||||
laneLeft: 20,
|
||||
laneRight: 340,
|
||||
baseTop: 40,
|
||||
baseBottom: 460,
|
||||
gap: 10,
|
||||
obstacles,
|
||||
});
|
||||
// Together they cover 100 to 470: the only room is above, 40 to 90.
|
||||
for (const layout of [layoutWith([a, b]), layoutWith([b, a])]) {
|
||||
assert.equal(layout.safeTop, 40);
|
||||
assert.equal(layout.safeBottom, 90);
|
||||
assert.equal(layout.maxHeight, 50);
|
||||
}
|
||||
});
|
||||
|
||||
test('HUD rail layout can anchor controls to the start of the safe corridor', () => {
|
||||
|
||||
+21
-15
@@ -118,7 +118,10 @@ export function layoutLeftPanelRail({
|
||||
let safeTop = baseTop;
|
||||
let safeBottom = viewportHeight - baseBottomInset;
|
||||
const bottomObstacles = [];
|
||||
const straddling = [];
|
||||
// Obstacles across the midpoint all cover it, so together they cover one
|
||||
// span: from the highest top to the lowest bottom.
|
||||
let spanTop = Infinity;
|
||||
let spanBottom = -Infinity;
|
||||
|
||||
for (const obstacle of obstacles) {
|
||||
if (stack.contains(obstacle)) continue;
|
||||
@@ -152,28 +155,31 @@ export function layoutLeftPanelRail({
|
||||
const obstacleBottom = rect.bottom + safeGap;
|
||||
obstacleSafeTop = Math.max(obstacleSafeTop, obstacleBottom);
|
||||
safeTop = Math.max(safeTop, obstacleBottom);
|
||||
} else if (rect.top >= baseTop) {
|
||||
bottomObstacles.push({ top: rect.top });
|
||||
} else if (
|
||||
rect.top < viewportHeight * 0.5 &&
|
||||
rect.bottom > viewportHeight * 0.5
|
||||
) {
|
||||
spanTop = Math.min(spanTop, rect.top);
|
||||
spanBottom = Math.max(spanBottom, rect.bottom);
|
||||
} else {
|
||||
straddling.push(rect);
|
||||
bottomObstacles.push({ top: rect.top });
|
||||
}
|
||||
}
|
||||
// An obstacle from above the corridor across the midpoint (common in short
|
||||
// windows) still limits it: the panels go on whichever side of it leaves
|
||||
// more room.
|
||||
for (const rect of straddling) {
|
||||
const roomAbove = rect.top - safeGap - obstacleSafeTop;
|
||||
// The panels go on whichever side of that span leaves more room (common in
|
||||
// short windows), above it on a tie. With no room on either side the
|
||||
// corridor stays as it is.
|
||||
if (spanBottom > spanTop) {
|
||||
const roomAbove = spanTop - safeGap - obstacleSafeTop;
|
||||
const lowerBottom = resolveLeftStackBottomBoundary({
|
||||
baseBottom: safeBottom,
|
||||
obstacles: bottomObstacles,
|
||||
safeGap,
|
||||
});
|
||||
const roomBelow = lowerBottom - (rect.bottom + safeGap);
|
||||
if (roomBelow > roomAbove) {
|
||||
const obstacleBottom = rect.bottom + safeGap;
|
||||
obstacleSafeTop = Math.max(obstacleSafeTop, obstacleBottom);
|
||||
safeTop = Math.max(safeTop, obstacleBottom);
|
||||
} else bottomObstacles.push({ top: rect.top });
|
||||
const roomBelow = lowerBottom - (spanBottom + safeGap);
|
||||
if (roomBelow > roomAbove && roomBelow > 0) {
|
||||
obstacleSafeTop = Math.max(obstacleSafeTop, spanBottom + safeGap);
|
||||
safeTop = Math.max(safeTop, spanBottom + safeGap);
|
||||
} else if (roomAbove > 0) bottomObstacles.push({ top: spanTop });
|
||||
}
|
||||
safeBottom = resolveLeftStackBottomBoundary({
|
||||
baseBottom: safeBottom,
|
||||
|
||||
+17
-10
@@ -2,7 +2,8 @@
|
||||
* Resolve a vertically centered panel slot inside a HUD rail while respecting
|
||||
* live rectangles that intersect that rail. A rectangle above the viewport
|
||||
* center lowers the top, one below it raises the bottom, and one across the
|
||||
* center does whichever leaves the band more room.
|
||||
* center puts the band on whichever side of it has more room, or leaves the
|
||||
* band as it is when neither side has any.
|
||||
*/
|
||||
export function resolveHudRailLayout({
|
||||
viewportHeight,
|
||||
@@ -31,7 +32,10 @@ export function resolveHudRailLayout({
|
||||
const midpoint = viewportHeight * 0.5;
|
||||
let safeTop = Math.max(0, baseTop);
|
||||
let safeBottom = Math.min(viewportHeight, baseBottom);
|
||||
const straddling = [];
|
||||
// Every obstacle across the midpoint covers it, so together they cover one
|
||||
// span: from the highest top to the lowest bottom.
|
||||
let spanTop = Infinity;
|
||||
let spanBottom = -Infinity;
|
||||
|
||||
for (const rect of obstacles) {
|
||||
if (
|
||||
@@ -47,15 +51,18 @@ export function resolveHudRailLayout({
|
||||
if (rect.bottom <= midpoint) safeTop = Math.max(safeTop, rect.bottom + gap);
|
||||
else if (rect.top >= midpoint)
|
||||
safeBottom = Math.min(safeBottom, rect.top - gap);
|
||||
else straddling.push(rect);
|
||||
else {
|
||||
spanTop = Math.min(spanTop, rect.top);
|
||||
spanBottom = Math.max(spanBottom, rect.bottom);
|
||||
}
|
||||
}
|
||||
// An obstacle across the midpoint (common in short windows) still limits
|
||||
// the band: the band goes on whichever side of it leaves more room.
|
||||
for (const rect of straddling) {
|
||||
const roomAbove = rect.top - gap - safeTop;
|
||||
const roomBelow = safeBottom - (rect.bottom + gap);
|
||||
if (roomBelow > roomAbove) safeTop = Math.max(safeTop, rect.bottom + gap);
|
||||
else safeBottom = Math.min(safeBottom, rect.top - gap);
|
||||
// The band goes on whichever side of that span leaves more room, above it
|
||||
// on a tie. With no room on either side the band stays as it is.
|
||||
if (spanBottom > spanTop) {
|
||||
const roomAbove = spanTop - gap - safeTop;
|
||||
const roomBelow = safeBottom - (spanBottom + gap);
|
||||
if (roomBelow > roomAbove && roomBelow > 0) safeTop = spanBottom + gap;
|
||||
else if (roomAbove > 0) safeBottom = spanTop - gap;
|
||||
}
|
||||
|
||||
safeBottom = Math.max(safeTop, safeBottom);
|
||||
|
||||
@@ -220,22 +220,42 @@ test('left corridor respects a lower obstacle but ignores an obstacle hidden by
|
||||
});
|
||||
|
||||
test('in a short window the left corridor stays clear of an obstacle across the midpoint', () => {
|
||||
// 480px window, midpoint 240. Neither card is wholly above or below it.
|
||||
// 480px window, midpoint 240.
|
||||
const f = fixture('left');
|
||||
f.options.windowRef.innerHeight = 480;
|
||||
const low = element('card', { top: 100, height: 200 });
|
||||
f.options.obstacles = [low];
|
||||
f.options.obstacles = [element('card', { top: 100, height: 200 })];
|
||||
f.run();
|
||||
// More room below the card than above it: the corridor starts under it.
|
||||
assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 300);
|
||||
assert(Number(f.stack.dataset.safeBottomPct) * 4.8 <= 480);
|
||||
|
||||
const high = element('card', { top: 200, height: 200 });
|
||||
f.options.obstacles = [high];
|
||||
// A card starting below the corridor's usual top (26%, 124.8px) that
|
||||
// crosses the midpoint counts the same way: more room below it.
|
||||
f.options.obstacles = [element('card', { top: 130, height: 120 })];
|
||||
f.run();
|
||||
assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 250);
|
||||
|
||||
// More room above it: the corridor ends over it.
|
||||
f.options.obstacles = [element('card', { top: 200, height: 250 })];
|
||||
f.run();
|
||||
assert(Number(f.stack.dataset.safeBottomPct) * 4.8 <= 200);
|
||||
assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 0);
|
||||
});
|
||||
|
||||
test('several cards across the midpoint give the left corridor the same room in any order', () => {
|
||||
const f = fixture('left');
|
||||
f.options.windowRef.innerHeight = 480;
|
||||
const a = element('card', { top: 100, height: 160 });
|
||||
const b = element('card', { top: 110, height: 360 });
|
||||
f.options.obstacles = [a, b];
|
||||
f.run();
|
||||
const first = [f.stack.dataset.safeTopPct, f.stack.dataset.safeBottomPct];
|
||||
f.options.obstacles = [b, a];
|
||||
f.run();
|
||||
assert.deepEqual(
|
||||
[f.stack.dataset.safeTopPct, f.stack.dataset.safeBottomPct],
|
||||
first,
|
||||
);
|
||||
// Together they cover 100 to 470: the corridor ends above them.
|
||||
assert(Number(first[1]) * 4.8 <= 100);
|
||||
});
|
||||
|
||||
test('a centered timeline only shortens the corridor when it reaches a laid-out panel', () => {
|
||||
|
||||
Reference in new issue
Block a user