Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
Phone on its side: STOP fixed top-right inside the safe area, sticks in the lower corners once a turn starts, proven by a stylesheet test #329
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
quill/arm:quill/312-phone-on-its-side-stop-fixed-top-right-i → main 1 commit fork
3 files
changed +135
−7
Software/README.md +4 −2
| @@ -653,8 +653,10 @@ metrics and 3D calibration). | ||
| 653 | 653 | Long-press a message (or right-click it) to delete it, or mute or ban its |
| 654 | 654 | author. |
| 655 | 655 | - Phone on its side: the view fills the screen, the strip and the sheet |
| 656 | float over it, and **Hide** clears them away. A wide screen puts the | |
| 657 | sheet in a column beside the view. | |
| 656 | float over it, and **Hide** clears them away. STOP leaves the strip for | |
| 657 | the top-right corner, inside the notch's inset and over the sheet when | |
| 658 | the sheet is out, so it is in the same place whatever else is showing. | |
| 659 | A wide screen puts the sheet in a column beside the view. | |
| 658 | 660 | - Every tap target is at least 44 px. The safe-area insets are respected, |
| 659 | 661 | the page follows the system's light or dark mode, and nothing moves for |
| 660 | 662 | people who ask for reduced motion. The bottom-right corner belongs to the |
Software/so101/src/landscape-layout.test.ts added +119
| @@ -0,0 +1,119 @@ | ||
| 1 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 2 | import { mkdtempSync } from "node:fs"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { FeetechBus } from "./bus.ts"; | |
| 6 | import { FakeBus } from "./fake-bus.ts"; | |
| 7 | import { startServer, type RunningServer } from "./server.ts"; | |
| 8 | ||
| 9 | // A phone on its side (844x390, 915x412) matches "(orientation: landscape) and (max-height: 500px)". There is no browser | |
| 10 | // here, so the layout is read from the served stylesheet: each rule with the @media it sits in, the declarations by name. | |
| 11 | ||
| 12 | const SIDEWAYS = "(orientation: landscape) and (max-height: 500px)"; | |
| 13 | type Rule = { media: string; selector: string; decls: Record<string, string> }; | |
| 14 | ||
| 15 | function rules(css: string): Rule[] { | |
| 16 | const out: Rule[] = []; | |
| 17 | const walk = (src: string, media: string) => { | |
| 18 | let i = 0; | |
| 19 | while (i < src.length) { | |
| 20 | const open = src.indexOf("{", i); | |
| 21 | if (open < 0) break; | |
| 22 | let depth = 1; | |
| 23 | let j = open + 1; | |
| 24 | for (; j < src.length && depth; j++) depth += src[j] === "{" ? 1 : src[j] === "}" ? -1 : 0; | |
| 25 | const head = src.slice(i, open).trim(); | |
| 26 | const inner = src.slice(open + 1, j - 1); | |
| 27 | if (head.startsWith("@media")) walk(inner, head.slice(6).trim()); | |
| 28 | else if (!head.startsWith("@")) { | |
| 29 | const decls: Record<string, string> = {}; | |
| 30 | for (const d of inner.split(";")) { | |
| 31 | const at = d.indexOf(":"); | |
| 32 | if (at > 0) decls[d.slice(0, at).trim().toLowerCase()] = d.slice(at + 1).trim(); | |
| 33 | } | |
| 34 | for (const selector of head.split(",")) out.push({ media, selector: selector.trim(), decls }); | |
| 35 | } | |
| 36 | i = j; | |
| 37 | } | |
| 38 | }; | |
| 39 | walk(css.replace(/\/\*[\s\S]*?\*\//g, ""), ""); | |
| 40 | return out; | |
| 41 | } | |
| 42 | ||
| 43 | /** The declarations a selector gets on a phone on its side, later rules winning, as the cascade has them for equal selectors. */ | |
| 44 | function sideways(all: Rule[], selector: string): Record<string, string> { | |
| 45 | return Object.assign({}, ...all.filter((r) => r.selector === selector && (r.media === "" || r.media === SIDEWAYS)).map((r) => r.decls)); | |
| 46 | } | |
| 47 | ||
| 48 | let server: RunningServer; | |
| 49 | let html: string; | |
| 50 | let css: Rule[]; | |
| 51 | ||
| 52 | beforeAll(async () => { | |
| 53 | const dataDir = mkdtempSync(join(tmpdir(), "so101-landscape-")); | |
| 54 | server = await startServer(new FeetechBus(new FakeBus([1, 2, 6])), { host: "127.0.0.1", port: 0, ids: [1, 2, 6], posesFile: join(dataDir, "poses.json"), watchdogMs: 60 }); | |
| 55 | html = await (await fetch(`http://127.0.0.1:${server.port}/`)).text(); | |
| 56 | css = rules([...html.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/gi)].map((m) => m[1]!).join("\n")); | |
| 57 | }); | |
| 58 | afterAll(() => Promise.race([server.close(), new Promise((r) => setTimeout(r, 500))])); | |
| 59 | ||
| 60 | describe("a phone on its side", () => { | |
| 61 | test("the view fills the screen: one 100% row, the shell 100dvh tall", () => { | |
| 62 | expect(sideways(css, "#shell").height).toContain("100dvh"); | |
| 63 | expect(sideways(css, "#shell")["grid-template-rows"]).toBe("100%"); | |
| 64 | expect(sideways(css, "#shell.typing")["grid-template-rows"]).toBe("100%"); | |
| 65 | }); | |
| 66 | ||
| 67 | test("STOP sits top-right, inside the notch and the top inset, one width in both its states", () => { | |
| 68 | const stop = sideways(css, "#stop"); | |
| 69 | expect(stop.position).toBe("fixed"); | |
| 70 | expect(stop.top).toContain("var(--safe-t)"); | |
| 71 | expect(stop.right).toContain("var(--safe-r)"); | |
| 72 | expect(stop.left).toBeUndefined(); | |
| 73 | expect(stop.width).toBe("var(--stop-w)"); | |
| 74 | expect(sideways(css, ":root")["--safe-t"]).toBe("env(safe-area-inset-top, 0px)"); | |
| 75 | expect(Number.parseFloat(sideways(css, ":root")["--stop-w"]!)).toBeGreaterThanOrEqual(56); | |
| 76 | }); | |
| 77 | ||
| 78 | test("nothing around STOP pins a fixed element to itself (a backdrop-filter, transform or filter on the strip would)", () => { | |
| 79 | const strip = sideways(css, "#strip"); | |
| 80 | for (const p of ["backdrop-filter", "-webkit-backdrop-filter", "transform", "filter", "contain", "will-change"]) expect(strip[p] ?? "none").toBe("none"); | |
| 81 | for (const p of ["transform", "filter", "backdrop-filter"]) expect(sideways(css, "#shell")[p] ?? "none").toBe("none"); | |
| 82 | // the blur moved to a layer behind the strip's content | |
| 83 | expect(sideways(css, "#strip::before")["backdrop-filter"]).toContain("blur"); | |
| 84 | }); | |
| 85 | ||
| 86 | test("the joint sticks overlay the lower corners, inside the insets, while driving with the sheet away", () => { | |
| 87 | expect(sideways(css, "#shell.driving.bare #sticks").display).toBe("block"); | |
| 88 | const stick = sideways(css, ".stick"); | |
| 89 | expect(stick.position).toBe("absolute"); | |
| 90 | expect(stick.bottom).toContain("var(--safe-b)"); | |
| 91 | expect(sideways(css, "#stickL").left).toContain("var(--safe-l)"); | |
| 92 | expect(sideways(css, "#stickR").right).toContain("var(--safe-r)"); | |
| 93 | }); | |
| 94 | ||
| 95 | test("the strip and the view buttons leave STOP's corner free", () => { | |
| 96 | expect(sideways(css, "#shell.bare #strip")["max-width"]).toContain("var(--stop-w)"); | |
| 97 | const top = sideways(css, "#shell.driving.bare #top"); | |
| 98 | expect(top.right).toContain("var(--stop-w)"); | |
| 99 | expect(top["max-width"]).toContain("var(--stop-w)"); | |
| 100 | expect(sideways(css, "#sheet")["padding-top"]).toContain("var(--safe-t)"); | |
| 101 | }); | |
| 102 | ||
| 103 | test("a turn that starts on its side puts the sheet away, so the sticks come up", () => { | |
| 104 | const js = [...html.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/gi)].map((m) => m[1]!).join("\n"); | |
| 105 | expect(js).toMatch(/if \(can && !shell\.classList\.contains\("driving"\) && sideways\.matches\) setBare\(true\);\s*shell\.classList\.toggle\("driving", can\);/); | |
| 106 | }); | |
| 107 | }); | |
| 108 | ||
| 109 | describe("portrait and desktop are unchanged", () => { | |
| 110 | test("only the sideways layout moves STOP out of the strip", () => { | |
| 111 | const moved = css.filter((r) => /#stop\b|\.estop\b|\[data-stop\]/.test(r.selector) && ["position", "top", "right", "left", "bottom", "inset"].some((p) => p in r.decls)); | |
| 112 | expect(moved.length).toBeGreaterThan(0); | |
| 113 | for (const r of moved) expect(r.media).toBe(SIDEWAYS); | |
| 114 | }); | |
| 115 | ||
| 116 | test("STOP is in the status strip's markup, where portrait and desktop lay it out", () => { | |
| 117 | expect(html).toMatch(/<section id="strip"[^>]*>(?:(?!<\/section>)[\s\S])*<button id="stop" class="estop" data-stop\b/); | |
| 118 | }); | |
| 119 | }); |
Software/so101/src/viewer.html +12 −5
| @@ -30,7 +30,7 @@ | ||
| 30 | 30 | : #30363d; : #21262d; : #30363d; : #58a6ff; : #388bfd; : #fff; |
| 31 | 31 | : #3fb950; : #d29922; : #f85149; : rgba(248,81,73,.18); : rgba(56,139,253,.18); |
| 32 | 32 | : 44px; : 68px; : min(42svh, 75vw); |
| 33 | : env(safe-area-inset-left, 0px); : env(safe-area-inset-right, 0px); : env(safe-area-inset-bottom, 0px); | |
| 33 | : env(safe-area-inset-left, 0px); : env(safe-area-inset-right, 0px); : env(safe-area-inset-bottom, 0px); : env(safe-area-inset-top, 0px); | |
| 34 | 34 | } |
| 35 | 35 | @media (prefers-color-scheme: light) { |
| 36 | 36 | :root { color-scheme: light; : #f6f8fa; : #fff; : #fff; : #1f2328; : #31363c; : #59636e; |
| @@ -257,10 +257,12 @@ | ||
| 257 | 257 | } |
| 258 | 258 | /* A phone on its side: the view fills the screen, the controls float over it. */ |
| 259 | 259 | @media (orientation: landscape) and (max-height: 500px) { |
| 260 | :root { : 112px; } | |
| 260 | 261 | #shell, #shell.typing { grid-template-columns: 100%; grid-template-rows: 100%; grid-template-areas: "view"; } |
| 261 | 262 | #app, #strip, #sheet { grid-area: auto; } |
| 262 | #strip { position: absolute; z-index: 7; top: 6px; left: calc(6px + var()); max-width: calc(100% - min(380px, 48vw) - 18px - var() - var()); min-height: 0; padding: 6px 6px 6px 12px; border: 1px solid rgba(255,255,255,.12); border-radius: 14px; background: rgba(13,17,23,.82); color: #e8eaed; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); } | |
| 263 | #shell.bare #strip { max-width: calc(100% - 12px - var() - var()); } | |
| 263 | #strip { position: absolute; z-index: 7; top: calc(6px + var()); left: calc(6px + var()); max-width: calc(100% - min(380px, 48vw) - 18px - var() - var()); min-height: 0; padding: 6px 6px 6px 12px; border: 1px solid rgba(255,255,255,.12); border-radius: 14px; background: none; color: #e8eaed; } | |
| 264 | #strip::before { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; background: rgba(13,17,23,.82); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); } | |
| 265 | #shell.bare #strip { max-width: calc(100% - var() - 18px - var() - var()); } | |
| 264 | 266 | #strip #clock { color: #9aa4ae; } |
| 265 | 267 | #sheetToggle { display: inline-flex ; align-items: center; background: rgba(255,255,255,.08); color: #e8eaed; border-color: rgba(255,255,255,.18); } |
| 266 | 268 | #sheet { position: absolute; z-index: 7; top: 0; bottom: 0; right: 0; width: calc(min(380px, 48vw) + var()); background: rgba(13,17,23,.9); background: color-mix(in srgb, var() 90%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-left: 1px solid var(); transition: transform .2s ease-out; } |
| @@ -273,10 +275,13 @@ | ||
| 273 | 275 | #pad { width: min(30vh, 150px); } |
| 274 | 276 | } |
| 275 | 277 | @media (max-width: 640px) and (orientation: portrait) { #touch { display: grid; } #reach, #joints { display: none ; } } |
| 276 | /* One STOP in every layout; it holds until Resume. */ | |
| 278 | /* One STOP in every layout; it holds until Resume. Sideways it is fixed top-right (the strip's blur sits on ::before | |
| 279 | so it does not pin STOP to the strip). */ | |
| 277 | 280 | @media (orientation: landscape) and (max-height: 500px) { |
| 281 | #stop { position: fixed; z-index: 9; top: calc(var(, 0px) + 6px + var()); right: calc(6px + var()); width: var(); } | |
| 282 | #sheet { padding-top: calc(68px + var()); } | |
| 278 | 283 | #shell.driving.bare #sticks { display: block; } |
| 279 | #shell.driving.bare #top { top: 6px; bottom: auto; left: auto; right: calc(6px + var()); max-width: 42%; justify-content: flex-end; } | |
| 284 | #shell.driving.bare #top { top: calc(6px + var()); bottom: auto; left: auto; right: calc(var() + 14px + var()); max-width: calc(42% - var() - 8px); justify-content: flex-end; } | |
| 280 | 285 | #shell.driving.bare #strip { max-width: calc(58% - 18px - var()); } |
| 281 | 286 | #shell.driving.bare #msg { bottom: auto; top: 110px; } |
| 282 | 287 | } |
| @@ -1537,6 +1542,8 @@ | ||
| 1537 | 1542 | $("t-admin").hidden = !owner; |
| 1538 | 1543 | $("t-chat").hidden = $("t-queue").hidden = !relayed; |
| 1539 | 1544 | for (const id of ["joints", "poses", "drive", "reach", "touch", "sticks"]) $(id).inert = !can; |
| 1545 | // A turn that starts sideways shows the sticks at once. | |
| 1546 | if (can && !shell.classList.contains("driving") && sideways.matches) setBare(true); | |
| 1540 | 1547 | shell.classList.toggle("driving", can); |
| 1541 | 1548 | if (!can) driver.releaseAll(); |
| 1542 | 1549 | wake(can); |
new above
offline