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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NYASJ6JNxhYwNNJK7ypK2V
This commit is contained in:
Claude committed 2026-10-22 02:17:11 +00:00
1 parent 8426bd3b0a
commit 3f64b32df8
5 files changed
+40 -22

No files matched your search

+9 -1
View File
@@ -115,7 +115,7 @@ const BASE = process.env.BASE || "http://localhost:8000";
await p.mouse.up(); await settle(); await p.mouse.up(); await settle();
const [w1, h1] = await size(); 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.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"); assert.ok(await p.$(".widget-slot.resizing"), "letting go of a handle keeps the handles");
await p.click(".resize-bar >> text=Done"); await settle(); await p.click(".resize-bar >> text=Done"); await settle();
assert.ok(!(await p.$(".resize-handle"))); 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.move(first.x + first.width / 2, first.y + first.height / 2, { steps: 8 }); await settle();
await p.mouse.up(); await settle(); await p.mouse.up(); await settle();
assert.equal((await order())[0], "W", "dragged to the front"); 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.$(".widget-slot.resizing"), "it keeps its handles after the move");
assert.ok(!(await p.$(".sheet"))); assert.ok(!(await p.$(".sheet")));
await p.click(".resize-bar >> text=Remove"); await settle(); await p.click(".resize-bar >> text=Remove"); await settle();
+15 -8
View File
@@ -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 # 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 # 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: # 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 them snaps the widget to whole grid columns and rows of app tiles,
# dragging the widget itself moves it, staying in that mode once let go. # 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 # The native shell (android/) serves this folder in a WebView, answers
# apps.json and widgets.json, hosts the widgets as native views over the # apps.json and widgets.json, hosts the widgets as native views over the
@@ -621,6 +622,14 @@ def view_resize_bar() -> None:
end() 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: def view_home_slot(i: i32) -> None:
row: i32 row: i32
if hkind[i] == WIDGET: if hkind[i] == WIDGET:
@@ -630,14 +639,12 @@ def view_home_slot(i: i32) -> None:
cls_if("lifted", i == lifted) cls_if("lifted", i == lifted)
cls_if("resizing", i == resizing) cls_if("resizing", i == resizing)
attr_num("data-slot", i) 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: if hw[i] > 0:
s_set(scratch, "grid-column:span ") s_add(scratch, ";grid-column:span ")
s_add_num(scratch, hw[i]) 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) attr_ref("style", scratch)
# The native widget view is laid over slots marked live, so only mark # 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 # them while nothing covers the home screen. While one is resized the
BIN
View File
Binary file not shown.
+5 -6
View File
@@ -186,9 +186,8 @@
// Resizing a widget. Holding a widget and letting go without moving shows handles on // 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 // 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). // (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; let rs = null, swallowClick = false;
const span = (k, size, gap) => k * size + (k - 1) * gap; const span = (k, size, gap) => k * size + (k - 1) * gap;
const fit = (want, lo, hi, size, gap, min, max) => { const fit = (want, lo, hi, size, gap, min, max) => {
@@ -210,6 +209,7 @@
const r = li.getBoundingClientRect(); const r = li.getBoundingClientRect();
rs = { li, edge: h.dataset.edge, left: r.left, top: r.top, lim, n: cols.length, colW: cols[0], 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, 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))), cols: Math.round((r.width + (parseFloat(cs.columnGap) || 0)) / (cols[0] + (parseFloat(cs.columnGap) || 0))),
h: Math.round(r.height) }; h: Math.round(r.height) };
dragged = true; dragged = true;
@@ -217,14 +217,13 @@
}, true); }, true);
addEventListener("pointermove", (e) => { addEventListener("pointermove", (e) => {
if (!rs) return; 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; let cols = rs.cols, h = rs.h;
if (rs.edge !== "b" && lim.h !== false) if (rs.edge !== "b" && lim.h !== false)
cols = fit(e.clientX - rs.left, 1, n, colW, gap, lim.minW || 0, lim.maxW || 0); cols = fit(e.clientX - rs.left, 1, n, colW, gap, lim.minW || 0, lim.maxW || 0);
if (rs.edge !== "r" && lim.v !== false) { 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, 1, 20, cell, rgap, lim.minH || 0, lim.maxH || 0);
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(span(k, cell, rgap));
h = Math.round(k * half - rgap);
} }
if (cols === rs.cols && h === rs.h) return; if (cols === rs.cols && h === rs.h) return;
rs.cols = cols; rs.h = h; rs.cols = cols; rs.h = h;
+11 -7
View File
@@ -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); } .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; .slots, .apps { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.25rem .5rem;
grid-template-columns: repeat(4, minmax(0, 1fr)); } 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)); } } @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; .tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: .4rem;
padding: .35rem .15rem; border-radius: calc(var(--radius) + 4px); cursor: pointer; } 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; .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; } 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). */ 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; .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); 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; } .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 /* 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 { 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; } outline-offset: 3px; transition: none; }
.resize-handle { position: absolute; z-index: 2; touch-action: none; cursor: nwse-resize; } .resize-handle { position: absolute; z-index: 2; touch-action: none; cursor: nwse-resize; }
.resize-handle::after { content: ""; position: absolute; border-radius: 999px; background: #fff; .resize-handle::after { content: ""; position: absolute; border-radius: 999px; background: #fff;
box-shadow: 0 1px 6px rgb(0 0 0 / .45); } 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"] { 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="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"] { left: 0; right: 0; bottom: -1.25rem; height: 1.25rem; 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="b"]::after { left: 50%; top: 7px; 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"] { right: -16px; bottom: -1.25rem; width: 2.75rem; height: 1.25rem; }
.resize-handle[data-edge="rb"]::after { right: 4px; top: 6px; width: 14px; height: 14px; border-radius: 4px; } .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%); .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; 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; background: rgb(0 0 0 / .8); color: #fff; font-size: .875rem; white-space: nowrap;