+ {/* The search filter lives here so it clearly applies to the Items tab only, not Summary/Ration/Export.
+ No margin of its own: it is a top-level block and the page's stack spaces it. */}
+
diff --git a/app/src/components/ui/ui-layout.cy.js b/app/src/components/ui/ui-layout.cy.js
index 93ed74b7..8e9d1105 100644
--- a/app/src/components/ui/ui-layout.cy.js
+++ b/app/src/components/ui/ui-layout.cy.js
@@ -116,6 +116,158 @@ describe('the interface scale actually reaches what it is supposed to', () => {
});
});
+describe('a page stacks its own blocks', () => {
+ /*
+ * A page is built out of panels -- the dashboard is five, Status is six, Settings is six --
+ * and nothing put space between them, so every pair shared an edge. Two 1px borders meeting
+ * do not read as a seam between two surfaces; they read as one tall surface with a rule across
+ * it, and which heading owns which content stops being obvious.
+ *
+ * The space is the page's, not the panel's. How far a panel sits from its neighbour is a
+ * property of the two of them being stacked, and the same panel also appears inside modals,
+ * grids and Mantine `Stack`s that space it themselves. This was tried the other way first, as
+ * `margin-bottom` on `.wrolpi-panel`, and it failed in both of the ways that rule is known to
+ * fail -- see the sibling test below, which is what stops it being tried again.
+ */
+
+ const gapsBetween = ($panels) => {
+ const rects = [...$panels].map((el) => el.getBoundingClientRect());
+ return rects.slice(1).map((rect, index) => rect.top - rects[index].bottom);
+ };
+
+ it('leaves a gap between the panels it stacks', () => {
+ cy.mountUI(
+
Tags
+
Status
+
Calculators
+
);
+
+ cy.get('.wrolpi-panel').should(($panels) => {
+ const gaps = gapsBetween($panels);
+ expect(gaps, 'both pairs measured').to.have.length(2);
+ gaps.forEach((gap) => {
+ // Enough to read as a seam rather than a heavier border ...
+ expect(gap, 'gap between panels').to.be.at.least(12);
+ // ... and not so much that one page reads as unrelated cards.
+ expect(gap, 'gap between panels').to.be.at.most(28);
+ });
+ });
+ });
+
+ it('spaces a block that is wrapped as readily as a bare one', () => {
+ /*
+ * This is the case that chose where the rule lives. Several pages put a panel inside the
+ * responsive `Media` component, so the page's child is a wrapper rather than the panel.
+ *
+ * Spacing from the page handles that for free -- it spaces the wrapper, and the wrapper is
+ * the sibling. A `margin-bottom` on the panel plus the `:last-child` reset that would
+ * keep the trailing space off the bottom of a container does NOT: the panel is the only
+ * child of its wrapper, so `:last-child` matches it, zeroes the margin, and leaves it hard
+ * against the next panel. On Status that separated four pairs out of five and left the
+ * first touching -- one page showing both, which reads as a rendering glitch.
+ */
+ cy.mountUI(
+
Wrapped, as Media does it
+
Bare
+
);
+
+ cy.get('.wrolpi-panel').should(($panels) =>
+ expect(gapsBetween($panels)[0], 'gap across a wrapper').to.be.at.least(12));
+ });
+
+ it('survives a block that zeroes its own margin', () => {
+ /*
+ * The reason this is a gap and not `> * + * { margin-top }`. The responsive `Media`
+ * component injects `.fresnel-container { margin: 0; padding: 0 }` into the document at
+ * runtime -- same specificity as the owl selector, later in source order -- so a wrapped
+ * block threw the margin away and went on touching its neighbour, while the bare blocks
+ * on the same page separated. A gap is the parent's, and a child cannot zero it.
+ *
+ * The margin here stands in for fresnel's rule; the point is that the spacing does not
+ * depend on the child's own margin being left alone.
+ */
+ cy.mountUI(
);
+
+ cy.get('.wrolpi-panel').should(($panels) =>
+ expect(gapsBetween($panels)[0], 'gap despite the child margin').to.be.at.least(12));
+ });
+
+ it('adds nothing before the first block or after the last', () => {
+ // A gap goes only between, so the page's own padding decides its edges.
+ cy.mountUI(
);
+
+ cy.get('.wrolpi-stack').should(($stack) => {
+ const stack = $stack[0].getBoundingClientRect();
+ const panels = [...$stack[0].querySelectorAll('.wrolpi-panel')]
+ .map(el => el.getBoundingClientRect());
+ expect(panels[0].top - stack.top, 'above the first').to.be.closeTo(0, 0.5);
+ expect(stack.bottom - panels[1].bottom, 'below the last').to.be.closeTo(0, 0.5);
+ });
+ });
+
+ it('grows the gap with the interface scale', () => {
+ // In px it would hold still while the panels either side of it grew.
+ cy.mountUI(
);
+
+ cy.get('.wrolpi-stack').should(($stack) => {
+ const before = parseFloat(getComputedStyle($stack[0]).rowGap);
+ const root = Cypress.$('html')[0];
+ const scale = parseFloat(getComputedStyle(root).getPropertyValue('--ui-scale')) || 1;
+ root.style.setProperty('--ui-scale', String(scale * 2));
+ const after = parseFloat(getComputedStyle($stack[0]).rowGap);
+ root.style.removeProperty('--ui-scale');
+
+ expect(before, 'the gap exists at all').to.be.greaterThan(0);
+ expect(after / before, 'and doubles with the scale').to.be.closeTo(2, 0.05);
+ });
+ });
+
+ it('contributes no gap for the half of a Media pair that is hidden', () => {
+ /*
+ * `Media` renders both viewports and hides one with `display: none`. A hidden flex item
+ * is not a flex item at all, so it takes no gap -- where `* + *` would have put space
+ * around something invisible and left a page with a stray 1rem hole in it.
+ */
+ cy.mountUI(
);
+
+ cy.get('.wrolpi-panel:visible').should(($panels) => {
+ expect($panels, 'the hidden panel is not measured').to.have.length(2);
+ expect(gapsBetween($panels)[0], 'one gap, not two').to.be.at.most(28);
+ });
+ });
+
+ it('leaves a panel with no outer margin, so a Stack can space it instead', () => {
+ /*
+ * The inverse rule, and the reason it is worth its own test: the moment a panel carries
+ * its own margin, it adds to the spacing of every container that already spaces its
+ * children. Four `Stack`s in the app hold nothing but panels -- the conflict list, both
+ * halves of the one-time pad, the electrical calculators -- and with `margin-bottom` on
+ * the panel they spaced those lists at 35.2px against the 17.6px used everywhere else.
+ */
+ cy.mountUI(
Composable);
+
+ cy.get('.wrolpi-panel').should(($panel) => {
+ const styles = getComputedStyle($panel[0]);
+ ['marginTop', 'marginRight', 'marginBottom', 'marginLeft'].forEach((side) => {
+ expect(parseFloat(styles[side]), side).to.equal(0);
+ });
+ });
+ });
+});
+
/* `--panel` is authored as a hex; computed backgrounds come back as rgb(). */
const hexToRgb = (hex) => {
const value = hex.replace('#', '');
diff --git a/app/src/components/ui/ui.css b/app/src/components/ui/ui.css
index 925c9c84..2706a468 100644
--- a/app/src/components/ui/ui.css
+++ b/app/src/components/ui/ui.css
@@ -250,7 +250,11 @@ html[data-theme="amber"] .wrolpi-pagination button[data-active] {
justify-content: space-between;
gap: 0.75rem;
border-bottom: 1px solid var(--border);
- margin-bottom: 0.875rem;
+ /*
+ * No `margin-bottom`. A tab bar is always the first block of a page, inside the page's own
+ * stack, so the 0.875rem it used to carry was added to the stack's gap and put the bar 33px
+ * from the content it labels where every other pair of blocks sat 17.6px apart.
+ */
}
.wrolpi-tabs-links {
@@ -1270,12 +1274,57 @@ html[data-theme="amber"] .wrolpi-progress-fill {
background: var(--muted);
}
+/* ----------------------------------------------------------------- Stacks */
+
+/*
+ * The space between stacked blocks, owned by whatever stacks them rather than by the blocks.
+ *
+ * `PageContainer` puts this on every page, so a page's own blocks are spaced without asking. A
+ * component that stacks blocks one level deeper -- Settings holds its six panels in a wrapper of
+ * its own -- puts it on that wrapper. Mantine's `Stack` is the same thing with the same 1rem gap
+ * and is equally correct where a call site already reaches for it.
+ *
+ * `gap`, not the `> * + * { margin-top }` this was written as first. The margin version is the
+ * older recommendation and it is quietly broken here: the responsive `Media` component injects
+ * `.fresnel-container { margin: 0; padding: 0 }` into the document at runtime, which has the same
+ * specificity as `.wrolpi-stack > * + *` and comes later in source order -- so every block a
+ * page wraps in `Media`, which on Status is the one carrying the CPU and RAM bars, threw the
+ * margin away and went on touching its neighbour. A gap belongs to the parent and a child cannot
+ * zero it.
+ *
+ * It also handles `Media`'s hidden half for free: the branch for the other viewport is
+ * `display: none`, so it is not a flex item and contributes no gap, where `* + *` would have
+ * spaced around something invisible.
+ *
+ * `align-items: stretch` is the default and is what keeps every block full-width, as it was as a
+ * block element. Heights are unaffected: the column is auto-height, so nothing shrinks, and the
+ * map's 85vh box and the CBZ viewer's full-height page measure the same as before.
+ */
+.wrolpi-stack {
+ display: flex;
+ flex-direction: column;
+ gap: 1rem;
+}
+
/* ----------------------------------------------------------------- Panels */
.wrolpi-panel {
background: var(--panel);
border: 1px solid var(--border);
padding: 0.875rem 1rem;
+ /*
+ * Deliberately NO outer margin. A panel is dropped into pages, modals, Stacks and grids, and
+ * how far it sits from its neighbour is a property of that relationship rather than of the
+ * panel -- so the space between stacked panels is owned by whatever stacks them
+ * (`.wrolpi-stack` for a page, Mantine's `Stack` gap inside a modal).
+ *
+ * This was tried the other way first, as `margin-bottom: 1rem` here, and it went wrong in
+ * both of the documented ways within the hour: it compounded with the gap of every `Stack`
+ * that already held panels (four of them, spacing those lists at 35.2px against the app's
+ * 17.6px), and the `:last-child` reset that would have kept the trailing space off the bottom
+ * of a container silently did nothing, because WROLPi wraps panels in the responsive `Media`
+ * component and a panel is frequently the only child of its own wrapper.
+ */
}
/* Danger zones are dashed in every theme; it doubles as a colorblind-safe cue. */