fix(ui): panel rails keep clear of an obstacle across the middle of the window

An obstacle that crossed the middle of the window (the World Timeline, the
voice control or a card in a window under about 520px tall) was neither
above nor below it, so neither rail counted it and panels could be laid out
over it. Such an obstacle now puts the panels on whichever side of it has
more room. When neither side has room, the rails keep their existing
minimum (the right rail's empty band, the left rail's minimum lane height).

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-18 22:32:40 -08:00
1 parent ec1fc6bc09
commit 8b055a1423
5 files changed
+109 -2

No files matched your search

+20
View File
@@ -118,6 +118,7 @@ export function layoutLeftPanelRail({
let safeTop = baseTop;
let safeBottom = viewportHeight - baseBottomInset;
const bottomObstacles = [];
const straddling = [];
for (const obstacle of obstacles) {
if (stack.contains(obstacle)) continue;
@@ -153,8 +154,27 @@ export function layoutLeftPanelRail({
safeTop = Math.max(safeTop, obstacleBottom);
} else if (rect.top >= baseTop) {
bottomObstacles.push({ top: rect.top });
} else {
straddling.push(rect);
}
}
// 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;
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 });
}
safeBottom = resolveLeftStackBottomBoundary({
baseBottom: safeBottom,
obstacles: bottomObstacles,
+13 -1
View File
@@ -1,6 +1,8 @@
/**
* Resolve a vertically centered panel slot inside a HUD rail while respecting
* live rectangles that intersect that rail above or below the viewport center.
* 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.
*/
export function resolveHudRailLayout({
viewportHeight,
@@ -29,6 +31,7 @@ export function resolveHudRailLayout({
const midpoint = viewportHeight * 0.5;
let safeTop = Math.max(0, baseTop);
let safeBottom = Math.min(viewportHeight, baseBottom);
const straddling = [];
for (const rect of obstacles) {
if (
@@ -44,6 +47,15 @@ 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);
}
// 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);
}
safeBottom = Math.max(safeTop, safeBottom);
+19
View File
@@ -219,6 +219,25 @@ test('left corridor respects a lower obstacle but ignores an obstacle hidden by
assert.equal(Number(f.stack.dataset.safeBottomPct), 65.47);
});
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.
const f = fixture('left');
f.options.windowRef.innerHeight = 480;
const low = element('card', { top: 100, height: 200 });
f.options.obstacles = [low];
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];
f.run();
// More room above it: the corridor ends over it.
assert(Number(f.stack.dataset.safeBottomPct) * 4.8 <= 200);
assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 0);
});
test('a centered timeline only shortens the corridor when it reaches a laid-out panel', () => {
const f = fixture('left');
f.stack.rect.width = 360;