From 10dbd2f937b77e349c2d96707775dd0d69bf5780 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 23:14:26 -0800 Subject: [PATCH] fix(ui): a side of a midpoint block thinner than 8% of the window holds no panel; pin the lower merge edge Co-authored-by: Manjunath Paparaju --- docs/CURRENT-STATE.md | 3 ++- src/cockpitMath.test.mjs | 6 ++++++ src/ui/leftPanelRail.js | 2 ++ src/ui/panelRailGeometry.js | 10 ++++++++-- src/ui/panelRails.test.mjs | 7 ++++--- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 91655cb712..6cd948e474 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -1204,7 +1204,8 @@ block has more room up to the next obstacle, above it on a tie, whatever order the obstacles come in (`bandBesideMidpointObstacles` in `src/ui/panelRailGeometry.js`); on the left rail the panels may then rise above the corridor's usual top to use all the room above. With no room on -either side the obstacles are read as before. +either side (a side under 8% of the window's height counts as none) the +obstacles are read 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. diff --git a/src/cockpitMath.test.mjs b/src/cockpitMath.test.mjs index cda54d2c6a..dd4d55a689 100644 --- a/src/cockpitMath.test.mjs +++ b/src/cockpitMath.test.mjs @@ -390,6 +390,12 @@ test('HUD rail layout counts obstacles beside those across the midpoint', () => // Neighbours exactly two gaps away leave no room between: one block, 100 // to 400, and a tie (50px a side) goes above. assert.deepEqual(band([[100, 180], [200, 300], [320, 400]]), [40, 90]); + // A neighbour exactly two gaps below joins it too: 150 to 300, 110px + // above against 150 below. + assert.deepEqual(band([[150, 250], [270, 300]]), [310, 460]); + // A side under 8% of the window (38.4px) is no room: 30px above, none + // below, so the band stays as it is. + assert.deepEqual(band([[80, 455]]), [40, 460]); }); test('HUD rail layout keeps a band beside a midpoint obstacle inside its own edges', () => { diff --git a/src/ui/leftPanelRail.js b/src/ui/leftPanelRail.js index 4def1dcfc6..5b6af7be0f 100644 --- a/src/ui/leftPanelRail.js +++ b/src/ui/leftPanelRail.js @@ -169,6 +169,8 @@ export function layoutLeftPanelRail({ bottom: safeBottom, obstacles: inLane, gap: safeGap, + // A side thinner than this holds no usable panel. + minimum: viewportHeight * 0.08, }); if (beside) { obstacleSafeTop = beside.top; diff --git a/src/ui/panelRailGeometry.js b/src/ui/panelRailGeometry.js index b845a1a5c5..c7266d8c72 100644 --- a/src/ui/panelRailGeometry.js +++ b/src/ui/panelRailGeometry.js @@ -56,6 +56,8 @@ export function resolveHudRailLayout({ bottom: Math.min(viewportHeight, baseBottom), obstacles: inLane, gap, + // A side thinner than this holds no usable panel. + minimum: viewportHeight * 0.08, }); if (beside) ({ top: safeTop, bottom: safeBottom } = beside); @@ -86,6 +88,8 @@ export function resolveHudRailLayout({ * @param {number} input.bottom The band's lowest bottom. * @param {Array<{top: number, bottom: number}>} input.obstacles Rectangles that reach the rail. * @param {number} input.gap Space kept between the band and an obstacle. + * @param {number} [input.minimum=0] The least room a side needs to count; + * a thinner side is no room at all. * @returns {{side: 'above' | 'below', top: number, bottom: number} | null} * Null when nothing crosses the midpoint or neither side has room. */ @@ -95,6 +99,7 @@ export function bandBesideMidpointObstacles({ bottom, obstacles, gap, + minimum = 0, }) { const crossing = obstacles.filter( (rect) => rect.top < midpoint && rect.bottom > midpoint, @@ -134,8 +139,9 @@ export function bandBesideMidpointObstacles({ }; const roomAbove = above.bottom - above.top; const roomBelow = below.bottom - below.top; - if (roomBelow > roomAbove && roomBelow > 0) return below; - return roomAbove > 0 ? above : null; + const least = Math.max(minimum, Number.EPSILON); + if (roomBelow > roomAbove && roomBelow >= least) return below; + return roomAbove >= least ? above : null; } /** diff --git a/src/ui/panelRails.test.mjs b/src/ui/panelRails.test.mjs index 1b67600b88..d4a67ed523 100644 --- a/src/ui/panelRails.test.mjs +++ b/src/ui/panelRails.test.mjs @@ -268,14 +268,15 @@ test('the left corridor counts cards beside those across the midpoint', () => { ]; f.run(); assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 300); - // Only a little room above the cards: the corridor stays there rather - // than run down through the lower one. + // About 25px above the cards is under the least usable room (8% of the + // window): they are read as before, the upper card pushing the corridor + // down past it rather than into a sliver at the top. f.options.obstacles = [ element('card', { top: 50, height: 150 }), element('card', { top: 150, height: 320 }), ]; f.run(); - assert(Number(f.stack.dataset.safeBottomPct) * 4.8 <= 50); + assert(Number(f.stack.dataset.safeTopPct) * 4.8 >= 200); // The room above a card is all the panels' to use, above the corridor's // usual top (26%) too: 700px window, card 300 to 420, about 263px above // against 244 below.