Files
gods-eye-view/src/ui/panelMeasurement.js
T
Manjunath PaparajuandSameh Khamis 7ee047961b Move Visual to the left rail and let panels sit at the screen edge
The left rail holds Data Layers, Utilities, Authoring and Visual; the right
rail holds Context, CCTV and Street Level. A button in each panel header
moves that side's panels to the screen edge, with the rail as a row above
them, and scrolling at a screen edge steps through a rail's panels. An open
right panel starts just under the HUD readouts, and Context and CCTV take
the column's full height. The right rail stays level with the left column's
top whichever left panel is open, in both layouts.

Co-authored-by: Sameh Khamis <[email protected]>
2026-11-14 13:41:07 -08:00

56 lines
2.1 KiB
JavaScript

/**
* Measure unconstrained visible content without feeding the allocated outer
* height back into the next layout pass.
* @param {HTMLElement} panel Panel whose natural height is needed.
* @param {Function} getComputedStyle Style reader for the panel's document.
* @returns {number} Natural height in CSS pixels.
*/
export function measurePanelNaturalHeight(panel, getComputedStyle) {
const content = [...panel.children].filter(
(child) => !child.classList.contains('panel-glow'),
);
// A panel built as a header row and a body (Visual) scrolls as a whole, so
// its full scroll height is its natural height.
if (content.length > 1) {
const panelStyle = getComputedStyle(panel);
return Math.ceil(
panel.scrollHeight +
(parseFloat(panelStyle.borderTopWidth) || 0) +
(parseFloat(panelStyle.borderBottomWidth) || 0),
);
}
const inner = content[0];
if (!inner)
return Math.ceil(
panel.scrollHeight || panel.getBoundingClientRect().height,
);
const innerRect = inner.getBoundingClientRect();
const panelStyle = getComputedStyle(panel);
const innerStyle = getComputedStyle(inner);
const paddingBottom = parseFloat(innerStyle.paddingBottom) || 0;
let contentBottom = parseFloat(innerStyle.paddingTop) || 0;
for (const child of inner.children) {
const childStyle = getComputedStyle(child);
if (childStyle.display === 'none' || childStyle.visibility === 'hidden')
continue;
const childRect = child.getBoundingClientRect();
const marginBottom = parseFloat(childStyle.marginBottom) || 0;
const naturalChildHeight = Math.max(
childRect.height,
child.scrollHeight || 0,
);
const childBottom =
childRect.top - innerRect.top + naturalChildHeight + marginBottom;
contentBottom = Math.max(contentBottom, childBottom);
}
const wrapperChrome =
(parseFloat(panelStyle.borderTopWidth) || 0) +
(parseFloat(panelStyle.borderBottomWidth) || 0) +
(parseFloat(panelStyle.paddingTop) || 0) +
(parseFloat(panelStyle.paddingBottom) || 0);
return Math.ceil(contentBottom + paddingBottom + wrapperChrome);
}