mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
Keep the HUD corners, the dock and a wrapped credit line apart at every width
The credit line now wraps at every width instead of running under the corner row, and right to left it takes the bottom right at every width. A small watcher keeps its height in --credit-line-height, so the coordinates (and, right to left, the Tactical readout) stay above it however many lines it wraps onto, and the dock and World Timeline rise when it is taller than their usual clearance. Narrower than 1120px the dock leaves no room between the bottom corners, so the coordinates and the readout sit above the dock instead of under it. Outside the Omnibar layout, the coordinate rule meant for 981 to 1199px no longer overrides the two-row dock's placement at 980px and below. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
1 parent
8ed14efdbf
commit
c69a421678
10 files changed
+288
-60
No files matched your search
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @module ui/creditLineHeight
|
||||
* @description Keeps `--credit-line-height` on the page's root at the
|
||||
* height of the attribution line at the bottom of the screen, so what sits
|
||||
* above it (the HUD's bottom corners) clears it when it wraps onto more
|
||||
* lines. The line is the application's own (`#gev-credits`) or the one a
|
||||
* renderer draws inside `#cesium-credits`.
|
||||
*/
|
||||
|
||||
const LINES = ['#gev-credits', '#cesium-credits .cesium-widget-credits'];
|
||||
|
||||
/**
|
||||
* Follow the attribution line's height in `--credit-line-height`.
|
||||
* @param {Document} [doc]
|
||||
* @returns {() => void} Stops following it and clears the property.
|
||||
*/
|
||||
export function trackCreditLineHeight(doc = globalThis.document) {
|
||||
const Observer = doc?.defaultView?.ResizeObserver;
|
||||
if (!doc?.documentElement || typeof Observer !== 'function') return () => {};
|
||||
const root = doc.documentElement;
|
||||
const lines = LINES.map((selector) => doc.querySelector(selector)).filter(
|
||||
Boolean,
|
||||
);
|
||||
if (!lines.length) return () => {};
|
||||
const update = () => {
|
||||
const height = Math.max(
|
||||
0,
|
||||
...lines.map((line) => line.getBoundingClientRect().height),
|
||||
);
|
||||
if (height > 0)
|
||||
root.style.setProperty('--credit-line-height', `${Math.ceil(height)}px`);
|
||||
else root.style.removeProperty('--credit-line-height');
|
||||
};
|
||||
const observer = new Observer(update);
|
||||
for (const line of lines) observer.observe(line);
|
||||
update();
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
root.style.removeProperty('--credit-line-height');
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import '../testSupport/registerDom.mjs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { trackCreditLineHeight } from './creditLineHeight.js';
|
||||
|
||||
/** A ResizeObserver the test drives, with each line's height set by hand. */
|
||||
function fakeResizing() {
|
||||
const observers = [];
|
||||
const window = document.defaultView;
|
||||
const original = window.ResizeObserver;
|
||||
window.ResizeObserver = class {
|
||||
constructor(callback) {
|
||||
this.callback = callback;
|
||||
this.targets = new Set();
|
||||
observers.push(this);
|
||||
}
|
||||
observe(target) {
|
||||
this.targets.add(target);
|
||||
}
|
||||
disconnect() {
|
||||
this.targets.clear();
|
||||
}
|
||||
};
|
||||
return {
|
||||
resize(element, height) {
|
||||
element.getBoundingClientRect = () => ({ height });
|
||||
for (const observer of observers)
|
||||
if (observer.targets.has(element)) observer.callback([]);
|
||||
},
|
||||
restore() {
|
||||
window.ResizeObserver = original;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test("the credit line's height follows it as it wraps, for either renderer's line", () => {
|
||||
const resizing = fakeResizing();
|
||||
try {
|
||||
for (const markup of [
|
||||
'<div id="gev-credits"></div>',
|
||||
'<div id="cesium-credits"><div class="cesium-widget-credits"></div></div>',
|
||||
]) {
|
||||
document.body.innerHTML = markup;
|
||||
const line = document.querySelector(
|
||||
'#gev-credits, #cesium-credits .cesium-widget-credits',
|
||||
);
|
||||
line.getBoundingClientRect = () => ({ height: 28 });
|
||||
const stop = trackCreditLineHeight(document);
|
||||
const root = document.documentElement.style;
|
||||
assert.equal(root.getPropertyValue('--credit-line-height'), '28px');
|
||||
resizing.resize(line, 66.4);
|
||||
assert.equal(root.getPropertyValue('--credit-line-height'), '67px');
|
||||
// Hidden, it holds no room.
|
||||
resizing.resize(line, 0);
|
||||
assert.equal(root.getPropertyValue('--credit-line-height'), '');
|
||||
resizing.resize(line, 28);
|
||||
stop();
|
||||
assert.equal(root.getPropertyValue('--credit-line-height'), '');
|
||||
}
|
||||
} finally {
|
||||
resizing.restore();
|
||||
document.body.replaceChildren();
|
||||
}
|
||||
});
|
||||
|
||||
test('without a credit line nothing is followed', () => {
|
||||
const resizing = fakeResizing();
|
||||
try {
|
||||
document.body.replaceChildren();
|
||||
const stop = trackCreditLineHeight(document);
|
||||
assert.equal(
|
||||
document.documentElement.style.getPropertyValue('--credit-line-height'),
|
||||
'',
|
||||
);
|
||||
stop();
|
||||
} finally {
|
||||
resizing.restore();
|
||||
}
|
||||
});
|
||||
@@ -458,8 +458,10 @@ test('the desktop bottom row: credits on the Power Up baseline, the dock lifted,
|
||||
const anchor = trays.match(
|
||||
/#cesium-credits \{\s*right: auto;\s*bottom: ([\d.]+)rem;\s*left: 1\.5rem;/,
|
||||
);
|
||||
const box = trayWide.match(
|
||||
/\n #cesium-credits \.cesium-widget-credits \{\s*width: max-content;\s*max-width: calc\(100vw - 1\.5rem - ([\d.]+)rem\);\s*white-space: normal;/,
|
||||
// At every width: a long line wraps rather than running under the
|
||||
// corner row.
|
||||
const box = trays.match(
|
||||
/\n#cesium-credits \.cesium-widget-credits \{\s*width: max-content;\s*max-width: calc\(100vw - 1\.5rem - ([\d.]+)rem\);\s*white-space: normal;/,
|
||||
);
|
||||
return anchor && box && [null, anchor[1], box[1]];
|
||||
})(),
|
||||
@@ -491,13 +493,14 @@ test('the desktop bottom row: credits on the Power Up baseline, the dock lifted,
|
||||
/html\[dir='rtl'\]\s*body:not\(\.context-docked\):not\(\.ui-clean-view\):not\(\.recording-mode\)\s*:is\(#cesium-credits, #gev-credits\),\s*html\[dir='rtl'\]\s*body:not\(\.context-docked\):not\(\.ui-clean-view\):not\(\.recording-mode\):has\(\s*#intel-hud\[data-variant='minimal'\]\.active\s*\)\s*:is\(#cesium-credits, #gev-credits\) \{\s*right: 1\.5rem;\s*left: auto;/,
|
||||
);
|
||||
assert.match(
|
||||
trayWide,
|
||||
/#cesium-credits\s*\.cesium-widget-credits \{\s*right: 0;\s*left: auto;/,
|
||||
trays,
|
||||
/html\[dir='rtl'\] #cesium-credits \.cesium-widget-credits \{\s*right: 0;\s*left: auto;/,
|
||||
);
|
||||
// There the readout clears two lines of the row under it.
|
||||
// There the readout clears the row under it, however many lines it wraps
|
||||
// onto (--credit-line-height).
|
||||
assert.match(
|
||||
read('./styles/omnibar-dock.css'),
|
||||
/html\[dir='rtl'\] \*\)\s*#intel-hud\[data-variant='tactical'\]\s*\.hud-bottom-right \{\s*bottom: calc\(3\.375rem \+ 1\.5rem\);/,
|
||||
/html\[dir='rtl'\] \*\):not\(\.context-docked\)\s*#intel-hud\[data-variant='tactical'\]\s*\.hud-bottom-right \{\s*bottom: max\(3\.375rem, var\(--omnibar-credits-clear\)\);/,
|
||||
);
|
||||
const locale = read('./styles/locale-picker.css');
|
||||
assert.match(locale, /#corner-actions \{[^}]*inset-inline-end: 0\.9rem;/);
|
||||
|
||||
@@ -501,13 +501,16 @@ body:not(.ui-clean-view):not(.recording-mode):has(
|
||||
|
||||
/* The coordinate readout shares the bottom-left corner with the attribution
|
||||
row below 1200px: it sits clear of the row's 28px logo line, with a 6px gap
|
||||
(from 1200px, rail-split.css). */
|
||||
#intel-hud:is([data-variant='tactical'], [data-variant='minimal'])
|
||||
.hud-bottom-left,
|
||||
:root[data-scope-mask='off']
|
||||
#intel-hud[data-variant='minimal']
|
||||
.hud-bottom-left {
|
||||
bottom: calc(2vh + 7.125rem + var(--world-timeline-lift, 0px));
|
||||
(from 1200px, rail-split.css). At 980px and below the dock is two rows
|
||||
tall and command-dock.css places it. */
|
||||
@media (min-width: 981px) {
|
||||
#intel-hud:is([data-variant='tactical'], [data-variant='minimal'])
|
||||
.hud-bottom-left,
|
||||
:root[data-scope-mask='off']
|
||||
#intel-hud[data-variant='minimal']
|
||||
.hud-bottom-left {
|
||||
bottom: calc(2vh + 7.125rem + var(--world-timeline-lift, 0px));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 1199px) {
|
||||
@@ -528,15 +531,22 @@ body:not(.ui-clean-view):not(.recording-mode):has(
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1200px) {
|
||||
/* Cesium draws the line in an absolutely placed box inside the empty
|
||||
#cesium-credits anchor, so the cap and the wrapping go on that box. */
|
||||
#cesium-credits .cesium-widget-credits {
|
||||
width: max-content;
|
||||
max-width: calc(100vw - 1.5rem - 26rem);
|
||||
white-space: normal;
|
||||
}
|
||||
/* Cesium draws the line in an absolutely placed box inside the empty
|
||||
#cesium-credits anchor, so the cap and the wrapping go on that box, at
|
||||
every width: a long line wraps rather than running under the corner row.
|
||||
Right to left it hangs from the anchor's right edge. */
|
||||
#cesium-credits .cesium-widget-credits {
|
||||
width: max-content;
|
||||
max-width: calc(100vw - 1.5rem - 26rem);
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
html[dir='rtl'] #cesium-credits .cesium-widget-credits {
|
||||
right: 0;
|
||||
left: auto;
|
||||
}
|
||||
|
||||
@media (min-width: 1200px) {
|
||||
/* Right to left, the corner row sits at the bottom left
|
||||
(locale-picker.css), so the attribution row takes the bottom right.
|
||||
Expanded Context places it itself (context-dock.css). */
|
||||
@@ -554,14 +564,6 @@ body:not(.ui-clean-view):not(.recording-mode):has(
|
||||
left: auto;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
html[dir='rtl']
|
||||
body:not(.context-docked):not(.ui-clean-view):not(.recording-mode)
|
||||
#cesium-credits
|
||||
.cesium-widget-credits {
|
||||
right: 0;
|
||||
left: auto;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
|
||||
@@ -5,8 +5,13 @@ body:not(.mobile-shell):not(.cockpit-mode):not(.scene-playback-mode):not(
|
||||
:has(#gev-omnibar):has(#command-dock > #gev-voice-control)
|
||||
) {
|
||||
--omnibar-dock-width: clamp(400px, 32vw, 460px);
|
||||
--omnibar-dock-bottom: 74px;
|
||||
--omnibar-coordinates-bottom: 4.25rem;
|
||||
/* Clear of the attribution line under it, however many lines it wraps
|
||||
onto (--credit-line-height, src/ui/creditLineHeight.js). */
|
||||
--omnibar-credits-clear: calc(1rem + var(--credit-line-height, 28px) + 6px);
|
||||
/* The dock, and the World Timeline and narrow corners placed from it,
|
||||
rise over a line wrapped taller than its usual one or two lines. */
|
||||
--omnibar-dock-bottom: max(74px, calc(var(--omnibar-credits-clear) + 2px));
|
||||
--omnibar-coordinates-bottom: max(4.25rem, var(--omnibar-credits-clear));
|
||||
--world-timeline-lift: 0px;
|
||||
|
||||
#intel-hud:is([data-variant='tactical'], [data-variant='minimal'])
|
||||
@@ -320,24 +325,54 @@ body:not(.mobile-shell):not(.cockpit-mode):not(.scene-playback-mode):not(
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Align the plain credits with Power Up. */
|
||||
/* Align the plain credits with Power Up. The line wraps at every width
|
||||
rather than running under the corner row (Power Up and the language
|
||||
picker), whose side it stays clear of. */
|
||||
:is(#cesium-credits, #gev-credits),
|
||||
&:has(#intel-hud[data-variant='minimal'].active)
|
||||
:is(#cesium-credits, #gev-credits) {
|
||||
bottom: 1rem;
|
||||
}
|
||||
#gev-credits {
|
||||
width: max-content !important;
|
||||
max-width: calc(100vw - 1.5rem - 26rem);
|
||||
white-space: normal;
|
||||
}
|
||||
/* Right to left the corner row is at the bottom left, so the line takes
|
||||
the bottom right at every width. Expanded Context places it itself. */
|
||||
&:where(html[dir='rtl'] *):not(.context-docked) {
|
||||
:is(#cesium-credits, #gev-credits),
|
||||
&:has(#intel-hud[data-variant='minimal'].active)
|
||||
:is(#cesium-credits, #gev-credits) {
|
||||
right: 1.5rem;
|
||||
left: auto;
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
/* 8px above the bottom-right corner row (Power Up and the language picker:
|
||||
32px tall, 14px up), as outside the Omnibar layout. */
|
||||
#intel-hud[data-variant='tactical'] .hud-bottom-right {
|
||||
bottom: 3.375rem;
|
||||
}
|
||||
/* Right to left the attribution row takes the bottom right: the readout
|
||||
clears two lines of it (rail-split.css). */
|
||||
@media (min-width: 1200px) {
|
||||
&:where(html[dir='rtl'] *)
|
||||
/* Right to left the attribution line is under the readout, which clears
|
||||
it however many lines it wraps onto. */
|
||||
&:where(html[dir='rtl'] *):not(.context-docked)
|
||||
#intel-hud[data-variant='tactical']
|
||||
.hud-bottom-right {
|
||||
bottom: max(3.375rem, var(--omnibar-credits-clear));
|
||||
}
|
||||
/* Narrower than the two corners and the dock between them, the corners
|
||||
rise above the dock. */
|
||||
@media (max-width: 1119px) {
|
||||
--omnibar-coordinates-bottom: max(
|
||||
calc(var(--omnibar-dock-bottom) + 56px + 10px),
|
||||
var(--omnibar-credits-clear)
|
||||
);
|
||||
#intel-hud[data-variant='tactical'] .hud-bottom-right,
|
||||
&:where(html[dir='rtl'] *):not(.context-docked)
|
||||
#intel-hud[data-variant='tactical']
|
||||
.hud-bottom-right {
|
||||
bottom: calc(3.375rem + 1.5rem);
|
||||
bottom: var(--omnibar-coordinates-bottom);
|
||||
}
|
||||
}
|
||||
#intel-hud:is([data-variant='tactical'], [data-variant='minimal'])
|
||||
|
||||
Reference in new issue
Block a user