From 3f64b32df85b52ffccbbfa98741aa6d7365983d1 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 22 Oct 2026 02:17:11 +0000 Subject: [PATCH] Snap widgets to whole rows and let apps fill the cells beside them Home rows now share one height (an app tile's) and widgets span whole rows of it, so they line up with the apps. The grid packs densely, so apps fill free cells next to a widget instead of leaving holes. Resizing snaps to whole rows. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01NYASJ6JNxhYwNNJK7ypK2V --- tests/e2e.cjs | 10 +++++++++- web/app.py | 23 +++++++++++++++-------- web/app.wasm | Bin 13955 -> 14070 bytes web/index.html | 11 +++++------ web/style.css | 18 +++++++++++------- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/tests/e2e.cjs b/tests/e2e.cjs index 646d2cc..874dea2 100644 --- a/tests/e2e.cjs +++ b/tests/e2e.cjs @@ -115,7 +115,7 @@ const BASE = process.env.BASE || "http://localhost:8000"; await p.mouse.up(); await settle(); const [w1, h1] = await size(); assert.ok(w1 < w0 && Math.abs(w1 - (2 * tile.width + 8)) < 3, `two columns wide: ${w1} (tile ${tile.width})`); - assert.equal(h1, 250, "snapped to half rows"); + assert.equal(h1, Math.round(2 * tile.height + 20), "snapped to two whole rows of tiles"); assert.ok(await p.$(".widget-slot.resizing"), "letting go of a handle keeps the handles"); await p.click(".resize-bar >> text=Done"); await settle(); assert.ok(!(await p.$(".resize-handle"))); @@ -132,6 +132,14 @@ const BASE = process.env.BASE || "http://localhost:8000"; await p.mouse.move(first.x + first.width / 2, first.y + first.height / 2, { steps: 8 }); await settle(); await p.mouse.up(); await settle(); assert.equal((await order())[0], "W", "dragged to the front"); + // the apps flow into the cells beside it: a 2x2 widget leaves room for all four + const beside = await p.$eval(".widget-slot", (w) => { + const r = w.getBoundingClientRect(); + return [...document.querySelectorAll(".slots .tile")].filter((t) => { + const b = t.getBoundingClientRect(); return b.top >= r.top - 1 && b.bottom <= r.bottom + 1; + }).length; + }); + assert.equal(beside, 4, "apps fill the cells beside the widget"); assert.ok(await p.$(".widget-slot.resizing"), "it keeps its handles after the move"); assert.ok(!(await p.$(".sheet"))); await p.click(".resize-bar >> text=Remove"); await settle(); diff --git a/web/app.py b/web/app.py index 7c2b0e6..4acaa44 100644 --- a/web/app.py +++ b/web/app.py @@ -12,8 +12,9 @@ from ui import btn_open, input_open, alert # A long press on a home app or widget picks it up: drag it to move it, or let go # without moving to get its menu (index.html does the dragging). Letting go of a # widget that way shows resize handles on its right and bottom edges instead: -# dragging them snaps the widget to the grid, within the sizes it allows, and -# dragging the widget itself moves it, staying in that mode once let go. +# dragging them snaps the widget to whole grid columns and rows of app tiles, +# within the sizes it allows, and dragging the widget itself moves it, staying +# in that mode once let go. Apps flow into the free cells beside widgets. # # The native shell (android/) serves this folder in a WebView, answers # apps.json and widgets.json, hosts the widgets as native views over the @@ -621,6 +622,14 @@ def view_resize_bar() -> None: end() +def widget_rows(h: i32) -> i32: + """Rows of app tiles nearest to a widget height in CSS px, at least one.""" + k: i32 = (h + 20 + 54) // 108 + if k < 1: + k = 1 + return k + + def view_home_slot(i: i32) -> None: row: i32 if hkind[i] == WIDGET: @@ -630,14 +639,12 @@ def view_home_slot(i: i32) -> None: cls_if("lifted", i == lifted) cls_if("resizing", i == resizing) attr_num("data-slot", i) + # Its height spans whole rows of app tiles (88px rows, 20px gaps; style.css). + s_set(scratch, "grid-row:span ") + s_add_num(scratch, widget_rows(hh[i])) if hw[i] > 0: - s_set(scratch, "grid-column:span ") + s_add(scratch, ";grid-column:span ") s_add_num(scratch, hw[i]) - s_add(scratch, ";height:") - else: - s_set(scratch, "height:") - s_add_num(scratch, hh[i]) - s_add(scratch, "px") attr_ref("style", scratch) # The native widget view is laid over slots marked live, so only mark # them while nothing covers the home screen. While one is resized the diff --git a/web/app.wasm b/web/app.wasm index 157c2fb8094ef2204a078bb03acdb5085d67355a..55422233ac0ce65f8ae0b54958c9be720593c5d3 100644 GIT binary patch delta 2406 zcmZ8iPfQeN6#r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-gvAkpQJVZVEVv^~nGD-atp%Ar#V&Gj+c9i6q8>l=`ntCP` zd1C&VqJOHtt(_FhZcF7GO4|Lh^0S+>jT1Ka7F@e74>Kqib2AG%w^w}~rW`U~=Izo zXMAut#ruC8a9bz%(50fU+1>K2%M>9Yms586g3WOQb}5);Q& zfA3BWh6r{WR>G?RCXs)v9t7rK>#tiE_y#=)R-bvT>RFu`_Dg^V!mTup&3U?F;z6tLem6Orp?ZKr|vVYCOhI+G1B zL(qxEETZv_1n+?5GKo9?@efCOsOs1nTwR9Zh*T`Q|J2tfu`*ETYmDuZheHJ0%xLT? zD$T?Q!GmDEDvlA1+mWbY_kqQN;p$Pa-gi#|YKgFkR)f238GZ7*v2(ckK2%;i-ytYf z#3pGIarGQ%FM%b3!H8kSLX-eD6d>3Fncf@S_Z8R1%EK*>vp!iUDt+@s03)d5a z1;*6@FkVFlHsI@}=R_Rz8D?oC3CUSkw$8x@^;=PQl*e>Le82h))s}!C=6M z#}k+(f^%TK^ybK)Sa0Ge3G7I&E<)jT>LMxH4a%x4x-!zoBTag6K w$-pM${_8t^GX%J^LVFDK28NXs0VuqdP7zE*k%vrTf?yq3@5QFv`weCP0!3b@^8f$< diff --git a/web/index.html b/web/index.html index 184191a..f8a3dd9 100644 --- a/web/index.html +++ b/web/index.html @@ -186,9 +186,8 @@ // Resizing a widget. Holding a widget and letting go without moving shows handles on // its right edge, bottom edge and corner (app.py). Dragging one snaps the widget to - // whole grid columns and half rows, within the shell's limits for that widget + // whole grid columns and rows, within the shell's limits for that widget // (widgetLimits, CSS px: min/max size, 0 = no max, and whether it resizes h and v). - const CELL = 88; // a row of app tiles let rs = null, swallowClick = false; const span = (k, size, gap) => k * size + (k - 1) * gap; const fit = (want, lo, hi, size, gap, min, max) => { @@ -210,6 +209,7 @@ const r = li.getBoundingClientRect(); rs = { li, edge: h.dataset.edge, left: r.left, top: r.top, lim, n: cols.length, colW: cols[0], gap: parseFloat(cs.columnGap) || 0, rgap: parseFloat(cs.rowGap) || 0, + cell: parseFloat(cs.gridAutoRows) || 88, // a row of app tiles cols: Math.round((r.width + (parseFloat(cs.columnGap) || 0)) / (cols[0] + (parseFloat(cs.columnGap) || 0))), h: Math.round(r.height) }; dragged = true; @@ -217,14 +217,13 @@ }, true); addEventListener("pointermove", (e) => { if (!rs) return; - const { lim, n, colW, gap, rgap } = rs, half = (CELL + rgap) / 2; + const { lim, n, colW, gap, rgap, cell } = rs; let cols = rs.cols, h = rs.h; if (rs.edge !== "b" && lim.h !== false) cols = fit(e.clientX - rs.left, 1, n, colW, gap, lim.minW || 0, lim.maxW || 0); if (rs.edge !== "r" && lim.v !== false) { - // half-row steps: 2 halves are one row of tiles, 4 are two rows with the gap between - const k = fit(e.clientY - rs.top + rgap, 2, 40, half, 0, (lim.minH || 0) + rgap, lim.maxH ? lim.maxH + rgap : 0); - h = Math.round(k * half - rgap); + const k = fit(e.clientY - rs.top, 1, 20, cell, rgap, lim.minH || 0, lim.maxH || 0); + h = Math.round(span(k, cell, rgap)); } if (cols === rs.cols && h === rs.h) return; rs.cols = cols; rs.h = h; diff --git a/web/style.css b/web/style.css index a6854b9..b948fde 100644 --- a/web/style.css +++ b/web/style.css @@ -36,6 +36,10 @@ body { margin: 0; min-height: 100vh; color: #fff; -webkit-tap-highlight-color: t .windows-glyph::after { inset: .3rem 0 0 .3rem; background: rgb(255 255 255 / .15); } .slots, .apps { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.25rem .5rem; grid-template-columns: repeat(4, minmax(0, 1fr)); } +/* Home rows are all one height, so a widget spans whole rows of app tiles, and apps + fill the cells beside a widget rather than leaving holes (dense packing). Keep + --cell and the gap in sync with widget_rows in app.py. */ +.slots { grid-auto-rows: 5.5rem; grid-auto-flow: row dense; } @media (min-width: 480px) { .slots, .apps { grid-template-columns: repeat(5, minmax(0, 1fr)); } } .tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: .4rem; padding: .35rem .15rem; border-radius: calc(var(--radius) + 4px); cursor: pointer; } @@ -46,7 +50,7 @@ body { margin: 0; min-height: 100vh; color: #fff; -webkit-tap-highlight-color: t .name { max-width: 100%; font-size: .75rem; line-height: 1.2; text-align: center; text-shadow: var(--shadow-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } -/* A widget takes a whole row. On a phone the native widget view covers the slot; +/* A widget takes whole rows. On a phone the native widget view covers the slot; the label only shows while the slot is not live (or in a desktop browser). */ .widget-slot { grid-column: 1 / -1; display: grid; place-items: center; box-sizing: border-box; border-radius: 1.25rem; background: rgb(255 255 255 / .1); @@ -57,19 +61,19 @@ body { margin: 0; min-height: 100vh; color: #fff; -webkit-tap-highlight-color: t .widget-slot[data-wid]:not(.lifted):not(.resizing) { background: none; border-color: transparent; } /* A widget being resized: handles sit just outside its right and bottom edges, where the - native widget view doesn't cover them; the extra margin keeps the next row clear. */ + native widget view doesn't cover them; the bottom one sits in the gap below the row. */ .widget-slot { position: relative; } -.widget-slot.resizing { margin-bottom: 1.75rem; outline: 2px solid rgb(255 255 255 / .85); +.widget-slot.resizing { z-index: 2; outline: 2px solid rgb(255 255 255 / .85); outline-offset: 3px; transition: none; } .resize-handle { position: absolute; z-index: 2; touch-action: none; cursor: nwse-resize; } .resize-handle::after { content: ""; position: absolute; border-radius: 999px; background: #fff; box-shadow: 0 1px 6px rgb(0 0 0 / .45); } .resize-handle[data-edge="r"] { top: 0; bottom: 0; right: -16px; width: 16px; cursor: ew-resize; } .resize-handle[data-edge="r"]::after { top: 50%; left: 6px; width: 6px; height: 2.5rem; transform: translateY(-50%); } -.resize-handle[data-edge="b"] { left: 0; right: 0; bottom: -1.75rem; height: 1.75rem; cursor: ns-resize; } -.resize-handle[data-edge="b"]::after { left: 50%; top: 8px; width: 2.5rem; height: 6px; transform: translateX(-50%); } -.resize-handle[data-edge="rb"] { right: -16px; bottom: -1.75rem; width: 2.75rem; height: 1.75rem; } -.resize-handle[data-edge="rb"]::after { right: 4px; top: 6px; width: 14px; height: 14px; border-radius: 4px; } +.resize-handle[data-edge="b"] { left: 0; right: 0; bottom: -1.25rem; height: 1.25rem; cursor: ns-resize; } +.resize-handle[data-edge="b"]::after { left: 50%; top: 7px; width: 2.5rem; height: 6px; transform: translateX(-50%); } +.resize-handle[data-edge="rb"] { right: -16px; bottom: -1.25rem; width: 2.75rem; height: 1.25rem; } +.resize-handle[data-edge="rb"]::after { right: 4px; top: 3px; width: 14px; height: 14px; border-radius: 4px; } .resize-bar { position: fixed; left: 50%; bottom: calc(var(--bottom) + 1rem); z-index: 15; transform: translateX(-50%); display: flex; align-items: center; gap: .5rem; padding: .4rem .4rem .4rem 1rem; border-radius: 999px; background: rgb(0 0 0 / .8); color: #fff; font-size: .875rem; white-space: nowrap;